Fix some more pylint warnings
Fix some more warnings from pylint. Move check_output into common.py and use this instead of local copy. Change-Id: Ifc2079e8d4302d313cfe438d11e4601482637764
This commit is contained in:
parent
4fb4906e9e
commit
6b27ac7092
@ -18,28 +18,7 @@ import subprocess
|
||||
import sys
|
||||
|
||||
import os_doc_tools
|
||||
|
||||
|
||||
# NOTE(berendt): check_output as provided in Python 2.7.5 to make script
|
||||
# usable with Python < 2.7
|
||||
def check_output(*popenargs, **kwargs):
|
||||
"""Run command with arguments and return its output as a byte string.
|
||||
|
||||
If the exit code was non-zero it raises a CalledProcessError. The
|
||||
CalledProcessError object will have the return code in the returncode
|
||||
attribute and output in the output attribute.
|
||||
"""
|
||||
if 'stdout' in kwargs:
|
||||
raise ValueError('stdout argument not allowed, it will be overridden.')
|
||||
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
|
||||
output, unused_err = process.communicate()
|
||||
retcode = process.poll()
|
||||
if retcode:
|
||||
cmd = kwargs.get("args")
|
||||
if cmd is None:
|
||||
cmd = popenargs[0]
|
||||
raise subprocess.CalledProcessError(retcode, cmd, output=output)
|
||||
return output
|
||||
from os_doc_tools.common import check_output # noqa
|
||||
|
||||
|
||||
def quote_xml(line):
|
||||
|
41
os_doc_tools/common.py
Normal file
41
os_doc_tools/common.py
Normal file
@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
'''
|
||||
Common functions for os_doc_tools.
|
||||
'''
|
||||
|
||||
import subprocess
|
||||
|
||||
|
||||
# NOTE(berendt): check_output as provided in Python 2.7.5 to make script
|
||||
# usable with Python < 2.7
|
||||
def check_output(*popenargs, **kwargs):
|
||||
"""Run command with arguments and return its output as a byte string.
|
||||
|
||||
If the exit code was non-zero it raises a CalledProcessError. The
|
||||
CalledProcessError object will have the return code in the returncode
|
||||
attribute and output in the output attribute.
|
||||
"""
|
||||
if 'stdout' in kwargs:
|
||||
raise ValueError('stdout argument not allowed, it will be overridden.')
|
||||
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
|
||||
output, _ = process.communicate()
|
||||
retcode = process.poll()
|
||||
if retcode:
|
||||
cmd = kwargs.get("args")
|
||||
if cmd is None:
|
||||
cmd = popenargs[0]
|
||||
raise subprocess.CalledProcessError(retcode, cmd, output=output)
|
||||
return output
|
@ -45,6 +45,7 @@ import sys
|
||||
from lxml import etree
|
||||
|
||||
import os_doc_tools
|
||||
from os_doc_tools.common import check_output # noqa
|
||||
from oslo.config import cfg
|
||||
|
||||
|
||||
@ -95,28 +96,6 @@ WADL_XSD = os.path.join(BASE_RNG, 'wadl.xsd')
|
||||
SCRIPTS_DIR = os.path.join(OS_DOC_TOOLS_DIR, 'scripts')
|
||||
|
||||
|
||||
# NOTE(berendt): check_output as provided in Python 2.7.5 to make script
|
||||
# usable with Python < 2.7
|
||||
def check_output(*popenargs, **kwargs):
|
||||
"""Run command with arguments and return its output as a byte string.
|
||||
|
||||
If the exit code was non-zero it raises a CalledProcessError. The
|
||||
CalledProcessError object will have the return code in the returncode
|
||||
attribute and output in the output attribute.
|
||||
"""
|
||||
if 'stdout' in kwargs:
|
||||
raise ValueError('stdout argument not allowed, it will be overridden.')
|
||||
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
|
||||
output, unused_err = process.communicate()
|
||||
retcode = process.poll()
|
||||
if retcode:
|
||||
cmd = kwargs.get("args")
|
||||
if cmd is None:
|
||||
cmd = popenargs[0]
|
||||
raise subprocess.CalledProcessError(retcode, cmd, output=output)
|
||||
return output
|
||||
|
||||
|
||||
def get_schema(is_api_site=False):
|
||||
"""Return the DocBook RELAX NG schema."""
|
||||
if is_api_site:
|
||||
@ -207,7 +186,7 @@ def verify_profiling(doc):
|
||||
verify_attribute_profiling(doc, "audience", KNOWN_AUDIENCE_VALUES)
|
||||
|
||||
|
||||
def verify_nice_usage_of_whitespaces(docfile):
|
||||
def verify_whitespace_niceness(docfile):
|
||||
"""Check that no unnecessary whitespaces are used."""
|
||||
checks = [
|
||||
re.compile(".*\s+\n$"),
|
||||
@ -473,7 +452,7 @@ def validate_one_json_file(rootdir, path, verbose, check_syntax,
|
||||
(os.path.relpath(path, rootdir), e))
|
||||
try:
|
||||
if check_niceness:
|
||||
verify_nice_usage_of_whitespaces(path)
|
||||
verify_whitespace_niceness(path)
|
||||
except ValueError as e:
|
||||
any_failures = True
|
||||
print(" %s: %s" % (os.path.relpath(path, rootdir), e))
|
||||
@ -499,7 +478,7 @@ def validate_one_file(schema, rootdir, path, verbose,
|
||||
verify_section_tags_have_xmid(doc)
|
||||
verify_profiling(doc)
|
||||
if check_niceness:
|
||||
verify_nice_usage_of_whitespaces(path)
|
||||
verify_whitespace_niceness(path)
|
||||
except etree.XMLSyntaxError as e:
|
||||
any_failures = True
|
||||
print(" %s: %s" % (os.path.relpath(path, rootdir), e))
|
||||
@ -680,7 +659,7 @@ def publish_www():
|
||||
shutil.copytree(source, www_path)
|
||||
|
||||
|
||||
def ignore_for_publishing(path, names):
|
||||
def ignore_for_publishing(_, names):
|
||||
"""Return list of files that should be ignored for publishing."""
|
||||
|
||||
# Ignore:
|
||||
|
@ -156,34 +156,12 @@ def get_default_book(root):
|
||||
return os.listdir(root)[0]
|
||||
|
||||
|
||||
# NOTE(berendt): check_output as provided in Python 2.7.5 to make script
|
||||
# usable with Python < 2.7
|
||||
def check_output(*popenargs, **kwargs):
|
||||
"""Run command with arguments and return its output as a byte string.
|
||||
|
||||
If the exit code was non-zero it raises a CalledProcessError. The
|
||||
CalledProcessError object will have the return code in the returncode
|
||||
attribute and output in the output attribute.
|
||||
"""
|
||||
if 'stdout' in kwargs:
|
||||
raise ValueError('stdout argument not allowed, it will be overridden.')
|
||||
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
|
||||
output, unused_err = process.communicate()
|
||||
retcode = process.poll()
|
||||
if retcode:
|
||||
cmd = kwargs.get("args")
|
||||
if cmd is None:
|
||||
cmd = popenargs[0]
|
||||
raise subprocess.CalledProcessError(retcode, cmd, output=output)
|
||||
return output
|
||||
|
||||
|
||||
def generatedocbook():
|
||||
global IGNORE_FOLDER, IGNORE_FILE
|
||||
|
||||
usage = "usage: %prog [options] command [cmd_options]"
|
||||
description = "This is the tool to generate translated docbooks, which"
|
||||
" will be stored in 'generated/[language]/"
|
||||
description = "This is the tool to generate translated docbooks, which "
|
||||
"will be stored in 'generated/[language]/"
|
||||
|
||||
IGNORE_FOLDER = ["docbkx-example"]
|
||||
IGNORE_FILE = []
|
||||
|
Loading…
x
Reference in New Issue
Block a user