changeset 76:4af10dce21e0

keep all code lines under 80 chars in length
author Alexander Solovyov <alexander@solovyov.net>
date Sat, 06 Nov 2010 09:47:28 +0100
parents 5549bca4dcec
children d4a4f739a039
files crecord/chunk_selector.py crecord/crpatch.py crecord/textpad.py
diffstat 3 files changed, 114 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/crecord/chunk_selector.py
+++ b/crecord/chunk_selector.py
@@ -34,7 +34,8 @@
 try:
     curses
 except NameError:
-    raise util.Abort(_('the python curses/wcurses module is not available/installed'))
+    raise util.Abort(
+        _('the python curses/wcurses module is not available/installed'))
 
 
 orig_stdout = sys.__stdout__ # used by gethw()
@@ -139,9 +140,9 @@
 
     def upArrowShiftEvent(self):
         """
-        Select (if possible) the previous item on the same level as the currently
-        selected item.  Otherwise, select (if possible) the parent-item of the
-        currently selected item.
+        Select (if possible) the previous item on the same level as the
+        currently selected item.  Otherwise, select (if possible) the
+        parent-item of the currently selected item.
 
         If the currently selected item is already at the top of the screen,
         scroll the screen down to show the new-selected item.
@@ -183,8 +184,9 @@
 
     def downArrowShiftEvent(self):
         """
-        If the cursor is already at the bottom chunk, scroll the screen up and move the cursor-position
-        to the subsequent chunk.  Otherwise, only move the cursor position down one chunk.
+        If the cursor is already at the bottom chunk, scroll the screen up and
+        move the cursor-position to the subsequent chunk.  Otherwise, only move
+        the cursor position down one chunk.
 
         """
         # TODO: update docstring
@@ -250,7 +252,7 @@
         self.currentSelectedItem = nextItem
 
     def updateScroll(self):
-        "Scroll the screen in such a way to fully show the currently-selected item."
+        "Scroll the screen to fully show the currently-selected"
         selStart = self.selectedItemStartLine
         selEnd = self.selectedItemEndLine
         #selNumLines = selEnd - selStart
@@ -335,7 +337,7 @@
                                         not allSiblingsApplied)
 
         elif isinstance(item, HunkLine):
-            siblingAppliedStatus = [hnkln.applied for hnkln in item.hunk.changedLines]
+            siblingAppliedStatus = [ln.applied for ln in item.hunk.changedLines]
             allSiblingsApplied = not (False in siblingAppliedStatus)
             noSiblingsApplied = not (True in siblingAppliedStatus)
 
@@ -350,12 +352,14 @@
                 item.hunk.applied = True
                 item.hunk.partial = True
 
-            parentSiblingsAppliedStatus = [hnk.applied for hnk in item.hunk.header.hunks]
-            noParentSiblingsApplied = not (True in parentSiblingsAppliedStatus)
-            allParentSiblingsApplied = not (False in parentSiblingsAppliedStatus)
+            parentSiblingsApplied = [hnk.applied for hnk
+                                     in item.hunk.header.hunks]
+            noParentSiblingsApplied = not (True in parentSiblingsApplied)
+            allParentSiblingsApplied = not (False in parentSiblingsApplied)
 
-            parentSiblingsPartialStatus = [hnk.partial for hnk in item.hunk.header.hunks]
-            someParentSiblingsPartial = (True in parentSiblingsPartialStatus)
+            parentSiblingsPartial = [hnk.partial for hnk
+                                     in item.hunk.header.hunks]
+            someParentSiblingsPartial = (True in parentSiblingsPartial)
 
             # if all parent hunks are not applied, un-apply header
             if noParentSiblingsApplied:
@@ -517,8 +521,14 @@
 
         # print out the status lines at the top
         try:
-            printString(self.statuswin, "SELECT CHUNKS: (j/k/up/dn/pgup/pgdn) move cursor; (space/A) toggle hunk/all", pairName="legend")
-            printString(self.statuswin, " (f)old/unfold; (c)ommit applied; (q)uit; (?) help | [X]=hunk applied **=folded", pairName="legend")
+            printString(self.statuswin,
+                        "SELECT CHUNKS: (j/k/up/dn/pgup/pgdn) move cursor; "
+                        "(space/A) toggle hunk/all",
+                        pairName="legend")
+            printString(self.statuswin,
+                        " (f)old/unfold; (c)ommit applied; (q)uit; (?) help "
+                        "| [X]=hunk applied **=folded",
+                        pairName="legend")
         except curses.error:
             pass
 
@@ -526,7 +536,10 @@
         try:
             self.printItem()
             self.updateScroll()
-            self.chunkpad.refresh(self.firstLineOfPadToPrint,0,self.numStatusLines,0,self.yScreenSize+1-self.numStatusLines,self.xScreenSize)
+            self.chunkpad.refresh(self.firstLineOfPadToPrint, 0,
+                                  self.numStatusLines, 0,
+                                  self.yScreenSize+1-self.numStatusLines,
+                                  self.xScreenSize)
         except curses.error:
             pass
 
@@ -566,7 +579,8 @@
 
         return checkBox
 
-    def printHeader(self, header, selected=False, toWin=True, ignoreFolding=False):
+    def printHeader(self, header, selected=False, toWin=True,
+                    ignoreFolding=False):
         """
         Print the header to the pad.  If countLines is True, don't print
         anything, but just count the number of lines which would be printed.
@@ -578,12 +592,11 @@
 
         if chunkIndex != 0 and not header.folded:
             # add separating line before headers
-            outStr += self.printString(self.chunkpad, '_'*self.xScreenSize, toWin=toWin, align=False)
+            outStr += self.printString(self.chunkpad, '_' * self.xScreenSize,
+                                       toWin=toWin, align=False)
         # select color-pair based on if the header is selected
-        if selected:
-            colorPair = self.getColorPair(name="selected", attrList=[curses.A_BOLD])
-        else:
-            colorPair = self.getColorPair(name="normal", attrList=[curses.A_BOLD])
+        colorPair = self.getColorPair(name=selected and "selected" or "normal",
+                                      attrList=[curses.A_BOLD])
 
         # print out each line of the chunk, expanding it to screen width
 
@@ -595,16 +608,19 @@
             lineStr = checkBox + textList[0]
         else:
             lineStr = checkBox + header.filename()
-        outStr += self.printString(self.chunkpad, lineStr, pair=colorPair, toWin=toWin)
+        outStr += self.printString(self.chunkpad, lineStr, pair=colorPair,
+                                   toWin=toWin)
         if not header.folded or ignoreFolding:
             if len(textList) > 1:
                 for line in textList[1:]:
                     lineStr = " "*(indentNumChars + len(checkBox)) + line
-                    outStr += self.printString(self.chunkpad, lineStr, pair=colorPair, toWin=toWin)
+                    outStr += self.printString(self.chunkpad, lineStr,
+                                               pair=colorPair, toWin=toWin)
 
         return outStr
 
-    def printHunkLinesBefore(self, hunk, selected=False, toWin=True, ignoreFolding=False):
+    def printHunkLinesBefore(self, hunk, selected=False, toWin=True,
+                             ignoreFolding=False):
         "includes start/end line indicator"
         outStr = ""
         # where hunk is in list of siblings
@@ -612,12 +628,11 @@
 
         if hunkIndex != 0:
             # add separating line before headers
-            outStr += self.printString(self.chunkpad, ' '*self.xScreenSize, toWin=toWin, align=False)
+            outStr += self.printString(self.chunkpad, ' '*self.xScreenSize,
+                                       toWin=toWin, align=False)
 
-        if selected:
-            colorPair = self.getColorPair(name="selected", attrList=[curses.A_BOLD])
-        else:
-            colorPair = self.getColorPair(name="normal", attrList=[curses.A_BOLD])
+        colorPair = self.getColorPair(name=selected and "selected" or "normal",
+                                      attrList=[curses.A_BOLD])
 
         # print out from-to line with checkbox
         checkBox = self.getStatusPrefixString(hunk)
@@ -626,8 +641,10 @@
         frToLine = "   " + hunk.getFromToLine().strip("\n")
 
 
-        outStr += self.printString(self.chunkpad, linePrefix, toWin=toWin, align=False) # add uncolored checkbox/indent
-        outStr += self.printString(self.chunkpad, frToLine, pair=colorPair, toWin=toWin)
+        outStr += self.printString(self.chunkpad, linePrefix, toWin=toWin,
+                                   align=False) # add uncolored checkbox/indent
+        outStr += self.printString(self.chunkpad, frToLine, pair=colorPair,
+                                   toWin=toWin)
 
         if hunk.folded and not ignoreFolding:
             # skip remainder of output
@@ -672,11 +689,14 @@
             colorPair = self.getColorPair(name="normal")
 
         linePrefix = " "*indentNumChars + checkBox
-        outStr += self.printString(self.chunkpad, linePrefix, toWin=toWin, align=False) # add uncolored checkbox/indent
-        outStr += self.printString(self.chunkpad, lineStr, pair=colorPair, toWin=toWin, showWhtSpc=True)
+        outStr += self.printString(self.chunkpad, linePrefix, toWin=toWin,
+                                   align=False) # add uncolored checkbox/indent
+        outStr += self.printString(self.chunkpad, lineStr, pair=colorPair,
+                                   toWin=toWin, showWhtSpc=True)
         return outStr
 
-    def printItem(self, item=None, ignoreFolding=False, recurseChildren=True, toWin=True):
+    def printItem(self, item=None, ignoreFolding=False, recurseChildren=True,
+                  toWin=True):
         """
         Use __printItem() to print the the specified item.applied.
         If item is not specified, then print the entire patch.
@@ -687,7 +707,8 @@
         if recurseChildren:
             self.linesPrintedToPadSoFar = 0
             global outStr
-        retStr = self.__printItem(item, ignoreFolding, recurseChildren, toWin=toWin)
+        retStr = self.__printItem(item, ignoreFolding, recurseChildren,
+                                  toWin=toWin)
         if recurseChildren:
             # remove the string when finished, so it doesn't accumulate
             del outStr
@@ -720,8 +741,10 @@
         if selected and recurseChildren:
             # assumes line numbering starting from line 0
             self.selectedItemStartLine = self.linesPrintedToPadSoFar
-            selectedItemLines = self.getNumLinesDisplayed(item, recurseChildren=False)
-            self.selectedItemEndLine = self.selectedItemStartLine + selectedItemLines - 1
+            selectedItemLines = self.getNumLinesDisplayed(item,
+                                                          recurseChildren=False)
+            self.selectedItemEndLine = (self.selectedItemStartLine +
+                                        selectedItemLines - 1)
 
         # Patch object is a list of headers
         if isinstance(item, Patch):
@@ -730,24 +753,29 @@
                     self.__printItem(hdr, ignoreFolding, recurseChildren, toWin)
         # TODO: eliminate all isinstance() calls
         if isinstance(item, header):
-            outStr += self.printHeader(item, selected, toWin=toWin, ignoreFolding=ignoreFolding)
+            outStr += self.printHeader(item, selected, toWin=toWin,
+                                       ignoreFolding=ignoreFolding)
             if recurseChildren:
                 for hnk in item.hunks:
                     self.__printItem(hnk, ignoreFolding, recurseChildren, toWin)
         elif (isinstance(item, hunk) and
               ((not item.header.folded) or ignoreFolding)):
             # print the hunk data which comes before the changed-lines
-            outStr += self.printHunkLinesBefore(item, selected, toWin=toWin, ignoreFolding=ignoreFolding)
+            outStr += self.printHunkLinesBefore(item, selected, toWin=toWin,
+                                                ignoreFolding=ignoreFolding)
             if recurseChildren:
-                for line in item.changedLines:
-                    self.__printItem(line, ignoreFolding, recurseChildren, toWin)
-                outStr += self.printHunkLinesAfter(item, toWin=toWin, ignoreFolding=ignoreFolding)
-        elif isinstance(item, HunkLine) and ((not item.hunk.folded) or ignoreFolding):
+                for l in item.changedLines:
+                    self.__printItem(l, ignoreFolding, recurseChildren, toWin)
+                outStr += self.printHunkLinesAfter(item, toWin=toWin,
+                                                   ignoreFolding=ignoreFolding)
+        elif (isinstance(item, HunkLine) and
+              ((not item.hunk.folded) or ignoreFolding)):
             outStr += self.printHunkChangedLine(item, selected, toWin=toWin)
 
         return outStr
 
-    def getNumLinesDisplayed(self, item=None, ignoreFolding=False, recurseChildren=True):
+    def getNumLinesDisplayed(self, item=None, ignoreFolding=False,
+                             recurseChildren=True):
         """
         Return the number of lines which would be displayed if the item were
         to be printed to the display.  The item will NOT be printed to the
@@ -758,7 +786,8 @@
 
         """
         # temporarily disable printing to windows by printString
-        patchDisplayString = self.printItem(item, ignoreFolding, recurseChildren, toWin=False)
+        patchDisplayString = self.printItem(item, ignoreFolding,
+                                            recurseChildren, toWin=False)
         numLines = len(patchDisplayString)/self.xScreenSize
         return numLines
 
@@ -774,15 +803,17 @@
         except curses.error:
             pass
 
-    def getColorPair(self, fgColor=None, bgColor=None, name=None, attrList=None):
+    def getColorPair(self, fgColor=None, bgColor=None, name=None,
+                     attrList=None):
         """
-        Get a curses color pair, adding it to self.colorPairs if it is not already
-        defined.  An optional string, name, can be passed as a shortcut for
-        referring to the color-pair.  By default, if no arguments are specified,
-        the white foreground / black background color-pair is returned.
+        Get a curses color pair, adding it to self.colorPairs if it is not
+        already defined.  An optional string, name, can be passed as a shortcut
+        for referring to the color-pair.  By default, if no arguments are
+        specified, the white foreground / black background color-pair is
+        returned.
 
-        It is expected that this function will be used exclusively for initializing
-        color pairs, and NOT curses.init_pair().
+        It is expected that this function will be used exclusively for
+        initializing color pairs, and NOT curses.init_pair().
 
         attrList is used to 'flavor' the returned color-pair.  This information
         is not stored in self.colorPairs.  It contains attribute values like
@@ -802,7 +833,8 @@
             else:
                 pairIndex = len(self.colorPairs) + 1
                 curses.init_pair(pairIndex, fgColor, bgColor)
-                colorPair = self.colorPairs[(fgColor, bgColor)] = curses.color_pair(pairIndex)
+                colorPair = self.colorPairs[(fgColor, bgColor)] = (
+                    curses.color_pair(pairIndex))
                 if name is not None:
                     self.colorPairNames[name] = curses.color_pair(pairIndex)
 
@@ -847,9 +879,10 @@
                       q : quit without committing (no changes will be made)
                       ? : help (what you're currently reading)"""
 
-        helpwin = curses.newwin(self.yScreenSize,0,0,0)
+        helpwin = curses.newwin(self.yScreenSize, 0, 0, 0)
         helpLines = helpText.split("\n")
-        helpLines = helpLines + [" "]*(self.yScreenSize-self.numStatusLines-len(helpLines)-1)
+        helpLines = helpLines + [" "]*(
+            self.yScreenSize - self.numStatusLines - len(helpLines) - 1)
         try:
             for line in helpLines:
                 self.printString(helpwin, line, pairName="legend")
@@ -898,9 +931,10 @@
 
 Are you sure you want to review/edit and commit the selected changes [yN]? """)
         else:
-            confirmText = "Are you sure you want to commit the selected changes [yN]? "
+            confirmText = (
+                "Are you sure you want to commit the selected changes [yN]? ")
 
-        confirmWin = curses.newwin(self.yScreenSize,0,0,0)
+        confirmWin = curses.newwin(self.yScreenSize, 0, 0, 0)
         try:
             lines = confirmText.split("\n")
             for line in lines:
@@ -933,7 +967,8 @@
         # available colors: black, blue, cyan, green, magenta, white, yellow
         # init_pair(color_id, foreground_color, background_color)
         self.initColorPair(None, None, name="normal")
-        self.initColorPair(curses.COLOR_WHITE, curses.COLOR_MAGENTA, name="selected")
+        self.initColorPair(curses.COLOR_WHITE, curses.COLOR_MAGENTA,
+                           name="selected")
         self.initColorPair(curses.COLOR_RED, None, name="deletion")
         self.initColorPair(curses.COLOR_GREEN, None, name="addition")
         self.initColorPair(curses.COLOR_WHITE, curses.COLOR_BLUE, name="legend")
@@ -952,7 +987,8 @@
         self.chunkpad = curses.newpad(self.numPadLines, self.xScreenSize)
 
         # initialize selecteItemEndLine (initial start-line is 0)
-        self.selectedItemEndLine = self.getNumLinesDisplayed(self.currentSelectedItem, recurseChildren=False)
+        self.selectedItemEndLine = self.getNumLinesDisplayed(
+            self.currentSelectedItem, recurseChildren=False)
 
         # option which enables/disables patch-review (in editor) step
         opts['crecord_reviewpatch'] = False
--- a/crecord/crpatch.py
+++ b/crecord/crpatch.py
@@ -59,7 +59,9 @@
                 raise patch.PatchError('unknown patch content: %r' % line)
 
 class PatchNode(object):
-    "Abstract Class for Patch Graph Nodes (i.e. PatchRoot, header, hunk, HunkLine)"
+    """Abstract Class for Patch Graph Nodes
+    (i.e. PatchRoot, header, hunk, HunkLine)
+    """
 
     def firstChild(self):
         raise NotImplementedError("method must be implemented by subclass")
@@ -171,9 +173,11 @@
             prevSibling = self.prevSibling()
             if prevSibling is not None:
                 prevSiblingLastChild = prevSibling.lastChild()
-                if (prevSiblingLastChild is not None) and not prevSibling.folded:
+                if ((prevSiblingLastChild is not None) and
+                    not prevSibling.folded):
                     prevSiblingLCLC = prevSiblingLastChild.lastChild()
-                    if (prevSiblingLCLC is not None) and not prevSiblingLastChild.folded:
+                    if ((prevSiblingLCLC is not None) and
+                        not prevSiblingLastChild.folded):
                         return prevSiblingLCLC
                     else:
                         return prevSiblingLastChild
@@ -259,9 +263,9 @@
 
     def allhunks(self):
         """
-        Return True if the file which the header represents was changed completely (i.e.
-        there is no possibility of applying a hunk of changes smaller than the size of the
-        entire file.)  Otherwise return False
+        Return True if the file which the header represents was changed
+        completely (i.e.  there is no possibility of applying a hunk of changes
+        smaller than the size of the entire file.)  Otherwise return False
 
         """
         for h in self.header:
@@ -446,8 +450,10 @@
         return self.changedLines
     def countchanges(self):
         """changedLines -> (n+,n-)"""
-        add = len([l for l in self.changedLines if l.applied and l.prettyStr()[0] == '+'])
-        rem = len([l for l in self.changedLines if l.applied and l.prettyStr()[0] == '-'])
+        add = len([l for l in self.changedLines if l.applied
+                   and l.prettyStr()[0] == '+'])
+        rem = len([l for l in self.changedLines if l.applied
+                   and l.prettyStr()[0] == '-'])
         return add, rem
 
     def getFromToLine(self):
@@ -645,7 +651,8 @@
 
     appliedHunkList = []
     for hdr in headers:
-        if hdr.applied and (hdr.special() or len([h for h in hdr.hunks if h.applied]) > 0):
+        if (hdr.applied and
+            (hdr.special() or len([h for h in hdr.hunks if h.applied]) > 0)):
             appliedHunkList.append(hdr)
             fixoffset = 0
             for hnk in hdr.hunks:
--- a/crecord/textpad.py
+++ b/crecord/textpad.py
@@ -90,7 +90,8 @@
                 self._insert_printable_char(ch)
         elif ch == curses.ascii.SOH:                           # ^a
             self.win.move(y, 0)
-        elif ch in (curses.ascii.STX,curses.KEY_LEFT, curses.ascii.BS,curses.KEY_BACKSPACE):
+        elif ch in (curses.ascii.STX,curses.KEY_LEFT, curses.ascii.BS,
+                    curses.KEY_BACKSPACE):
             if x > 0:
                 self.win.move(y, x-1)
             elif y == 0: