Use a more pythonic syntax

Don't use len(var) when not needed.

Change-Id: Ic067c7dcef875dcc6143be047c1a96bcb96deda9
This commit is contained in:
Gauvain Pocentek 2015-11-09 07:57:52 +01:00
parent 9925ca9cf8
commit 5dea03b26f
3 changed files with 15 additions and 15 deletions

View File

@ -217,13 +217,13 @@ def extract_options(line):
w0 = words[0]
del words[0]
w1 = ''
if len(words) > 0:
if words:
w1 = words[0]
del words[0]
for w in words:
w1 += " " + w
if len(w1) == 0:
if not w1:
split_line = [w0]
else:
split_line = [w0, w1]
@ -238,11 +238,11 @@ def format_table(title, lines, os_file):
close_entry = False
os_file.write(" <variablelist wordsize=\"10\">\n")
if len(title) > 0:
if title:
os_file.write(" <title>%s</title>\n" % title)
for line in lines:
if len(line) == 0 or line[0] != ' ':
if not line or line[0] != ' ':
break
# We have to handle these cases:
# 1. command Explanation
@ -301,7 +301,7 @@ def generate_command(os_command, os_file):
for line in help_lines:
line_index += 1
xline = quote_xml(line)
if len(line) > 0 and line[0] != ' ':
if line and line[0] != ' ':
# XXX: Might have whitespace before!!
if '<subcommands>' in line:
ignore_next_lines = False
@ -381,7 +381,7 @@ def generate_command(os_command, os_file):
os_file.write(" <screen><computeroutput>%s" % xline)
next_line_screen = False
in_screen = True
elif len(line) > 0:
elif line:
os_file.write("\n%s" % xline.rstrip())
if in_screen:
@ -483,7 +483,7 @@ def generate_subcommand(os_command, os_subcommand, os_file, extra_params,
break
if skip_lines:
continue
if len(line) == 0:
if not line:
if not in_para:
os_file.write("</computeroutput></screen>")
os_file.write("\n <para>")

View File

@ -191,7 +191,7 @@ def verify_attribute_profiling(doc, attribute, known_values):
"profiling of %s on line %d." %
(p_tag[len_ns:], attribute, p_att_list,
attribute, c_tag[len_ns:], c_line))
if len(msg) > 0:
if msg:
raise ValueError("\n ".join(msg))
@ -223,7 +223,7 @@ def verify_unicode_niceness(docfile):
lc += 1
any(c in line for c in invalid_characters)
if len(affected_lines):
if affected_lines:
raise ValueError("unwanted unicode charaters (one of %s) "
"found in line(s): %" % (" ".join(invalid_characters),
", ".join(affected_lines)))
@ -321,7 +321,7 @@ def verify_valid_links(doc):
msg.append("URL %s invalid at line %d, error %s" % (
url, e_line, e))
if len(msg) > 0:
if msg:
raise ValueError("\n ".join(msg))
@ -1093,7 +1093,7 @@ def generate_affected_books(rootdir, book_bk, ignore_dirs, abs_ignore_dirs,
# 3. Iterate over files that have includes on modified files
# and build a closure - the set of all files (affected_files)
# that have a path to a modified file via includes.
while len(new_files) > 0:
while new_files:
new_files_to_check = new_files
new_files = []
for f in new_files_to_check:

View File

@ -53,7 +53,7 @@ def mergeback(folder, language, root):
path = root
else:
outputFiles = mergeSingleDocument(folder, language, root)
if (outputFiles is not None) and (len(outputFiles) > 0):
if outputFiles:
for outXML in outputFiles:
changeXMLLangSetting(outXML, language)
return
@ -65,7 +65,7 @@ def mergeback(folder, language, root):
for aFile in files:
if not (aFile in IGNORE_FOLDER):
outputFiles = mergeSingleDocument(aFile, language, root)
if (outputFiles is not None) and (len(outputFiles) > 0):
if outputFiles:
for outXML in outputFiles:
changeXMLLangSetting(outXML, language)
@ -79,7 +79,7 @@ def mergeSingleDocument(folder, language, root):
else:
return None
if len(xmlfiles) > 0:
if xmlfiles:
popath = os.path.join(abspath, "locale", language + ".po")
# generate MO file
mofile_handler, mofile_tmppath = tempfile.mkstemp()
@ -247,7 +247,7 @@ def generateSinglePoT(folder, root):
else:
return
if len(xmlfiles) > 0:
if xmlfiles:
output = os.path.join(abspath, "locale")
if not os.path.exists(output):
os.mkdir(output)