From 7cc615f31f10b3b5434f427c09a10a7dbbdd62db Mon Sep 17 00:00:00 2001 From: Chuck Lever Date: Wed, 2 Nov 2005 16:55:42 -0500 Subject: [PATCH] Replace a variable that uses the same name as a built-in Maintainability: "str" hides the name of a Python built-in function (found by pychecker). I've also replaced the use of the variable "string" throughout, as it hides the name of the Python 'string' module. Signed-off-by: Chuck Lever --- stgit/commands/common.py | 36 +++++++++++------------ stgit/commands/mail.py | 10 +++---- stgit/git.py | 24 ++++++++-------- stgit/stack.py | 74 ++++++++++++++++++++++++------------------------ stgit/utils.py | 34 +++++++++++----------- 5 files changed, 89 insertions(+), 89 deletions(-) diff --git a/stgit/commands/common.py b/stgit/commands/common.py index 9747981..e437111 100644 --- a/stgit/commands/common.py +++ b/stgit/commands/common.py @@ -33,29 +33,29 @@ class CmdException(Exception): # Utility functions -def git_id(string): +def git_id(rev): """Return the GIT id """ - if not string: + if not rev: return None - string_list = string.split('/') - if len(string_list) == 2: - patch_id = string_list[1] + rev_list = rev.split('/') + if len(rev_list) == 2: + patch_id = rev_list[1] if not patch_id: patch_id = 'top' - elif len(string_list) == 1: + elif len(rev_list) == 1: patch_id = 'top' else: patch_id = None - patch_branch = string_list[0].split('@') + patch_branch = rev_list[0].split('@') if len(patch_branch) == 1: series = crt_series elif len(patch_branch) == 2: series = stack.Series(patch_branch[1]) else: - raise CmdException, 'Unknown id: %s' % string + raise CmdException, 'Unknown id: %s' % rev patch_name = patch_branch[0] if not patch_name: @@ -77,11 +77,11 @@ def git_id(string): return series.get_patch(patch_name).get_old_bottom() # base - if patch_name == 'base' and len(string_list) == 1: + if patch_name == 'base' and len(rev_list) == 1: return read_string(series.get_base_file()) # anything else failed - return git.rev_parse(string) + return git.rev_parse(rev) def check_local_changes(): if git.local_changes(): @@ -132,24 +132,24 @@ def resolved_all(reset = None): resolved(filename, reset) os.remove(os.path.join(git.base_dir, 'conflicts')) -def name_email(string): +def name_email(address): """Return a tuple consisting of the name and email parsed from a standard 'name ' string """ - string = re.sub('([^\w\s<>@.])', '\\\\\\1', string) - str_list = re.findall('^(.*)\s*<(.*)>\s*$', string) + address = re.sub('([^\w\s<>@.])', '\\\\\\1', address) + str_list = re.findall('^(.*)\s*<(.*)>\s*$', address) if not str_list: - raise CmdException, 'Incorrect "name " string: %s' % string + raise CmdException, 'Incorrect "name " string: %s' % address return str_list[0] -def name_email_date(string): +def name_email_date(address): """Return a tuple consisting of the name, email and date parsed from a 'name date' string """ - string = re.sub('([^\w\s<>@.])', '\\\\\\1', string) - str_list = re.findall('^(.*)\s*<(.*)>\s*(.*)\s*$', string) + address = re.sub('([^\w\s<>@.])', '\\\\\\1', address) + str_list = re.findall('^(.*)\s*<(.*)>\s*(.*)\s*$', address) if not str_list: - raise CmdException, 'Incorrect "name date" string: %s' % string + raise CmdException, 'Incorrect "name date" string: %s' % address return str_list[0] diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py index 6a7d5d2..7cc18bc 100644 --- a/stgit/commands/mail.py +++ b/stgit/commands/mail.py @@ -124,18 +124,18 @@ def __get_maintainer(): else: return None -def __parse_addresses(string): +def __parse_addresses(addresses): """Return a two elements tuple: (from, [to]) """ - def __addr_list(string): - m = re.search('[^@\s<,]+@[^>\s,]+', string); + def __addr_list(addrs): + m = re.search('[^@\s<,]+@[^>\s,]+', addrs); if (m == None): return [] - return [ m.group() ] + __addr_list(string[m.end():]) + return [ m.group() ] + __addr_list(addrs[m.end():]) from_addr_list = [] to_addr_list = [] - for line in string.split('\n'): + for line in addresses.split('\n'): if re.match('from:\s+', line, re.I): from_addr_list += __addr_list(line) elif re.match('(to|cc|bcc):\s+', line, re.I): diff --git a/stgit/git.py b/stgit/git.py index 0cdc125..9a07fa5 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -126,10 +126,10 @@ def _input(cmd, file_desc): def _output(cmd): p=popen2.Popen3(cmd, True) - string = p.fromchild.read() + output = p.fromchild.read() if p.wait(): raise GitException, '%s failed' % str(cmd) - return string + return output def _output_one_line(cmd, file_desc = None): p=popen2.Popen3(cmd, True) @@ -137,10 +137,10 @@ def _output_one_line(cmd, file_desc = None): for line in file_desc: p.tochild.write(line) p.tochild.close() - string = p.fromchild.readline().strip() + output = p.fromchild.readline().strip() if p.wait(): raise GitException, '%s failed' % str(cmd) - return string + return output def _output_lines(cmd): p=popen2.Popen3(cmd, True) @@ -540,30 +540,30 @@ def diffstat(files = None, rev1 = 'HEAD', rev2 = None): p=popen2.Popen3('git-apply --stat') diff(files, rev1, rev2, p.tochild) p.tochild.close() - str = p.fromchild.read().rstrip() + diff_str = p.fromchild.read().rstrip() if p.wait(): raise GitException, 'git.diffstat failed' - return str + return diff_str def files(rev1, rev2): """Return the files modified between rev1 and rev2 """ - str = '' + result = '' for line in _output_lines('git-diff-tree -r %s %s' % (rev1, rev2)): - str += '%s %s\n' % tuple(line.rstrip().split(' ',4)[-1].split('\t',1)) + result += '%s %s\n' % tuple(line.rstrip().split(' ',4)[-1].split('\t',1)) - return str.rstrip() + return result.rstrip() def barefiles(rev1, rev2): """Return the files modified between rev1 and rev2, without status info """ - str = '' + result = '' for line in _output_lines('git-diff-tree -r %s %s' % (rev1, rev2)): - str += '%s\n' % line.rstrip().split(' ',4)[-1].split('\t',1)[-1] + result += '%s\n' % line.rstrip().split(' ',4)[-1].split('\t',1)[-1] - return str.rstrip() + return result.rstrip() def checkout(files = None, tree_id = None, force = False): """Check out the given or all files diff --git a/stgit/stack.py b/stgit/stack.py index cd7677b..23f3039 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -64,13 +64,13 @@ def __clean_comments(f): f.seek(0); f.truncate() f.writelines(lines) -def edit_file(series, string, comment, show_patch = True): +def edit_file(series, line, comment, show_patch = True): fname = '.stgit.msg' tmpl = os.path.join(git.base_dir, 'patchdescr.tmpl') f = file(fname, 'w+') - if string: - print >> f, string + if line: + print >> f, line elif os.path.isfile(tmpl): print >> f, file(tmpl).read().rstrip() else: @@ -108,12 +108,12 @@ def edit_file(series, string, comment, show_patch = True): __clean_comments(f) f.seek(0) - string = f.read() + result = f.read() f.close() os.remove(fname) - return string + return result # # Classes @@ -150,18 +150,18 @@ class Patch: def __get_field(self, name, multiline = False): id_file = os.path.join(self.__dir, name) if os.path.isfile(id_file): - string = read_string(id_file, multiline) - if string == '': + line = read_string(id_file, multiline) + if line == '': return None else: - return string + return line else: return None - def __set_field(self, name, string, multiline = False): + def __set_field(self, name, value, multiline = False): fname = os.path.join(self.__dir, name) - if string and string != '': - write_string(fname, string, multiline) + if value and value != '': + write_string(fname, value, multiline) elif os.path.isfile(fname): os.remove(fname) @@ -171,14 +171,14 @@ class Patch: def get_bottom(self): return self.__get_field('bottom') - def set_bottom(self, string, backup = False): + def set_bottom(self, value, backup = False): if backup: curr = self.__get_field('bottom') - if curr != string: + if curr != value: self.__set_field('bottom.old', curr) else: self.__set_field('bottom.old', None) - self.__set_field('bottom', string) + self.__set_field('bottom', value) def get_old_top(self): return self.__get_field('top.old') @@ -186,14 +186,14 @@ class Patch: def get_top(self): return self.__get_field('top') - def set_top(self, string, backup = False): + def set_top(self, value, backup = False): if backup: curr = self.__get_field('top') - if curr != string: + if curr != value: self.__set_field('top.old', curr) else: self.__set_field('top.old', None) - self.__set_field('top', string) + self.__set_field('top', value) def restore_old_boundaries(self): bottom = self.__get_field('bottom.old') @@ -209,46 +209,46 @@ class Patch: def get_description(self): return self.__get_field('description', True) - def set_description(self, string): - self.__set_field('description', string, True) + def set_description(self, line): + self.__set_field('description', line, True) def get_authname(self): return self.__get_field('authname') - def set_authname(self, string): - if not string and config.has_option('stgit', 'authname'): - string = config.get('stgit', 'authname') - self.__set_field('authname', string) + def set_authname(self, name): + if not name and config.has_option('stgit', 'authname'): + name = config.get('stgit', 'authname') + self.__set_field('authname', name) def get_authemail(self): return self.__get_field('authemail') - def set_authemail(self, string): - if not string and config.has_option('stgit', 'authemail'): - string = config.get('stgit', 'authemail') - self.__set_field('authemail', string) + def set_authemail(self, address): + if not address and config.has_option('stgit', 'authemail'): + address = config.get('stgit', 'authemail') + self.__set_field('authemail', address) def get_authdate(self): return self.__get_field('authdate') - def set_authdate(self, string): - self.__set_field('authdate', string) + def set_authdate(self, authdate): + self.__set_field('authdate', authdate) def get_commname(self): return self.__get_field('commname') - def set_commname(self, string): - if not string and config.has_option('stgit', 'commname'): - string = config.get('stgit', 'commname') - self.__set_field('commname', string) + def set_commname(self, name): + if not name and config.has_option('stgit', 'commname'): + name = config.get('stgit', 'commname') + self.__set_field('commname', name) def get_commemail(self): return self.__get_field('commemail') - def set_commemail(self, string): - if not string and config.has_option('stgit', 'commemail'): - string = config.get('stgit', 'commemail') - self.__set_field('commemail', string) + def set_commemail(self, address): + if not address and config.has_option('stgit', 'commemail'): + address = config.get('stgit', 'commemail') + self.__set_field('commemail', address) class Series: diff --git a/stgit/utils.py b/stgit/utils.py index b941f7c..5749b3b 100644 --- a/stgit/utils.py +++ b/stgit/utils.py @@ -23,44 +23,44 @@ def read_string(filename, multiline = False): """ f = file(filename, 'r') if multiline: - string = f.read() + result = f.read() else: - string = f.readline().strip() + result = f.readline().strip() f.close() - return string + return result -def write_string(filename, string, multiline = False): - """Writes string to file and truncates it +def write_string(filename, line, multiline = False): + """Writes 'line' to file and truncates it """ f = file(filename, 'w+') if multiline: - f.write(string) + f.write(line) else: - print >> f, string + print >> f, line f.close() -def append_strings(filename, strings): - """Appends string sequence to file +def append_strings(filename, lines): + """Appends 'lines' sequence to file """ f = file(filename, 'a+') - for string in strings: - print >> f, string + for line in lines: + print >> f, line f.close() -def append_string(filename, string): - """Appends string to file +def append_string(filename, line): + """Appends 'line' to file """ f = file(filename, 'a+') - print >> f, string + print >> f, line f.close() -def insert_string(filename, string): - """Inserts a string at the beginning of the file +def insert_string(filename, line): + """Inserts 'line' at the beginning of the file """ f = file(filename, 'r+') lines = f.readlines() f.seek(0); f.truncate() - print >> f, string + print >> f, line f.writelines(lines) f.close() -- 2.11.0