Add pep8 conformity using flake8
This commit is contained in:
parent
3a649c1112
commit
1feb4df58e
12 changed files with 80 additions and 27 deletions
8
Makefile
Normal file
8
Makefile
Normal file
|
@ -0,0 +1,8 @@
|
|||
.PHONY: clean lint
|
||||
|
||||
clean:
|
||||
find . -type f -name '*.py[cod]' -delete
|
||||
find . -type f -name '*.*~' -delete
|
||||
|
||||
lint: clean
|
||||
-flake8 .
|
|
@ -4,24 +4,30 @@ from .dispatcher import Dispatcher, DispatchError
|
|||
from .messenger import Messenger
|
||||
from .messenger import Level
|
||||
|
||||
|
||||
def add_options(parser):
|
||||
parser.add_argument('-Q', '--super-quiet', dest='super_quiet', action='store_true',
|
||||
parser.add_argument('-Q', '--super-quiet', dest='super_quiet',
|
||||
action='store_true',
|
||||
help='suppress almost all output')
|
||||
parser.add_argument('-q', '--quiet', dest='quiet', action='store_true',
|
||||
help='suppress most output')
|
||||
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
|
||||
help='enable verbose output')
|
||||
parser.add_argument('-d', '--base-directory', nargs=1,
|
||||
dest='base_directory', help='execute commands from within BASEDIR',
|
||||
dest='base_directory',
|
||||
help='execute commands from within BASEDIR',
|
||||
metavar='BASEDIR', required=True)
|
||||
parser.add_argument('-c', '--config-file', nargs=1, dest='config_file',
|
||||
help='run commands given in CONFIGFILE', metavar='CONFIGFILE',
|
||||
help='run commands given in CONFIGFILE',
|
||||
metavar='CONFIGFILE',
|
||||
required=True)
|
||||
|
||||
|
||||
def read_config(config_file):
|
||||
reader = ConfigReader(config_file)
|
||||
return reader.get_config()
|
||||
|
||||
|
||||
def main():
|
||||
log = Messenger()
|
||||
try:
|
||||
|
@ -40,7 +46,8 @@ def main():
|
|||
if success:
|
||||
log.info('\n==> All tasks executed successfully')
|
||||
else:
|
||||
raise DispatchError('\n==> Some tasks were not executed successfully')
|
||||
raise DispatchError(
|
||||
'\n==> Some tasks were not executed successfully')
|
||||
except (ReadingError, DispatchError) as e:
|
||||
log.error('%s' % e)
|
||||
exit(1)
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import yaml
|
||||
from .util import string
|
||||
|
||||
|
||||
class ConfigReader(object):
|
||||
|
||||
def __init__(self, config_file_path):
|
||||
self._config = self._read(config_file_path)
|
||||
|
||||
|
@ -17,5 +19,6 @@ class ConfigReader(object):
|
|||
def get_config(self):
|
||||
return self._config
|
||||
|
||||
|
||||
class ReadingError(Exception):
|
||||
pass
|
||||
|
|
|
@ -2,7 +2,9 @@ import os
|
|||
from .executor import Executor
|
||||
from .messenger import Messenger
|
||||
|
||||
|
||||
class Dispatcher(object):
|
||||
|
||||
def __init__(self, base_directory):
|
||||
self._log = Messenger()
|
||||
self._set_base_directory(base_directory)
|
||||
|
@ -28,7 +30,8 @@ class Dispatcher(object):
|
|||
handled = True
|
||||
except Exception:
|
||||
self._log.error(
|
||||
'An error was encountered while executing action %s' %
|
||||
'An error was encountered\
|
||||
while executing action %s' %
|
||||
action)
|
||||
if not handled:
|
||||
success = False
|
||||
|
@ -39,5 +42,6 @@ class Dispatcher(object):
|
|||
self._plugins = [plugin(self._base_directory)
|
||||
for plugin in Executor.__subclasses__()]
|
||||
|
||||
|
||||
class DispatchError(Exception):
|
||||
pass
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import os
|
||||
from . import Executor
|
||||
|
||||
|
||||
class Cleaner(Executor):
|
||||
|
||||
'''
|
||||
Cleans broken symbolic links.
|
||||
'''
|
||||
|
@ -39,7 +41,10 @@ class Cleaner(Executor):
|
|||
if not os.path.exists(path) and os.path.islink(path):
|
||||
if self._in_directory(path, self._base_directory):
|
||||
self._log.lowinfo('Removing invalid link %s -> %s' %
|
||||
(path, os.path.join(os.path.dirname(path), os.readlink(path))))
|
||||
(path,
|
||||
os.path.join(os.path.dirname(path),
|
||||
os.readlink(path)
|
||||
)))
|
||||
os.remove(path)
|
||||
return True
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import os, subprocess
|
||||
import os
|
||||
import subprocess
|
||||
from . import Executor
|
||||
|
||||
|
||||
class CommandRunner(Executor):
|
||||
|
||||
'''
|
||||
Run arbitrary shell commands.
|
||||
'''
|
||||
|
@ -41,7 +44,8 @@ class CommandRunner(Executor):
|
|||
self._log.lowinfo(cmd)
|
||||
else:
|
||||
self._log.lowinfo('%s [%s]' % (msg, cmd))
|
||||
ret = subprocess.call(cmd, shell=True, stdin=stdin, stdout=stdout,
|
||||
ret = subprocess.call(cmd, shell=True,
|
||||
stdin=stdin, stdout=stdout,
|
||||
stderr=stderr, cwd=self._base_directory)
|
||||
if ret != 0:
|
||||
success = False
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
from ..messenger import Messenger
|
||||
|
||||
|
||||
class Executor(object):
|
||||
|
||||
'''
|
||||
Abstract base class for commands that process directives.
|
||||
'''
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import os, shutil
|
||||
import os
|
||||
import shutil
|
||||
from . import Executor
|
||||
|
||||
|
||||
class Linker(Executor):
|
||||
|
||||
'''
|
||||
Symbolically links dotfiles.
|
||||
'''
|
||||
|
@ -60,7 +63,8 @@ class Linker(Executor):
|
|||
|
||||
def _create(self, path):
|
||||
success = True
|
||||
parent = os.path.abspath(os.path.join(os.path.expanduser(path), os.pardir))
|
||||
parent = os.path.abspath(
|
||||
os.path.join(os.path.expanduser(path), os.pardir))
|
||||
if not self._exists(parent):
|
||||
try:
|
||||
os.makedirs(parent)
|
||||
|
@ -105,15 +109,18 @@ class Linker(Executor):
|
|||
try:
|
||||
os.symlink(source, os.path.expanduser(link_name))
|
||||
except OSError:
|
||||
self._log.warning('Linking failed %s -> %s' % (link_name, source))
|
||||
self._log.warning('Linking failed %s -> %s' %
|
||||
(link_name, source))
|
||||
else:
|
||||
self._log.lowinfo('Creating link %s -> %s' % (link_name, source))
|
||||
self._log.lowinfo('Creating link %s -> %s' %
|
||||
(link_name, source))
|
||||
success = True
|
||||
elif self._exists(link_name) and not self._is_link(link_name):
|
||||
self._log.warning(
|
||||
'%s already exists but is a regular file or directory' %
|
||||
link_name)
|
||||
elif self._is_link(link_name) and self._link_destination(link_name) != source:
|
||||
elif self._is_link(link_name)\
|
||||
and self._link_destination(link_name) != source:
|
||||
self._log.warning('Incorrect link %s -> %s' %
|
||||
(link_name, self._link_destination(link_name)))
|
||||
elif not self._exists(source):
|
||||
|
|
|
@ -4,7 +4,9 @@ from ..util.compat import with_metaclass
|
|||
from .color import Color
|
||||
from .level import Level
|
||||
|
||||
|
||||
class Messenger(with_metaclass(Singleton, object)):
|
||||
|
||||
def __init__(self, level=Level.LOWINFO):
|
||||
self.set_level(level)
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
def with_metaclass(meta, *bases):
|
||||
class metaclass(meta):
|
||||
|
||||
def __new__(cls, name, this_bases, d):
|
||||
return meta(name, bases, d)
|
||||
return type.__new__(metaclass, 'temporary_class', (), {})
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
class Singleton(type):
|
||||
_instances = {}
|
||||
|
||||
def __call__(cls, *args, **kwargs):
|
||||
if cls not in cls._instances:
|
||||
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
|
||||
cls._instances[cls] = super(
|
||||
Singleton, cls).__call__(*args, **kwargs)
|
||||
return cls._instances[cls]
|
||||
|
|
8
setup.cfg
Normal file
8
setup.cfg
Normal file
|
@ -0,0 +1,8 @@
|
|||
[flake8]
|
||||
exclude = lib/*
|
||||
|
||||
# List of errors and warnings:
|
||||
# http://flake8.readthedocs.org/en/latest/warnings.html
|
||||
# Things we ignore:
|
||||
# F401 module imported but unused
|
||||
ignore = F401
|
Loading…
Reference in a new issue