Skip to content

Commit 510cbc1

Browse files
committed
Fix pylint messages in src/vcs
1 parent 560f8a4 commit 510cbc1

File tree

13 files changed

+214
-152
lines changed

13 files changed

+214
-152
lines changed

src/diffuse.in

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121

2222
import sys
2323
import gettext
24-
import locale
2524

26-
pkgdatadir = '@pkgdatadir@'
27-
localedir = '@localedir@'
25+
PKGDATADIR = '@pkgdatadir@'
26+
LOCALEDIR = '@localedir@'
2827

29-
sys.path.insert(1, pkgdatadir)
30-
gettext.install('diffuse', localedir)
28+
sys.path.insert(1, PKGDATADIR)
29+
gettext.install('diffuse', LOCALEDIR)
3130

3231
if __name__ == '__main__':
3332
from diffuse import main

src/main.py

Lines changed: 20 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@
5555
from diffuse import constants
5656
from diffuse.vcs.vcs_registry import VcsRegistry
5757

58-
if not hasattr(__builtins__, 'WindowsError'):
59-
# define 'WindowsError' so 'except' statements will work on all platforms
60-
WindowsError = IOError
61-
6258
# avoid some dictionary lookups when string.whitespace is used in loops
6359
# this is sorted based upon frequency to speed up code for stripping whitespace
6460
whitespace = ' \t\n\r\x0b\x0c'
@@ -131,38 +127,6 @@ def parse(self, state_name, s):
131127
start = end
132128
return state_name, blocks
133129

134-
# split string into lines based upon DOS, Mac, and Unix line endings
135-
def splitlines(s):
136-
# split on new line characters
137-
temp, i, n = [], 0, len(s)
138-
while i < n:
139-
j = s.find('\n', i)
140-
if j < 0:
141-
temp.append(s[i:])
142-
break
143-
j += 1
144-
temp.append(s[i:j])
145-
i = j
146-
# split on carriage return characters
147-
ss = []
148-
for s in temp:
149-
i, n = 0, len(s)
150-
while i < n:
151-
j = s.find('\r', i)
152-
if j < 0:
153-
ss.append(s[i:])
154-
break
155-
j += 1
156-
if j < n and s[j] == '\n':
157-
j += 1
158-
ss.append(s[i:j])
159-
i = j
160-
return ss
161-
162-
# also recognise old Mac OS line endings
163-
def readlines(fd):
164-
return strip_eols(splitlines(fd.read()))
165-
166130
def readconfiglines(fd):
167131
return fd.read().replace('\r', '').split('\n')
168132

@@ -1141,33 +1105,12 @@ def getFormat(ss):
11411105
flags |= UNIX_FORMAT
11421106
return flags
11431107

1144-
# returns the number of characters in the string excluding any line ending
1145-
# characters
1146-
def len_minus_line_ending(s):
1147-
if s is None:
1148-
return 0
1149-
n = len(s)
1150-
if s.endswith('\r\n'):
1151-
n -= 2
1152-
elif s.endswith('\r') or s.endswith('\n'):
1153-
n -= 1
1154-
return n
1155-
1156-
# returns the string without the line ending characters
1157-
def strip_eol(s):
1158-
if s is not None:
1159-
return s[:len_minus_line_ending(s)]
1160-
1161-
# returns the list of strings without line ending characters
1162-
def strip_eols(ss):
1163-
return [ strip_eol(s) for s in ss ]
1164-
11651108
# convenience method to change the line ending of a string
11661109
def convert_to_format(s, format):
11671110
if s is not None and format != 0:
11681111
old_format = getFormat([ s ])
11691112
if old_format != 0 and (old_format & format) == 0:
1170-
s = strip_eol(s)
1113+
s = utils.strip_eol(s)
11711114
# prefer the host line ending style
11721115
if (format & DOS_FORMAT) and os.linesep == '\r\n':
11731116
s += os.linesep
@@ -1913,7 +1856,7 @@ def setFont(self, font):
19131856
# This is an inline loop over self.characterWidth() for performance reasons.
19141857
def stringWidth(self, s):
19151858
if not self.prefs.getBool('display_show_whitespace'):
1916-
s = strip_eol(s)
1859+
s = utils.strip_eol(s)
19171860
col = 0
19181861
for c in s:
19191862
try:
@@ -1965,7 +1908,7 @@ def characterWidth(self, i, c):
19651908
def expand(self, s):
19661909
visible = self.prefs.getBool('display_show_whitespace')
19671910
if not visible:
1968-
s = strip_eol(s)
1911+
s = utils.strip_eol(s)
19691912
tab_width = self.prefs.getInt('display_tab_width')
19701913
col = 0
19711914
result = []
@@ -2563,7 +2506,7 @@ def _alignmentHash(self, line):
25632506
# hashes for non-null lines should start with '+' to distinguish
25642507
# them from blank lines
25652508
if pref('align_ignore_endofline'):
2566-
text = strip_eol(text)
2509+
text = utils.strip_eol(text)
25672510
if pref('align_ignore_blanklines') and isBlank(text):
25682511
# consider all lines containing only white space as the same
25692512
return ''
@@ -2792,8 +2735,8 @@ def replaceText(self, text):
27922735
if text is None:
27932736
text = ''
27942737
# split the replacement text into lines
2795-
ss = splitlines(text)
2796-
if len(ss) == 0 or len(ss[-1]) != len_minus_line_ending(ss[-1]):
2738+
ss = utils.splitlines(text)
2739+
if len(ss) == 0 or len(ss[-1]) != utils.len_minus_line_ending(ss[-1]):
27972740
ss.append('')
27982741
# change the format to that of the target pane
27992742
if pane.format == 0:
@@ -2807,7 +2750,7 @@ def replaceText(self, text):
28072750
lastcol = 0
28082751
if len(ss) > 0:
28092752
last = ss[-1]
2810-
if len(last) == len_minus_line_ending(last):
2753+
if len(last) == utils.len_minus_line_ending(last):
28112754
del ss[-1]
28122755
lastcol = len(last)
28132756
cur_line = line0 + len(ss)
@@ -3200,7 +3143,7 @@ def button_press(self, f, x, y, extend):
32003143
x, y = -1, 0
32013144
i = min(y // self.font_height, len(self.panes[f].lines))
32023145
if self.mode == CHAR_MODE and f == self.current_pane:
3203-
text = strip_eol(self.getLineText(f, i))
3146+
text = utils.strip_eol(self.getLineText(f, i))
32043147
j = self._getPickedCharacter(text, x, True)
32053148
if extend:
32063149
si, sj = self.selection_line, self.selection_char
@@ -3241,7 +3184,7 @@ def darea_button_press_cb(self, widget, event, f):
32413184
self.emit('mode_changed')
32423185
elif self.mode == CHAR_MODE and self.current_pane == f:
32433186
# select word
3244-
text = strip_eol(self.getLineText(f, i))
3187+
text = utils.strip_eol(self.getLineText(f, i))
32453188
if text is not None:
32463189
n = len(text)
32473190
j = self._getPickedCharacter(text, x, False)
@@ -3323,7 +3266,7 @@ def getDiffRanges(self, f, i, idx, flag):
33233266
else:
33243267
s = s2
33253268
if self.prefs.getBool('display_ignore_endofline'):
3326-
s = strip_eol(s)
3269+
s = utils.strip_eol(s)
33273270

33283271
s1 = nullToEmpty(self.getCompareString(f, i))
33293272
s2 = nullToEmpty(self.getCompareString(f + 1, i))
@@ -3394,7 +3337,7 @@ def getCompareString(self, f, i):
33943337
s = line.getText()
33953338
if s is not None:
33963339
if self.prefs.getBool('display_ignore_endofline'):
3397-
s = strip_eol(s)
3340+
s = utils.strip_eol(s)
33983341
if self.prefs.getBool('display_ignore_blanklines') and isBlank(s):
33993342
return None
34003343
if self.prefs.getBool('display_ignore_whitespace'):
@@ -3906,7 +3849,7 @@ def diffmap_draw_cb(self, widget, cr):
39063849
# returns the maximum valid offset for a cursor position
39073850
# cursors cannot be moved to the right of line ending characters
39083851
def getMaxCharPosition(self, i):
3909-
return len_minus_line_ending(self.getLineText(self.current_pane, i))
3852+
return utils.len_minus_line_ending(self.getLineText(self.current_pane, i))
39103853

39113854
# 'enter_align_mode' keybinding action
39123855
def _line_mode_enter_align_mode(self):
@@ -4132,7 +4075,7 @@ def key_press_cb(self, widget, event):
41324075
# move the cursor to column 'col' if possible
41334076
s = self.getLineText(f, i)
41344077
if s is not None:
4135-
s = strip_eol(s)
4078+
s = utils.strip_eol(s)
41364079
idx = 0
41374080
for c in s:
41384081
w = self.characterWidth(idx, c)
@@ -4282,7 +4225,7 @@ def key_press_cb(self, widget, event):
42824225
self.recordEditMode()
42834226
for i in range(start, end + 1):
42844227
text = self.getLineText(f, i)
4285-
if text is not None and len_minus_line_ending(text) > 0:
4228+
if text is not None and utils.len_minus_line_ending(text) > 0:
42864229
# count spacing before the first non-whitespace character
42874230
j, w = 0, 0
42884231
while j < len(text) and text[j] in ' \t':
@@ -4807,7 +4750,7 @@ def remove_trailing_white_space(self):
48074750
text = self.getLineText(f, i)
48084751
if text is not None:
48094752
# locate trailing whitespace
4810-
old_n = n = len_minus_line_ending(text)
4753+
old_n = n = utils.len_minus_line_ending(text)
48114754
while n > 0 and text[n - 1] in whitespace:
48124755
n -= 1
48134756
# update line if it changed
@@ -4914,7 +4857,7 @@ def _adjust_indenting(self, offset):
49144857
self.recordEditMode()
49154858
for i in range(start, end + 1):
49164859
text = self.getLineText(f, i)
4917-
if text is not None and len_minus_line_ending(text) > 0:
4860+
if text is not None and utils.len_minus_line_ending(text) > 0:
49184861
# count spacing before the first non-whitespace character
49194862
j, w = 0, 0
49204863
while j < len(text) and text[j] in ' \t':
@@ -5628,8 +5571,8 @@ def load(self, f, info):
56285571
s, encoding = self.prefs.convertToUnicode(s)
56295572
else:
56305573
s = str(s, encoding=encoding)
5631-
ss = splitlines(s)
5632-
except (IOError, OSError, UnicodeDecodeError, WindowsError, LookupError):
5574+
ss = utils.splitlines(s)
5575+
except (IOError, OSError, UnicodeDecodeError, LookupError):
56335576
# FIXME: this can occur before the toplevel window is drawn
56345577
if rev is not None:
56355578
msg = _('Error reading revision %(rev)s of %(file)s.') % { 'rev': rev, 'file': name }
@@ -6460,7 +6403,7 @@ def createCommitFileTabs(self, items, labels, options):
64606403
name, rev = spec
64616404
viewer.load(i, FileInfo(name, encoding, vcs, rev))
64626405
viewer.setOptions(options)
6463-
except (IOError, OSError, WindowsError):
6406+
except (IOError, OSError):
64646407
utils.logErrorAndDialog(_('Error retrieving commits for %s.') % (dn, ), self.get_toplevel())
64656408

64666409
# create a new viewer for each modified file found in 'items'
@@ -6489,7 +6432,7 @@ def createModifiedFileTabs(self, items, labels, options):
64896432
name, rev = spec
64906433
viewer.load(i, FileInfo(name, encoding, vcs, rev))
64916434
viewer.setOptions(options)
6492-
except (IOError, OSError, WindowsError):
6435+
except (IOError, OSError):
64936436
utils.logErrorAndDialog(_('Error retrieving modifications for %s.') % (dn, ), self.get_toplevel())
64946437

64956438
# close all tabs without differences

src/utils.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ def relpath(a, b):
9696
# helper function prevent files from being confused with command line options
9797
# by prepending './' to the basename
9898
def safeRelativePath(abspath1, name, prefs, cygwin_pref):
99-
s = os.path.join(os.curdir, utils.relpath(abspath1, os.path.abspath(name)))
100-
if utils.isWindows():
99+
s = os.path.join(os.curdir, relpath(abspath1, os.path.abspath(name)))
100+
if isWindows():
101101
if prefs.getBool(cygwin_pref):
102102
s = s.replace('\\', '/')
103103
else:
@@ -182,6 +182,55 @@ def globEscape(s):
182182
m = dict([ (c, f'[{c}]') for c in '[]?*' ])
183183
return ''.join([ m.get(c, c) for c in s ])
184184

185+
# returns the number of characters in the string excluding any line ending
186+
# characters
187+
def len_minus_line_ending(s):
188+
if s is None:
189+
return 0
190+
n = len(s)
191+
if s.endswith('\r\n'):
192+
n -= 2
193+
elif s.endswith('\r') or s.endswith('\n'):
194+
n -= 1
195+
return n
196+
197+
# returns the string without the line ending characters
198+
def strip_eol(s):
199+
if s is not None:
200+
return s[:len_minus_line_ending(s)]
201+
202+
# split string into lines based upon DOS, Mac, and Unix line endings
203+
def splitlines(s):
204+
# split on new line characters
205+
temp, i, n = [], 0, len(s)
206+
while i < n:
207+
j = s.find('\n', i)
208+
if j < 0:
209+
temp.append(s[i:])
210+
break
211+
j += 1
212+
temp.append(s[i:j])
213+
i = j
214+
# split on carriage return characters
215+
ss = []
216+
for s in temp:
217+
i, n = 0, len(s)
218+
while i < n:
219+
j = s.find('\r', i)
220+
if j < 0:
221+
ss.append(s[i:])
222+
break
223+
j += 1
224+
if j < n and s[j] == '\n':
225+
j += 1
226+
ss.append(s[i:j])
227+
i = j
228+
return ss
229+
230+
# also recognize old Mac OS line endings
231+
def readlines(fd):
232+
return [ strip_eol(s) for s in splitlines(fd.read()) ]
233+
185234
# use the program's location as a starting place to search for supporting files
186235
# such as icon and help documentation
187236
if hasattr(sys, 'frozen'):

src/vcs/cvs.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ def getCommitTemplate(self, prefs, rev, names):
4141
if len(r):
4242
prev = '.'.join(r)
4343
for k in sorted(names):
44-
if prev is None:
45-
k0 = None
46-
else:
47-
k0 = k
48-
result.append([ (k0, prev), (k, rev) ])
44+
if prev is None:
45+
k0 = None
46+
else:
47+
k0 = k
48+
result.append([ (k0, prev), (k, rev) ])
4949
except ValueError:
5050
utils.logError(_('Error parsing revision %s.') % (rev, ))
5151
return result
@@ -73,7 +73,6 @@ def getFolderTemplate(self, prefs, names):
7373
if s[0] == 'R':
7474
# removed
7575
modified[k] = [ (k, prev), (None, None) ]
76-
pass
7776
elif s[0] == 'A':
7877
# added
7978
modified[k] = [ (None, None), (k, None) ]

src/vcs/folder_set.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,3 @@ def contains(self, abspath):
4242
if abspath.startswith(f):
4343
return True
4444
return False
45-

src/vcs/git.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ def _extractPath(self, s, prefs):
6565

6666
def getFolderTemplate(self, prefs, names):
6767
# build command
68-
args = [ prefs.getString('git_bin'), 'status', '--porcelain', '-s', '--untracked-files=no', '--ignore-submodules=all' ]
68+
args = [
69+
prefs.getString('git_bin'),
70+
'status',
71+
'--porcelain',
72+
'-s',
73+
'--untracked-files=no',
74+
'--ignore-submodules=all'
75+
]
6976
# build list of interesting files
7077
pwd = os.path.abspath(os.curdir)
7178
isabs = False
@@ -142,14 +149,13 @@ def getFolderTemplate(self, prefs, names):
142149
return result
143150

144151
def getRevision(self, prefs, name, rev):
152+
relpath = utils.relpath(self.root, os.path.abspath(name)).replace(os.sep, '/')
145153
return utils.popenRead(
146154
self.root,
147155
[
148156
prefs.getString('git_bin'),
149157
'show',
150-
'{}:{}'.format(
151-
rev,
152-
utils.relpath(self.root, os.path.abspath(name)).replace(os.sep, '/'))
158+
f'{rev}:{relpath}'
153159
],
154160
prefs,
155161
'git_bash')

0 commit comments

Comments
 (0)