Commit bc522fdb authored by Maciej Delmanowski's avatar Maciej Delmanowski

Fix pycodestyle errors in debops-tools code

parent 3cc5d3e3
......@@ -36,13 +36,15 @@ try:
except ImportError:
# implement subset of shlex.quote
def shquote(s):
if not s: return "''"
if not s:
return "''"
return "'" + s.replace("'", "'\"'\"'") + "'"
from .config import *
__author__ = "Hartmut Goebel <h.goebel@crazy-compilers.com>"
__copyright__ = "Copyright 2014-2015 by Hartmut Goebel <h.goebel@crazy-compilers.com>"
__copyright__ = "Copyright 2014-2015 by Hartmut Goebel "
"<h.goebel@crazy-compilers.com>"
__licence__ = "GNU General Public License version 3 (GPL v3) or later"
......@@ -50,17 +52,17 @@ __licence__ = "GNU General Public License version 3 (GPL v3) or later"
ANSIBLE_CONFIG_FILE = "ansible.cfg"
#--- Roles
# --- Roles
# Default role prefix if no roles with prefixes are specified
ROLE_PREFIX = "debops"
#--- Playbooks
# --- Playbooks
# Default site.yml playbook to look for
DEBOPS_SITE_PLAYBOOK = os.path.join("playbooks", "site.yml")
#--- Inventories
# --- Inventories
INVENTORY = "inventory"
......@@ -70,7 +72,7 @@ ANSIBLE_INVENTORY_PATHS = [
os.path.join("ansible", INVENTORY),
INVENTORY]
#--- Encryption
# --- Encryption
# Name of the script used to unlock/lock the encrypted directory
PADLOCK_CMD = "padlock"
......@@ -155,6 +157,7 @@ def find_inventorypath(project_root):
if os.path.isdir(ansible_inventory):
return ansible_inventory
# ---- Encryption support ----
def padlock_lock(encrypted_path):
......
......@@ -33,7 +33,7 @@ import sys
import platform
import subprocess
try:
from subprocess import DEVNULL # py3k
from subprocess import DEVNULL # py3k
except ImportError:
import os
# open DEVNULL like `subprocess` module does
......@@ -45,7 +45,8 @@ from .. import find_debops_project as _find_debops_project, \
find_inventorypath as _find_inventorypath
__author__ = "Hartmut Goebel <h.goebel@crazy-compilers.com>"
__copyright__ = "Copyright 2014-2015 by Hartmut Goebel <h.goebel@crazy-compilers.com>"
__copyright__ = "Copyright 2014-2015 by Hartmut Goebel "
"<h.goebel@crazy-compilers.com>"
__licence__ = "GNU General Public License version 3 (GPL v3) or later"
......@@ -64,6 +65,7 @@ def error_msg(message, severity="Error"):
if severity == "Error":
raise SystemExit(1)
def require_commands(*cmd_names):
"""
Check if required commands exist.
......@@ -85,18 +87,21 @@ def find_debops_project(path=None, required=True):
error_msg("Not a DebOps project directory")
return project_root
def find_monorepopath(config, project_root, required=True):
monorepo_path = _find_monorepopath(config, project_root)
if required and not monorepo_path:
error_msg("DebOps monorepo not installed")
return monorepo_path
def find_playbookpath(config, project_root, required=True):
playbooks_path = _find_playbookpath(config, project_root)
if required and not playbooks_path:
error_msg("DebOps playbooks not installed")
return playbooks_path
def find_inventorypath(project_root, required=True):
inventory = _find_inventorypath(project_root)
if required and not inventory:
......
......@@ -32,7 +32,8 @@ import ConfigParser
__all__ = ['DEBOPS_CONFIG', 'read_config']
__author__ = "Hartmut Goebel <h.goebel@crazy-compilers.com>"
__copyright__ = "Copyright 2015 by Hartmut Goebel <h.goebel@crazy-compilers.com>"
__copyright__ = "Copyright 2015 by Hartmut Goebel "
"<h.goebel@crazy-compilers.com>"
__licence__ = "GNU General Public License version 3 (GPL v3) or later"
......@@ -70,9 +71,9 @@ def _set_xdg_defaults():
http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
"""
for name, default in (
('XDG_CONFIG_HOME', '~/.config'),
('XDG_CONFIG_DIRS', '/etc/xdg'),
('XDG_DATA_HOME', '~/.local/share')):
('XDG_CONFIG_HOME', '~/.config'),
('XDG_CONFIG_DIRS', '/etc/xdg'),
('XDG_DATA_HOME', '~/.local/share')):
if not os.environ.get(name):
os.environ[name] = default
......@@ -94,16 +95,20 @@ def _get_config_filenames():
configdirs.reverse()
return [os.path.join(d, 'debops.cfg') for d in configdirs]
_configfiles = _get_config_filenames()
def _expandpath(path):
return os.path.expanduser(os.path.expandvars(path.strip()))
def read_config(project_root):
if project_root is None:
configfiles = _configfiles
else:
configfiles = _configfiles + [os.path.join(project_root, DEBOPS_CONFIG)]
configfiles = _configfiles + [os.path.join(project_root,
DEBOPS_CONFIG)]
cfgparser = ConfigParser.SafeConfigParser()
cfgparser.readfp(cStringIO.StringIO(DEFAULTS))
try:
......
......@@ -6,53 +6,53 @@ import os
SCRIPTS = [os.path.join('bin', n) for n in [
'debops', 'debops-init', 'debops-task',
'debops-defaults', 'debops-padlock', 'debops-update']]
# 'padlock.py'
README = open('README.rst').read()
setup(
name = "debops",
version = "0.5.0",
install_requires = ['netaddr', 'argparse', 'passlib'],
scripts = ['bin/debops',
'bin/debops-defaults',
'bin/debops-init',
'bin/debops-padlock',
'bin/debops-task',
'bin/debops-update'],
packages = find_packages(exclude=['tests']),
package_data = {
name="debops",
version="0.5.0",
install_requires=['netaddr', 'argparse', 'passlib'],
scripts=['bin/debops',
'bin/debops-defaults',
'bin/debops-init',
'bin/debops-padlock',
'bin/debops-task',
'bin/debops-update'],
packages=find_packages(exclude=['tests']),
package_data={
'debops': ['padlock-script'],
},
# metadata for upload to PyPI
author = "DebOps Developers",
author_email = "debops-users@lists.debops.org",
description = "Your Debian-based data center in a box.",
long_description = README,
license = "GPL-3.0",
keywords = "ansible",
url = "https://debops.org/",
download_url = "https://github.com/debops/debops/archive/v0.5.0.tar.gz",
classifiers = [
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Topic :: System :: Systems Administration',
author="DebOps Developers",
author_email="debops-users@lists.debops.org",
description="Your Debian-based data center in a box.",
long_description=README,
license="GPL-3.0",
keywords="ansible",
url="https://debops.org/",
download_url="https://github.com/debops/debops/archive/v0.5.0.tar.gz",
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: GNU General Public License v3 '
'or later (GPLv3+)',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Topic :: System :: Systems Administration',
],
# these are for easy_install (used by bdist_*)
zip_safe = True,
# entry_points = {
# "console_scripts": [
# "debops = debops.cmds.main:run",
# ],
# },
zip_safe=True
# entry_points = {
# "console_scripts": [
# "debops = debops.cmds.main:run",
# ],
# },
)
......@@ -35,15 +35,19 @@ import shutil
import debops
__author__ = "Hartmut Goebel <h.goebel@crazy-compilers.com>"
__copyright__ = "Copyright 2014-2015 by Hartmut Goebel <h.goebel@crazy-compilers.com>"
__copyright__ = "Copyright 2014-2015 by Hartmut Goebel "
"<h.goebel@crazy-compilers.com>"
__licence__ = "GNU General Public License version 3 (GPL v3) or later"
def setenv(name, value):
os.environ[name] = value
def unsetenv(name):
os.environ[name] = ''
class TestConfigFilenames(TestCase):
def test_get_config_filenames_no_env(self):
......@@ -74,7 +78,6 @@ class TestConfigFilenames(TestCase):
'/tmp/etc/debops.cfg',
'/tmp/mindy/debops.cfg',
os.path.expanduser('~/.config/debops.cfg')])
def test_get_config_filenames_with_XDG_vars_set(self):
setenv('XDG_CONFIG_HOME', '/myhome/mindy')
......@@ -88,7 +91,7 @@ class TestConfigFilenames(TestCase):
ANSIBLE_DEFAULTS = {'ansible_managed':
'This file is managed remotely, all changes will be lost'}
'This file is managed remotely, all changes will be lost'}
class TestReadConfig(TestCase):
......@@ -137,7 +140,7 @@ class TestReadConfig(TestCase):
'debops': {'home': '/var/home',
'name1': 'value1',
'name2': 'value2'}
})
})
def test_read_config_files_precedence(self):
dirs = [self._make_configfile(dir, sect, data) for
......@@ -154,7 +157,7 @@ class TestReadConfig(TestCase):
{'ansible defaults': ANSIBLE_DEFAULTS,
'debops': {'home': '/var/home',
'name1': 'value1'}
})
})
def test_read_config_files_with_project_root(self):
dirs = [self._make_configfile(dir, sect, data) for
......@@ -173,14 +176,15 @@ class TestReadConfig(TestCase):
'debops': {'home': '/var/home',
'name1': 'value1',
'name2': 'value2'}
})
})
def test_read_config_files_with_project_root_precedence(self):
dirs = [self._make_configfile(dir, sect, *data) for
dir, sect, data in (
['xdg_home', 'debops', ('home: /var/home',)],
['xdg_dir1', 'debops', ('name1: value1',)],
['pro_root', 'debops', ('name1: value2', 'home: /my/home')],
['pro_root', 'debops', ('name1: value2',
'home: /my/home')],
)]
setenv('XDG_CONFIG_HOME', dirs[0])
setenv('XDG_CONFIG_DIRS', dirs[1])
......@@ -191,7 +195,8 @@ class TestReadConfig(TestCase):
{'ansible defaults': ANSIBLE_DEFAULTS,
'debops': {'home': '/my/home',
'name1': 'value2'}
})
})
class TestReadConfig2(TestCase):
......@@ -232,9 +237,11 @@ class TestReadConfig2(TestCase):
self.assertDictEqual(
cfg['paths'],
{'data-home': os.path.expanduser('~/.local/share/debops'),
'install-path': os.path.expanduser('~/.local/share/debops/debops-playbooks'),
'playbooks-paths': [os.path.expanduser('~/.local/share/debops/debops-playbooks/playbooks')],
})
'install-path': os.path.expanduser(
'~/.local/share/debops/debops-playbooks'),
'playbooks-paths': [os.path.expanduser(
'~/.local/share/debops/debops-playbooks/playbooks')],
})
def test_read_config_files_simple(self):
dirs = [self._make_configfile(dir, sect, data) for
......@@ -248,7 +255,8 @@ class TestReadConfig2(TestCase):
{'data-home': '/opt/my/debops',
'install-path': '/opt/my/debops/debops-playbooks',
'playbooks-paths': ['/opt/my/debops/debops-playbooks/playbooks'],
})
})
class TestReadConfigDefaultsForPlattforms(TestCase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment