Browse Source

Merge "Fix issues found by flake8"

changes/98/63598/1
Jenkins 8 years ago
committed by Gerrit Code Review
parent
commit
64f2f860c8
  1. 3
      autogenerate-config-docs/autohelp.py
  2. 43
      autogenerate-config-docs/common.py
  3. 46
      autogenerate-config-docs/extract_swift_flags.py
  4. 2
      autogenerate-config-docs/test/generator.py
  5. 11
      cleanup/remove_unnecessary_spaces.py
  6. 12
      os_doc_tools/doctest.py

3
autogenerate-config-docs/autohelp.py

@ -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
@ -54,7 +53,7 @@ def main(action, file, format, repo, verbose=0, name=False, test=False):
sys.exit(0)
if __name__ == "__main__":
if __name__ == "__main__":
args = common.parse_me_args()
main(args['action'],
args['file'],

43
autogenerate-config-docs/common.py

@ -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
'/transfer' 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 and
'/transfer' 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:
@ -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\

46
autogenerate-config-docs/extract_swift_flags.py

@ -80,33 +80,37 @@ 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
option_descs[option] = line_parts[2]
prev_option = option
return option_descs
def new_section_file(sample, current_section):
section_filename = ('swift-' +
path.basename(sample).split('.conf')[0]
+ '-'
+ current_section.replace('[', '').replace(']', '').replace(':', '-')
+ '.xml')
section_file = open(section_filename, 'w')
section_file.write('<?xml version="1.0" encoding="UTF-8"?>\n\
section_filename = ('swift-' +
path.basename(sample).split('.conf')[0]
+ '-'
+ current_section.replace('[', '').
replace(']', '').replace(':', '-')
+ '.xml')
section_file = open(section_filename, 'w')
section_file.write('<?xml version="1.0" encoding="UTF-8"?>\n\
<!-- The tool that generated this table lives in the\n\
tools directory of this repository. As it was a one-time\n\
generation, you can edit this file. -->\n\
<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) +
'</literal></caption>\n\
<col width="50%"/>\n\
+ current_section + '</literal> in <literal>'
+ path.basename(sample) +
'</literal></caption>\n\
<col width="50%"/>\n\
<col width="50%"/>\n\
<thead>\n\
<tr>\n\
@ -115,7 +119,7 @@ def new_section_file(sample, current_section):
</tr>\n\
</thead>\n\
<tbody>')
return section_file
return section_file
def create_new_tables(repo, verbose):
@ -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:
@ -187,5 +193,5 @@ def main(repo, verbose=0):
create_new_tables(repo, verbose)
if __name__ == "__main__":
if __name__ == "__main__":
main(sys.argv[1])

2
autogenerate-config-docs/test/generator.py

@ -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

11
cleanup/remove_unnecessary_spaces.py

@ -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:
@ -42,7 +45,7 @@ for root, dirs, files in os.walk('doc/'):
continue
docfile = os.path.abspath(os.path.join(root, f))
tmpfile = tempfile.mkstemp()
tmpfd = os.fdopen(tmpfile[0], "w")
tmpfd = os.fdopen(tmpfile[0], "w")
match = False
for line in open(docfile, 'r'):
for check in checks:

12
os_doc_tools/doctest.py

@ -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():

Loading…
Cancel
Save