From 4c6f382adfada44f6d82b3928895599ec1782af9 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Tue, 11 Feb 2014 19:20:55 +0000 Subject: [PATCH 1/3] No short variable names. --- salt/modules/lxc.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/salt/modules/lxc.py b/salt/modules/lxc.py index cfab07fb5df9..018520e46c69 100644 --- a/salt/modules/lxc.py +++ b/salt/modules/lxc.py @@ -288,25 +288,25 @@ def list_(): frozen = [] running = [] - for c in ctnrs: - lines = __salt__['cmd.run']('lxc-info -n ' + c).splitlines() + for container in ctnrs: + c_infos = __salt__['cmd.run']('lxc-info -n {0}'.format(container)) - for line in lines: - stat = line.split(':') + for info in c_infos: + stat = info.split(':') if stat[0] == 'state': - s = stat[1].strip() + state = stat[1].strip() break - if not len(s): + if not len(state): continue - if s == 'STOPPED': - stopped.append(c) + if state == 'STOPPED': + stopped.append(container) continue - if s == 'FROZEN': - frozen.append(c) + if state == 'FROZEN': + frozen.append(container) continue - if s == 'RUNNING': - running.append(c) + if state == 'RUNNING': + running.append(container) continue return {'running': running, From e3f568e96c7b496b37008d0da1547db4a2a6eee7 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Tue, 11 Feb 2014 16:34:15 +0000 Subject: [PATCH 2/3] Do additional preparation in a separate method. This way we always call the parent class `__init__` and PyLint does not complain about it. --- salt/key.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/salt/key.py b/salt/key.py index 18de51ffd0a4..4d5d62df9f1d 100644 --- a/salt/key.py +++ b/salt/key.py @@ -312,8 +312,16 @@ class Key(object): ''' The object that encapsulates saltkey actions ''' + def __init__(self, opts): self.opts = opts + self._prepare() + + def _prepare(self): + ''' + Simple method called when this class is initialized used for additional + setup + ''' self.event = salt.utils.event.MasterEvent(opts['sock_dir']) def _check_minions_directories(self): @@ -678,8 +686,12 @@ class RaetKey(Key): ''' Manage keys from the raet backend ''' - def __init__(self, opts): - self.opts = opts + + def _prepare(self): + ''' + Simple method called when this class is initialized used for additional + setup + ''' self.serial = salt.payload.Serial(self.opts) def _check_minions_directories(self): @@ -766,7 +778,7 @@ def status(self, minion_id, device_id, pub, verify): def _get_key_str(self, minion_id, status): ''' Return the key string in the form of: - + pub: verify: ''' From 9784f649a3394bcb0105bdb861af8746513921a2 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Tue, 11 Feb 2014 16:38:07 +0000 Subject: [PATCH 3/3] Remove unnecesary parens and `format()` call --- salt/fileserver/gitfs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/salt/fileserver/gitfs.py b/salt/fileserver/gitfs.py index 101ab3b2be31..f0f794c3ac42 100644 --- a/salt/fileserver/gitfs.py +++ b/salt/fileserver/gitfs.py @@ -445,7 +445,7 @@ def _stale_refs_pygit2(repo): key = ' * [would prune] ' ret = [] for line in subprocess.Popen( - 'git remote prune --dry-run origin'.format(remote), + 'git remote prune --dry-run origin', shell=True, close_fds=True, cwd=repo.workdir, @@ -657,7 +657,7 @@ def update(): # Prune stale refs for ref in repo.get_refs(): if ref not in refs_post: - del(repo[ref]) + del repo[ref] except Exception as exc: log.warning( 'Exception caught while fetching: {0}'.format(exc)