Replace some 'if len(s) == 0' by 'if not s', remove unnecessary code

This commit is contained in:
Daniel Martí 2013-11-05 19:42:29 +01:00
parent 749739ec72
commit 40488a9486

View file

@ -91,19 +91,14 @@ class vcs:
self.sdk_path = sdk_path self.sdk_path = sdk_path
# It's possible to sneak a username and password in with # svn, git-svn and bzr may require auth
# the remote address for svn...
self.username = None self.username = None
if self.repotype() in ('svn', 'git-svn'): if self.repotype() in ('svn', 'git-svn', 'bzr'):
index = remote.find('@') if '@' in remote:
if index != -1: self.username, remote = remote.split('@')
self.username = remote[:index] if ':' not in self.username:
remote = remote[index+1:]
index = self.username.find(':')
if index == -1:
raise VCSException("Password required with username") raise VCSException("Password required with username")
self.password = self.username[index+1:] self.username, self.password = self.username.split(':')
self.username = self.username[:index]
self.remote = remote self.remote = remote
self.local = local self.local = local
@ -318,7 +313,7 @@ class vcs_gitsvn(vcs):
p = subprocess.Popen(['git', 'svn', 'find-rev', 'r' + rev], p = subprocess.Popen(['git', 'svn', 'find-rev', 'r' + rev],
cwd=self.local, stdout=subprocess.PIPE) cwd=self.local, stdout=subprocess.PIPE)
git_rev = p.communicate()[0].rstrip() git_rev = p.communicate()[0].rstrip()
if p.returncode != 0 or len(git_rev) == 0: if p.returncode != 0 or not git_rev:
# Try a plain git checkout as a last resort # Try a plain git checkout as a last resort
p = subprocess.Popen(['git', 'checkout', rev], cwd=self.local, p = subprocess.Popen(['git', 'checkout', rev], cwd=self.local,
stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@ -447,27 +442,6 @@ class vcs_bzr(vcs):
cwd=self.local) != 0: cwd=self.local) != 0:
raise VCSException("Bzr revert failed") raise VCSException("Bzr revert failed")
def __init__(self, remote, local, sdk_path):
self.sdk_path = sdk_path
index = remote.find('@')
if index != -1:
self.username = remote[:index]
remote = remote[index+1:]
index = self.username.find(':')
if index == -1:
raise VCSException("Password required with username")
self.password = self.username[index+1:]
self.username = self.username[:index]
else:
self.username = None
self.remote = remote
self.local = local
self.refreshed = False
self.srclib = None
def gettags(self): def gettags(self):
p = subprocess.Popen(['bzr', 'tags'], p = subprocess.Popen(['bzr', 'tags'],
stdout=subprocess.PIPE, cwd=self.local) stdout=subprocess.PIPE, cwd=self.local)
@ -550,7 +524,7 @@ def parse_metadata(metafile):
return thisbuild return thisbuild
def add_comments(key): def add_comments(key):
if len(curcomments) == 0: if not curcomments:
return return
for comment in curcomments: for comment in curcomments:
thisinfo['comments'].append((key, comment)) thisinfo['comments'].append((key, comment))
@ -631,7 +605,7 @@ def parse_metadata(metafile):
buildlines = [] buildlines = []
if mode == 0: if mode == 0:
if len(line) == 0: if not line:
continue continue
if line.startswith("#"): if line.startswith("#"):
curcomments.append(line) curcomments.append(line)
@ -654,7 +628,7 @@ def parse_metadata(metafile):
if fieldtype == 'multiline': if fieldtype == 'multiline':
mode = 1 mode = 1
thisinfo[field] = [] thisinfo[field] = []
if len(value) > 0: if value:
raise MetaDataException("Unexpected text on same line as " + field + " in " + metafile.name) raise MetaDataException("Unexpected text on same line as " + field + " in " + metafile.name)
elif fieldtype == 'string': elif fieldtype == 'string':
if field == 'Category' and thisinfo['Categories'] == 'None': if field == 'Category' and thisinfo['Categories'] == 'None':
@ -716,7 +690,7 @@ def parse_metadata(metafile):
elif mode == 3: elif mode == 3:
raise MetaDataException("Unterminated build in " + metafile.name) raise MetaDataException("Unterminated build in " + metafile.name)
if len(thisinfo['Description']) == 0: if not thisinfo['Description']:
thisinfo['Description'].append('No description available') thisinfo['Description'].append('No description available')
# Validate archive policy... # Validate archive policy...
@ -795,7 +769,7 @@ def write_metadata(dest, app):
mf.write('\n') mf.write('\n')
if app['Name']: if app['Name']:
writefield('Name') writefield('Name')
if len(app['Auto Name']) > 0: if app['Auto Name']:
writefield('Auto Name') writefield('Auto Name')
writefield('Summary') writefield('Summary')
writefield('Description', '') writefield('Description', '')
@ -806,7 +780,7 @@ def write_metadata(dest, app):
if app['Requires Root']: if app['Requires Root']:
writefield('Requires Root', 'Yes') writefield('Requires Root', 'Yes')
mf.write('\n') mf.write('\n')
if len(app['Repo Type']) > 0: if app['Repo Type']:
writefield('Repo Type') writefield('Repo Type')
writefield('Repo') writefield('Repo')
mf.write('\n') mf.write('\n')
@ -860,11 +834,11 @@ def write_metadata(dest, app):
writefield('Vercode Operation') writefield('Vercode Operation')
if 'Update Check Data' in app: if 'Update Check Data' in app:
writefield('Update Check Data') writefield('Update Check Data')
if len(app['Current Version']) > 0: if app['Current Version']:
writefield('Current Version') writefield('Current Version')
writefield('Current Version Code') writefield('Current Version Code')
mf.write('\n') mf.write('\n')
if len(app['No Source Since']) > 0: if app['No Source Since']:
writefield('No Source Since') writefield('No Source Since')
mf.write('\n') mf.write('\n')
writecomments(None) writecomments(None)
@ -1014,7 +988,7 @@ class DescriptionFormatter:
def parseline(self, line): def parseline(self, line):
self.text_wiki += line + '\n' self.text_wiki += line + '\n'
if len(line) == 0: if not line:
self.endcur() self.endcur()
elif line.startswith('*'): elif line.startswith('*'):
self.endcur([self.stUL]) self.endcur([self.stUL])
@ -1125,7 +1099,7 @@ def version_name(original, app_dir, flavour):
continue continue
xml_dir = os.path.join(f[:-19], 'res', 'values') xml_dir = os.path.join(f[:-19], 'res', 'values')
string = retrieve_string(xml_dir, original) string = retrieve_string(xml_dir, original)
if len(string) > 0: if string:
return string return string
return original return original
@ -1272,10 +1246,9 @@ def parse_srclib(metafile, **kw):
for line in metafile: for line in metafile:
line = line.rstrip('\r\n') line = line.rstrip('\r\n')
if len(line) == 0: if not line or line.startswith("#"):
continue
if line.startswith("#"):
continue continue
index = line.find(':') index = line.find(':')
if index == -1: if index == -1:
raise MetaDataException("Invalid metadata in " + metafile.name + " at: " + line) raise MetaDataException("Invalid metadata in " + metafile.name + " at: " + line)