]> code.ossystems Code Review - openembedded-core.git/commitdiff
Apply some 2to3 transforms that don't cause issues in 2.6
authorChris Larson <chris_larson@mentor.com>
Mon, 12 Apr 2010 00:03:55 +0000 (17:03 -0700)
committerRichard Purdie <rpurdie@linux.intel.com>
Fri, 2 Jul 2010 14:41:33 +0000 (15:41 +0100)
(Bitbake rev: d39ab776e7ceaefc8361150151cf0892dcb70d9c)

Signed-off-by: Chris Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
26 files changed:
bitbake/lib/bb/build.py
bitbake/lib/bb/cache.py
bitbake/lib/bb/daemonize.py
bitbake/lib/bb/data.py
bitbake/lib/bb/data_smart.py
bitbake/lib/bb/fetch/cvs.py
bitbake/lib/bb/fetch/perforce.py
bitbake/lib/bb/fetch/wget.py
bitbake/lib/bb/parse/__init__.py
bitbake/lib/bb/parse/ast.py
bitbake/lib/bb/parse/parse_py/BBHandler.py
bitbake/lib/bb/parse/parse_py/ConfHandler.py
bitbake/lib/bb/persist_data.py
bitbake/lib/bb/runqueue.py
bitbake/lib/bb/server/none.py
bitbake/lib/bb/server/xmlrpc.py
bitbake/lib/bb/taskdata.py
bitbake/lib/bb/ui/crumbs/buildmanager.py
bitbake/lib/bb/ui/crumbs/runningbuild.py
bitbake/lib/bb/ui/depexp.py
bitbake/lib/bb/ui/goggle.py
bitbake/lib/bb/ui/knotty.py
bitbake/lib/bb/ui/ncurses.py
bitbake/lib/bb/ui/puccho.py
bitbake/lib/bb/ui/uievent.py
bitbake/lib/bb/utils.py

index 3d7101399891eda6fa509c478d78f2fda331b3f2..4f14e63ac7e25283c7872bd2d262d69c4ce535b8 100644 (file)
@@ -140,7 +140,7 @@ def exec_func(func, d, dirs = None):
             so = os.popen("tee \"%s\"" % logfile, "w")
         else:
             so = file(logfile, 'w')
-    except OSError, e:
+    except OSError as e:
         bb.msg.error(bb.msg.domain.Build, "opening log file: %s" % e)
         pass
 
@@ -285,7 +285,7 @@ def exec_task(task, d):
         event.fire(TaskStarted(task, localdata), localdata)
         exec_func(task, localdata)
         event.fire(TaskSucceeded(task, localdata), localdata)
-    except FuncFailed, message:
+    except FuncFailed as message:
         # Try to extract the optional logfile
         try:
             (msg, logfile) = message
index 0d165aec2f2eb305a4ca93ec6e40cc8f1dd3e62c..6e124b2e83c1008454072f64e2dd0a5365b78d86 100644 (file)
@@ -61,7 +61,7 @@ class Cache:
             return
 
         self.has_cache = True
-        self.cachefile = os.path.join(self.cachedir,"bb_cache.dat")
+        self.cachefile = os.path.join(self.cachedir, "bb_cache.dat")
 
         bb.msg.debug(1, bb.msg.domain.Cache, "Using cache in '%s'" % self.cachedir)
         try:
@@ -82,9 +82,9 @@ class Cache:
                 p = pickle.Unpickler(file(self.cachefile, "rb"))
                 self.depends_cache, version_data = p.load()
                 if version_data['CACHE_VER'] != __cache_version__:
-                    raise ValueError, 'Cache Version Mismatch'
+                    raise ValueError('Cache Version Mismatch')
                 if version_data['BITBAKE_VER'] != bb.__version__:
-                    raise ValueError, 'Bitbake Version Mismatch'
+                    raise ValueError('Bitbake Version Mismatch')
             except EOFError:
                 bb.msg.note(1, bb.msg.domain.Cache, "Truncated cache found, rebuilding...")
                 self.depends_cache = {}
@@ -446,7 +446,7 @@ class Cache:
         self.getVar('__BB_DONT_CACHE', file_name, True)
         self.getVar('__VARIANTS', file_name, True)
 
-    def load_bbfile( self, bbfile , config):
+    def load_bbfile( self, bbfile, config):
         """
         Load and parse one .bb build file
         Return the data and whether parsing resulted in the file being skipped
index a944af22385655a44bc498c9cc0546b1c710113c..f0714b3af6166048585bfd963aef75ee8f45b262 100644 (file)
-"""\r
-Python Deamonizing helper\r
-\r
-Configurable daemon behaviors:\r
-\r
-    1.) The current working directory set to the "/" directory.\r
-    2.) The current file creation mode mask set to 0.\r
-    3.) Close all open files (1024). \r
-    4.) Redirect standard I/O streams to "/dev/null".\r
-\r
-A failed call to fork() now raises an exception.\r
-\r
-References:\r
-    1) Advanced Programming in the Unix Environment: W. Richard Stevens\r
-    2) Unix Programming Frequently Asked Questions:\r
-            http://www.erlenstar.demon.co.uk/unix/faq_toc.html\r
-\r
-Modified to allow a function to be daemonized and return for \r
-bitbake use by Richard Purdie\r
-"""\r
-\r
-__author__ = "Chad J. Schroeder"\r
-__copyright__ = "Copyright (C) 2005 Chad J. Schroeder"\r
-__version__ = "0.2"\r
-\r
-# Standard Python modules.\r
-import os                    # Miscellaneous OS interfaces.\r
-import sys                  # System-specific parameters and functions.\r
-\r
-# Default daemon parameters.\r
-# File mode creation mask of the daemon.\r
-# For BitBake's children, we do want to inherit the parent umask.\r
-UMASK = None\r
-\r
-# Default maximum for the number of available file descriptors.\r
-MAXFD = 1024\r
-\r
-# The standard I/O file descriptors are redirected to /dev/null by default.\r
-if (hasattr(os, "devnull")):\r
-    REDIRECT_TO = os.devnull\r
-else:\r
-    REDIRECT_TO = "/dev/null"\r
-\r
-def createDaemon(function, logfile):\r
-    """\r
-    Detach a process from the controlling terminal and run it in the\r
-    background as a daemon, returning control to the caller.\r
-    """\r
-\r
-    try:\r
-        # Fork a child process so the parent can exit.  This returns control to\r
-        # the command-line or shell.  It also guarantees that the child will not\r
-        # be a process group leader, since the child receives a new process ID\r
-        # and inherits the parent's process group ID.  This step is required\r
-        # to insure that the next call to os.setsid is successful.\r
-        pid = os.fork()\r
-    except OSError, e:\r
-        raise Exception, "%s [%d]" % (e.strerror, e.errno)\r
-\r
-    if (pid == 0):      # The first child.\r
-        # To become the session leader of this new session and the process group\r
-        # leader of the new process group, we call os.setsid().  The process is\r
-        # also guaranteed not to have a controlling terminal.\r
-        os.setsid()\r
-\r
-        # Is ignoring SIGHUP necessary?\r
-        #\r
-        # It's often suggested that the SIGHUP signal should be ignored before\r
-        # the second fork to avoid premature termination of the process.  The\r
-        # reason is that when the first child terminates, all processes, e.g.\r
-        # the second child, in the orphaned group will be sent a SIGHUP.\r
-        #\r
-        # "However, as part of the session management system, there are exactly\r
-        # two cases where SIGHUP is sent on the death of a process:\r
-        #\r
-        #    1) When the process that dies is the session leader of a session that\r
-        #        is attached to a terminal device, SIGHUP is sent to all processes\r
-        #        in the foreground process group of that terminal device.\r
-        #    2) When the death of a process causes a process group to become\r
-        #        orphaned, and one or more processes in the orphaned group are\r
-        #        stopped, then SIGHUP and SIGCONT are sent to all members of the\r
-        #        orphaned group." [2]\r
-        #\r
-        # The first case can be ignored since the child is guaranteed not to have\r
-        # a controlling terminal.  The second case isn't so easy to dismiss.\r
-        # The process group is orphaned when the first child terminates and\r
-        # POSIX.1 requires that every STOPPED process in an orphaned process\r
-        # group be sent a SIGHUP signal followed by a SIGCONT signal.  Since the\r
-        # second child is not STOPPED though, we can safely forego ignoring the\r
-        # SIGHUP signal.  In any case, there are no ill-effects if it is ignored.\r
-        #\r
-        # import signal              # Set handlers for asynchronous events.\r
-        # signal.signal(signal.SIGHUP, signal.SIG_IGN)\r
-\r
-        try:\r
-            # Fork a second child and exit immediately to prevent zombies.  This\r
-            # causes the second child process to be orphaned, making the init\r
-            # process responsible for its cleanup.  And, since the first child is\r
-            # a session leader without a controlling terminal, it's possible for\r
-            # it to acquire one by opening a terminal in the future (System V-\r
-            # based systems).  This second fork guarantees that the child is no\r
-            # longer a session leader, preventing the daemon from ever acquiring\r
-            # a controlling terminal.\r
-            pid = os.fork()     # Fork a second child.\r
-        except OSError, e:\r
-            raise Exception, "%s [%d]" % (e.strerror, e.errno)\r
-\r
-        if (pid == 0):  # The second child.\r
-            # We probably don't want the file mode creation mask inherited from\r
-            # the parent, so we give the child complete control over permissions.\r
-            if UMASK is not None:\r
-                os.umask(UMASK)\r
-        else:\r
-            # Parent (the first child) of the second child.\r
-            os._exit(0)\r
-    else:\r
-        # exit() or _exit()?\r
-        # _exit is like exit(), but it doesn't call any functions registered\r
-        # with atexit (and on_exit) or any registered signal handlers.  It also\r
-        # closes any open file descriptors.  Using exit() may cause all stdio\r
-        # streams to be flushed twice and any temporary files may be unexpectedly\r
-        # removed.  It's therefore recommended that child branches of a fork()\r
-        # and the parent branch(es) of a daemon use _exit().\r
-        return\r
-\r
-    # Close all open file descriptors.  This prevents the child from keeping\r
-    # open any file descriptors inherited from the parent.  There is a variety\r
-    # of methods to accomplish this task.  Three are listed below.\r
-    #\r
-    # Try the system configuration variable, SC_OPEN_MAX, to obtain the maximum\r
-    # number of open file descriptors to close.  If it doesn't exists, use\r
-    # the default value (configurable).\r
-    #\r
-    # try:\r
-    #     maxfd = os.sysconf("SC_OPEN_MAX")\r
-    # except (AttributeError, ValueError):\r
-    #     maxfd = MAXFD\r
-    #\r
-    # OR\r
-    #\r
-    # if (os.sysconf_names.has_key("SC_OPEN_MAX")):\r
-    #     maxfd = os.sysconf("SC_OPEN_MAX")\r
-    # else:\r
-    #     maxfd = MAXFD\r
-    #\r
-    # OR\r
-    #\r
-    # Use the getrlimit method to retrieve the maximum file descriptor number\r
-    # that can be opened by this process.  If there is not limit on the\r
-    # resource, use the default value.\r
-    #\r
-    import resource             # Resource usage information.\r
-    maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]\r
-    if (maxfd == resource.RLIM_INFINITY):\r
-        maxfd = MAXFD\r
-  \r
-    # Iterate through and close all file descriptors.\r
-#    for fd in range(0, maxfd):\r
-#        try:\r
-#            os.close(fd)\r
-#        except OSError:        # ERROR, fd wasn't open to begin with (ignored)\r
-#            pass\r
-\r
-    # Redirect the standard I/O file descriptors to the specified file.  Since\r
-    # the daemon has no controlling terminal, most daemons redirect stdin,\r
-    # stdout, and stderr to /dev/null.  This is done to prevent side-effects\r
-    # from reads and writes to the standard I/O file descriptors.\r
-\r
-    # This call to open is guaranteed to return the lowest file descriptor,\r
-    # which will be 0 (stdin), since it was closed above.\r
-#    os.open(REDIRECT_TO, os.O_RDWR)    # standard input (0)\r
-\r
-    # Duplicate standard input to standard output and standard error.\r
-#    os.dup2(0, 1)                      # standard output (1)\r
-#    os.dup2(0, 2)                      # standard error (2)\r
-\r
-\r
-    si = file('/dev/null', 'r')\r
-    so = file(logfile, 'w')\r
-    se = so\r
-\r
-\r
-    # Replace those fds with our own\r
-    os.dup2(si.fileno(), sys.stdin.fileno())\r
-    os.dup2(so.fileno(), sys.stdout.fileno())\r
-    os.dup2(se.fileno(), sys.stderr.fileno())\r
-\r
-    function()\r
-\r
-    os._exit(0)\r
+"""
+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".
+
+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
+
+Modified to allow a function to be daemonized and return for 
+bitbake use by Richard Purdie
+"""
+
+__author__ = "Chad J. Schroeder"
+__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.
+
+# Default daemon parameters.
+# File mode creation mask of the daemon.
+# For BitBake's children, we do want to inherit the parent umask.
+UMASK = None
+
+# Default maximum for the number of available file descriptors.
+MAXFD = 1024
+
+# The standard I/O file descriptors are redirected to /dev/null by default.
+if (hasattr(os, "devnull")):
+    REDIRECT_TO = os.devnull
+else:
+    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 as 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 as 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
+
+    # 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)
+
+    # 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
+
+
+    # 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)
index 85de6bfeb3cbaff594d02d5bf0b8fa2e8e04d79c..e401c53429e32b4cb007eb3a59957ba8d5c8c34c 100644 (file)
@@ -193,7 +193,7 @@ def emit_var(var, o=sys.__stdout__, d = init(), all=False):
     if all:
         o.write('# %s=%s\n' % (var, oval))
 
-    if type(val) is not types.StringType:
+    if not isinstance(val, types.StringType):
         return 0
 
     if (var.find("-") != -1 or var.find(".") != -1 or var.find('{') != -1 or var.find('}') != -1 or var.find('+') != -1) and not all:
index 2edeec064eb19b0e6cc54b9ab4ae67aa9a5e8132..1704ed631ca6ccee4492ce56ca455e58f0223c86 100644 (file)
@@ -66,10 +66,10 @@ class DataSmart:
             code = match.group()[3:-1]
             codeobj = compile(code.strip(), varname or "<expansion>", "eval")
             s = utils.better_eval(codeobj, {"d": self})
-            if type(s) == types.IntType: s = str(s)
+            if isinstance(s, types.IntType): s = str(s)
             return s
 
-        if type(s) is not types.StringType: # sanity check
+        if not isinstance(s, types.StringType): # sanity check
             return s
 
         if varname and varname in self.expand_cache:
@@ -81,7 +81,7 @@ class DataSmart:
                 s = __expand_var_regexp__.sub(var_sub, s)
                 s = __expand_python_regexp__.sub(python_sub, s)
                 if s == olds: break
-                if type(s) is not types.StringType: # sanity check
+                if not isinstance(s, types.StringType): # sanity check
                     bb.msg.error(bb.msg.domain.Data, 'expansion of %s returned non-string %s' % (olds, s))
             except KeyboardInterrupt:
                 raise
@@ -118,7 +118,7 @@ class DataSmart:
             l    = len(o)+1
 
             # see if one should even try
-            if not self._seen_overrides.has_key(o):
+            if o not in self._seen_overrides:
                 continue
 
             vars = self._seen_overrides[o]
@@ -130,7 +130,7 @@ class DataSmart:
                     bb.msg.note(1, bb.msg.domain.Data, "Untracked delVar")
 
         # now on to the appends and prepends
-        if self._special_values.has_key("_append"):
+        if "_append" in self._special_values:
             appends = self._special_values['_append'] or []
             for append in appends:
                 for (a, o) in self.getVarFlag(append, '_append') or []:
@@ -145,7 +145,7 @@ class DataSmart:
                     self.setVar(append, sval)
 
 
-        if self._special_values.has_key("_prepend"):
+        if "_prepend" in self._special_values:
             prepends = self._special_values['_prepend'] or []
 
             for prepend in prepends:
@@ -215,7 +215,7 @@ class DataSmart:
         # more cookies for the cookie monster
         if '_' in var:
             override = var[var.rfind('_')+1:]
-            if not self._seen_overrides.has_key(override):
+            if override not in self._seen_overrides:
                 self._seen_overrides[override] = set()
             self._seen_overrides[override].add( var )
 
@@ -246,7 +246,7 @@ class DataSmart:
             dest.extend(src)
             self.setVarFlag(newkey, i, dest)
 
-            if self._special_values.has_key(i) and key in self._special_values[i]:
+            if i in self._special_values and key in self._special_values[i]:
                 self._special_values[i].remove(key)
                 self._special_values[i].add(newkey)
 
index c0d43618f98d6601cfdcc2c4aead74d884c88f34..61976f7ef48f094feed9c2cbb5304c0eb7668a8a 100644 (file)
@@ -139,8 +139,8 @@ class Cvs(Fetch):
         bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: checking for module directory")
         pkg = data.expand('${PN}', d)
         pkgdir = os.path.join(data.expand('${CVSDIR}', localdata), pkg)
-        moddir = os.path.join(pkgdir,localdir)
-        if os.access(os.path.join(moddir,'CVS'), os.R_OK):
+        moddir = os.path.join(pkgdir, localdir)
+        if os.access(os.path.join(moddir, 'CVS'), os.R_OK):
             bb.msg.note(1, bb.msg.domain.Fetcher, "Update " + loc)
             # update sources there
             os.chdir(moddir)
index 67de6f59fa9105971371b9f722d127e48d44a8c2..5b6c60187608f71720249de45671c8cb6b5904ec 100644 (file)
@@ -35,15 +35,15 @@ class Perforce(Fetch):
     def supports(self, url, ud, d):
         return ud.type in ['p4']
 
-    def doparse(url,d):
+    def doparse(url, d):
         parm = {}
         path = url.split("://")[1]
         delim = path.find("@");
         if delim != -1:
-            (user,pswd,host,port) = path.split('@')[0].split(":")
+            (user, pswd, host, port) = path.split('@')[0].split(":")
             path = path.split('@')[1]
         else:
-            (host,port) = data.getVar('P4PORT', d).split(':')
+            (host, port) = data.getVar('P4PORT', d).split(':')
             user = ""
             pswd = ""
 
@@ -53,19 +53,19 @@ class Perforce(Fetch):
             plist = path.split(';')
             for item in plist:
                 if item.count('='):
-                    (key,value) = item.split('=')
+                    (key, value) = item.split('=')
                     keys.append(key)
                     values.append(value)
 
-            parm = dict(zip(keys,values))
+            parm = dict(zip(keys, values))
         path = "//" + path.split(';')[0]
         host += ":%s" % (port)
         parm["cset"] = Perforce.getcset(d, path, host, user, pswd, parm)
 
-        return host,path,user,pswd,parm
+        return host, path, user, pswd, parm
     doparse = staticmethod(doparse)
 
-    def getcset(d, depot,host,user,pswd,parm):
+    def getcset(d, depot, host, user, pswd, parm):
         p4opt = ""
         if "cset" in parm:
             return parm["cset"];
@@ -97,7 +97,7 @@ class Perforce(Fetch):
 
     def localpath(self, url, ud, d):
 
-        (host,path,user,pswd,parm) = Perforce.doparse(url,d)
+        (host, path, user, pswd, parm) = Perforce.doparse(url, d)
 
         # If a label is specified, we use that as our filename
 
@@ -115,7 +115,7 @@ class Perforce(Fetch):
 
         cset = Perforce.getcset(d, path, host, user, pswd, parm)
 
-        ud.localfile = data.expand('%s+%s+%s.tar.gz' % (host,base.replace('/', '.'), cset), d)
+        ud.localfile = data.expand('%s+%s+%s.tar.gz' % (host, base.replace('/', '.'), cset), d)
 
         return os.path.join(data.getVar("DL_DIR", d, 1), ud.localfile)
 
@@ -124,7 +124,7 @@ class Perforce(Fetch):
         Fetch urls
         """
 
-        (host,depot,user,pswd,parm) = Perforce.doparse(loc, d)
+        (host, depot, user, pswd, parm) = Perforce.doparse(loc, d)
 
         if depot.find('/...') != -1:
             path = depot[:depot.find('/...')]
@@ -164,10 +164,10 @@ class Perforce(Fetch):
             raise FetchError(module)
 
         if "label" in parm:
-            depot = "%s@%s" % (depot,parm["label"])
+            depot = "%s@%s" % (depot, parm["label"])
         else:
             cset = Perforce.getcset(d, depot, host, user, pswd, parm)
-            depot = "%s@%s" % (depot,cset)
+            depot = "%s@%s" % (depot, cset)
 
         os.chdir(tmpfile)
         bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc)
@@ -189,7 +189,7 @@ class Perforce(Fetch):
             dest = list[0][len(path)+1:]
             where = dest.find("#")
 
-            os.system("%s%s print -o %s/%s %s" % (p4cmd, p4opt, module,dest[:where],list[0]))
+            os.system("%s%s print -o %s/%s %s" % (p4cmd, p4opt, module, dest[:where], list[0]))
             count = count + 1
 
         if count == 0:
index 8b687372a4f8407bb01607f07ca518ef4fab9f63..581362038a9cdef1954f1883fde5c22c6969c237 100644 (file)
@@ -38,7 +38,7 @@ class Wget(Fetch):
         """
         Check to see if a given url can be fetched with wget.
         """
-        return ud.type in ['http','https','ftp']
+        return ud.type in ['http', 'https', 'ftp']
 
     def localpath(self, url, ud, d):
 
index adc1408b9e83bf065728f752e0fd59edae9c2195..4b957884cc0aa4480dfd172d0adf2d40af642636 100644 (file)
@@ -37,12 +37,12 @@ class SkipPackage(Exception):
 
 __mtime_cache = {}
 def cached_mtime(f):
-    if not __mtime_cache.has_key(f):
+    if f not in __mtime_cache:
         __mtime_cache[f] = os.stat(f)[8]
     return __mtime_cache[f]
 
 def cached_mtime_noerror(f):
-    if not __mtime_cache.has_key(f):
+    if f not in __mtime_cache:
         try:
             __mtime_cache[f] = os.stat(f)[8]
         except OSError:
index a586c5cde1d7cbf0619c1d63d11d2a2c5184d494..e7d389e7a5a1091c1f5192759a6d2d4e48797705 100644 (file)
@@ -311,7 +311,7 @@ def finalize(fn, d):
     all_handlers = {}
     for var in bb.data.getVar('__BBHANDLERS', d) or []:
         # try to add the handler
-        handler = bb.data.getVar(var,d)
+        handler = bb.data.getVar(var, d)
         bb.event.register(var, handler)
 
     tasklist = bb.data.getVar('__BBTASKS', d) or []
index a770131fbcdb6651ee2e71c78c531c461e561e7f..a388773bb78f5c040a498de4f4db5749529006a2 100644 (file)
@@ -90,7 +90,7 @@ def get_statements(filename, absolsute_filename, base_name):
         statements = ast.StatementGroup()
 
         lineno = 0
-        while 1:
+        while True:
             lineno = lineno + 1
             s = file.readline()
             if not s: break
@@ -118,7 +118,7 @@ def handle(fn, d, include):
         bb.msg.debug(2, bb.msg.domain.Parsing, "BB " + fn + ": handle(data, include)")
 
     (root, ext) = os.path.splitext(os.path.basename(fn))
-    base_name = "%s%s" % (root,ext)
+    base_name = "%s%s" % (root, ext)
     init(d)
 
     if ext == ".bbclass":
@@ -164,7 +164,7 @@ def handle(fn, d, include):
     return d
 
 def feeder(lineno, s, fn, root, statements):
-    global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__,__infunc__, __body__, classes, bb, __residue__
+    global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__, __infunc__, __body__, classes, bb, __residue__
     if __infunc__:
         if s == '}':
             __body__.append('')
index 8e17182ba7f948b9e14ef473f90e04a9c927c1ce..9188119e4d4326001e8c9603bb0ea23bb061e2ab 100644 (file)
@@ -89,7 +89,7 @@ def handle(fn, data, include):
 
     statements = ast.StatementGroup()
     lineno = 0
-    while 1:
+    while True:
         lineno = lineno + 1
         s = f.readline()
         if not s: break
index a26244510a99d30a757c7b2829d7683971b0dc0e..80ddeb55601c22c8f404e4528484694d8aa2bf8a 100644 (file)
@@ -52,7 +52,7 @@ class PersistData:
         except OSError:
             bb.utils.mkdirhier(self.cachedir)
 
-        self.cachefile = os.path.join(self.cachedir,"bb_persist_data.sqlite3")
+        self.cachefile = os.path.join(self.cachedir, "bb_persist_data.sqlite3")
         bb.msg.debug(1, bb.msg.domain.PersistData, "Using '%s' as the persistent data cache" % self.cachefile)
 
         self.connection = sqlite3.connect(self.cachefile, timeout=5, isolation_level=None)
@@ -113,7 +113,7 @@ class PersistData:
             try:
                 self.connection.execute(*query)
                 return
-            except sqlite3.OperationalError, e:
+            except sqlite3.OperationalError as e:
                 if 'database is locked' in str(e):
                     continue
                 raise
index de1160eb87c6b77789ae33f142675b19e3f1417a..6025142e0880890b72bfeab3ceb48fc104f6bee3 100644 (file)
@@ -109,8 +109,7 @@ class RunQueueSchedulerSpeed(RunQueueScheduler):
 
         self.rq = runqueue
 
-        sortweight = deepcopy(self.rq.runq_weight)
-        sortweight.sort()
+        sortweight = sorted(deepcopy(self.rq.runq_weight))
         copyweight = deepcopy(self.rq.runq_weight)
         self.prio_map = []
 
@@ -307,7 +306,7 @@ class RunQueue:
             weight[listid] = 1
             task_done[listid] = True
 
-        while 1:
+        while True:
             next_points = []
             for listid in endpoints:
                 for revdep in self.runq_depends[listid]:
@@ -631,7 +630,7 @@ class RunQueue:
             for dep in revdeps:
                 if dep in self.runq_depends[listid]:
                     #self.dump_data(taskData)
-                    bb.msg.fatal(bb.msg.domain.RunQueue, "Task %s (%s) has circular dependency on %s (%s)" % (taskData.fn_index[self.runq_fnid[dep]], self.runq_task[dep] , taskData.fn_index[self.runq_fnid[listid]], self.runq_task[listid]))
+                    bb.msg.fatal(bb.msg.domain.RunQueue, "Task %s (%s) has circular dependency on %s (%s)" % (taskData.fn_index[self.runq_fnid[dep]], self.runq_task[dep], taskData.fn_index[self.runq_fnid[listid]], self.runq_task[listid]))
 
         bb.msg.note(2, bb.msg.domain.RunQueue, "Compute totals (have %s endpoint(s))" % len(endpoints))
 
@@ -814,7 +813,7 @@ class RunQueue:
                             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
@@ -948,7 +947,7 @@ class RunQueue:
                 try:
                     pipein, pipeout = os.pipe()
                     pid = os.fork() 
-                except OSError, e: 
+                except OSError as e: 
                     bb.msg.fatal(bb.msg.domain.RunQueue, "fork failed: %d (%s)" % (e.errno, e.strerror))
                 if pid == 0:
                     os.close(pipein)
index d4b7fdeea6bdee83623f254ae39db40c7e336c01..e28aa8d7d734edb1a1456dc1c317d937569ca146 100644 (file)
@@ -115,7 +115,7 @@ class BitBakeServer():
 
     def register_idle_function(self, function, data):
         """Register a function to be called while the server is idle"""
-        assert callable(function)
+        assert hasattr(function, '__call__')
         self._idlefuns[function] = data
 
     def idle_commands(self, delay):
index 3844a1e33e2e2c7c42fcd423aac58b2747804a32..cb2949fb9f3f3f36c56ab76f4e9ec9950e95c9ac 100644 (file)
@@ -112,7 +112,7 @@ class BitBakeServer(SimpleXMLRPCServer):
 
     def register_idle_function(self, function, data):
         """Register a function to be called while the server is idle"""
-        assert callable(function)
+        assert hasattr(function, '__call__')
         self._idlefuns[function] = data
 
     def serve_forever(self):
index 58e0d9d8f202bffd810ba28978e3477c12d41f28..d4fd1498b6f4b127c1142bd6f5aab75f78b18b5a 100644 (file)
@@ -34,7 +34,7 @@ def re_match_strings(target, strings):
 
     for name in strings:
         if (name==target or
-                re.search(name,target)!=None):
+                re.search(name, target)!=None):
             return True
     return False
 
@@ -539,7 +539,7 @@ class TaskData:
         Resolve all unresolved build and runtime targets
         """
         bb.msg.note(1, bb.msg.domain.TaskData, "Resolving any missing task queue dependencies")
-        while 1:
+        while True:
             added = 0
             for target in self.get_unresolved_build_targets(dataCache):
                 try:
index 37a62f189ff92023b19cd4fed00bd4ea3b319c54..b5a4dae0dea7c75106b200fc0d27e683aca3ced4 100644 (file)
@@ -157,7 +157,7 @@ class BuildResult(gobject.GObject):
         # format build-<year><month><day>-<ordinal> we can easily
         # pull it out.
         # TODO: Better to stat a file?
-        (_ , date, revision) = identifier.split ("-")
+        (_, date, revision) = identifier.split ("-")
         print(date)
 
         year = int (date[0:4])
@@ -385,7 +385,7 @@ class BuildManager (gobject.GObject):
                 build_directory])
             server.runCommand(["buildTargets", [conf.image], "rootfs"])
 
-        except Exception, e:
+        except Exception as e:
             print(e)
 
 class BuildManagerTreeView (gtk.TreeView):
index 79e2c9060d0a3df4e2a51823e79d3d938cce6051..b4416ecbb32a0d59898659000871ae364e235202 100644 (file)
@@ -63,7 +63,7 @@ class RunningBuild (gobject.GObject):
         # for the message.
         if hasattr(event, 'pid'):
             pid = event.pid
-            if self.pids_to_task.has_key(pid):
+            if pid in self.pids_to_task:
                 (package, task) = self.pids_to_task[pid]
                 parent = self.tasks_to_iter[(package, task)]
 
@@ -93,12 +93,12 @@ class RunningBuild (gobject.GObject):
             (package, task) = (event._package, event._task)
 
             # Save out this PID.
-            self.pids_to_task[pid] = (package,task)
+            self.pids_to_task[pid] = (package, task)
 
             # Check if we already have this package in our model. If so then
             # that can be the parent for the task. Otherwise we create a new
             # top level for the package.
-            if (self.tasks_to_iter.has_key ((package, None))):
+            if ((package, None) in self.tasks_to_iter):
                 parent = self.tasks_to_iter[(package, None)]
             else:
                 parent = self.model.append (None, (None,
index e386e34958c7d6bb43d9189e9b478f0c4ad65783..1cd58cac18c0820f1a32fc7692d1710d0bffb4ed 100644 (file)
@@ -207,7 +207,7 @@ def init(server, eventHandler):
         if ret != True:
             print("Couldn't run command! %s" % ret)
             return
-    except xmlrpclib.Fault, x:
+    except xmlrpclib.Fault as x:
         print("XMLRPC Fault getting commandline:\n %s" % x)
         return
 
index 7a3427f715bcadb5eaa4a5d83383423801840e75..2cfa002f8aebba3d81c9e42d19315f945f51cb5f 100644 (file)
@@ -62,7 +62,7 @@ def init (server, eventHandler):
         if ret != True:
             print("Couldn't get default commandline! %s" % ret)
             return 1
-    except xmlrpclib.Fault, x:
+    except xmlrpclib.Fault as x:
         print("XMLRPC Fault getting commandline:\n %s" % x)
         return 1
 
index dba9530ef639f791eb60c369abfab5c02a1cc229..b6ca15b4fbdcd01f906dbc0c7f9e48826cf1fb46 100644 (file)
@@ -46,7 +46,7 @@ def init(server, eventHandler):
         if ret != True:
             print("Couldn't get default commandline! %s" % ret)
             return 1
-    except xmlrpclib.Fault, x:
+    except xmlrpclib.Fault as x:
         print("XMLRPC Fault getting commandline:\n %s" % x)
         return 1
 
index 89e67900b2e72db9a87050cc08d4a109a7d07668..e3bca2af8367cef7ad02035e9afe8229b89a248b 100644 (file)
@@ -234,7 +234,7 @@ class NCursesUI:
             if ret != True:
                 print("Couldn't get default commandlind! %s" % ret)
                 return
-        except xmlrpclib.Fault, x:
+        except xmlrpclib.Fault as x:
             print("XMLRPC Fault getting commandline:\n %s" % x)
             return
 
index 7dffa5c3ba6f4bf199e7d2e8f735f1d4f1261980..2ac025303efb7b5930ad4615bf4c1444ad77ffcd 100644 (file)
@@ -104,10 +104,10 @@ class MetaDataLoader(gobject.GObject):
                 gobject.idle_add (MetaDataLoader.emit_success_signal,
                     self.loader)
 
-            except MetaDataLoader.LoaderThread.LoaderImportException, e:
+            except MetaDataLoader.LoaderThread.LoaderImportException as e:
                 gobject.idle_add (MetaDataLoader.emit_error_signal, self.loader,
                     "Repository metadata corrupt")
-            except Exception, e:
+            except Exception as e:
                 gobject.idle_add (MetaDataLoader.emit_error_signal, self.loader,
                     "Unable to download repository metadata")
                 print(e)
@@ -211,7 +211,7 @@ class BuildSetupDialog (gtk.Dialog):
         # Build
         button = gtk.Button ("_Build", None, True)
         image = gtk.Image ()
-        image.set_from_stock (gtk.STOCK_EXECUTE,gtk.ICON_SIZE_BUTTON)
+        image.set_from_stock (gtk.STOCK_EXECUTE, gtk.ICON_SIZE_BUTTON)
         button.set_image (image)
         self.add_action_widget (button, BuildSetupDialog.RESPONSE_BUILD)
         button.show_all ()
index 5b3efffcbad9a6b69d7f6eefdfbf5d763b8cda4f..f1e4d791eec72a6fd6ffdc63c47ba9204693d134 100644 (file)
@@ -110,7 +110,7 @@ class UIXMLRPCServer (SimpleXMLRPCServer):
                 return (sock, addr)
             except socket.timeout:
                 pass
-        return (None,None)
+        return (None, None)
 
     def close_request(self, request):
         if request is None:
index 7446be875dcd8494f0bf1709d108ebae8b072211..02668b16c4e95b577b1322651dcc2362bfbb4f6a 100644 (file)
@@ -72,9 +72,9 @@ def vercmp_part(a, b):
         if ca == None and cb == None:
             return 0
 
-        if type(ca) is types.StringType:
+        if isinstance(ca, types.StringType):
             sa = ca in separators
-        if type(cb) is types.StringType:
+        if isinstance(cb, types.StringType):
             sb = cb in separators
         if sa and not sb:
             return -1
@@ -306,7 +306,7 @@ def better_compile(text, file, realfile, mode = "exec"):
     """
     try:
         return compile(text, file, mode)
-    except Exception, e:
+    except Exception as e:
         # split the text into lines again
         body = text.split('\n')
         bb.msg.error(bb.msg.domain.Util, "Error in compiling python function in: ", realfile)
@@ -385,7 +385,7 @@ def lockfile(name):
                     return lf
             # File no longer exists or changed, retry
             lf.close
-        except Exception, e:
+        except Exception as e:
             continue
 
 def unlockfile(lf):
@@ -546,7 +546,7 @@ def mkdirhier(dir):
     try:
         os.makedirs(dir)
         bb.msg.debug(2, bb.msg.domain.Util, "created " + dir)
-    except OSError, e:
+    except OSError as e:
         if e.errno != errno.EEXIST:
             raise e
 
@@ -561,7 +561,7 @@ def movefile(src, dest, newmtime = None, sstat = None):
     try:
         if not sstat:
             sstat = os.lstat(src)
-    except Exception, e:
+    except Exception as e:
         print("movefile: Stating source file failed...", e)
         return None
 
@@ -577,7 +577,7 @@ def movefile(src, dest, newmtime = None, sstat = None):
             try:
                 os.unlink(dest)
                 destexists = 0
-            except Exception, e:
+            except Exception as e:
                 pass
 
     if stat.S_ISLNK(sstat[stat.ST_MODE]):
@@ -589,7 +589,7 @@ def movefile(src, dest, newmtime = None, sstat = None):
             #os.lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID])
             os.unlink(src)
             return os.lstat(dest)
-        except Exception, e:
+        except Exception as e:
             print("movefile: failed to properly create symlink:", dest, "->", target, e)
             return None
 
@@ -598,7 +598,7 @@ def movefile(src, dest, newmtime = None, sstat = None):
         try:
             os.rename(src, dest)
             renamefailed = 0
-        except Exception, e:
+        except Exception as e:
             if e[0] != errno.EXDEV:
                 # Some random error.
                 print("movefile: Failed to move", src, "to", dest, e)
@@ -612,7 +612,7 @@ def movefile(src, dest, newmtime = None, sstat = None):
                 shutil.copyfile(src, dest + "#new")
                 os.rename(dest + "#new", dest)
                 didcopy = 1
-            except Exception, e:
+            except Exception as e:
                 print('movefile: copy', src, '->', dest, 'failed.', e)
                 return None
         else:
@@ -626,7 +626,7 @@ def movefile(src, dest, newmtime = None, sstat = None):
                 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:
+        except Exception as e:
             print("movefile: Failed to chown/chmod/unlink", dest, e)
             return None
 
@@ -647,7 +647,7 @@ def copyfile(src, dest, newmtime = None, sstat = None):
     try:
         if not sstat:
             sstat = os.lstat(src)
-    except Exception, e:
+    except Exception as e:
         print("copyfile: Stating source file failed...", e)
         return False
 
@@ -663,7 +663,7 @@ def copyfile(src, dest, newmtime = None, sstat = None):
             try:
                 os.unlink(dest)
                 destexists = 0
-            except Exception, e:
+            except Exception as e:
                 pass
 
     if stat.S_ISLNK(sstat[stat.ST_MODE]):
@@ -674,7 +674,7 @@ def copyfile(src, dest, newmtime = None, sstat = None):
             os.symlink(target, dest)
             #os.lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID])
             return os.lstat(dest)
-        except Exception, e:
+        except Exception as e:
             print("copyfile: failed to properly create symlink:", dest, "->", target, e)
             return False
 
@@ -682,7 +682,7 @@ def copyfile(src, dest, newmtime = None, sstat = None):
         try: # For safety copy then move it over.
             shutil.copyfile(src, dest + "#new")
             os.rename(dest + "#new", dest)
-        except Exception, e:
+        except Exception as e:
             print('copyfile: copy', src, '->', dest, 'failed.', e)
             return False
     else:
@@ -694,7 +694,7 @@ def copyfile(src, dest, newmtime = None, sstat = None):
     try:
         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:
+    except Exception as e:
         print("copyfile: Failed to chown/chmod/unlink", dest, e)
         return False