diff options
Diffstat (limited to 'bitbake/lib')
40 files changed, 544 insertions, 575 deletions
diff --git a/bitbake/lib/bb/COW.py b/bitbake/lib/bb/COW.py index ca206cf4b..224213db5 100644 --- a/bitbake/lib/bb/COW.py +++ b/bitbake/lib/bb/COW.py @@ -3,7 +3,7 @@ # # This is a copy on write dictionary and set which abuses classes to try and be nice and fast. # -# Copyright (C) 2006 Tim Amsell +# Copyright (C) 2006 Tim Amsell # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -18,7 +18,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -#Please Note: +#Please Note: # Be careful when using mutable types (ie Dict and Lists) - operations involving these are SLOW. # Assign a file to __warn__ to get warnings about slow operations. # @@ -40,7 +40,7 @@ MUTABLE = "__mutable__" class COWMeta(type): pass - + class COWDictMeta(COWMeta): __warn__ = False __hasmutable__ = False @@ -64,7 +64,7 @@ class COWDictMeta(COWMeta): cls.__hasmutable__ = True key += MUTABLE setattr(cls, key, value) - + def __getmutable__(cls, key, readonly=False): nkey = key + MUTABLE try: @@ -98,8 +98,8 @@ class COWDictMeta(COWMeta): value = getattr(cls, key) except AttributeError: value = cls.__getmutable__(key, readonly) - - # This is for values which have been deleted + + # This is for values which have been deleted if value is cls.__marker__: raise AttributeError("key %s does not exist." % key) @@ -127,7 +127,7 @@ class COWDictMeta(COWMeta): def iter(cls, type, readonly=False): for key in dir(cls): if key.startswith("__"): - continue + continue if key.endswith(MUTABLE): key = key[:-len(MUTABLE)] @@ -176,13 +176,13 @@ class COWSetMeta(COWDictMeta): def remove(cls, value): COWDictMeta.__delitem__(cls, repr(hash(value))) - + def __in__(cls, value): return COWDictMeta.has_key(repr(hash(value))) def iterkeys(cls): raise TypeError("sets don't have keys") - + def iteritems(cls): raise TypeError("sets don't have 'items'") @@ -286,7 +286,7 @@ if __name__ == "__main__": print "Boo!" else: print "Yay - has_key with delete works!" - + print "a", a for x in a.iteritems(): print x diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py index 16d69281f..7ca1663b7 100644 --- a/bitbake/lib/bb/build.py +++ b/bitbake/lib/bb/build.py @@ -28,7 +28,7 @@ from bb import data, event, mkdirhier, utils import bb, os, sys -# When we execute a python function we'd like certain things +# When we execute a python function we'd like certain things # in all namespaces, hence we add them to __builtins__ # If we do not do this and use the exec globals, they will # not be available to subfunctions. @@ -212,7 +212,7 @@ def exec_func_python(func, d, runfile, logfile): try: utils.better_exec(comp, {"d": d}, tmp, bbfile) except: - (t,value,tb) = sys.exc_info() + (t, value, tb) = sys.exc_info() if t in [bb.parse.SkipPackage, bb.build.FuncFailed]: raise @@ -303,8 +303,8 @@ def exec_task(task, d): def extract_stamp(d, fn): """ - Extracts stamp format which is either a data dictonary (fn unset) - or a dataCache entry (fn set). + Extracts stamp format which is either a data dictonary (fn unset) + or a dataCache entry (fn set). """ if fn: return d.stamp[fn] @@ -361,7 +361,7 @@ def add_tasks(tasklist, d): if not task in task_deps['tasks']: task_deps['tasks'].append(task) - flags = data.getVarFlags(task, d) + flags = data.getVarFlags(task, d) def getTask(name): if not name in task_deps: task_deps[name] = {} @@ -387,4 +387,3 @@ def remove_task(task, kill, d): If kill is 1, also remove tasks that depend on this task.""" data.delVarFlag(task, 'task', d) - diff --git a/bitbake/lib/bb/cache.py b/bitbake/lib/bb/cache.py index 106621911..300acc5fc 100644 --- a/bitbake/lib/bb/cache.py +++ b/bitbake/lib/bb/cache.py @@ -73,7 +73,7 @@ class Cache: # cache there isn't even any point in loading it... newest_mtime = 0 deps = bb.data.getVar("__depends", data, True) - for f,old_mtime in deps: + for f, old_mtime in deps: if old_mtime > newest_mtime: newest_mtime = old_mtime @@ -102,10 +102,10 @@ class Cache: """ Gets the value of a variable (similar to getVar in the data class) - + There are two scenarios: 1. We have cached data - serve from depends_cache[fn] - 2. We're learning what data to cache - serve from data + 2. We're learning what data to cache - serve from data backend but add a copy of the data to the cache. """ if fn in self.clean: @@ -134,7 +134,7 @@ class Cache: self.data = data # Make sure __depends makes the depends_cache - # If we're a virtual class we need to make sure all our depends are appended + # If we're a virtual class we need to make sure all our depends are appended # to the depends of fn. depends = self.getVar("__depends", virtualfn, True) or [] self.depends_cache.setdefault(fn, {}) @@ -259,7 +259,7 @@ class Cache: self.remove(fn) return False - mtime = bb.parse.cached_mtime_noerror(fn) + mtime = bb.parse.cached_mtime_noerror(fn) # Check file still exists if mtime == 0: @@ -276,7 +276,7 @@ class Cache: # Check dependencies are still valid depends = self.getVar("__depends", fn, True) if depends: - for f,old_mtime in depends: + for f, old_mtime in depends: fmtime = bb.parse.cached_mtime_noerror(f) # Check if file still exists if old_mtime != 0 and fmtime == 0: @@ -346,7 +346,7 @@ class Cache: def handle_data(self, file_name, cacheData): """ - Save data we need into the cache + Save data we need into the cache """ pn = self.getVar('PN', file_name, True) @@ -372,7 +372,7 @@ class Cache: # build FileName to PackageName lookup table cacheData.pkg_fn[file_name] = pn - cacheData.pkg_pepvpr[file_name] = (pe,pv,pr) + cacheData.pkg_pepvpr[file_name] = (pe, pv, pr) cacheData.pkg_dp[file_name] = dp provides = [pn] @@ -401,13 +401,13 @@ class Cache: if not dep in cacheData.all_depends: cacheData.all_depends.append(dep) - # Build reverse hash for PACKAGES, so runtime dependencies + # Build reverse hash for PACKAGES, so runtime dependencies # can be be resolved (RDEPENDS, RRECOMMENDS etc.) for package in packages: if not package in cacheData.packages: cacheData.packages[package] = [] cacheData.packages[package].append(file_name) - rprovides += (self.getVar("RPROVIDES_%s" % package, file_name, 1) or "").split() + rprovides += (self.getVar("RPROVIDES_%s" % package, file_name, 1) or "").split() for package in packages_dynamic: if not package in cacheData.packages_dynamic: @@ -472,12 +472,12 @@ class Cache: def init(cooker): """ - The Objective: Cache the minimum amount of data possible yet get to the + The Objective: Cache the minimum amount of data possible yet get to the stage of building packages (i.e. tryBuild) without reparsing any .bb files. - To do this, we intercept getVar calls and only cache the variables we see - being accessed. We rely on the cache getVar calls being made for all - variables bitbake might need to use to reach this stage. For each cached + To do this, we intercept getVar calls and only cache the variables we see + being accessed. We rely on the cache getVar calls being made for all + variables bitbake might need to use to reach this stage. For each cached file we need to track: * Its mtime diff --git a/bitbake/lib/bb/command.py b/bitbake/lib/bb/command.py index 06bd203c9..a590e61ab 100644 --- a/bitbake/lib/bb/command.py +++ b/bitbake/lib/bb/command.py @@ -20,7 +20,7 @@ Provide an interface to interact with the bitbake server through 'commands' # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """ -The bitbake server takes 'commands' from its UI/commandline. +The bitbake server takes 'commands' from its UI/commandline. Commands are either synchronous or asynchronous. Async commands return data to the client in the form of events. Sync commands must only return data through the function return value @@ -62,7 +62,7 @@ class Command: try: command = commandline.pop(0) if command in CommandsSync.__dict__: - # Can run synchronous commands straight away + # Can run synchronous commands straight away return getattr(CommandsSync, command)(self.cmds_sync, self, commandline) if self.currentAsyncCommand is not None: return "Busy (%s in progress)" % self.currentAsyncCommand[0] @@ -268,6 +268,3 @@ class CookerCommandSetExitCode(bb.event.Event): def __init__(self, exitcode): bb.event.Event.__init__(self) self.exitcode = int(exitcode) - - - diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py index a413c8a85..743e4be06 100644 --- a/bitbake/lib/bb/cooker.py +++ b/bitbake/lib/bb/cooker.py @@ -181,7 +181,7 @@ class BBCooker: def tryBuild(self, fn, task): """ - Build a provider and its dependencies. + Build a provider and its dependencies. build_depends is a list of previous build dependencies (not runtime) If build_depends is empty, we're dealing with a runtime depends """ @@ -206,7 +206,7 @@ class BBCooker: # Sort by priority for pn in pkg_pn: - (last_ver,last_file,pref_ver,pref_file) = bb.providers.findBestProvider(pn, self.configuration.data, self.status) + (last_ver, last_file, pref_ver, pref_file) = bb.providers.findBestProvider(pn, self.configuration.data, self.status) preferred_versions[pn] = (pref_ver, pref_file) latest_versions[pn] = (last_ver, last_file) @@ -315,7 +315,7 @@ class BBCooker: rq = bb.runqueue.RunQueue(self, self.configuration.data, self.status, taskdata, runlist) rq.prepare_runqueue() - seen_fnids = [] + seen_fnids = [] depend_tree = {} depend_tree["depends"] = {} depend_tree["tdepends"] = {} @@ -352,7 +352,7 @@ class BBCooker: depend_tree["rdepends-pn"][pn] = [] for rdep in taskdata.rdepids[fnid]: - depend_tree["rdepends-pn"][pn].append(taskdata.run_names_index[rdep]) + depend_tree["rdepends-pn"][pn].append(taskdata.run_names_index[rdep]) rdepends = self.status.rundeps[fn] for package in rdepends: @@ -542,7 +542,7 @@ class BBCooker: # Nomally we only register event handlers at the end of parsing .bb files # We register any handlers we've found so far here... for var in data.getVar('__BBHANDLERS', self.configuration.data) or []: - bb.event.register(var,bb.data.getVar(var, self.configuration.data)) + bb.event.register(var, bb.data.getVar(var, self.configuration.data)) bb.fetch.fetcher_init(self.configuration.data) @@ -583,7 +583,7 @@ class BBCooker: """ if not bb.data.getVar("BUILDNAME", self.configuration.data): bb.data.setVar("BUILDNAME", os.popen('date +%Y%m%d%H%M').readline().strip(), self.configuration.data) - bb.data.setVar("BUILDSTART", time.strftime('%m/%d/%Y %H:%M:%S',time.gmtime()), self.configuration.data) + bb.data.setVar("BUILDSTART", time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime()), self.configuration.data) def matchFiles(self, buildfile): """ @@ -775,10 +775,10 @@ class BBCooker: ignore = bb.data.getVar("ASSUME_PROVIDED", self.configuration.data, 1) or "" self.status.ignored_dependencies = set(ignore.split()) - + for dep in self.configuration.extra_assume_provided: self.status.ignored_dependencies.add(dep) - + self.handleCollections( bb.data.getVar("BBFILE_COLLECTIONS", self.configuration.data, 1) ) bb.msg.debug(1, bb.msg.domain.Collection, "collecting .bb files") @@ -816,7 +816,7 @@ class BBCooker: for f in contents: (root, ext) = os.path.splitext(f) if ext == ".bb": - bbfiles.append(os.path.abspath(os.path.join(os.getcwd(),f))) + bbfiles.append(os.path.abspath(os.path.join(os.getcwd(), f))) return bbfiles def find_bbfiles( self, path ): @@ -828,7 +828,7 @@ class BBCooker: for ignored in ('SCCS', 'CVS', '.svn'): if ignored in dirs: dirs.remove(ignored) - found += [join(dir,f) for f in files if f.endswith('.bb')] + found += [join(dir, f) for f in files if f.endswith('.bb')] return found @@ -912,9 +912,9 @@ class BBCooker: pout.close() else: self.server.serve_forever() - + bb.event.fire(CookerExit(), self.configuration.event_data) - + class CookerExit(bb.event.Event): """ Notify clients of the Cooker shutdown @@ -984,4 +984,3 @@ class CookerParser: raise ParsingErrorsFound return False return True - diff --git a/bitbake/lib/bb/daemonize.py b/bitbake/lib/bb/daemonize.py index 1a8bb379f..a944af223 100644 --- a/bitbake/lib/bb/daemonize.py +++ b/bitbake/lib/bb/daemonize.py @@ -3,17 +3,17 @@ Python Deamonizing helper Configurable daemon behaviors:
- 1.) The current working directory set to the "/" directory.
- 2.) The current file creation mode mask set to 0.
- 3.) Close all open files (1024).
- 4.) Redirect standard I/O streams to "/dev/null".
+ 1.) The current working directory set to the "/" directory.
+ 2.) The current file creation mode mask set to 0.
+ 3.) Close all open files (1024).
+ 4.) Redirect standard I/O streams to "/dev/null".
A failed call to fork() now raises an exception.
References:
- 1) Advanced Programming in the Unix Environment: W. Richard Stevens
- 2) Unix Programming Frequently Asked Questions:
- http://www.erlenstar.demon.co.uk/unix/faq_toc.html
+ 1) Advanced Programming in the Unix Environment: W. Richard Stevens
+ 2) Unix Programming Frequently Asked Questions:
+ http://www.erlenstar.demon.co.uk/unix/faq_toc.html
Modified to allow a function to be daemonized and return for
bitbake use by Richard Purdie
@@ -24,8 +24,8 @@ __copyright__ = "Copyright (C) 2005 Chad J. Schroeder" __version__ = "0.2"
# Standard Python modules.
-import os # Miscellaneous OS interfaces.
-import sys # System-specific parameters and functions.
+import os # Miscellaneous OS interfaces.
+import sys # System-specific parameters and functions.
# Default daemon parameters.
# File mode creation mask of the daemon.
@@ -37,155 +37,154 @@ MAXFD = 1024 # The standard I/O file descriptors are redirected to /dev/null by default.
if (hasattr(os, "devnull")):
- REDIRECT_TO = os.devnull
+ REDIRECT_TO = os.devnull
else:
- REDIRECT_TO = "/dev/null"
+ REDIRECT_TO = "/dev/null"
def createDaemon(function, logfile):
- """
- Detach a process from the controlling terminal and run it in the
- background as a daemon, returning control to the caller.
- """
-
- try:
- # Fork a child process so the parent can exit. This returns control to
- # the command-line or shell. It also guarantees that the child will not
- # be a process group leader, since the child receives a new process ID
- # and inherits the parent's process group ID. This step is required
- # to insure that the next call to os.setsid is successful.
- pid = os.fork()
- except OSError, e:
- raise Exception, "%s [%d]" % (e.strerror, e.errno)
-
- if (pid == 0): # The first child.
- # To become the session leader of this new session and the process group
- # leader of the new process group, we call os.setsid(). The process is
- # also guaranteed not to have a controlling terminal.
- os.setsid()
-
- # Is ignoring SIGHUP necessary?
- #
- # It's often suggested that the SIGHUP signal should be ignored before
- # the second fork to avoid premature termination of the process. The
- # reason is that when the first child terminates, all processes, e.g.
- # the second child, in the orphaned group will be sent a SIGHUP.
- #
- # "However, as part of the session management system, there are exactly
- # two cases where SIGHUP is sent on the death of a process:
- #
- # 1) When the process that dies is the session leader of a session that
- # is attached to a terminal device, SIGHUP is sent to all processes
- # in the foreground process group of that terminal device.
- # 2) When the death of a process causes a process group to become
- # orphaned, and one or more processes in the orphaned group are
- # stopped, then SIGHUP and SIGCONT are sent to all members of the
- # orphaned group." [2]
- #
- # The first case can be ignored since the child is guaranteed not to have
- # a controlling terminal. The second case isn't so easy to dismiss.
- # The process group is orphaned when the first child terminates and
- # POSIX.1 requires that every STOPPED process in an orphaned process
- # group be sent a SIGHUP signal followed by a SIGCONT signal. Since the
- # second child is not STOPPED though, we can safely forego ignoring the
- # SIGHUP signal. In any case, there are no ill-effects if it is ignored.
- #
- # import signal # Set handlers for asynchronous events.
- # signal.signal(signal.SIGHUP, signal.SIG_IGN)
-
- try:
- # Fork a second child and exit immediately to prevent zombies. This
- # causes the second child process to be orphaned, making the init
- # process responsible for its cleanup. And, since the first child is
- # a session leader without a controlling terminal, it's possible for
- # it to acquire one by opening a terminal in the future (System V-
- # based systems). This second fork guarantees that the child is no
- # longer a session leader, preventing the daemon from ever acquiring
- # a controlling terminal.
- pid = os.fork() # Fork a second child.
- except OSError, e:
- raise Exception, "%s [%d]" % (e.strerror, e.errno)
-
- if (pid == 0): # The second child.
- # We probably don't want the file mode creation mask inherited from
- # the parent, so we give the child complete control over permissions.
- if UMASK is not None:
- os.umask(UMASK)
- else:
- # Parent (the first child) of the second child.
- os._exit(0)
- else:
- # exit() or _exit()?
- # _exit is like exit(), but it doesn't call any functions registered
- # with atexit (and on_exit) or any registered signal handlers. It also
- # closes any open file descriptors. Using exit() may cause all stdio
- # streams to be flushed twice and any temporary files may be unexpectedly
- # removed. It's therefore recommended that child branches of a fork()
- # and the parent branch(es) of a daemon use _exit().
- return
-
- # Close all open file descriptors. This prevents the child from keeping
- # open any file descriptors inherited from the parent. There is a variety
- # of methods to accomplish this task. Three are listed below.
- #
- # Try the system configuration variable, SC_OPEN_MAX, to obtain the maximum
- # number of open file descriptors to close. If it doesn't exists, use
- # the default value (configurable).
- #
- # try:
- # maxfd = os.sysconf("SC_OPEN_MAX")
- # except (AttributeError, ValueError):
- # maxfd = MAXFD
- #
- # OR
- #
- # if (os.sysconf_names.has_key("SC_OPEN_MAX")):
- # maxfd = os.sysconf("SC_OPEN_MAX")
- # else:
- # maxfd = MAXFD
- #
- # OR
- #
- # Use the getrlimit method to retrieve the maximum file descriptor number
- # that can be opened by this process. If there is not limit on the
- # resource, use the default value.
- #
- import resource # Resource usage information.
- maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
- if (maxfd == resource.RLIM_INFINITY):
- maxfd = MAXFD
+ """
+ Detach a process from the controlling terminal and run it in the
+ background as a daemon, returning control to the caller.
+ """
+
+ try:
+ # Fork a child process so the parent can exit. This returns control to
+ # the command-line or shell. It also guarantees that the child will not
+ # be a process group leader, since the child receives a new process ID
+ # and inherits the parent's process group ID. This step is required
+ # to insure that the next call to os.setsid is successful.
+ pid = os.fork()
+ except OSError, e:
+ raise Exception, "%s [%d]" % (e.strerror, e.errno)
+
+ if (pid == 0): # The first child.
+ # To become the session leader of this new session and the process group
+ # leader of the new process group, we call os.setsid(). The process is
+ # also guaranteed not to have a controlling terminal.
+ os.setsid()
+
+ # Is ignoring SIGHUP necessary?
+ #
+ # It's often suggested that the SIGHUP signal should be ignored before
+ # the second fork to avoid premature termination of the process. The
+ # reason is that when the first child terminates, all processes, e.g.
+ # the second child, in the orphaned group will be sent a SIGHUP.
+ #
+ # "However, as part of the session management system, there are exactly
+ # two cases where SIGHUP is sent on the death of a process:
+ #
+ # 1) When the process that dies is the session leader of a session that
+ # is attached to a terminal device, SIGHUP is sent to all processes
+ # in the foreground process group of that terminal device.
+ # 2) When the death of a process causes a process group to become
+ # orphaned, and one or more processes in the orphaned group are
+ # stopped, then SIGHUP and SIGCONT are sent to all members of the
+ # orphaned group." [2]
+ #
+ # The first case can be ignored since the child is guaranteed not to have
+ # a controlling terminal. The second case isn't so easy to dismiss.
+ # The process group is orphaned when the first child terminates and
+ # POSIX.1 requires that every STOPPED process in an orphaned process
+ # group be sent a SIGHUP signal followed by a SIGCONT signal. Since the
+ # second child is not STOPPED though, we can safely forego ignoring the
+ # SIGHUP signal. In any case, there are no ill-effects if it is ignored.
+ #
+ # import signal # Set handlers for asynchronous events.
+ # signal.signal(signal.SIGHUP, signal.SIG_IGN)
+
+ try:
+ # Fork a second child and exit immediately to prevent zombies. This
+ # causes the second child process to be orphaned, making the init
+ # process responsible for its cleanup. And, since the first child is
+ # a session leader without a controlling terminal, it's possible for
+ # it to acquire one by opening a terminal in the future (System V-
+ # based systems). This second fork guarantees that the child is no
+ # longer a session leader, preventing the daemon from ever acquiring
+ # a controlling terminal.
+ pid = os.fork() # Fork a second child.
+ except OSError, e:
+ raise Exception, "%s [%d]" % (e.strerror, e.errno)
+
+ if (pid == 0): # The second child.
+ # We probably don't want the file mode creation mask inherited from
+ # the parent, so we give the child complete control over permissions.
+ if UMASK is not None:
+ os.umask(UMASK)
+ else:
+ # Parent (the first child) of the second child.
+ os._exit(0)
+ else:
+ # exit() or _exit()?
+ # _exit is like exit(), but it doesn't call any functions registered
+ # with atexit (and on_exit) or any registered signal handlers. It also
+ # closes any open file descriptors. Using exit() may cause all stdio
+ # streams to be flushed twice and any temporary files may be unexpectedly
+ # removed. It's therefore recommended that child branches of a fork()
+ # and the parent branch(es) of a daemon use _exit().
+ return
+
+ # Close all open file descriptors. This prevents the child from keeping
+ # open any file descriptors inherited from the parent. There is a variety
+ # of methods to accomplish this task. Three are listed below.
+ #
+ # Try the system configuration variable, SC_OPEN_MAX, to obtain the maximum
+ # number of open file descriptors to close. If it doesn't exists, use
+ # the default value (configurable).
+ #
+ # try:
+ # maxfd = os.sysconf("SC_OPEN_MAX")
+ # except (AttributeError, ValueError):
+ # maxfd = MAXFD
+ #
+ # OR
+ #
+ # if (os.sysconf_names.has_key("SC_OPEN_MAX")):
+ # maxfd = os.sysconf("SC_OPEN_MAX")
+ # else:
+ # maxfd = MAXFD
+ #
+ # OR
+ #
+ # Use the getrlimit method to retrieve the maximum file descriptor number
+ # that can be opened by this process. If there is not limit on the
+ # resource, use the default value.
+ #
+ import resource # Resource usage information.
+ maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
+ if (maxfd == resource.RLIM_INFINITY):
+ maxfd = MAXFD
- # Iterate through and close all file descriptors.
-# for fd in range(0, maxfd):
-# try:
-# os.close(fd)
-# except OSError: # ERROR, fd wasn't open to begin with (ignored)
-# pass
+ # Iterate through and close all file descriptors.
+# for fd in range(0, maxfd):
+# try:
+# os.close(fd)
+# except OSError: # ERROR, fd wasn't open to begin with (ignored)
+# pass
- # Redirect the standard I/O file descriptors to the specified file. Since
- # the daemon has no controlling terminal, most daemons redirect stdin,
- # stdout, and stderr to /dev/null. This is done to prevent side-effects
- # from reads and writes to the standard I/O file descriptors.
+ # Redirect the standard I/O file descriptors to the specified file. Since
+ # the daemon has no controlling terminal, most daemons redirect stdin,
+ # stdout, and stderr to /dev/null. This is done to prevent side-effects
+ # from reads and writes to the standard I/O file descriptors.
- # This call to open is guaranteed to return the lowest file descriptor,
- # which will be 0 (stdin), since it was closed above.
-# os.open(REDIRECT_TO, os.O_RDWR) # standard input (0)
+ # This call to open is guaranteed to return the lowest file descriptor,
+ # which will be 0 (stdin), since it was closed above.
+# os.open(REDIRECT_TO, os.O_RDWR) # standard input (0)
- # Duplicate standard input to standard output and standard error.
-# os.dup2(0, 1) # standard output (1)
-# os.dup2(0, 2) # standard error (2)
+ # Duplicate standard input to standard output and standard error.
+# os.dup2(0, 1) # standard output (1)
+# os.dup2(0, 2) # standard error (2)
- si = file('/dev/null', 'r')
- so = file(logfile, 'w')
- se = so
+ si = file('/dev/null', 'r')
+ so = file(logfile, 'w')
+ se = so
- # Replace those fds with our own
- os.dup2(si.fileno(), sys.stdin.fileno())
- os.dup2(so.fileno(), sys.stdout.fileno())
- os.dup2(se.fileno(), sys.stderr.fileno())
+ # Replace those fds with our own
+ os.dup2(si.fileno(), sys.stdin.fileno())
+ os.dup2(so.fileno(), sys.stdout.fileno())
+ os.dup2(se.fileno(), sys.stderr.fileno())
- function()
-
- os._exit(0)
+ function()
+ os._exit(0)
diff --git a/bitbake/lib/bb/data.py b/bitbake/lib/bb/data.py index cc5594e41..e71ad6b9c 100644 --- a/bitbake/lib/bb/data.py +++ b/bitbake/lib/bb/data.py @@ -11,7 +11,7 @@ operations. At night the cookie monster came by and suggested 'give me cookies on setting the variables and things will work out'. Taking this suggestion into account applying the skills from the not yet passed 'Entwurf und -Analyse von Algorithmen' lecture and the cookie +Analyse von Algorithmen' lecture and the cookie monster seems to be right. We will track setVar more carefully to have faster update_data and expandKeys operations. @@ -42,7 +42,7 @@ if sys.argv[0][-5:] == "pydoc": path = os.path.dirname(os.path.dirname(sys.argv[1])) else: path = os.path.dirname(os.path.dirname(sys.argv[0])) -sys.path.insert(0,path) +sys.path.insert(0, path) from bb import data_smart import bb @@ -62,14 +62,14 @@ def init_db(parent = None): return _dict_type() def createCopy(source): - """Link the source set to the destination - If one does not find the value in the destination set, - search will go on to the source set to get the value. - Value from source are copy-on-write. i.e. any try to - modify one of them will end up putting the modified value - in the destination set. - """ - return source.createCopy() + """Link the source set to the destination + If one does not find the value in the destination set, + search will go on to the source set to get the value. + Value from source are copy-on-write. i.e. any try to + modify one of them will end up putting the modified value + in the destination set. + """ + return source.createCopy() def initVar(var, d): """Non-destructive var init for data structure""" @@ -78,12 +78,12 @@ def initVar(var, d): def setVar(var, value, d): """Set a variable to a given value""" - d.setVar(var,value) + d.setVar(var, value) def getVar(var, d, exp = 0): """Gets the value of a variable""" - return d.getVar(var,exp) + return d.getVar(var, exp) def renameVar(key, newkey, d): @@ -96,15 +96,15 @@ def delVar(var, d): def setVarFlag(var, flag, flagvalue, d): """Set a flag for a given variable to a given value""" - d.setVarFlag(var,flag,flagvalue) + d.setVarFlag(var, flag, flagvalue) def getVarFlag(var, flag, d): """Gets given flag from given var""" - return d.getVarFlag(var,flag) + return d.getVarFlag(var, flag) def delVarFlag(var, flag, d): """Removes a given flag from the variable's flags""" - d.delVarFlag(var,flag) + d.delVarFlag(var, flag) def setVarFlags(var, flags, d): """Set the flags for a given variable @@ -114,7 +114,7 @@ def setVarFlags(var, flags, d): flags. Think of this method as addVarFlags """ - d.setVarFlags(var,flags) + d.setVarFlags(var, flags) def getVarFlags(var, d): """Gets a variable's flags""" @@ -178,7 +178,7 @@ def expandKeys(alterdata, readdata = None): continue todolist[key] = ekey - # These two for loops are split for performance to maximise the + # These two for loops are split for performance to maximise the # usefulness of the expand cache for key in todolist: @@ -267,7 +267,6 @@ def emit_var(var, o=sys.__stdout__, d = init(), all=False): o.write('%s="%s"\n' % (varExpanded, alter)) return 1 - def emit_env(o=sys.__stdout__, d = init(), all=False): """Emits all items in the data store in a format such that it can be sourced by a shell.""" diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py index 6ea018285..5ff0b37bf 100644 --- a/bitbake/lib/bb/data_smart.py +++ b/bitbake/lib/bb/data_smart.py @@ -31,11 +31,11 @@ BitBake build tools. import copy, os, re, sys, time, types import bb from bb import utils, methodpool -from COW import COWDictBase +from bb.COW import COWDictBase from new import classobj -__setvar_keyword__ = ["_append","_prepend"] +__setvar_keyword__ = ["_append", "_prepend"] __setvar_regexp__ = re.compile('(?P<base>.*?)(?P<keyword>_append|_prepend)(_(?P<add>.*))?') __expand_var_regexp__ = re.compile(r"\${[^{}]+}") __expand_python_regexp__ = re.compile(r"\${@.+?}") @@ -51,7 +51,7 @@ class DataSmart: self.expand_cache = {} - def expand(self,s, varname): + def expand(self, s, varname): def var_sub(match): key = match.group()[2:-1] if varname and key: @@ -165,7 +165,7 @@ class DataSmart: if not var in self.dict: self.dict[var] = {} - def _findVar(self,var): + def _findVar(self, var): _dest = self.dict while (_dest and var not in _dest): @@ -189,7 +189,7 @@ class DataSmart: else: self.initVar(var) - def setVar(self,var,value): + def setVar(self, var, value): self.expand_cache = {} match = __setvar_regexp__.match(var) if match and match.group("keyword") in __setvar_keyword__: @@ -223,16 +223,16 @@ class DataSmart: # setting var self.dict[var]["content"] = value - def getVar(self,var,exp): - value = self.getVarFlag(var,"content") + def getVar(self, var, exp): + value = self.getVarFlag(var, "content") if exp and value: - return self.expand(value,var) + return self.expand(value, var) return value def renameVar(self, key, newkey): """ - Rename the variable key to newkey + Rename the variable key to newkey """ val = self.getVar(key, 0) if val is not None: @@ -246,30 +246,30 @@ class DataSmart: dest = self.getVarFlag(newkey, i) or [] dest.extend(src) self.setVarFlag(newkey, i, dest) - + if self._special_values.has_key(i) and key in self._special_values[i]: self._special_values[i].remove(key) self._special_values[i].add(newkey) self.delVar(key) - def delVar(self,var): + def delVar(self, var): self.expand_cache = {} self.dict[var] = {} - def setVarFlag(self,var,flag,flagvalue): + def setVarFlag(self, var, flag, flagvalue): if not var in self.dict: self._makeShadowCopy(var) self.dict[var][flag] = flagvalue - def getVarFlag(self,var,flag): + def getVarFlag(self, var, flag): local_var = self._findVar(var) if local_var: if flag in local_var: return copy.copy(local_var[flag]) return None - def delVarFlag(self,var,flag): + def delVarFlag(self, var, flag): local_var = self._findVar(var) if not local_var: return @@ -279,7 +279,7 @@ class DataSmart: if var in self.dict and flag in self.dict[var]: del self.dict[var][flag] - def setVarFlags(self,var,flags): + def setVarFlags(self, var, flags): if not var in self.dict: self._makeShadowCopy(var) @@ -288,7 +288,7 @@ class DataSmart: continue self.dict[var][i] = flags[i] - def getVarFlags(self,var): + def getVarFlags(self, var): local_var = self._findVar(var) flags = {} @@ -303,7 +303,7 @@ class DataSmart: return flags - def delVarFlags(self,var): + def delVarFlags(self, var): if not var in self.dict: self._makeShadowCopy(var) @@ -333,21 +333,19 @@ class DataSmart: def keys(self): def _keys(d, mykey): if "_data" in d: - _keys(d["_data"],mykey) + _keys(d["_data"], mykey) for key in d.keys(): if key != "_data": mykey[key] = None keytab = {} - _keys(self.dict,keytab) + _keys(self.dict, keytab) return keytab.keys() - def __getitem__(self,item): + def __getitem__(self, item): #print "Warning deprecated" return self.getVar(item, False) - def __setitem__(self,var,data): + def __setitem__(self, var, data): #print "Warning deprecated" - self.setVar(var,data) - - + self.setVar(var, data) diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py index aa3a4471d..456b89caf 100644 --- a/bitbake/lib/bb/event.py +++ b/bitbake/lib/bb/event.py @@ -89,9 +89,9 @@ def fire_ui_handlers(event, d): def fire(event, d): """Fire off an Event""" - # We can fire class handlers in the worker process context and this is + # We can fire class handlers in the worker process context and this is # desired so they get the task based datastore. - # UI handlers need to be fired in the server context so we defer this. They + # UI handlers need to be fired in the server context so we defer this. They # don't have a datastore so the datastore context isn't a problem. fire_class_handlers(event, d) @@ -297,4 +297,3 @@ class DepTreeGenerated(Event): def __init__(self, depgraph): Event.__init__(self) self._depgraph = depgraph - diff --git a/bitbake/lib/bb/fetch/__init__.py b/bitbake/lib/bb/fetch/__init__.py index b1b5eda35..09c83b026 100644 --- a/bitbake/lib/bb/fetch/__init__.py +++ b/bitbake/lib/bb/fetch/__init__.py @@ -85,7 +85,7 @@ def decodeurl(url): p = {} if parm: for s in parm.split(';'): - s1,s2 = s.split('=') + s1, s2 = s.split('=') p[s1] = s2 return (type, host, path, user, pswd, p) @@ -121,7 +121,7 @@ def uri_replace(uri, uri_find, uri_replace, d): uri_decoded = list(decodeurl(uri)) uri_find_decoded = list(decodeurl(uri_find)) uri_replace_decoded = list(decodeurl(uri_replace)) - result_decoded = ['','','','','',{}] + result_decoded = ['', '', '', '', '', {}] for i in uri_find_decoded: loc = uri_find_decoded.index(i) result_decoded[loc] = uri_decoded[loc] @@ -214,7 +214,7 @@ def init(urls, d, setup = True): if setup: for url in urldata: if not urldata[url].setup: - urldata[url].setup_localpath(d) + urldata[url].setup_localpath(d) urldata_cache[fn] = urldata return urldata @@ -243,7 +243,7 @@ def go(d, urls = None): continue lf = bb.utils.lockfile(ud.lockfile) if not m.forcefetch(u, ud, d) and os.path.exists(ud.md5): - # If someone else fetched this before we got the lock, + # If someone else fetched this before we got the lock, # notice and don't try again try: os.utime(ud.md5, None) @@ -309,7 +309,7 @@ def localpaths(d): urldata = init([], d, True) for u in urldata: - ud = urldata[u] + ud = urldata[u] local.append(ud.localpath) return local @@ -321,15 +321,15 @@ def get_srcrev(d): Return the version string for the current package (usually to be used as PV) Most packages usually only have one SCM so we just pass on the call. - In the multi SCM case, we build a value based on SRCREV_FORMAT which must + In the multi SCM case, we build a value based on SRCREV_FORMAT which must have been set. """ # - # Ugly code alert. localpath in the fetchers will try to evaluate SRCREV which + # Ugly code alert. localpath in the fetchers will try to evaluate SRCREV which # could translate into a call to here. If it does, we need to catch this # and provide some way so it knows get_srcrev is active instead of being - # some number etc. hence the srcrev_internal_call tracking and the magic + # some number etc. hence the srcrev_internal_call tracking and the magic # "SRCREVINACTION" return value. # # Neater solutions welcome! @@ -339,7 +339,7 @@ def get_srcrev(d): scms = [] - # Only call setup_localpath on URIs which suppports_srcrev() + # Only call setup_localpath on URIs which suppports_srcrev() urldata = init(bb.data.getVar('SRC_URI', d, 1).split(), d, False) for u in urldata: ud = urldata[u] @@ -352,7 +352,7 @@ def get_srcrev(d): bb.msg.error(bb.msg.domain.Fetcher, "SRCREV was used yet no valid SCM was found in SRC_URI") raise ParameterError - bb.data.setVar('__BB_DONT_CACHE','1', d) + bb.data.setVar('__BB_DONT_CACHE', '1', d) if len(scms) == 1: return urldata[scms[0]].method.sortable_revision(scms[0], urldata[scms[0]], d) @@ -375,7 +375,7 @@ def get_srcrev(d): def localpath(url, d, cache = True): """ - Called from the parser with cache=False since the cache isn't ready + Called from the parser with cache=False since the cache isn't ready at this point. Also called from classed in OE e.g. patch.bbclass """ ud = init([url], d) @@ -538,7 +538,7 @@ class Fetch(object): def localpath(self, url, urldata, d): """ Return the local filename of a given url assuming a successful fetch. - Can also setup variables in urldata for use in go (saving code duplication + Can also setup variables in urldata for use in go (saving code duplication and duplicate code execution) """ return url @@ -599,8 +599,8 @@ class Fetch(object): """ Return: a) a source revision if specified - b) True if auto srcrev is in action - c) False otherwise + b) True if auto srcrev is in action + c) False otherwise """ if 'rev' in ud.parm: @@ -632,7 +632,7 @@ class Fetch(object): b) None otherwise """ - localcount= None + localcount = None if 'name' in ud.parm: pn = data.getVar("PN", d, 1) localcount = data.getVar("LOCALCOUNT_" + ud.parm['name'], d, 1) @@ -685,7 +685,7 @@ class Fetch(object): def sortable_revision(self, url, ud, d): """ - + """ if hasattr(self, "_sortable_revision"): return self._sortable_revision(url, ud, d) diff --git a/bitbake/lib/bb/fetch/bzr.py b/bitbake/lib/bb/fetch/bzr.py index c6e33c334..813d7d8c8 100644 --- a/bitbake/lib/bb/fetch/bzr.py +++ b/bitbake/lib/bb/fetch/bzr.py @@ -46,15 +46,15 @@ class Bzr(Fetch): revision = Fetch.srcrev_internal_helper(ud, d) if revision is True: - ud.revision = self.latest_revision(url, ud, d) + ud.revision = self.latest_revision(url, ud, d) elif revision: ud.revision = revision if not ud.revision: - ud.revision = self.latest_revision(url, ud, d) + ud.revision = self.latest_revision(url, ud, d) ud.localfile = data.expand('bzr_%s_%s_%s.tar.gz' % (ud.host, ud.path.replace('/', '.'), ud.revision), d) - + return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile) def _buildbzrcommand(self, ud, d, command): @@ -145,4 +145,3 @@ class Bzr(Fetch): def _build_revision(self, url, ud, d): return ud.revision - diff --git a/bitbake/lib/bb/fetch/cvs.py b/bitbake/lib/bb/fetch/cvs.py index 443f52131..c0d43618f 100644 --- a/bitbake/lib/bb/fetch/cvs.py +++ b/bitbake/lib/bb/fetch/cvs.py @@ -157,7 +157,7 @@ class Cvs(Fetch): try: os.rmdir(moddir) except OSError: - pass + pass raise FetchError(ud.module) # tar them up to a defined filename diff --git a/bitbake/lib/bb/fetch/git.py b/bitbake/lib/bb/fetch/git.py index 41ebc5b99..533268625 100644 --- a/bitbake/lib/bb/fetch/git.py +++ b/bitbake/lib/bb/fetch/git.py @@ -57,12 +57,12 @@ class Git(Fetch): tag = Fetch.srcrev_internal_helper(ud, d) if tag is True: - ud.tag = self.latest_revision(url, ud, d) + ud.tag = self.latest_revision(url, ud, d) elif tag: ud.tag = tag if not ud.tag or ud.tag == "master": - ud.tag = self.latest_revision(url, ud, d) + ud.tag = self.latest_revision(url, ud, d) subdir = ud.parm.get("subpath", "") if subdir != "": @@ -114,7 +114,7 @@ class Git(Fetch): os.chdir(ud.clonedir) mirror_tarballs = data.getVar("BB_GENERATE_MIRROR_TARBALLS", d, True) - if mirror_tarballs != "0" or 'fullclone' in ud.parm: + if mirror_tarballs != "0" or 'fullclone' in ud.parm: bb.msg.note(1, bb.msg.domain.Fetcher, "Creating tarball of git repository") runfetchcmd("tar -czf %s %s" % (repofile, os.path.join(".", ".git", "*") ), d) @@ -188,7 +188,7 @@ class Git(Fetch): def _sortable_buildindex_disabled(self, url, ud, d, rev): """ - Return a suitable buildindex for the revision specified. This is done by counting revisions + Return a suitable buildindex for the revision specified. This is done by counting revisions using "git rev-list" which may or may not work in different circumstances. """ @@ -213,5 +213,4 @@ class Git(Fetch): buildindex = "%s" % output.split()[0] bb.msg.debug(1, bb.msg.domain.Fetcher, "GIT repository for %s in %s is returning %s revisions in rev-list before %s" % (url, ud.clonedir, buildindex, rev)) - return buildindex - + return buildindex diff --git a/bitbake/lib/bb/fetch/hg.py b/bitbake/lib/bb/fetch/hg.py index d0756382f..efb3b5c76 100644 --- a/bitbake/lib/bb/fetch/hg.py +++ b/bitbake/lib/bb/fetch/hg.py @@ -134,9 +134,9 @@ class Hg(Fetch): os.chdir(ud.pkgdir) bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % fetchcmd) runfetchcmd(fetchcmd, d) - - # Even when we clone (fetch), we still need to update as hg's clone - # won't checkout the specified revision if its on a branch + + # Even when we clone (fetch), we still need to update as hg's clone + # won't checkout the specified revision if its on a branch updatecmd = self._buildhgcommand(ud, d, "update") bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % updatecmd) runfetchcmd(updatecmd, d) @@ -170,4 +170,3 @@ class Hg(Fetch): Return a unique key for the url """ return "hg:" + ud.moddir - diff --git a/bitbake/lib/bb/fetch/local.py b/bitbake/lib/bb/fetch/local.py index f9bdf589c..a2abc8639 100644 --- a/bitbake/lib/bb/fetch/local.py +++ b/bitbake/lib/bb/fetch/local.py @@ -65,8 +65,8 @@ class Local(Fetch): Check the status of the url """ if urldata.localpath.find("*") != -1: - bb.msg.note(1, bb.msg.domain.Fetcher, "URL %s looks like a glob and was therefore not checked." % url) - return True + bb.msg.note(1, bb.msg.domain.Fetcher, "URL %s looks like a glob and was therefore not checked." % url) + return True if os.path.exists(urldata.localpath): - return True + return True return False diff --git a/bitbake/lib/bb/fetch/osc.py b/bitbake/lib/bb/fetch/osc.py index 548dd9d07..ed773939b 100644 --- a/bitbake/lib/bb/fetch/osc.py +++ b/bitbake/lib/bb/fetch/osc.py @@ -16,7 +16,7 @@ from bb.fetch import MissingParameterError from bb.fetch import runfetchcmd class Osc(Fetch): - """Class to fetch a module or modules from Opensuse build server + """Class to fetch a module or modules from Opensuse build server repositories.""" def supports(self, url, ud, d): @@ -64,7 +64,7 @@ class Osc(Fetch): proto = "ocs" if "proto" in ud.parm: proto = ud.parm["proto"] - + options = [] config = "-c %s" % self.generate_config(ud, d) @@ -108,7 +108,7 @@ class Osc(Fetch): os.chdir(ud.pkgdir) bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % oscfetchcmd) runfetchcmd(oscfetchcmd, d) - + os.chdir(os.path.join(ud.pkgdir + ud.path)) # tar them up to a defined filename try: @@ -131,7 +131,7 @@ class Osc(Fetch): config_path = "%s/oscrc" % data.expand('${OSCDIR}', d) if (os.path.exists(config_path)): - os.remove(config_path) + os.remove(config_path) f = open(config_path, 'w') f.write("[general]\n") @@ -146,5 +146,5 @@ class Osc(Fetch): f.write("user = %s\n" % ud.parm["user"]) f.write("pass = %s\n" % ud.parm["pswd"]) f.close() - + return config_path diff --git a/bitbake/lib/bb/fetch/perforce.py b/bitbake/lib/bb/fetch/perforce.py index 8bc3205c2..67de6f59f 100644 --- a/bitbake/lib/bb/fetch/perforce.py +++ b/bitbake/lib/bb/fetch/perforce.py @@ -95,7 +95,7 @@ class Perforce(Fetch): return cset.split(' ')[1] getcset = staticmethod(getcset) - def localpath(self, url, ud, d): + def localpath(self, url, ud, d): (host,path,user,pswd,parm) = Perforce.doparse(url,d) @@ -180,7 +180,7 @@ class Perforce(Fetch): count = 0 - for file in p4file: + for file in p4file: list = file.split() if list[2] == "delete": @@ -191,7 +191,7 @@ class Perforce(Fetch): os.system("%s%s print -o %s/%s %s" % (p4cmd, p4opt, module,dest[:where],list[0])) count = count + 1 - + if count == 0: bb.msg.error(bb.msg.domain.Fetcher, "Fetch: No files gathered from the P4 fetch") raise FetchError(module) @@ -205,5 +205,3 @@ class Perforce(Fetch): raise FetchError(module) # cleanup os.system('rm -rf %s' % tmpfile) - - diff --git a/bitbake/lib/bb/fetch/svn.py b/bitbake/lib/bb/fetch/svn.py index ba9f6ab10..375e8df05 100644 --- a/bitbake/lib/bb/fetch/svn.py +++ b/bitbake/lib/bb/fetch/svn.py @@ -78,7 +78,7 @@ class Svn(Fetch): ud.revision = rev ud.date = "" else: - ud.revision = "" + ud.revision = "" ud.localfile = data.expand('%s_%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision, ud.date), d) diff --git a/bitbake/lib/bb/msg.py b/bitbake/lib/bb/msg.py index b4d3a2c98..17d1a0852 100644 --- a/bitbake/lib/bb/msg.py +++ b/bitbake/lib/bb/msg.py @@ -33,7 +33,7 @@ def _NamedTuple(name, fields): Tuple = collections.namedtuple(name, " ".join(fields)) return Tuple(*range(len(fields))) -domain = _NamedTuple("Domain",( +domain = _NamedTuple("Domain", ( "Default", "Build", "Cache", diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py index affe4bed4..6d4f28562 100644 --- a/bitbake/lib/bb/parse/ast.py +++ b/bitbake/lib/bb/parse/ast.py @@ -254,7 +254,7 @@ class InheritNode(AstNode): def eval(self, data): bb.parse.BBHandler.inherit(self.n, data) - + def handleInclude(statements, m, fn, lineno, force): statements.append(IncludeNode(m.group(1), fn, lineno, force)) diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py index 262c883c9..f9f185ff7 100644 --- a/bitbake/lib/bb/parse/parse_py/BBHandler.py +++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py @@ -11,7 +11,7 @@ # Copyright (C) 2003, 2004 Chris Larson # Copyright (C) 2003, 2004 Phil Blundell -# +# # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. diff --git a/bitbake/lib/bb/parse/parse_py/ConfHandler.py b/bitbake/lib/bb/parse/parse_py/ConfHandler.py index 5c0229952..e50acbe5e 100644 --- a/bitbake/lib/bb/parse/parse_py/ConfHandler.py +++ b/bitbake/lib/bb/parse/parse_py/ConfHandler.py @@ -10,7 +10,7 @@ # Copyright (C) 2003, 2004 Chris Larson # Copyright (C) 2003, 2004 Phil Blundell -# +# # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. diff --git a/bitbake/lib/bb/persist_data.py b/bitbake/lib/bb/persist_data.py index bc4045fe8..e2bbbe54f 100644 --- a/bitbake/lib/bb/persist_data.py +++ b/bitbake/lib/bb/persist_data.py @@ -33,11 +33,11 @@ class PersistData: """ BitBake Persistent Data Store - Used to store data in a central location such that other threads/tasks can + Used to store data in a central location such that other threads/tasks can access them at some future date. - The "domain" is used as a key to isolate each data pool and in this - implementation corresponds to an SQL table. The SQL table consists of a + The "domain" is used as a key to isolate each data pool and in this + implementation corresponds to an SQL table. The SQL table consists of a simple key and value pair. Why sqlite? It handles all the locking issues for us. @@ -78,7 +78,7 @@ class PersistData: for row in data: ret[str(row[0])] = str(row[1]) - return ret + return ret def getValue(self, domain, key): """ @@ -108,7 +108,7 @@ class PersistData: self._execute("DELETE from %s where key=?;" % domain, [key]) def _execute(self, *query): - while True: + while True: try: self.connection.execute(*query) return @@ -116,6 +116,3 @@ class PersistData: if 'database is locked' in str(e): continue raise - - - diff --git a/bitbake/lib/bb/providers.py b/bitbake/lib/bb/providers.py index 058996ba5..58326f039 100644 --- a/bitbake/lib/bb/providers.py +++ b/bitbake/lib/bb/providers.py @@ -62,7 +62,7 @@ def sortPriorities(pn, dataCache, pkg_pn = None): def preferredVersionMatch(pe, pv, pr, preferred_e, preferred_v, preferred_r): """ Check if the version pe,pv,pr is the preferred one. - If there is preferred version defined and ends with '%', then pv has to start with that version after removing the '%' + If there is preferred version defined and ends with '%', then pv has to start with that version after removing the '%' """ if (pr == preferred_r or preferred_r == None): if (pe == preferred_e or preferred_e == None): @@ -103,7 +103,7 @@ def findPreferredProvider(pn, cfgData, dataCache, pkg_pn = None, item = None): for file_set in pkg_pn: for f in file_set: - pe,pv,pr = dataCache.pkg_pepvpr[f] + pe, pv, pr = dataCache.pkg_pepvpr[f] if preferredVersionMatch(pe, pv, pr, preferred_e, preferred_v, preferred_r): preferred_file = f preferred_ver = (pe, pv, pr) @@ -136,7 +136,7 @@ def findLatestProvider(pn, cfgData, dataCache, file_set): latest_p = 0 latest_f = None for file_name in file_set: - pe,pv,pr = dataCache.pkg_pepvpr[file_name] + pe, pv, pr = dataCache.pkg_pepvpr[file_name] dp = dataCache.pkg_dp[file_name] if (latest is None) or ((latest_p == dp) and (utils.vercmp(latest, (pe, pv, pr)) < 0)) or (dp > latest_p): @@ -169,14 +169,14 @@ def findBestProvider(pn, cfgData, dataCache, pkg_pn = None, item = None): def _filterProviders(providers, item, cfgData, dataCache): """ - Take a list of providers and filter/reorder according to the + Take a list of providers and filter/reorder according to the environment variables and previous build results """ eligible = [] preferred_versions = {} sortpkg_pn = {} - # The order of providers depends on the order of the files on the disk + # The order of providers depends on the order of the files on the disk # up to here. Sort pkg_pn to make dependency issues reproducible rather # than effectively random. providers.sort() @@ -226,7 +226,7 @@ def _filterProviders(providers, item, cfgData, dataCache): def filterProviders(providers, item, cfgData, dataCache): """ - Take a list of providers and filter/reorder according to the + Take a list of providers and filter/reorder according to the environment variables and previous build results Takes a "normal" target item """ @@ -254,7 +254,7 @@ def filterProviders(providers, item, cfgData, dataCache): def filterProvidersRunTime(providers, item, cfgData, dataCache): """ - Take a list of providers and filter/reorder according to the + Take a list of providers and filter/reorder according to the environment variables and previous build results Takes a "runtime" target item """ @@ -297,7 +297,7 @@ def getRuntimeProviders(dataCache, rdepend): rproviders = [] if rdepend in dataCache.rproviders: - rproviders += dataCache.rproviders[rdepend] + rproviders += dataCache.rproviders[rdepend] if rdepend in dataCache.packages: rproviders += dataCache.packages[rdepend] diff --git a/bitbake/lib/bb/runqueue.py b/bitbake/lib/bb/runqueue.py index 9a368b862..2ecfd0946 100644 --- a/bitbake/lib/bb/runqueue.py +++ b/bitbake/lib/bb/runqueue.py @@ -30,7 +30,7 @@ import fcntl class TaskFailure(Exception): """Exception raised when a task in a runqueue fails""" - def __init__(self, x): + def __init__(self, x): self.args = x @@ -60,7 +60,7 @@ class RunQueueStats: def taskActive(self): self.active = self.active + 1 -# These values indicate the next step due to be run in the +# These values indicate the next step due to be run in the # runQueue state machine runQueuePrepare = 2 runQueueRunInit = 3 @@ -76,7 +76,7 @@ class RunQueueScheduler: """ def __init__(self, runqueue): """ - The default scheduler just returns the first buildable task (the + The default scheduler just returns the first buildable task (the priority map is sorted by task numer) """ self.rq = runqueue @@ -123,10 +123,10 @@ class RunQueueSchedulerSpeed(RunQueueScheduler): class RunQueueSchedulerCompletion(RunQueueSchedulerSpeed): """ - A scheduler optimised to complete .bb files are quickly as possible. The - priority map is sorted by task weight, but then reordered so once a given + A scheduler optimised to complete .bb files are quickly as possible. The + priority map is sorted by task weight, but then reordered so once a given .bb file starts to build, its completed as quickly as possible. This works - well where disk space is at a premium and classes like OE's rm_work are in + well where disk space is at a premium and classes like OE's rm_work are in force. """ def __init__(self, runqueue): @@ -135,7 +135,7 @@ class RunQueueSchedulerCompletion(RunQueueSchedulerSpeed): #FIXME - whilst this groups all fnids together it does not reorder the #fnid groups optimally. - + basemap = deepcopy(self.prio_map) self.prio_map = [] while (len(basemap) > 0): @@ -231,7 +231,7 @@ class RunQueue: if chain1[index] != chain2[index]: return False return True - + def chain_array_contains(chain, chain_array): """ Return True if chain_array contains chain @@ -286,7 +286,7 @@ class RunQueue: def calculate_task_weights(self, endpoints): """ - Calculate a number representing the "weight" of each task. Heavier weighted tasks + Calculate a number representing the "weight" of each task. Heavier weighted tasks have more dependencies and hence should be executed sooner for maximum speed. This function also sanity checks the task list finding tasks that its not @@ -318,7 +318,7 @@ class RunQueue: task_done[revdep] = True endpoints = next_points if len(next_points) == 0: - break + break # Circular dependency sanity check problem_tasks = [] @@ -345,7 +345,7 @@ class RunQueue: def prepare_runqueue(self): """ - Turn a set of taskData into a RunQueue and compute data needed + Turn a set of taskData into a RunQueue and compute data needed to optimise the execution order. """ @@ -365,12 +365,12 @@ class RunQueue: # Step A - Work out a list of tasks to run # # Taskdata gives us a list of possible providers for every build and run - # target ordered by priority. It also gives information on each of those + # target ordered by priority. It also gives information on each of those # providers. # - # To create the actual list of tasks to execute we fix the list of - # providers and then resolve the dependencies into task IDs. This - # process is repeated for each type of dependency (tdepends, deptask, + # To create the actual list of tasks to execute we fix the list of + # providers and then resolve the dependencies into task IDs. This + # process is repeated for each type of dependency (tdepends, deptask, # rdeptast, recrdeptask, idepends). def add_build_dependencies(depids, tasknames, depends): @@ -411,12 +411,12 @@ class RunQueue: if fnid not in taskData.failed_fnids: - # Resolve task internal dependencies + # Resolve task internal dependencies # # e.g. addtask before X after Y depends = taskData.tasks_tdepends[task] - # Resolve 'deptask' dependencies + # Resolve 'deptask' dependencies # # e.g. do_sometask[deptask] = "do_someothertask" # (makes sure sometask runs after someothertask of all DEPENDS) @@ -424,7 +424,7 @@ class RunQueue: tasknames = task_deps['deptask'][taskData.tasks_name[task]].split() add_build_dependencies(taskData.depids[fnid], tasknames, depends) - # Resolve 'rdeptask' dependencies + # Resolve 'rdeptask' dependencies # # e.g. do_sometask[rdeptask] = "do_someothertask" # (makes sure sometask runs after someothertask of all RDEPENDS) @@ -432,7 +432,7 @@ class RunQueue: taskname = task_deps['rdeptask'][taskData.tasks_name[task]] add_runtime_dependencies(taskData.rdepids[fnid], [taskname], depends) - # Resolve inter-task dependencies + # Resolve inter-task dependencies # # e.g. do_sometask[depends] = "targetname:do_someothertask" # (makes sure sometask runs after targetname's someothertask) @@ -467,8 +467,8 @@ class RunQueue: newdep = [] bb.msg.debug(2, bb.msg.domain.RunQueue, "Task %s (%s %s) contains self reference! %s" % (task, taskData.fn_index[taskData.tasks_fnid[task]], taskData.tasks_name[task], depends)) for dep in depends: - if task != dep: - newdep.append(dep) + if task != dep: + newdep.append(dep) depends = newdep self.runq_fnid.append(taskData.tasks_fnid[task]) @@ -482,7 +482,7 @@ class RunQueue: # # Build a list of recursive cumulative dependencies for each fnid # We do this by fnid, since if A depends on some task in B - # we're interested in later tasks B's fnid might have but B itself + # we're interested in later tasks B's fnid might have but B itself # doesn't depend on # # Algorithm is O(tasks) + O(tasks)*O(fnids) @@ -513,7 +513,7 @@ class RunQueue: if len(runq_recrdepends[task]) > 0: taskfnid = self.runq_fnid[task] for dep in reccumdepends[taskfnid]: - # Ignore self references + # Ignore self references if dep == task: continue for taskname in runq_recrdepends[task]: @@ -635,7 +635,7 @@ class RunQueue: bb.msg.note(2, bb.msg.domain.RunQueue, "Compute totals (have %s endpoint(s))" % len(endpoints)) - # Calculate task weights + # Calculate task weights # Check of higher length circular dependencies self.runq_weight = self.calculate_task_weights(endpoints) @@ -657,7 +657,7 @@ class RunQueue: for prov in self.dataCache.fn_provides[fn]: if prov not in prov_list: prov_list[prov] = [fn] - elif fn not in prov_list[prov]: + elif fn not in prov_list[prov]: prov_list[prov].append(fn) error = False for prov in prov_list: @@ -703,7 +703,7 @@ class RunQueue: buildable.append(task) def check_buildable(self, task, buildable): - for revdep in self.runq_revdeps[task]: + for revdep in self.runq_revdeps[task]: alldeps = 1 for dep in self.runq_depends[revdep]: if dep in unchecked: @@ -811,10 +811,10 @@ class RunQueue: try: t2 = os.stat(stampfile2)[stat.ST_MTIME] if t1 < t2: - bb.msg.debug(2, bb.msg.domain.RunQueue, "Stampfile %s < %s" % (stampfile,stampfile2)) + bb.msg.debug(2, bb.msg.domain.RunQueue, "Stampfile %s < %s" % (stampfile, stampfile2)) iscurrent = False except: - bb.msg.debug(2, bb.msg.domain.RunQueue, "Exception reading %s for %s" % (stampfile2 ,stampfile)) + bb.msg.debug(2, bb.msg.domain.RunQueue, "Exception reading %s for %s" % (stampfile2 , stampfile)) iscurrent = False return iscurrent @@ -885,7 +885,7 @@ class RunQueue: def task_complete(self, task): """ Mark a task as completed - Look at the reverse dependencies and mark any task with + Look at the reverse dependencies and mark any task with completed dependencies as buildable """ self.runq_complete[task] = 1 @@ -1033,10 +1033,10 @@ class RunQueue: def finish_runqueue_now(self): bb.msg.note(1, bb.msg.domain.RunQueue, "Sending SIGINT to remaining %s tasks" % self.stats.active) for k, v in self.build_pids.iteritems(): - try: - os.kill(-k, signal.SIGINT) - except: - pass + try: + os.kill(-k, signal.SIGINT) + except: + pass for pipe in self.build_pipes: self.build_pipes[pipe].read() @@ -1085,30 +1085,30 @@ class RunQueue: """ bb.msg.debug(3, bb.msg.domain.RunQueue, "run_tasks:") for task in range(len(self.runq_task)): - bb.msg.debug(3, bb.msg.domain.RunQueue, " (%s)%s - %s: %s Deps %s RevDeps %s" % (task, - taskQueue.fn_index[self.runq_fnid[task]], - self.runq_task[task], - self.runq_weight[task], - self.runq_depends[task], - self.runq_revdeps[task])) + bb.msg.debug(3, bb.msg.domain.RunQueue, " (%s)%s - %s: %s Deps %s RevDeps %s" % (task, + taskQueue.fn_index[self.runq_fnid[task]], + self.runq_task[task], + self.runq_weight[task], + self.runq_depends[task], + self.runq_revdeps[task])) bb.msg.debug(3, bb.msg.domain.RunQueue, "sorted_tasks:") for task1 in range(len(self.runq_task)): if task1 in self.prio_map: task = self.prio_map[task1] - bb.msg.debug(3, bb.msg.domain.RunQueue, " (%s)%s - %s: %s Deps %s RevDeps %s" % (task, - taskQueue.fn_index[self.runq_fnid[task]], - self.runq_task[task], - self.runq_weight[task], - self.runq_depends[task], - self.runq_revdeps[task])) + bb.msg.debug(3, bb.msg.domain.RunQueue, " (%s)%s - %s: %s Deps %s RevDeps %s" % (task, + taskQueue.fn_index[self.runq_fnid[task]], + self.runq_task[task], + self.runq_weight[task], + self.runq_depends[task], + self.runq_revdeps[task])) class TaskFailure(Exception): """ Exception raised when a task in a runqueue fails """ - def __init__(self, x): + def __init__(self, x): self.args = x @@ -1196,4 +1196,3 @@ class runQueuePipe(): if len(self.queue) > 0: print "Warning, worker left partial message" os.close(self.fd) - diff --git a/bitbake/lib/bb/server/none.py b/bitbake/lib/bb/server/none.py index ebda11158..d4b7fdeea 100644 --- a/bitbake/lib/bb/server/none.py +++ b/bitbake/lib/bb/server/none.py @@ -178,4 +178,3 @@ class BitBakeServerConnection(): self.connection.terminateServer() except: pass - diff --git a/bitbake/lib/bb/server/xmlrpc.py b/bitbake/lib/bb/server/xmlrpc.py index 3364918c7..e1e514fc9 100644 --- a/bitbake/lib/bb/server/xmlrpc.py +++ b/bitbake/lib/bb/server/xmlrpc.py @@ -89,8 +89,8 @@ class BitBakeServer(SimpleXMLRPCServer): def __init__(self, cooker, interface = ("localhost", 0)): """ - Constructor - """ + Constructor + """ SimpleXMLRPCServer.__init__(self, interface, requestHandler=SimpleXMLRPCRequestHandler, logRequests=False, allow_none=True) @@ -146,7 +146,7 @@ class BitBakeServer(SimpleXMLRPCServer): traceback.print_exc() pass if nextsleep is None and len(self._idlefuns) > 0: - nextsleep = 0 + nextsleep = 0 self.timeout = nextsleep # Tell idle functions we're exiting for function, data in self._idlefuns.items(): @@ -175,7 +175,7 @@ class BitBakeServerConnection(): def terminate(self): # Don't wait for server indefinitely import socket - socket.setdefaulttimeout(2) + socket.setdefaulttimeout(2) try: self.events.system_quit() except: @@ -184,4 +184,3 @@ class BitBakeServerConnection(): self.connection.terminateServer() except: pass - diff --git a/bitbake/lib/bb/shell.py b/bitbake/lib/bb/shell.py index 7abea0f12..512bcbf07 100644 --- a/bitbake/lib/bb/shell.py +++ b/bitbake/lib/bb/shell.py @@ -168,7 +168,7 @@ class BitBakeShellCommands: tasks.append([name, "do_%s" % cmd]) td.add_unresolved(localdata, cooker.status) - + rq = runqueue.RunQueue(cooker, localdata, cooker.status, td, tasks) rq.prepare_runqueue() rq.execute_runqueue() @@ -295,7 +295,7 @@ class BitBakeShellCommands: """Show a comprehensive list of commands and their purpose""" print "="*30, "Available Commands", "="*30 for cmd in sorted(cmds): - function,numparams,usage,helptext = cmds[cmd] + function, numparams, usage, helptext = cmds[cmd] print "| %s | %s" % (usage.ljust(30), helptext) print "="*78 @@ -343,7 +343,7 @@ class BitBakeShellCommands: return False print "SHELL: Creating '%s/%s'" % ( fulldirname, filename ) newpackage = open( "%s/%s" % ( fulldirname, filename ), "w" ) - print >>newpackage,"""DESCRIPTION = "" + print >>newpackage, """DESCRIPTION = "" SECTION = "" AUTHOR = "" HOMEPAGE = "" @@ -583,7 +583,7 @@ def sendToPastebin( desc, content ): mydata["nick"] = "%s@%s" % ( os.environ.get( "USER", "unknown" ), socket.gethostname() or "unknown" ) mydata["text"] = content params = urllib.urlencode( mydata ) - headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"} + headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} host = "rafb.net" conn = httplib.HTTPConnection( "%s:80" % host ) diff --git a/bitbake/lib/bb/taskdata.py b/bitbake/lib/bb/taskdata.py index 3e5e006f5..58e0d9d8f 100644 --- a/bitbake/lib/bb/taskdata.py +++ b/bitbake/lib/bb/taskdata.py @@ -84,7 +84,7 @@ class TaskData: def getrun_id(self, name): """ - Return an ID number for the run target name. + Return an ID number for the run target name. If it doesn't exist, create one. """ if not name in self.run_names_index: @@ -95,7 +95,7 @@ class TaskData: def getfn_id(self, name): """ - Return an ID number for the filename. + Return an ID number for the filename. If it doesn't exist, create one. """ if not name in self.fn_index: @@ -271,7 +271,7 @@ class TaskData: def get_unresolved_build_targets(self, dataCache): """ - Return a list of build targets who's providers + Return a list of build targets who's providers are unknown. """ unresolved = [] @@ -286,7 +286,7 @@ class TaskData: def get_unresolved_run_targets(self, dataCache): """ - Return a list of runtime targets who's providers + Return a list of runtime targets who's providers are unknown. """ unresolved = [] @@ -304,7 +304,7 @@ class TaskData: Return a list of providers of item """ targetid = self.getbuild_id(item) - + return self.build_targets[targetid] def get_dependees(self, itemid): @@ -367,7 +367,7 @@ class TaskData: def add_provider_internal(self, cfgData, dataCache, item): """ Add the providers of item to the task data - Mark entries were specifically added externally as against dependencies + Mark entries were specifically added externally as against dependencies added internally during dependency resolution """ @@ -450,7 +450,7 @@ class TaskData: providers_list.append(dataCache.pkg_fn[fn]) bb.msg.note(2, bb.msg.domain.Provider, "multiple providers are available for runtime %s (%s);" % (item, ", ".join(providers_list))) bb.msg.note(2, bb.msg.domain.Provider, "consider defining a PREFERRED_PROVIDER entry to match runtime %s" % item) - bb.event.fire(bb.event.MultipleProviders(item,providers_list, runtime=True), cfgData) + bb.event.fire(bb.event.MultipleProviders(item, providers_list, runtime=True), cfgData) self.consider_msgs_cache.append(item) if numberPreferred > 1: @@ -460,7 +460,7 @@ class TaskData: providers_list.append(dataCache.pkg_fn[fn]) bb.msg.note(2, bb.msg.domain.Provider, "multiple providers are available for runtime %s (top %s entries preferred) (%s);" % (item, numberPreferred, ", ".join(providers_list))) bb.msg.note(2, bb.msg.domain.Provider, "consider defining only one PREFERRED_PROVIDER entry to match runtime %s" % item) - bb.event.fire(bb.event.MultipleProviders(item,providers_list, runtime=True), cfgData) + bb.event.fire(bb.event.MultipleProviders(item, providers_list, runtime=True), cfgData) self.consider_msgs_cache.append(item) # run through the list until we find one that we can build @@ -594,9 +594,9 @@ class TaskData: bb.msg.debug(3, bb.msg.domain.TaskData, "tasks:") for task in range(len(self.tasks_name)): bb.msg.debug(3, bb.msg.domain.TaskData, " (%s)%s - %s: %s" % ( - task, - self.fn_index[self.tasks_fnid[task]], - self.tasks_name[task], + task, + self.fn_index[self.tasks_fnid[task]], + self.tasks_name[task], self.tasks_tdepends[task])) bb.msg.debug(3, bb.msg.domain.TaskData, "dependency ids (per fn):") @@ -606,5 +606,3 @@ class TaskData: bb.msg.debug(3, bb.msg.domain.TaskData, "runtime dependency ids (per fn):") for fnid in self.rdepids: bb.msg.debug(3, bb.msg.domain.TaskData, " %s %s: %s" % (fnid, self.fn_index[fnid], self.rdepids[fnid])) - - diff --git a/bitbake/lib/bb/ui/__init__.py b/bitbake/lib/bb/ui/__init__.py index c6a377a8e..a4805ed02 100644 --- a/bitbake/lib/bb/ui/__init__.py +++ b/bitbake/lib/bb/ui/__init__.py @@ -15,4 +15,3 @@ # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - diff --git a/bitbake/lib/bb/ui/crumbs/__init__.py b/bitbake/lib/bb/ui/crumbs/__init__.py index c6a377a8e..a4805ed02 100644 --- a/bitbake/lib/bb/ui/crumbs/__init__.py +++ b/bitbake/lib/bb/ui/crumbs/__init__.py @@ -15,4 +15,3 @@ # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - diff --git a/bitbake/lib/bb/ui/crumbs/buildmanager.py b/bitbake/lib/bb/ui/crumbs/buildmanager.py index f89e8eefd..f5a15329d 100644 --- a/bitbake/lib/bb/ui/crumbs/buildmanager.py +++ b/bitbake/lib/bb/ui/crumbs/buildmanager.py @@ -28,7 +28,7 @@ import time class BuildConfiguration: """ Represents a potential *or* historic *or* concrete build. It encompasses all the things that we need to tell bitbake to do to make it - build what we want it to build. + build what we want it to build. It also stored the metadata URL and the set of possible machines (and the distros / images / uris for these. Apart from the metdata URL these are @@ -73,8 +73,8 @@ class BuildConfiguration: return self.urls # It might be a lot lot better if we stored these in like, bitbake conf - # file format. - @staticmethod + # file format. + @staticmethod def load_from_file (filename): f = open (filename, "r") @@ -140,13 +140,13 @@ class BuildResult(gobject.GObject): ".conf" in the directory for the build. This is GObject so that it can be included in the TreeStore.""" - + (STATE_COMPLETE, STATE_FAILED, STATE_ONGOING) = \ (0, 1, 2) def __init__ (self, parent, identifier): gobject.GObject.__init__ (self) - self.date = None + self.date = None self.files = [] self.status = None @@ -181,7 +181,7 @@ class BuildResult(gobject.GObject): self.add_file (file) def add_file (self, file): - # Just add the file for now. Don't care about the type. + # Just add the file for now. Don't care about the type. self.files += [(file, None)] class BuildManagerModel (gtk.TreeStore): @@ -194,7 +194,7 @@ class BuildManagerModel (gtk.TreeStore): def __init__ (self): gtk.TreeStore.__init__ (self, - gobject.TYPE_STRING, + gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, @@ -207,7 +207,7 @@ class BuildManager (gobject.GObject): "results" directory but is also used for starting a new build.""" __gsignals__ = { - 'population-finished' : (gobject.SIGNAL_RUN_LAST, + 'population-finished' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), 'populate-error' : (gobject.SIGNAL_RUN_LAST, @@ -220,13 +220,13 @@ class BuildManager (gobject.GObject): date = long (time.mktime (result.date.timetuple())) # Add a top level entry for the build - - self.model.set (iter, + + self.model.set (iter, BuildManagerModel.COL_IDENT, result.identifier, BuildManagerModel.COL_DESC, result.conf.image, - BuildManagerModel.COL_MACHINE, result.conf.machine, - BuildManagerModel.COL_DISTRO, result.conf.distro, - BuildManagerModel.COL_BUILD_RESULT, result, + BuildManagerModel.COL_MACHINE, result.conf.machine, + BuildManagerModel.COL_DISTRO, result.conf.distro, + BuildManagerModel.COL_BUILD_RESULT, result, BuildManagerModel.COL_DATE, date, BuildManagerModel.COL_STATE, result.state) @@ -257,7 +257,7 @@ class BuildManager (gobject.GObject): while (iter): (ident, state) = self.model.get(iter, - BuildManagerModel.COL_IDENT, + BuildManagerModel.COL_IDENT, BuildManagerModel.COL_STATE) if state == BuildResult.STATE_ONGOING: @@ -422,29 +422,29 @@ class BuildManagerTreeView (gtk.TreeView): # Misc descriptiony thing renderer = gtk.CellRendererText () - col = gtk.TreeViewColumn (None, renderer, + col = gtk.TreeViewColumn (None, renderer, text=BuildManagerModel.COL_DESC) self.append_column (col) # Machine renderer = gtk.CellRendererText () - col = gtk.TreeViewColumn ("Machine", renderer, + col = gtk.TreeViewColumn ("Machine", renderer, text=BuildManagerModel.COL_MACHINE) self.append_column (col) # distro renderer = gtk.CellRendererText () - col = gtk.TreeViewColumn ("Distribution", renderer, + col = gtk.TreeViewColumn ("Distribution", renderer, text=BuildManagerModel.COL_DISTRO) self.append_column (col) # date (using a custom function for formatting the cell contents it # takes epoch -> human readable string) renderer = gtk.CellRendererText () - col = gtk.TreeViewColumn ("Date", renderer, + col = gtk.TreeViewColumn ("Date", renderer, text=BuildManagerModel.COL_DATE) self.append_column (col) - col.set_cell_data_func (renderer, + col.set_cell_data_func (renderer, self.date_format_custom_cell_data_func) # For status. @@ -454,4 +454,3 @@ class BuildManagerTreeView (gtk.TreeView): self.append_column (col) col.set_cell_data_func (renderer, self.state_format_custom_cell_data_fun) - diff --git a/bitbake/lib/bb/ui/crumbs/runningbuild.py b/bitbake/lib/bb/ui/crumbs/runningbuild.py index 18afd6674..79e2c9060 100644 --- a/bitbake/lib/bb/ui/crumbs/runningbuild.py +++ b/bitbake/lib/bb/ui/crumbs/runningbuild.py @@ -24,7 +24,7 @@ import gobject class RunningBuildModel (gtk.TreeStore): (COL_TYPE, COL_PACKAGE, COL_TASK, COL_MESSAGE, COL_ICON, COL_ACTIVE) = (0, 1, 2, 3, 4, 5) def __init__ (self): - gtk.TreeStore.__init__ (self, + gtk.TreeStore.__init__ (self, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, @@ -34,7 +34,7 @@ class RunningBuildModel (gtk.TreeStore): class RunningBuild (gobject.GObject): __gsignals__ = { - 'build-succeeded' : (gobject.SIGNAL_RUN_LAST, + 'build-succeeded' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), 'build-failed' : (gobject.SIGNAL_RUN_LAST, @@ -82,12 +82,12 @@ class RunningBuild (gobject.GObject): # Add the message to the tree either at the top level if parent is # None otherwise as a descendent of a task. - self.model.append (parent, + self.model.append (parent, (event.__name__.split()[-1], # e.g. MsgWarn, MsgError - package, + package, task, event._message, - icon, + icon, False)) elif isinstance(event, bb.build.TaskStarted): (package, task) = (event._package, event._task) @@ -101,10 +101,10 @@ class RunningBuild (gobject.GObject): if (self.tasks_to_iter.has_key ((package, None))): parent = self.tasks_to_iter[(package, None)] else: - parent = self.model.append (None, (None, - package, + parent = self.model.append (None, (None, + package, None, - "Package: %s" % (package), + "Package: %s" % (package), None, False)) self.tasks_to_iter[(package, None)] = parent @@ -114,10 +114,10 @@ class RunningBuild (gobject.GObject): self.model.set(parent, self.model.COL_ICON, "gtk-execute") # Add an entry in the model for this task - i = self.model.append (parent, (None, - package, + i = self.model.append (parent, (None, + package, task, - "Task: %s" % (task), + "Task: %s" % (task), None, False)) @@ -176,5 +176,3 @@ class RunningBuildTreeView (gtk.TreeView): renderer = gtk.CellRendererText () col = gtk.TreeViewColumn ("Message", renderer, text=3) self.append_column (col) - - diff --git a/bitbake/lib/bb/ui/depexp.py b/bitbake/lib/bb/ui/depexp.py index cfa5b6564..c596cad5c 100644 --- a/bitbake/lib/bb/ui/depexp.py +++ b/bitbake/lib/bb/ui/depexp.py @@ -233,7 +233,7 @@ def init(server, eventHandler): x = event.sofar y = event.total if x == y: - print("\nParsing finished. %d cached, %d parsed, %d skipped, %d masked, %d errors." + print("\nParsing finished. %d cached, %d parsed, %d skipped, %d masked, %d errors." % ( event.cached, event.parsed, event.skipped, event.masked, event.errors)) pbar.hide() gtk.gdk.threads_enter() @@ -269,4 +269,3 @@ def init(server, eventHandler): server.runCommand(["stateShutdown"]) shutdown = shutdown + 1 pass - diff --git a/bitbake/lib/bb/ui/goggle.py b/bitbake/lib/bb/ui/goggle.py index 94995d82d..bcba38be9 100644 --- a/bitbake/lib/bb/ui/goggle.py +++ b/bitbake/lib/bb/ui/goggle.py @@ -25,13 +25,13 @@ from bb.ui.crumbs.runningbuild import RunningBuildTreeView, RunningBuild def event_handle_idle_func (eventHandler, build): - # Consume as many messages as we can in the time available to us - event = eventHandler.getEvent() - while event: - build.handle_event (event) - event = eventHandler.getEvent() + # Consume as many messages as we can in the time available to us + event = eventHandler.getEvent() + while event: + build.handle_event (event) + event = eventHandler.getEvent() - return True + return True class MainWindow (gtk.Window): def __init__ (self): @@ -74,4 +74,3 @@ def init (server, eventHandler): running_build) gtk.main() - diff --git a/bitbake/lib/bb/ui/knotty.py b/bitbake/lib/bb/ui/knotty.py index ed26bb2b4..3261792df 100644 --- a/bitbake/lib/bb/ui/knotty.py +++ b/bitbake/lib/bb/ui/knotty.py @@ -132,7 +132,7 @@ def init(server, eventHandler): sys.stdout.write("done.") sys.stdout.flush() if x == y: - print("\nParsing of %d .bb files complete (%d cached, %d parsed). %d targets, %d skipped, %d masked, %d errors." + print("\nParsing of %d .bb files complete (%d cached, %d parsed). %d targets, %d skipped, %d masked, %d errors." % ( event.total, event.cached, event.parsed, event.virtuals, event.skipped, event.masked, event.errors)) continue diff --git a/bitbake/lib/bb/ui/ncurses.py b/bitbake/lib/bb/ui/ncurses.py index da3690e5c..0eb1cf013 100644 --- a/bitbake/lib/bb/ui/ncurses.py +++ b/bitbake/lib/bb/ui/ncurses.py @@ -136,7 +136,7 @@ class NCursesUI: """Thread Activity Window""" def __init__( self, x, y, width, height ): NCursesUI.DecoratedWindow.__init__( self, "Thread Activity", x, y, width, height ) - + def setStatus( self, thread, text ): line = "%02d: %s" % ( thread, text ) width = self.dimensions[WIDTH] @@ -225,7 +225,7 @@ class NCursesUI: helper = uihelper.BBUIHelper() shutdown = 0 - + try: cmdline = server.runCommand(["getCmdLineAction"]) if not cmdline: @@ -263,7 +263,7 @@ class NCursesUI: y = event.total if x == y: mw.setStatus("Idle") - mw.appendText("Parsing finished. %d cached, %d parsed, %d skipped, %d masked." + mw.appendText("Parsing finished. %d cached, %d parsed, %d skipped, %d masked." % ( event.cached, event.parsed, event.skipped, event.masked )) else: mw.setStatus("Parsing: %s (%04d/%04d) [%2d %%]" % ( parsespin.next(), x, y, x*100/y ) ) @@ -332,4 +332,3 @@ def init(server, eventHandler): except: import traceback traceback.print_exc() - diff --git a/bitbake/lib/bb/ui/puccho.py b/bitbake/lib/bb/ui/puccho.py index 713aa1f4a..dfcb0f765 100644 --- a/bitbake/lib/bb/ui/puccho.py +++ b/bitbake/lib/bb/ui/puccho.py @@ -38,7 +38,7 @@ class MetaDataLoader(gobject.GObject): on what machines are available. The distribution and images available for the machine and the the uris to use for building the given machine.""" __gsignals__ = { - 'success' : (gobject.SIGNAL_RUN_LAST, + 'success' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), 'error' : (gobject.SIGNAL_RUN_LAST, @@ -293,7 +293,7 @@ class BuildSetupDialog (gtk.Dialog): if (active_iter): self.configuration.machine = model.get(active_iter, 0)[0] - # Extract the chosen distro from the combo + # Extract the chosen distro from the combo model = self.distribution_combo.get_model() active_iter = self.distribution_combo.get_active_iter() if (active_iter): @@ -311,62 +311,62 @@ class BuildSetupDialog (gtk.Dialog): # # TODO: Should be a method on the RunningBuild class def event_handle_timeout (eventHandler, build): - # Consume as many messages as we can ... - event = eventHandler.getEvent() - while event: - build.handle_event (event) - event = eventHandler.getEvent() - return True + # Consume as many messages as we can ... + event = eventHandler.getEvent() + while event: + build.handle_event (event) + event = eventHandler.getEvent() + return True class MainWindow (gtk.Window): - # Callback that gets fired when the user hits a button in the - # BuildSetupDialog. - def build_dialog_box_response_cb (self, dialog, response_id): - conf = None - if (response_id == BuildSetupDialog.RESPONSE_BUILD): - dialog.update_configuration() - print dialog.configuration.machine, dialog.configuration.distro, \ - dialog.configuration.image - conf = dialog.configuration - - dialog.destroy() - - if conf: - self.manager.do_build (conf) - - def build_button_clicked_cb (self, button): - dialog = BuildSetupDialog () - - # For some unknown reason Dialog.run causes nice little deadlocks ... :-( - dialog.connect ("response", self.build_dialog_box_response_cb) - dialog.show() - - def __init__ (self): - gtk.Window.__init__ (self) - - # Pull in *just* the main vbox from the Glade XML data and then pack - # that inside the window - gxml = gtk.glade.XML (os.path.dirname(__file__) + "/crumbs/puccho.glade", - root = "main_window_vbox") - vbox = gxml.get_widget ("main_window_vbox") - self.add (vbox) - - # Create the tree views for the build manager view and the progress view - self.build_manager_view = BuildManagerTreeView() - self.running_build_view = RunningBuildTreeView() - - # Grab the scrolled windows that we put the tree views into - self.results_scrolledwindow = gxml.get_widget ("results_scrolledwindow") - self.progress_scrolledwindow = gxml.get_widget ("progress_scrolledwindow") - - # Put the tree views inside ... - self.results_scrolledwindow.add (self.build_manager_view) - self.progress_scrolledwindow.add (self.running_build_view) - - # Hook up the build button... - self.build_button = gxml.get_widget ("main_toolbutton_build") - self.build_button.connect ("clicked", self.build_button_clicked_cb) + # Callback that gets fired when the user hits a button in the + # BuildSetupDialog. + def build_dialog_box_response_cb (self, dialog, response_id): + conf = None + if (response_id == BuildSetupDialog.RESPONSE_BUILD): + dialog.update_configuration() + print dialog.configuration.machine, dialog.configuration.distro, \ + dialog.configuration.image + conf = dialog.configuration + + dialog.destroy() + + if conf: + self.manager.do_build (conf) + + def build_button_clicked_cb (self, button): + dialog = BuildSetupDialog () + + # For some unknown reason Dialog.run causes nice little deadlocks ... :-( + dialog.connect ("response", self.build_dialog_box_response_cb) + dialog.show() + + def __init__ (self): + gtk.Window.__init__ (self) + + # Pull in *just* the main vbox from the Glade XML data and then pack + # that inside the window + gxml = gtk.glade.XML (os.path.dirname(__file__) + "/crumbs/puccho.glade", + root = "main_window_vbox") + vbox = gxml.get_widget ("main_window_vbox") + self.add (vbox) + + # Create the tree views for the build manager view and the progress view + self.build_manager_view = BuildManagerTreeView() + self.running_build_view = RunningBuildTreeView() + + # Grab the scrolled windows that we put the tree views into + self.results_scrolledwindow = gxml.get_widget ("results_scrolledwindow") + self.progress_scrolledwindow = gxml.get_widget ("progress_scrolledwindow") + + # Put the tree views inside ... + self.results_scrolledwindow.add (self.build_manager_view) + self.progress_scrolledwindow.add (self.running_build_view) + + # Hook up the build button... + self.build_button = gxml.get_widget ("main_toolbutton_build") + self.build_button.connect ("clicked", self.build_button_clicked_cb) # I'm not very happy about the current ownership of the RunningBuild. I have # my suspicions that this object should be held by the BuildManager since we diff --git a/bitbake/lib/bb/ui/uievent.py b/bitbake/lib/bb/ui/uievent.py index 36302f4da..5b3efffcb 100644 --- a/bitbake/lib/bb/ui/uievent.py +++ b/bitbake/lib/bb/ui/uievent.py @@ -19,7 +19,7 @@ """ -Use this class to fork off a thread to recieve event callbacks from the bitbake +Use this class to fork off a thread to recieve event callbacks from the bitbake server and queue them for the UI to process. This process must be used to avoid client/server deadlocks. """ @@ -116,10 +116,9 @@ class UIXMLRPCServer (SimpleXMLRPCServer): if request is None: return SimpleXMLRPCServer.close_request(self, request) - + def process_request(self, request, client_address): if request is None: return SimpleXMLRPCServer.process_request(self, request, client_address) - diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 5015ee440..93c158c60 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py @@ -19,11 +19,12 @@ BitBake Utility Functions # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -separators = ".-" - import re, fcntl, os, types, bb, string, stat, shutil, time from commands import getstatusoutput +# Version comparison +separators = ".-" + # Context used in better_exec, eval _context = { "os": os, @@ -92,19 +93,19 @@ def vercmp(ta, tb): r = vercmp_part(ra, rb) return r -_package_weights_ = {"pre":-2,"p":0,"alpha":-4,"beta":-3,"rc":-1} # dicts are unordered -_package_ends_ = ["pre", "p", "alpha", "beta", "rc", "cvs", "bk", "HEAD" ] # so we need ordered list +_package_weights_ = {"pre":-2, "p":0, "alpha":-4, "beta":-3, "rc":-1} # dicts are unordered +_package_ends_ = ["pre", "p", "alpha", "beta", "rc", "cvs", "bk", "HEAD" ] # so we need ordered list def relparse(myver): """Parses the last elements of a version number into a triplet, that can later be compared. """ - number = 0 - p1 = 0 - p2 = 0 + number = 0 + p1 = 0 + p2 = 0 mynewver = myver.split('_') - if len(mynewver)==2: + if len(mynewver) == 2: # an _package_weights_ number = float(mynewver[0]) match = 0 @@ -132,15 +133,15 @@ def relparse(myver): divider = len(myver)-1 if myver[divider:] not in "1234567890": #letter at end - p1 = ord(myver[divider:]) + p1 = ord(myver[divider:]) number = float(myver[0:divider]) else: number = float(myver) - return [number,p1,p2] + return [number, p1, p2] __vercmp_cache__ = {} -def vercmp_string(val1,val2): +def vercmp_string(val1, val2): """This takes two version strings and returns an integer to tell you whether the versions are the same, val1>val2 or val2>val1. """ @@ -148,13 +149,13 @@ def vercmp_string(val1,val2): # quick short-circuit if val1 == val2: return 0 - valkey = val1+" "+val2 + valkey = val1 + " " + val2 # cache lookup try: return __vercmp_cache__[valkey] try: - return - __vercmp_cache__[val2+" "+val1] + return - __vercmp_cache__[val2 + " " + val1] except KeyError: pass except KeyError: @@ -175,21 +176,21 @@ def vercmp_string(val1,val2): # replace '-' by '.' # FIXME: Is it needed? can val1/2 contain '-'? - val1 = string.split(val1,'-') + val1 = val1.split("-") if len(val1) == 2: - val1[0] = val1[0] +"."+ val1[1] - val2 = string.split(val2,'-') + val1[0] = val1[0] + "." + val1[1] + val2 = val2.split("-") if len(val2) == 2: - val2[0] = val2[0] +"."+ val2[1] + val2[0] = val2[0] + "." + val2[1] - val1 = string.split(val1[0],'.') - val2 = string.split(val2[0],'.') + val1 = val1[0].split('.') + val2 = val2[0].split('.') # add back decimal point so that .03 does not become "3" ! - for x in range(1,len(val1)): + for x in range(1, len(val1)): if val1[x][0] == '0' : val1[x] = '.' + val1[x] - for x in range(1,len(val2)): + for x in range(1, len(val2)): if val2[x][0] == '0' : val2[x] = '.' + val2[x] @@ -206,10 +207,10 @@ def vercmp_string(val1,val2): val2[-1] += '_' + val2_prepart # The above code will extend version numbers out so they # have the same number of digits. - for x in range(0,len(val1)): + for x in range(0, len(val1)): cmp1 = relparse(val1[x]) cmp2 = relparse(val2[x]) - for y in range(0,3): + for y in range(0, 3): myret = cmp1[y] - cmp2[y] if myret != 0: __vercmp_cache__[valkey] = myret @@ -290,9 +291,9 @@ def _print_trace(body, line): # print the environment of the method bb.msg.error(bb.msg.domain.Util, "Printing the environment of the function") - min_line = max(1,line-4) - max_line = min(line+4,len(body)-1) - for i in range(min_line,max_line+1): + min_line = max(1, line-4) + max_line = min(line + 4, len(body)-1) + for i in range(min_line, max_line + 1): bb.msg.error(bb.msg.domain.Util, "\t%.4d:%s" % (i, body[i-1]) ) @@ -304,7 +305,7 @@ def better_compile(text, file, realfile, mode = "exec"): try: return compile(text, file, mode) except Exception, e: - import bb,sys + import bb, sys # split the text into lines again body = text.split('\n') @@ -323,18 +324,18 @@ def better_exec(code, context, text, realfile): print the lines that are responsible for the error. """ - import bb,sys + import bb, sys try: exec code in _context, context except: - (t,value,tb) = sys.exc_info() + (t, value, tb) = sys.exc_info() if t in [bb.parse.SkipPackage, bb.build.FuncFailed]: raise # print the Header of the Error Message bb.msg.error(bb.msg.domain.Util, "Error in executing python function in: %s" % realfile) - bb.msg.error(bb.msg.domain.Util, "Exception:%s Message:%s" % (t,value) ) + bb.msg.error(bb.msg.domain.Util, "Exception:%s Message:%s" % (t, value)) # let us find the line number now while tb.tb_next: @@ -344,7 +345,7 @@ def better_exec(code, context, text, realfile): line = traceback.tb_lineno(tb) _print_trace( text.split('\n'), line ) - + raise def simple_exec(code, context): @@ -367,22 +368,22 @@ def lockfile(name): while True: # If we leave the lockfiles lying around there is no problem # but we should clean up after ourselves. This gives potential - # for races though. To work around this, when we acquire the lock - # we check the file we locked was still the lock file on disk. - # by comparing inode numbers. If they don't match or the lockfile + # for races though. To work around this, when we acquire the lock + # we check the file we locked was still the lock file on disk. + # by comparing inode numbers. If they don't match or the lockfile # no longer exists, we start again. - # This implementation is unfair since the last person to request the + # This implementation is unfair since the last person to request the # lock is the most likely to win it. try: - lf = open(name, "a+") + lf = open(name, "a + ") fcntl.flock(lf.fileno(), fcntl.LOCK_EX) statinfo = os.fstat(lf.fileno()) if os.path.exists(lf.name): - statinfo2 = os.stat(lf.name) - if statinfo.st_ino == statinfo2.st_ino: - return lf + statinfo2 = os.stat(lf.name) + if statinfo.st_ino == statinfo2.st_ino: + return lf # File no longer exists or changed, retry lf.close except Exception, e: @@ -390,7 +391,7 @@ def lockfile(name): def unlockfile(lf): """ - Unlock a file locked using lockfile() + Unlock a file locked using lockfile() """ os.unlink(lf.name) fcntl.flock(lf.fileno(), fcntl.LOCK_UN) @@ -406,7 +407,7 @@ def md5_file(filename): except ImportError: import md5 m = md5.new() - + for line in open(filename): m.update(line) return m.hexdigest() @@ -472,7 +473,7 @@ def filter_environment(good_vars): for key in os.environ.keys(): if key in good_vars: continue - + removed_vars.append(key) os.unsetenv(key) del os.environ[key] @@ -517,7 +518,7 @@ def build_environment(d): def prunedir(topdir): # Delete everything reachable from the directory named in 'topdir'. # CAUTION: This is dangerous! - for root, dirs, files in os.walk(topdir, topdown=False): + for root, dirs, files in os.walk(topdir, topdown = False): for name in files: os.remove(os.path.join(root, name)) for name in dirs: @@ -532,7 +533,7 @@ def prunedir(topdir): # but thats possibly insane and suffixes is probably going to be small # def prune_suffix(var, suffixes, d): - # See if var ends with any of the suffixes listed and + # See if var ends with any of the suffixes listed and # remove it if found for suffix in suffixes: if var.endswith(suffix): @@ -553,42 +554,42 @@ def mkdirhier(dir): import stat -def movefile(src,dest,newmtime=None,sstat=None): +def movefile(src, dest, newmtime = None, sstat = None): """Moves a file from src to dest, preserving all permissions and attributes; mtime will be preserved even when moving across filesystems. Returns true on success and false on failure. Move is atomic. """ - #print "movefile("+src+","+dest+","+str(newmtime)+","+str(sstat)+")" + #print "movefile(" + src + "," + dest + "," + str(newmtime) + "," + str(sstat) + ")" try: if not sstat: - sstat=os.lstat(src) + sstat = os.lstat(src) except Exception, e: print "movefile: Stating source file failed...", e return None - destexists=1 + destexists = 1 try: - dstat=os.lstat(dest) + dstat = os.lstat(dest) except: - dstat=os.lstat(os.path.dirname(dest)) - destexists=0 + dstat = os.lstat(os.path.dirname(dest)) + destexists = 0 if destexists: if stat.S_ISLNK(dstat[stat.ST_MODE]): try: os.unlink(dest) - destexists=0 + destexists = 0 except Exception, e: pass if stat.S_ISLNK(sstat[stat.ST_MODE]): try: - target=os.readlink(src) + target = os.readlink(src) if destexists and not stat.S_ISDIR(dstat[stat.ST_MODE]): os.unlink(dest) - os.symlink(target,dest) + os.symlink(target, dest) #os.lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID]) os.unlink(src) return os.lstat(dest) @@ -596,38 +597,38 @@ def movefile(src,dest,newmtime=None,sstat=None): print "movefile: failed to properly create symlink:", dest, "->", target, e return None - renamefailed=1 - if sstat[stat.ST_DEV]==dstat[stat.ST_DEV]: + renamefailed = 1 + if sstat[stat.ST_DEV] == dstat[stat.ST_DEV]: try: - ret=os.rename(src,dest) - renamefailed=0 + ret = os.rename(src, dest) + renamefailed = 0 except Exception, e: import errno - if e[0]!=errno.EXDEV: + if e[0] != errno.EXDEV: # Some random error. print "movefile: Failed to move", src, "to", dest, e return None # Invalid cross-device-link 'bind' mounted or actually Cross-Device if renamefailed: - didcopy=0 + didcopy = 0 if stat.S_ISREG(sstat[stat.ST_MODE]): try: # For safety copy then move it over. - shutil.copyfile(src,dest+"#new") - os.rename(dest+"#new",dest) - didcopy=1 + shutil.copyfile(src, dest + "#new") + os.rename(dest + "#new", dest) + didcopy = 1 except Exception, e: print 'movefile: copy', src, '->', dest, 'failed.', e return None else: #we don't yet handle special, so we need to fall back to /bin/mv - a=getstatusoutput("/bin/mv -f "+"'"+src+"' '"+dest+"'") - if a[0]!=0: + a = getstatusoutput("/bin/mv -f " + "'" + src + "' '" + dest + "'") + if a[0] != 0: print "movefile: Failed to move special file:" + src + "' to '" + dest + "'", a return None # failure try: if didcopy: - os.lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID]) + os.lchown(dest, sstat[stat.ST_UID], sstat[stat.ST_GID]) os.chmod(dest, stat.S_IMODE(sstat[stat.ST_MODE])) # Sticky is reset on chown os.unlink(src) except Exception, e: @@ -635,47 +636,47 @@ def movefile(src,dest,newmtime=None,sstat=None): return None if newmtime: - os.utime(dest,(newmtime,newmtime)) + os.utime(dest, (newmtime, newmtime)) else: os.utime(dest, (sstat[stat.ST_ATIME], sstat[stat.ST_MTIME])) - newmtime=sstat[stat.ST_MTIME] + newmtime = sstat[stat.ST_MTIME] return newmtime -def copyfile(src,dest,newmtime=None,sstat=None): +def copyfile(src, dest, newmtime = None, sstat = None): """ Copies a file from src to dest, preserving all permissions and attributes; mtime will be preserved even when moving across filesystems. Returns true on success and false on failure. """ - #print "copyfile("+src+","+dest+","+str(newmtime)+","+str(sstat)+")" + #print "copyfile(" + src + "," + dest + "," + str(newmtime) + "," + str(sstat) + ")" try: if not sstat: - sstat=os.lstat(src) + sstat = os.lstat(src) except Exception, e: print "copyfile: Stating source file failed...", e return False - destexists=1 + destexists = 1 try: - dstat=os.lstat(dest) + dstat = os.lstat(dest) except: - dstat=os.lstat(os.path.dirname(dest)) - destexists=0 + dstat = os.lstat(os.path.dirname(dest)) + destexists = 0 if destexists: if stat.S_ISLNK(dstat[stat.ST_MODE]): try: os.unlink(dest) - destexists=0 + destexists = 0 except Exception, e: pass if stat.S_ISLNK(sstat[stat.ST_MODE]): try: - target=os.readlink(src) + target = os.readlink(src) if destexists and not stat.S_ISDIR(dstat[stat.ST_MODE]): os.unlink(dest) - os.symlink(target,dest) + os.symlink(target, dest) #os.lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID]) return os.lstat(dest) except Exception, e: @@ -683,30 +684,30 @@ def copyfile(src,dest,newmtime=None,sstat=None): return False if stat.S_ISREG(sstat[stat.ST_MODE]): - try: # For safety copy then move it over. - shutil.copyfile(src,dest+"#new") - os.rename(dest+"#new",dest) - except Exception, e: - print 'copyfile: copy', src, '->', dest, 'failed.', e - return False + try: # For safety copy then move it over. + shutil.copyfile(src, dest + "#new") + os.rename(dest + "#new", dest) + except Exception, e: + print 'copyfile: copy', src, '->', dest, 'failed.', e + return False else: - #we don't yet handle special, so we need to fall back to /bin/mv - a=getstatusoutput("/bin/cp -f "+"'"+src+"' '"+dest+"'") - if a[0]!=0: - print "copyfile: Failed to copy special file:" + src + "' to '" + dest + "'", a - return False # failure + #we don't yet handle special, so we need to fall back to /bin/mv + a = getstatusoutput("/bin/cp -f " + "'" + src + "' '" + dest + "'") + if a[0] != 0: + print "copyfile: Failed to copy special file:" + src + "' to '" + dest + "'", a + return False # failure try: - os.lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID]) + os.lchown(dest, sstat[stat.ST_UID], sstat[stat.ST_GID]) os.chmod(dest, stat.S_IMODE(sstat[stat.ST_MODE])) # Sticky is reset on chown except Exception, e: print "copyfile: Failed to chown/chmod/unlink", dest, e return False if newmtime: - os.utime(dest,(newmtime,newmtime)) + os.utime(dest, (newmtime, newmtime)) else: os.utime(dest, (sstat[stat.ST_ATIME], sstat[stat.ST_MTIME])) - newmtime=sstat[stat.ST_MTIME] + newmtime = sstat[stat.ST_MTIME] return newmtime def which(path, item, direction = 0): |