mercurial/util.py
changeset 10282 08a0f04b56bd
parent 10264 d6512b3e9ac0
child 10344 9501cde4c034
--- a/mercurial/util.py	Mon Jan 25 00:05:22 2010 -0600
+++ b/mercurial/util.py	Mon Jan 25 00:05:27 2010 -0600
@@ -182,16 +182,21 @@
         code = os.system(cmd)
         if sys.platform == 'OpenVMS' and code & 1:
             code = 0
-        if code: raise Abort(_("command '%s' failed: %s") %
-                             (cmd, explain_exit(code)))
+        if code:
+            raise Abort(_("command '%s' failed: %s") %
+                        (cmd, explain_exit(code)))
         return open(outname, 'rb').read()
     finally:
         try:
-            if inname: os.unlink(inname)
-        except: pass
+            if inname:
+                os.unlink(inname)
+        except:
+            pass
         try:
-            if outname: os.unlink(outname)
-        except: pass
+            if outname:
+                os.unlink(outname)
+        except:
+            pass
 
 filtertable = {
     'tempfile:': tempfilter,
@@ -242,8 +247,11 @@
 
 Abort = error.Abort
 
-def always(fn): return True
-def never(fn): return False
+def always(fn):
+    return True
+
+def never(fn):
+    return False
 
 def pathto(root, n1, n2):
     '''return the relative path from one place to another.
@@ -256,7 +264,8 @@
     relative to root.
     n2 should always be relative to root.
     '''
-    if not n1: return localpath(n2)
+    if not n1:
+        return localpath(n2)
     if os.path.isabs(n1):
         if os.path.splitdrive(root)[0] != os.path.splitdrive(n1)[0]:
             return os.path.join(root, localpath(n2))
@@ -912,11 +921,15 @@
     assert size >= 0
     assert limit is None or limit >= 0
     while True:
-        if limit is None: nbytes = size
-        else: nbytes = min(limit, size)
+        if limit is None:
+            nbytes = size
+        else:
+            nbytes = min(limit, size)
         s = nbytes and f.read(nbytes)
-        if not s: break
-        if limit: limit -= len(s)
+        if not s:
+            break
+        if limit:
+            limit -= len(s)
         yield s
 
 def makedate():
@@ -1084,7 +1097,7 @@
         user = user[:f]
     f = user.find('<')
     if f >= 0:
-        user = user[f+1:]
+        user = user[f + 1:]
     f = user.find(' ')
     if f >= 0:
         user = user[:f]
@@ -1096,15 +1109,16 @@
 def email(author):
     '''get email of author.'''
     r = author.find('>')
-    if r == -1: r = None
-    return author[author.find('<')+1:r]
+    if r == -1:
+        r = None
+    return author[author.find('<') + 1:r]
 
 def ellipsis(text, maxlength=400):
     """Trim string to at most maxlength (default: 400) characters."""
     if len(text) <= maxlength:
         return text
     else:
-        return "%s..." % (text[:maxlength-3])
+        return "%s..." % (text[:maxlength - 3])
 
 def walkrepos(path, followsym=False, seen_dirs=None, recurse=False):
     '''yield every hg repository under path, recursively.'''
@@ -1173,7 +1187,8 @@
         if 'HGRCPATH' in os.environ:
             _rcpath = []
             for p in os.environ['HGRCPATH'].split(os.pathsep):
-                if not p: continue
+                if not p:
+                    continue
                 p = expandpath(p)
                 if os.path.isdir(p):
                     for f, kind in osutil.listdir(p):
@@ -1189,15 +1204,15 @@
     '''return byte count formatted as readable string, with units'''
 
     units = (
-        (100, 1<<30, _('%.0f GB')),
-        (10, 1<<30, _('%.1f GB')),
-        (1, 1<<30, _('%.2f GB')),
-        (100, 1<<20, _('%.0f MB')),
-        (10, 1<<20, _('%.1f MB')),
-        (1, 1<<20, _('%.2f MB')),
-        (100, 1<<10, _('%.0f KB')),
-        (10, 1<<10, _('%.1f KB')),
-        (1, 1<<10, _('%.2f KB')),
+        (100, 1 << 30, _('%.0f GB')),
+        (10, 1 << 30, _('%.1f GB')),
+        (1, 1 << 30, _('%.2f GB')),
+        (100, 1 << 20, _('%.0f MB')),
+        (10, 1 << 20, _('%.1f MB')),
+        (1, 1 << 20, _('%.2f MB')),
+        (100, 1 << 10, _('%.0f KB')),
+        (10, 1 << 10, _('%.1f KB')),
+        (1, 1 << 10, _('%.2f KB')),
         (1, 1, _('%.0f bytes')),
         )
 
@@ -1219,7 +1234,7 @@
                 # root. On POSIX they are rooted at the file system root.
                 if os.name == 'nt':
                     droot = os.path.splitdrive(os.getcwd())[0] + '/'
-                    path = os.path.join(droot, path[i+1:])
+                    path = os.path.join(droot, path[i + 1:])
                 else:
                     path = path[i:]
             else: