Pylint and pep8 cleanup
This commit is contained in:
parent
c9e9791d8a
commit
77a036c6c8
@ -53,7 +53,8 @@ class Action(object):
|
||||
self.keyring_encrypted = cli_opts.pop('keyring_encrypted')
|
||||
self.prompt_for_passwords = cli_opts.pop('prompt_for_passwords', False)
|
||||
self.store_passwords = cli_opts.pop('store_passwords', True)
|
||||
self.cli_opts = cli_opts # Stored for components to get any options
|
||||
# Stored for components to get any options
|
||||
self.cli_opts = cli_opts
|
||||
|
||||
def _establish_passwords(self, component_order, instances):
|
||||
kr = pw.KeyringProxy(self.keyring_path,
|
||||
|
@ -24,7 +24,7 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Component(object):
|
||||
def __init__(self, name, subsystems, instances, options, siblings, distro, passwords, **kwargs):
|
||||
def __init__(self, name, subsystems, instances, options, siblings, distro, passwords, **kwargs):
|
||||
# Subsystems this was requested with
|
||||
self.subsystems = subsystems
|
||||
|
||||
|
@ -61,6 +61,8 @@ STATUS_INSTALLED = 'installed'
|
||||
STATUS_STARTED = "started"
|
||||
STATUS_STOPPED = "stopped"
|
||||
STATUS_UNKNOWN = "unknown"
|
||||
|
||||
|
||||
class ProgramStatus(object):
|
||||
def __init__(self, status, name=None, details=''):
|
||||
self.name = name
|
||||
@ -71,6 +73,7 @@ class ProgramStatus(object):
|
||||
#### Utils...
|
||||
####
|
||||
|
||||
|
||||
def make_packager(package, default_class, **kwargs):
|
||||
cls = packager.get_packager_class(package, default_class)
|
||||
return cls(**kwargs)
|
||||
@ -80,6 +83,7 @@ def make_packager(package, default_class, **kwargs):
|
||||
#### INSTALL CLASSES
|
||||
####
|
||||
|
||||
|
||||
class PkgInstallComponent(component.Component):
|
||||
def __init__(self, *args, **kargs):
|
||||
component.Component.__init__(self, *args, **kargs)
|
||||
@ -828,6 +832,7 @@ class PythonTestingComponent(component.Component):
|
||||
app_dir = self.get_option('app_dir')
|
||||
tox_fn = sh.joinpths(app_dir, 'tox.ini')
|
||||
if sh.isfile(tox_fn):
|
||||
# Suck out some settings from the tox file
|
||||
try:
|
||||
tox_cfg = cfg.BuiltinConfigParser(fns=[tox_fn])
|
||||
env_values = tox_cfg.get('testenv', 'setenv') or ''
|
||||
|
@ -125,10 +125,6 @@ class GlanceInstaller(comp.PythonInstallComponent):
|
||||
}
|
||||
|
||||
def _config_adjust_paste(self, contents, fn):
|
||||
params = khelper.get_shared_params(ip=self.get_option('ip'),
|
||||
service_user='glance',
|
||||
**utils.merge_dicts(self.get_option('keystone'),
|
||||
khelper.get_shared_passwords(self)))
|
||||
with io.BytesIO(contents) as stream:
|
||||
config = cfg.create_parser(cfg.RewritableConfigParser, self)
|
||||
config.readfp(stream)
|
||||
@ -269,8 +265,7 @@ class GlanceTester(comp.PythonTestingComponent):
|
||||
#
|
||||
# It seems to assume tox is being used, which we can't use directly
|
||||
# since anvil doesn't really do venv stuff (its meant to avoid those...)
|
||||
cmd = ['nosetests','--exclude-dir=glance/tests/functional',
|
||||
'--with-coverage','--cover-package=glance']
|
||||
cmd = ['nosetests', '--exclude-dir=glance/tests/functional']
|
||||
for e in self._get_test_exclusions():
|
||||
cmd.append('--exclude=%s' % (e))
|
||||
return cmd
|
||||
|
@ -346,7 +346,6 @@ class Image(object):
|
||||
return (sh.exists(self.url) or (self.parsed_url.scheme == '' and self.parsed_url.netloc == ''))
|
||||
|
||||
def _cached_paths(self):
|
||||
url_fn = self._extract_url_fn()
|
||||
md5er = hashlib.new('md5')
|
||||
md5er.update(self.url)
|
||||
path = sh.joinpths(self.cache_dir, md5er.hexdigest())
|
||||
|
@ -19,6 +19,7 @@ from anvil import log
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
def get_shared_passwords(component):
|
||||
mp = {}
|
||||
mp['pw'] = component.get_password('rabbit')
|
||||
|
@ -59,12 +59,12 @@ class HorizonInstaller(comp.PythonInstallComponent):
|
||||
def __init__(self, *args, **kargs):
|
||||
comp.PythonInstallComponent.__init__(self, *args, **kargs)
|
||||
self.blackhole_dir = sh.joinpths(self.get_option('app_dir'), '.blackhole')
|
||||
self.access_log = sh.joinpths('/var/log/',
|
||||
self.distro.get_command_config('apache', 'name'),
|
||||
'horizon_access.log')
|
||||
self.error_log = sh.joinpths('/var/log/',
|
||||
self.distro.get_command_config('apache', 'name'),
|
||||
'horizon_error.log')
|
||||
self.access_log = sh.joinpths('/var/log/',
|
||||
self.distro.get_command_config('apache', 'name'),
|
||||
'horizon_access.log')
|
||||
self.error_log = sh.joinpths('/var/log/',
|
||||
self.distro.get_command_config('apache', 'name'),
|
||||
'horizon_error.log')
|
||||
|
||||
def _filter_pip_requires_line(self, fn, line):
|
||||
# Knock off all nova, quantum, swift, keystone, cinder
|
||||
|
@ -33,7 +33,6 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Distro(object):
|
||||
|
||||
def __init__(self, name, platform_pattern, packager_name, commands, components):
|
||||
self.name = name
|
||||
self._platform_pattern = re.compile(platform_pattern, re.IGNORECASE)
|
||||
|
@ -166,7 +166,7 @@ class NovaInstaller(nova.NovaInstaller):
|
||||
cmd = ['groupadd', 'libvirtd']
|
||||
sh.execute(*cmd, run_as_root=True)
|
||||
if not sh.isfile(LIBVIRT_POLICY_FN):
|
||||
contents = self._get_policy(self._get_policy_users())
|
||||
contents = self._get_policy(self._get_policy_users())
|
||||
with sh.Rooted(True):
|
||||
sh.mkdirslist(sh.dirname(LIBVIRT_POLICY_FN))
|
||||
sh.write_file(LIBVIRT_POLICY_FN, contents)
|
||||
|
@ -19,15 +19,13 @@ import contextlib
|
||||
import functools
|
||||
import urllib2
|
||||
|
||||
from urlparse import (urlparse, parse_qs)
|
||||
from urlparse import parse_qs
|
||||
|
||||
import progressbar
|
||||
|
||||
from anvil import colorizer
|
||||
from anvil import exceptions as excp
|
||||
from anvil import log as logging
|
||||
from anvil import shell as sh
|
||||
from anvil import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -37,6 +37,3 @@ def get_key(key, default_value=None):
|
||||
if value is None:
|
||||
value = default_value
|
||||
return value
|
||||
|
||||
|
||||
|
||||
|
@ -205,7 +205,8 @@ class PythonPackager(DependencyPackager):
|
||||
return [
|
||||
'python',
|
||||
'python-devel',
|
||||
'gcc', # Often used for building c python modules, should not be harmful...
|
||||
# Often used for building c python modules, should not be harmful...
|
||||
'gcc',
|
||||
'python-setuptools',
|
||||
]
|
||||
|
||||
|
@ -29,19 +29,6 @@ LOG = logging.getLogger(__name__)
|
||||
RAND_PW_LEN = 20
|
||||
PW_USER = 'anvil'
|
||||
|
||||
# There is some weird issue fixed after 0.9.2
|
||||
# this applies that fix for us for now (taken from the trunk code)...
|
||||
class FixedCryptedFileKeyring(CryptedFileKeyring):
|
||||
|
||||
@properties.NonDataProperty
|
||||
def keyring_key(self):
|
||||
# _unlock or _init_file will set the key or raise an exception
|
||||
if self._check_file():
|
||||
self._unlock()
|
||||
else:
|
||||
self._init_file()
|
||||
return self.keyring_key
|
||||
|
||||
|
||||
class KeyringProxy(object):
|
||||
def __init__(self, path, keyring_encrypted=False, enable_prompt=True, random_on_empty=True):
|
||||
@ -50,7 +37,7 @@ class KeyringProxy(object):
|
||||
path = "%s.crypt" % (path)
|
||||
self.path = path
|
||||
if keyring_encrypted:
|
||||
self.ring = FixedCryptedFileKeyring()
|
||||
self.ring = CryptedFileKeyring()
|
||||
else:
|
||||
self.ring = UncryptedFileKeyring()
|
||||
self.ring.file_path = path
|
||||
@ -89,8 +76,8 @@ class InputPassword(object):
|
||||
def _prompt_user(self, prompt_text):
|
||||
prompt_text = prompt_text.strip()
|
||||
message = ("Enter a secret to use for the %s "
|
||||
"[or press enter to get a generated one]: " % prompt_text
|
||||
)
|
||||
"[or press enter to get a generated one]: ")
|
||||
message = message % (prompt_text)
|
||||
rc = ""
|
||||
while True:
|
||||
rc = getpass.getpass(message)
|
||||
|
@ -40,7 +40,6 @@ def _pformat_list(lst, item_max_len):
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
|
||||
def _pformat_hash(hsh, item_max_len):
|
||||
lines = []
|
||||
if not hsh:
|
||||
@ -80,7 +79,7 @@ def _pformat_escape(item, item_max_len):
|
||||
|
||||
def _pformat_simple(item, item_max_len):
|
||||
if item_max_len is None or item_max_len < 0:
|
||||
return "%s" % (item)
|
||||
return "%s" % (item)
|
||||
if item_max_len == 0:
|
||||
return ''
|
||||
item_str = "%s" % (item)
|
||||
|
@ -23,4 +23,3 @@ COMPONENT_CONF_DIR = os.path.join(CONFIG_DIR, "components")
|
||||
DISTRO_DIR = os.path.join(CONFIG_DIR, "distros")
|
||||
PERSONA_DIR = os.path.join(CONFIG_DIR, "personas")
|
||||
TEMPLATE_DIR = os.path.join(CONFIG_DIR, "templates")
|
||||
|
||||
|
@ -516,9 +516,9 @@ def mkdir(path, recurse=True, adjust_suids=False):
|
||||
if not is_dry_run():
|
||||
os.mkdir(path)
|
||||
if adjust_suids:
|
||||
(uid, gid) = get_suids()
|
||||
if uid is not None and gid is not None:
|
||||
chown_r(path, uid, gid)
|
||||
(uid, gid) = get_suids()
|
||||
if uid is not None and gid is not None:
|
||||
chown_r(path, uid, gid)
|
||||
return path
|
||||
|
||||
|
||||
|
@ -483,10 +483,10 @@ ____ ___ ____ _ _ ____ ___ ____ ____ _ _
|
||||
return random.choice(possibles).strip("\n\r")
|
||||
|
||||
|
||||
|
||||
def _welcome_slang():
|
||||
potentials = list()
|
||||
potentials.append("And now for something completely different!")
|
||||
potentials = [
|
||||
"And now for something completely different!",
|
||||
]
|
||||
return random.choice(potentials)
|
||||
|
||||
|
||||
|
17
run_tests.sh
17
run_tests.sh
@ -31,20 +31,23 @@ function find_code {
|
||||
}
|
||||
|
||||
function run_pep8 {
|
||||
echo "Running pep8 ..."
|
||||
echo "+ Running pep8 ..."
|
||||
files=$(find_code)
|
||||
ignores="E202,E501"
|
||||
ignores="E202,E501,E128,E127,E126,E125,E124,E123,E121"
|
||||
output_filename="pep8.log"
|
||||
opts="--ignore=$ignores --repeat"
|
||||
pep8 ${opts} ${files} 2>&1 > $output_filename
|
||||
# Exit code is always 1 if any error or warning is found.
|
||||
if [ "$?" -ne "0" ]; then
|
||||
echo "Some badness was found!"
|
||||
echo "Check '$output_filename' for a full report."
|
||||
else
|
||||
echo "You are a pep8 guru!"
|
||||
fi
|
||||
echo "Check '$output_filename' for a full report."
|
||||
}
|
||||
|
||||
function run_pylint {
|
||||
echo "Running pylint ..."
|
||||
echo "+ Running pylint ..."
|
||||
opts="--rcfile=pylintrc --output-format=parseable"
|
||||
files=$(find_code)
|
||||
output_filename="pylint.log"
|
||||
@ -65,20 +68,20 @@ function run_pylint {
|
||||
else
|
||||
echo "You are not yet a code master."
|
||||
grep -i "Your code" $output_filename
|
||||
echo "Check '$output_filename' for a full report."
|
||||
fi
|
||||
fi
|
||||
echo "Check '$output_filename' for a full report."
|
||||
}
|
||||
|
||||
function run_tests {
|
||||
echo "Running tests ..."
|
||||
echo "+ Running tests ..."
|
||||
# Cleanup *.pyc
|
||||
find . -type f -name "*.pyc" -delete
|
||||
$NOSETESTS
|
||||
}
|
||||
|
||||
function validate_yaml {
|
||||
echo "Validating YAML files..."
|
||||
echo "+ Validating YAML files..."
|
||||
for f in `find conf/ -name *.yaml -type f`; do
|
||||
echo "Checking yaml file: $f"
|
||||
python tools/validate-yaml.py $f
|
||||
|
Loading…
Reference in New Issue
Block a user