Alexander Solovyov avatar Alexander Solovyov committed 4af10dc

keep all code lines under 80 chars in length

Comments (0)

Files changed (3)

crecord/chunk_selector.py

 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()
 
     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.
 
     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
         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
                                         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)
 
                 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:
 
         # 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
 
         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
 
 
         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.
 
         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
 
             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
 
         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)
         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
             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.
         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
         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):
                     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
 
         """
         # 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
 
         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
             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)
 
                       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")
 
 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:
         # 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")
         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

crecord/crpatch.py

                 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")
             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
 
     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:
         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):
 
     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:

crecord/textpad.py

                 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:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.