[meld] PEP8 cvs.py



commit e8eb7a0a8f70efe26342ffe8c5b7f056a66a05ad
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Mar 30 06:36:03 2013 +1000

    PEP8 cvs.py

 meld/vc/cvs.py |  119 ++++++++++++++++++++++++++++++++------------------------
 1 files changed, 68 insertions(+), 51 deletions(-)
---
diff --git a/meld/vc/cvs.py b/meld/vc/cvs.py
index 326d52c..1c5b326 100644
--- a/meld/vc/cvs.py
+++ b/meld/vc/cvs.py
@@ -1,25 +1,25 @@
-### Copyright (C) 2002-2005 Stephen Kennedy <stevek gnome org>
-
-### Redistribution and use in source and binary forms, with or without
-### modification, are permitted provided that the following conditions
-### are met:
-### 
-### 1. Redistributions of source code must retain the above copyright
-###    notice, this list of conditions and the following disclaimer.
-### 2. Redistributions in binary form must reproduce the above copyright
-###    notice, this list of conditions and the following disclaimer in the
-###    documentation and/or other materials provided with the distribution.
-
-### THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-### IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-### OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-### IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-### INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-### NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-### DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-### THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-### (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-### THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+# Copyright (C) 2002-2005 Stephen Kennedy <stevek gnome org>
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 import logging
 import os
@@ -46,17 +46,23 @@ class Vc(_vc.Vc):
             self.CMD = self.ALT_CMD
 
     def commit_command(self, message):
-        return [self.CMD,"commit","-m",message]
+        return [self.CMD, "commit", "-m", message]
+
     def diff_command(self):
-        return [self.CMD,"diff","-u"]
+        return [self.CMD, "diff", "-u"]
+
     def update_command(self):
-        return [self.CMD,"update"]
+        return [self.CMD, "update"]
+
     def add_command(self):
-        return [self.CMD,"add"]
+        return [self.CMD, "add"]
+
     def remove_command(self, force=0):
-        return [self.CMD,"rm","-f"]
+        return [self.CMD, "rm", "-f"]
+
     def revert_command(self):
-        return [self.CMD,"update","-C"]
+        return [self.CMD, "update", "-C"]
+
     def valid_repo(self):
         if _vc.call([self.CMD, "version"], cwd=self.root):
             return False
@@ -66,17 +72,22 @@ class Vc(_vc.Vc):
     def _get_dirsandfiles(self, directory, dirs, files):
         log = logging.getLogger(__name__)
 
+        vc_path = os.path.join(directory, self.VC_DIR)
+
         try:
-            entries = open(os.path.join(directory, self.VC_DIR, "Entries")).read()
+            with open(os.path.join(vc_path, "Entries")) as f:
+                entries = f.read()
             # poor mans universal newline
-            entries = entries.replace("\r","\n").replace("\n\n","\n")
-        except IOError as e: # no cvs dir
+            entries = entries.replace("\r", "\n").replace("\n\n", "\n")
+         # No CVS directory
+        except IOError as e:
             d = [_vc.Dir(x[1], x[0], _vc.STATE_NONE) for x in dirs]
             f = [_vc.File(x[1], x[0], _vc.STATE_NONE) for x in files]
             return d, f
 
         try:
-            logentries = open(os.path.join(directory, self.VC_DIR, "Entries.Log")).read()
+            with open(os.path.join(vc_path, "Entries.Log")) as f:
+                logentries = f.read()
         except IOError as e:
             pass
         else:
@@ -84,10 +95,10 @@ class Vc(_vc.Vc):
             toadd = []
             for match in matches:
                 if match[0] == "A":
-                    toadd.append( match[1] )
+                    toadd.append(match[1])
                 elif match[0] == "R":
                     try:
-                        toadd.remove( match[1] )
+                        toadd.remove(match[1])
                     except ValueError:
                         pass
                 else:
@@ -111,19 +122,20 @@ class Vc(_vc.Vc):
                     state = _vc.STATE_NORMAL
                 else:
                     state = _vc.STATE_MISSING
-                retdirs.append( _vc.Dir(path,name,state) )
+                retdirs.append(_vc.Dir(path, name, state))
             else:
                 if rev.startswith("-"):
                     state = _vc.STATE_REMOVED
-                elif date=="dummy timestamp":
+                elif date == "dummy timestamp":
                     if rev[0] == "0":
                         state = _vc.STATE_NEW
                     else:
                         state = _vc.STATE_ERROR
-                elif date=="dummy timestamp from new-entry":
+                elif date == "dummy timestamp from new-entry":
                     state = _vc.STATE_MODIFIED
                 else:
-                    date = re.sub(r"\s*\d+", lambda x : "%3i" % int(x.group()), date, 1)
+                    date_sub = lambda x: "%3i" % int(x.group())
+                    date = re.sub(r"\s*\d+", date_sub, date, 1)
                     plus = date.find("+")
                     if plus >= 0:
                         state = _vc.STATE_CONFLICT
@@ -140,7 +152,7 @@ class Vc(_vc.Vc):
                         except OSError:
                             state = _vc.STATE_MISSING
                         else:
-                            if time.asctime(time.gmtime(mtime))==date:
+                            if time.asctime(time.gmtime(mtime)) == date:
                                 state = _vc.STATE_NORMAL
                             else:
                                 state = _vc.STATE_MODIFIED
@@ -149,34 +161,39 @@ class Vc(_vc.Vc):
         cvsfiles = [x[1] for x in matches]
         # ignored
         try:
-            ignored = open(os.path.join(os.environ["HOME"], ".cvsignore")).read().split()
+            with open(os.path.join(os.environ["HOME"], ".cvsignore")) as f:
+                ignored = f.read().split()
         except (IOError, KeyError):
             ignored = []
         try:
-            ignored += open( os.path.join(directory, ".cvsignore")).read().split()
+            with open(os.path.join(directory, ".cvsignore")) as f:
+                ignored += f.read().split()
         except IOError:
             pass
 
         if len(ignored):
             try:
-                regexes = [ misc.shell_to_regex(i)[:-1] for i in ignored ]
-                ignore_re = re.compile( "(" + "|".join(regexes) + ")" )
+                regexes = [misc.shell_to_regex(i)[:-1] for i in ignored]
+                ignore_re = re.compile("(" + "|".join(regexes) + ")")
             except re.error as e:
                 misc.run_dialog(_("Error converting to a regular expression\n"
-                                  "The pattern was '%s'\n"
-                                  "The error was '%s'") % (",".join(ignored), e))
+                                  "The pattern was '%s'\nThe error was '%s'") %
+                                (",".join(ignored), e))
         else:
             class dummy(object):
-                def match(self, *args): return None
+                def match(self, *args):
+                    return None
             ignore_re = dummy()
 
-        for f,path in files:
+        for f, path in files:
             if f not in cvsfiles:
-                state = ignore_re.match(f) is None and _vc.STATE_NONE or _vc.STATE_IGNORED
+                state = (ignore_re.match(f) is None and _vc.STATE_NONE or
+                         _vc.STATE_IGNORED)
                 retfiles.append(_vc.File(path, f, state))
-        for d,path in dirs:
+        for d, path in dirs:
             if d not in cvsfiles:
-                state = ignore_re.match(d) is None and _vc.STATE_NONE or _vc.STATE_IGNORED
-                retdirs.append( _vc.Dir(path, d, state) )
+                state = (ignore_re.match(d) is None and _vc.STATE_NONE or
+                         _vc.STATE_IGNORED)
+                retdirs.append(_vc.Dir(path, d, state))
 
         return retdirs, retfiles


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]