Remove some pylint warnings

Remove some warnings noticed by pylint.

There're still a lot of warnings, this is just an iterative improvement.

Change-Id: Iafecf55176f230b91353ecd5b5014ba749056f89
This commit is contained in:
Andreas Jaeger 2014-05-18 15:23:59 +02:00
parent bd36d6f4b8
commit ff2a921194
3 changed files with 28 additions and 22 deletions

View File

@ -99,14 +99,14 @@ def generate_heading(os_command, api_name, title, os_file):
os_file.write(header.format(os_command, api_name, title, version))
def is_option(str):
def is_option(string):
"""Returns True if string specifies an argument."""
for x in str:
for x in string:
if not (x.isupper() or x == '_' or x == ','):
return False
if str.startswith('DEPRECATED'):
if string.startswith('DEPRECATED'):
return False
return True
@ -532,7 +532,7 @@ def main():
parser.add_argument('client', nargs='?',
help="OpenStack command to document.")
parser.add_argument("--all", help="Document all clients.",
action="store_true"),
action="store_true")
parser.add_argument("--output-dir", default=".",
help="Directory to write generated files to")
prog_args = parser.parse_args()

View File

@ -229,7 +229,7 @@ def verify_nice_usage_of_whitespaces(docfile):
for element in elements:
checks.append(re.compile(".*<%s>\s+[\w\-().:!?{}\[\]]+.*\n"
% element)),
% element))
checks.append(re.compile(".*[\w\-().:!?{}\[\]]+\s+<\/%s>.*\n"
% element))
@ -323,7 +323,7 @@ def ha_guide_touched():
return ha_changed
def check_modified_affects_all(rootdir, verbose):
def check_modified_affects_all(rootdir):
"""Check whether special files were modified.
There are some special files where we should rebuild all books
@ -400,7 +400,7 @@ def check_deleted_files(rootdir, file_exceptions, verbose):
for f in deleted_files:
print (" %s" % f)
deleted_files = map(lambda x: os.path.abspath(x), deleted_files)
deleted_files = [os.path.abspath(x) for x in deleted_files]
no_checked_files = 0
# Figure out whether files were included anywhere
@ -614,8 +614,7 @@ def validate_modified_files(rootdir, exceptions, verbose,
# Do not select deleted files, just Added, Copied, Modified, Renamed,
# or Type changed
modified_files = get_modified_files(rootdir, "--diff-filter=ACMRT")
modified_files = filter(is_xml_like, modified_files)
modified_files = [f for f in modified_files if is_xml_like(f)]
validate_individual_files(modified_files, rootdir, exceptions,
verbose,
@ -892,7 +891,7 @@ def is_book_master(filename):
def find_affected_books(rootdir, book_exceptions, file_exceptions,
verbose, force, ignore_dirs):
force, ignore_dirs):
"""Check which books are affected by modified files.
Returns a set with books.
@ -902,7 +901,7 @@ def find_affected_books(rootdir, book_exceptions, file_exceptions,
books = []
affected_books = set()
build_all_books = (force or check_modified_affects_all(rootdir, verbose) or
build_all_books = (force or check_modified_affects_all(rootdir) or
cfg.CONF.only_book)
# Dictionary that contains a set of files.
@ -1028,7 +1027,7 @@ def find_affected_books(rootdir, book_exceptions, file_exceptions,
# Do not select deleted files, just Added, Copied, Modified, Renamed,
# or Type changed
modified_files = get_modified_files(rootdir, "--diff-filter=ACMRT")
modified_files = map(lambda x: os.path.abspath(x), modified_files)
modified_files = [os.path.abspath(f) for f in modified_files]
# 2. Find all modified files and where they are included
@ -1122,8 +1121,8 @@ def generate_index_file():
def build_affected_books(rootdir, book_exceptions, file_exceptions,
verbose, force=False, ignore_errors=False,
ignore_dirs=[]):
force=False, ignore_errors=False,
ignore_dirs=None):
"""Build all the books which are affected by modified files.
Looks for all directories with "pom.xml" and checks if a
@ -1134,9 +1133,11 @@ def build_affected_books(rootdir, book_exceptions, file_exceptions,
This will throw an exception if a book fails to build
"""
if ignore_dirs is None:
ignore_dirs = []
books = find_affected_books(rootdir, book_exceptions,
file_exceptions, verbose,
force, ignore_dirs)
file_exceptions, force, ignore_dirs)
# Remove cache content which can cause build failures
shutil.rmtree(os.path.expanduser("~/.fop"),
@ -1391,7 +1392,8 @@ def handle_options():
print(" Comments enabled: %s" % cfg.CONF.comments_enabled)
def main():
def doctest():
"""Central entrypoint, parses arguments and runs tests."""
CONF = cfg.CONF
print ("\nOpenStack Doc Checks (using openstack-doc-tools version %s)\n"
@ -1442,10 +1444,10 @@ def main():
ensure_exists("mvn")
build_affected_books(doc_path, BOOK_EXCEPTIONS,
BUILD_FILE_EXCEPTIONS,
CONF.verbose, CONF.force,
CONF.force,
CONF.ignore_errors,
CONF.ignore_dir)
if __name__ == "__main__":
sys.exit(main())
sys.exit(doctest())

View File

@ -46,7 +46,7 @@ class myDocbookXmlMode(docbookXmlMode):
default_mode = 'docbook'
operation = 'merge'
options = {
xml_options = {
'mark_untranslated': False,
'expand_entities': True,
'expand_all_entities': False,
@ -57,6 +57,8 @@ IGNORE_FILE = []
def mergeback(folder, language, root):
"""Generate translated files for language in directory folder."""
if folder is None:
path = root
else:
@ -101,7 +103,7 @@ def mergeSingleDocument(folder, language, root):
relpath)
try:
xml2po_main = Main(default_mode, "merge", outputpath,
options)
xml_options)
xml2po_main.current_mode = myDocbookXmlMode()
xml2po_main.merge(mofile_tmppath, aXML)
outputfiles.append(outputpath)
@ -117,6 +119,8 @@ def mergeSingleDocument(folder, language, root):
def changeXMLLangSetting(xmlFile, language):
"""Update XML settings for file."""
dom = xml.dom.minidom.parse(xmlFile)
root = dom.documentElement
root.setAttribute("xml:lang", language[:2])
@ -276,7 +280,7 @@ def generateSinglePoT(folder, root):
os.mkdir(output)
output = os.path.join(output, folder + ".pot")
try:
xml2po_main = Main(default_mode, "pot", output, options)
xml2po_main = Main(default_mode, "pot", output, xml_options)
xml2po_main.current_mode = myDocbookXmlMode()
except IOError:
print("Error: cannot open aFile %s for writing." % (output))