Merge "Fix issues found by flake8"

This commit is contained in:
Jenkins 2013-12-20 08:17:10 +00:00 committed by Gerrit Code Review
commit 64f2f860c8
6 changed files with 70 additions and 47 deletions

View File

@ -6,7 +6,6 @@
# For an example of usage, run this program with the -h switch.
#
import os
import sys
# this is for the internationalisation function in gettext

View File

@ -7,7 +7,6 @@ from oslo.config import cfg
import os
import string
import sys
import pkgutil
import glob
from collections import defaultdict
from xml.sax.saxutils import escape
@ -64,15 +63,20 @@ def extract_flags(repo_location, module_name, verbose=0, names_only=True):
for root, dirs, files in os.walk(module_location + '/' + module_name):
for name in dirs:
abs_path = os.path.join(root.split(module_location)[1][1:], name)
if ('/tests' not in abs_path and '/locale' not in abs_path and
'/cmd' not in abs_path and '/db/migration' not in abs_path and
if ('/tests' not in abs_path and
'/locale' not in abs_path and
'/cmd' not in abs_path and
'/db/migration' not in abs_path and
'/transfer' not in abs_path):
usable_dirs.append(os.path.join(root.split(module_location)[1][1:], name))
usable_dirs.append(os.path.join(root.split(module_location)
[1][1:], name))
for directory in usable_dirs:
for python_file in glob.glob(module_location + '/' + directory + "/*.py"):
for python_file in glob.glob(module_location + '/' + directory
+ "/*.py"):
if '__init__' not in python_file:
usable_dirs.append(os.path.splitext(python_file)[0][len(module_location) + 1:])
usable_dirs.append(os.path.splitext(python_file)
[0][len(module_location) + 1:])
package_name = directory.replace('/', '.')
try:
@ -112,20 +116,24 @@ def extract_flags_test(repo_loc, module, verbose=0):
TEST TEST TEST TEST TEST TEST
"""
flag_data = {}
flag_files = []
usable_dirs = []
module_location = os.path.dirname(repo_loc + '/' + module)
for root, dirs, files in os.walk(module_location + '/' + module):
for name in dirs:
abs_path = os.path.join(root.split(module_location)[1][1:], name)
if ('/tests' not in abs_path and '/locale' not in abs_path and
'/cmd' not in abs_path and '/db/migration' not in abs_path):
usable_dirs.append(os.path.join(root.split(module_location)[1][1:], name))
if ('/tests' not in abs_path and
'/locale' not in abs_path and
'/cmd' not in abs_path and
'/db/migration' not in abs_path):
usable_dirs.append(os.path.join(root.split(module_location)
[1][1:], name))
for directory in usable_dirs:
for python_file in glob.glob(module_location + '/' + directory + "/*.py"):
for python_file in glob.glob(module_location + '/' + directory +
"/*.py"):
if '__init__' not in python_file:
usable_dirs.append(os.path.splitext(python_file)[0][len(module_location) + 1:])
usable_dirs.append(os.path.splitext(python_file)[0]
[len(module_location) + 1:])
package_name = directory.replace('/', '.')
try:
@ -165,7 +173,7 @@ def write_test(file, repo_dir, pkg_name):
print "\n -- end file name area --\n"
print len(flag_info)
for name, value in flag_info:
opt = value['opt']
#opt = value['opt']
#print type(opt)
#print opt
#print name
@ -183,7 +191,9 @@ def write_header(filepath, verbose=0):
def write_buffer(file, flags, verbose=0):
"""
Write flag data to file. (The header is written with the write_header function.)
Write flag data to file.
Note that the header is written with the write_header function.
"""
pass
#with open(os.path.expanduser(filepath), 'wb') as f:
@ -253,7 +263,8 @@ def write_docbook(directory, flags, groups, package_name, verbose=0):
opt = flag[1]["opt"]
if not opt.help:
opt.help = "No help text available for this option"
if type(opt).__name__ == "ListOpt" and opt.default is not None:
if (type(opt).__name__ == "ListOpt" and
opt.default is not None):
opt.default = ",".join(opt.default)
groups_file.write('\n <tr>\n\
<td>' + flag_name + '=' + str(opt.default) + '</td>\n\

View File

@ -80,10 +80,12 @@ def extract_descriptions_from_devref(repo, options):
+ ' ' + line.strip())
for option in options:
line_parts = line.strip().split(None, 2)
if (' ' in line and len(line_parts) == 3
and option == line_parts[0]
and line_parts[1] != '=' and option != 'use'
and (option not in option_descs or
if (' ' in line and
len(line_parts) == 3 and
option == line_parts[0] and
line_parts[1] != '=' and
option != 'use' and
(option not in option_descs or
len(option_descs[option]) < len(line_parts[2]))):
option_descs[option] = line_parts[2]
prev_option = option
@ -94,7 +96,8 @@ def new_section_file(sample, current_section):
section_filename = ('swift-' +
path.basename(sample).split('.conf')[0]
+ '-'
+ current_section.replace('[', '').replace(']', '').replace(':', '-')
+ current_section.replace('[', '').
replace(']', '').replace(':', '-')
+ '.xml')
section_file = open(section_filename, 'w')
section_file.write('<?xml version="1.0" encoding="UTF-8"?>\n\
@ -104,7 +107,8 @@ def new_section_file(sample, current_section):
<para xmlns="http://docbook.org/ns/docbook" version="5.0">\n\
<table rules="all">\n\
<caption>Description of configuration options for <literal>'
+ current_section + '</literal> in <literal>' + path.basename(sample) +
+ current_section + '</literal> in <literal>'
+ path.basename(sample) +
'</literal></caption>\n\
<col width="50%"/>\n\
<col width="50%"/>\n\
@ -159,10 +163,12 @@ def create_new_tables(repo, verbose):
if (parsed_line[0] in options.keys()
and 'No help text' not in options[parsed_line[0]]):
# use the help text from existing tables
option_desc = options[parsed_line[0]].replace(u'\xa0', u' ')
option_desc = options[parsed_line[0]].replace(u'\xa0',
u' ')
elif parsed_line[0] in option_descs:
# use the help text from the devref
option_desc = option_descs[parsed_line[0]].replace(u'\xa0', u' ')
option_desc = option_descs[parsed_line[0]].replace(
u'\xa0', u' ')
else:
option_desc = 'No help text available for this option'
if verbose > 0:

View File

@ -35,7 +35,7 @@ import textwrap
from oslo.config import cfg
from openstack.common import gettextutils
#from openstack.common import gettextutils
from openstack.common import importutils
# sld

View File

@ -13,7 +13,8 @@ import tempfile
import shutil
# should be the same like in tools/validate.py
FILE_EXCEPTIONS = ['ha-guide-docinfo.xml','bk001-ch003-associate-general.xml']
FILE_EXCEPTIONS = ['ha-guide-docinfo.xml',
'bk001-ch003-associate-general.xml']
elements = [
'listitem',
@ -31,8 +32,10 @@ elements = [
checks = []
for element in elements:
checks.append(re.compile("(.*<%s>)\s+([\w\-().:!?{}\[\]]+.*\n)" % element)),
checks.append(re.compile("(.*[\w\-().:!?{}\[\]]+)\s+(<\/%s>.*\n)" % element))
checks.append(re.compile("(.*<%s>)\s+([\w\-().:!?{}\[\]]+.*\n)"
% element)),
checks.append(re.compile("(.*[\w\-().:!?{}\[\]]+)\s+(<\/%s>.*\n)"
% element))
for root, dirs, files in os.walk('doc/'):
for f in files:

View File

@ -791,12 +791,15 @@ def main():
if prog_args.check_syntax or prog_args.check_niceness:
if prog_args.force:
validate_all_files(prog_args.path, FILE_EXCEPTIONS, prog_args.verbose,
prog_args.check_syntax, prog_args.check_niceness,
validate_all_files(prog_args.path, FILE_EXCEPTIONS,
prog_args.verbose,
prog_args.check_syntax,
prog_args.check_niceness,
prog_args.ignore_errors)
else:
validate_individual_files(prog_args.path, FILE_EXCEPTIONS,
prog_args.verbose, prog_args.check_syntax,
prog_args.verbose,
prog_args.check_syntax,
prog_args.check_niceness,
prog_args.ignore_errors)
@ -805,7 +808,8 @@ def main():
if prog_args.check_build:
build_affected_books(prog_args.path, BOOK_EXCEPTIONS,
prog_args.verbose, prog_args.force, prog_args.ignore_errors)
prog_args.verbose, prog_args.force,
prog_args.ignore_errors)
def default_root():