Permalink
Browse files

Merge pull request #3102 from s0undt3ch/hotfix/pylint/W0102

Some more PyLint fixes. W0102
  • Loading branch information...
2 parents 111226e + 292d4c6 commit db831a81dd1879464ebb30fd9805be500e21df5e @s0undt3ch s0undt3ch committed Jan 1, 2013
View
@@ -33,10 +33,13 @@ def _file_dict(self, fn_):
data = fp_.read()
return {fn_: data}
- def _recurse_dir(self, fn_, files={}):
+ def _recurse_dir(self, fn_, files=None):
'''
Recursively pull files from a directory
'''
+ if files is None:
+ files = {}
+
for base in os.listdir(fn_):
path = os.path.join(fn_, base)
if os.path.isdir(path):
View
@@ -237,13 +237,13 @@ def _get_image(image, vda):
def _gen_xml(name,
- cpus,
- mem,
- vmdir,
- disks,
- network,
- desc,
- opts):
+ cpus,
+ mem,
+ vmdir,
+ disks,
+ network,
+ desc,
+ opts):
'''
Generate the xml used for the libvirt configuration
'''
@@ -326,9 +326,9 @@ def init(
mem,
image,
storage_dir,
- network={'eth0': {'bridge': 'br0', 'mac': ''}},
+ network=None,
desc='',
- opts={}):
+ opts=None):
'''
Create a KVM virtual machine based on these passed options, the virtual
machine will be started upon creation
@@ -337,13 +337,15 @@ def init(
salt '*' hyper.init webserver 2 2048 salt://fedora/f16.img:virt /srv/vm/images
'''
+ if network is None:
+ network = {'eth0': {'bridge': 'br0', 'mac': ''}}
vmdir = os.path.join(storage_dir, name)
if not os.path.exists(vmdir):
os.makedirs(vmdir)
vda = os.path.join(vmdir, 'vda')
_get_image(image, vda)
# The image is in place
- xml = _gen_xml(name, cpus, mem, vmdir, network, desc, opts)
+ xml = _gen_xml(name, cpus, mem, vmdir, network, desc, opts or {})
config = os.path.join(vmdir, 'config.xml')
salt.utils.fopen(config, 'w+').write(xml)
return start(config)
@@ -68,12 +68,12 @@ def parse_deb(path):
if result['retcode'] == 0:
for line in result['stdout'].splitlines():
if not name:
- match = re.match('^\s*Package\s*:\s*(\S+)',line)
+ match = re.match('^\s*Package\s*:\s*(\S+)', line)
if match:
name = match.group(1)
continue
if not version:
- match = re.match('^\s*Version\s*:\s*(\S+)',line)
+ match = re.match('^\s*Version\s*:\s*(\S+)', line)
if match:
version = match.group(1)
continue
@@ -87,7 +87,7 @@ def parse_deb(path):
metaparser = parse_deb
else:
log.error('No metadata parser found for {0}'.format(path))
- return '',''
+ return '', ''
return metaparser(path)
@@ -161,11 +161,11 @@ def _verify_binary_pkg(srcinfo):
elif pkg_name != pkgmeta_name:
problems.append('Package file {0} (Name: {1}) does not '
'match the specified package name '
- '({2}).'.format(pkg_uri,pkgmeta_name,pkg_name))
+ '({2}).'.format(pkg_uri, pkgmeta_name, pkg_name))
return problems
-def check_targets(targets=[]):
+def check_targets(targets=None):
'''
Examines target package names to make sure they were formatted properly.
Returns a list of problems encountered.
@@ -175,7 +175,7 @@ def check_targets(targets=[]):
# properly submitted as category/pkgname. For any package that does not
# follow this format, offer matches from the portage tree.
if __grains__['os_family'] == 'Gentoo':
- for pkg in targets:
+ for pkg in (targets or []):
if '/' not in pkg:
matches = __salt__['pkg.porttree_matches'](pkg)
if matches:
@@ -232,7 +232,7 @@ def parse_targets(name=None, pkgs=None, sources=None):
return None, None
srcinfo = []
- for pkg_name,pkg_src in sources.iteritems():
+ for pkg_name, pkg_src in sources.iteritems():
if __salt__['config.valid_fileproto'](pkg_src):
# Cache package from remote source (salt master, http, ftp)
srcinfo.append((pkg_name,
@@ -241,7 +241,7 @@ def parse_targets(name=None, pkgs=None, sources=None):
'remote'))
else:
# Package file local to the minion
- srcinfo.append((pkg_name,pkg_src,pkg_src,'local'))
+ srcinfo.append((pkg_name, pkg_src, pkg_src, 'local'))
# Check metadata to make sure the name passed matches the source
if __grains__['os_family'] not in ('Solaris',) \
@@ -257,7 +257,7 @@ def parse_targets(name=None, pkgs=None, sources=None):
# srcinfo is a 4-tuple (pkg_name,pkg_uri,pkg_path,pkg_type), so grab
# the package path (3rd element of tuple).
- return [x[2] for x in srcinfo],'file'
+ return [x[2] for x in srcinfo], 'file'
elif name and __grains__['os_family'] != 'Solaris':
return [name], 'repository'
@@ -297,13 +297,13 @@ def sort_pkglist(pkgs):
pkgs[key].sort()
-def find_changes(old={}, new={}):
+def find_changes(old=None, new=None):
'''
Compare before and after results from pkg.list_pkgs() to determine what
changes were made to the packages installed on the minion.
'''
pkgs = {}
- for npkg in set(new.keys()).union(old.keys()):
+ for npkg in set((new or {}).keys()).union((old or {}).keys()):
if npkg not in old:
# the package is freshly installed
pkgs[npkg] = {'old': '',
View
@@ -2,14 +2,11 @@
Execute puppet routines
'''
-# Import python libs
-import re
-
# Import salt libs
from salt import utils
__outputter__ = {
- 'run': 'txt',
+ 'run': 'txt',
'noop': 'txt',
'fact': 'txt',
'facts': None,
@@ -25,12 +22,14 @@ def _check_puppet():
# minion was started, and that would be rubbish
utils.check_or_die('puppet')
+
def _check_facter():
'''
Checks if facter is installed
'''
utils.check_or_die('facter')
+
def _format_fact(output):
try:
fact, value = output.split(' => ', 1)
@@ -40,6 +39,7 @@ def _format_fact(output):
value = None
return (fact, value)
+
class _Puppet(object):
'''
Puppet helper class. Used to format command for execution.
@@ -64,22 +64,28 @@ def __repr__(self):
Format the command string to executed using cmd.run_all.
'''
- cmd = 'puppet {subcmd} --vardir {vardir} --confdir {confdir}'.format(**self.__dict__)
+ cmd = 'puppet {subcmd} --vardir {vardir} --confdir {confdir}'.format(
+ **self.__dict__
+ )
args = ' '.join(self.subcmd_args)
- args += ''.join([' --{0}'.format(k) for k in self.args]) # single spaces
- args += ''.join([' --{0} {1}'.format(k, v) for k, v in self.kwargs.items()])
+ args += ''.join(
+ [' --{0}'.format(k) for k in self.args] # single spaces
+ )
+ args += ''.join([
+ ' --{0} {1}'.format(k, v) for k, v in self.kwargs.items()]
+ )
return '{0} {1}'.format(cmd, args)
- def arguments(self, args=[]):
+ def arguments(self, args=None):
'''
- Read in arguments for the current subcommand. These are added to the cmd
- line without '--' appended. Any others are redirected as standard options
- with the double hyphen prefixed.
+ Read in arguments for the current subcommand. These are added to the
+ cmd line without '--' appended. Any others are redirected as standard
+ options with the double hyphen prefixed.
'''
# permits deleting elements rather than using slices
- args = list(args)
+ args = args and list(args) or []
# match against all known/supported subcmds
if self.subcmd == 'apply':
@@ -89,11 +95,15 @@ def arguments(self, args=[]):
if self.subcmd == 'agent':
# no arguments are required
- args.extend(['onetime', 'verbose', 'ignorecache', 'no-daemonize', 'no-usecacheonfailure', 'no-splay', 'show_diff'])
+ args.extend([
+ 'onetime', 'verbose', 'ignorecache', 'no-daemonize',
+ 'no-usecacheonfailure', 'no-splay', 'show_diff'
+ ])
# finally do this after subcmd has been matched for all remaining args
self.args = args
+
def run(*args, **kwargs):
'''
Execute a puppet run and return a dict with the stderr, stdout,
@@ -119,8 +129,8 @@ def run(*args, **kwargs):
if args:
# based on puppet documentation action must come first. making the same
- # assertion. need to ensure the list of supported cmds here matches those
- # defined in _Puppet.arguments()
+ # assertion. need to ensure the list of supported cmds here matches
+ # those defined in _Puppet.arguments()
if args[0] in ['agent', 'apply']:
puppet.subcmd = args[0]
puppet.arguments(args[1:])
@@ -132,6 +142,7 @@ def run(*args, **kwargs):
return __salt__['cmd.run_all'](repr(puppet))
+
def noop(*args, **kwargs):
'''
Execute a puppet noop run and return a dict with the stderr, stdout,
@@ -150,6 +161,7 @@ def noop(*args, **kwargs):
args += ('noop',)
return run(*args, **kwargs)
+
def facts():
'''
Run facter and return the results
@@ -175,6 +187,7 @@ def facts():
ret[fact] = value
return ret
+
def fact(name):
'''
Run facter for a specific fact
View
@@ -73,7 +73,7 @@ def _replace_auth_key(
key,
enc='ssh-rsa',
comment='',
- options=[],
+ options=None,
config='.ssh/authorized_keys'):
'''
Replace an existing key
@@ -82,7 +82,7 @@ def _replace_auth_key(
key,
enc,
comment,
- options)
+ options or [])
lines = []
uinfo = __salt__['user.info'](user)
@@ -391,7 +391,7 @@ def set_auth_key(
key,
enc='ssh-rsa',
comment='',
- options=[],
+ options=None,
config='.ssh/authorized_keys'):
'''
Add a key to the authorized_keys file. The "key" parameter must only be the
@@ -415,7 +415,7 @@ def set_auth_key(
key,
enc,
comment,
- options,
+ options or [],
config)
return 'replace'
elif status == 'exists':
View
@@ -711,7 +711,7 @@ def managed(name,
def directory(name,
user=None,
group=None,
- recurse=[],
+ recurse=None,
mode=None,
makedirs=False,
clean=False,
@@ -775,7 +775,7 @@ def directory(name,
name,
user,
group,
- recurse,
+ recurse or [],
mode,
clean,
require)
View
@@ -24,7 +24,7 @@ def mounted(
device,
fstype,
mkmnt=False,
- opts=['defaults'],
+ opts=None,
dump=0,
pass_num=0,
config='/etc/fstab',
@@ -75,6 +75,8 @@ def mounted(
# string
if isinstance(opts, string_types):
opts = opts.split(',')
+ elif opts is None:
+ opts = ['defaults']
# Get the active data
active = __salt__['mount.active']()
View
@@ -94,7 +94,7 @@ def present(
enc='ssh-rsa',
comment='',
source='',
- options=[],
+ options=None,
config='.ssh/authorized_keys',
**kwargs):
'''
@@ -135,7 +135,7 @@ def present(
name,
enc,
comment,
- options,
+ options or [],
source,
config,
kwargs.get('__env__', 'base')
@@ -174,7 +174,7 @@ def present(
name,
enc,
comment,
- options,
+ options or [],
config)
if data == 'replace':

0 comments on commit db831a8

Please sign in to comment.