diff --git a/.gitignore b/.gitignore index c60d141..5fba5c1 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,7 @@ venv/ ENV/ env.bak/ venv.bak/ + +# Backup files +*~ +*.swp diff --git a/docky/cmd/base.py b/docky/cmd/base.py index a06eb56..c7279eb 100644 --- a/docky/cmd/base.py +++ b/docky/cmd/base.py @@ -1,9 +1,7 @@ -# -*- coding: utf-8 -*- -# Copyright 2018 Akretion (http://www.akretion.com). +# Copyright 2018-TODAY Akretion (http://www.akretion.com). # @author Sébastien BEAU # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - from plumbum import cli, local from plumbum.commands.modifiers import FG import logging @@ -15,24 +13,24 @@ class Docky(cli.Application): PROGNAME = "docky" - VERSION = '7.1.0' + VERSION = "8.0.0" SUBCOMMAND_HELPMSG = None def _run(self, cmd, retcode=FG): """Run a command in a new process and log it""" - logger.debug(str(cmd).replace('/usr/local/bin/', '')) + logger.debug(str(cmd).replace("/usr/local/bin/", "")) return cmd & retcode def _exec(self, cmd, args=[]): """Run a command in the same process and log it this will replace the current process by the cmd""" - logger.debug(cmd + ' '.join(args)) + logger.debug(cmd + " ".join(args)) os.execvpe(cmd, [cmd] + args, local.env) @cli.switch("--verbose", help="Verbose mode", group="Meta-switches") def set_log_level(self): logger.setLevel(logging.DEBUG) - logger.debug('Verbose mode activated') + logger.debug("Verbose mode activated") class DockySub(cli.Application): @@ -46,7 +44,7 @@ def _run(self, *args, **kwargs): def _init_project(self): self.project = Project() - self.compose = local['docker-compose'] + self.compose = local["docker-compose"] def main(self, *args, **kwargs): if self._project_specific: diff --git a/docky/cmd/forward.py b/docky/cmd/forward.py index 1632d83..fab7e2c 100644 --- a/docky/cmd/forward.py +++ b/docky/cmd/forward.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# Copyright 2018 Akretion (http://www.akretion.com). +# Copyright 2018-TODAY Akretion (http://www.akretion.com). # @author Sébastien BEAU # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -10,7 +9,7 @@ class DockyForward(DockySub): _cmd = None def _main(self, *args): - cmd = self._cmd.split(' ') + cmd = self._cmd.split(" ") if args: cmd.append(*args) return self._run(self.compose[cmd]) @@ -30,7 +29,7 @@ class DockyUp(DockyForward): def _main(self, *args): self.project.display_service_tooltip() self.project.create_volume() - return super(DockyUp, self)._main(*args) + return super()._main(*args) @Docky.subcommand("down") diff --git a/docky/cmd/kill.py b/docky/cmd/kill.py index 12a6dac..4786222 100644 --- a/docky/cmd/kill.py +++ b/docky/cmd/kill.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# Copyright 2018 Akretion (http://www.akretion.com). +# Copyright 2018-TODAY Akretion (http://www.akretion.com). # @author Sébastien BEAU # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -15,4 +14,4 @@ def _main(self, *args): # docker compose do not kill the container odoo as is was run # manually, so we implement our own kill containers = self.project.get_containers() - parallel_kill(containers, {'signal': 'SIGKILL'}) + parallel_kill(containers, {"signal": "SIGKILL"}) diff --git a/docky/cmd/run_open.py b/docky/cmd/run_open.py index 33a3de5..ffcc80f 100644 --- a/docky/cmd/run_open.py +++ b/docky/cmd/run_open.py @@ -1,9 +1,7 @@ -# -*- coding: utf-8 -*- -# Copyright 2018 Akretion (http://www.akretion.com). +# Copyright 2018-TODAY Akretion (http://www.akretion.com). # @author Sébastien BEAU # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - from plumbum import cli from .base import Docky, DockySub from ..common.api import raise_error @@ -24,9 +22,9 @@ def _get_cmd_line(self, optionnal_command_line): user = self._use_specific_user(self.service) cmd = [] if user: - cmd = ['gosu', user] + cmd = ["gosu", user] if not optionnal_command_line: - cmd.append('bash') + cmd.append("bash") else: cmd += list(optionnal_command_line) return cmd @@ -56,11 +54,11 @@ def _main(self, *optionnal_command_line): super()._main(*optionnal_command_line) self._check_running() # Remove useless dead container before running a new one - self._run(self.compose['rm', '-f']) + self._run(self.compose["rm", "-f"]) self.project.display_service_tooltip() self.project.create_volume() - self._exec('docker-compose', [ - 'run', '--rm', '--service-ports', '--use-aliases', '-e', 'NOGOSU=True', + self._exec("docker-compose", [ + "run", "--rm", "--service-ports", "--use-aliases", "-e", "NOGOSU=True", self.service] + self.cmd) @@ -72,4 +70,4 @@ class DockyOpen(DockyExec): def _main(self, *optionnal_command_line): super()._main(*optionnal_command_line) - self._exec('dcpatched', ['exec', '-e', 'NOGOSU=True', self.service] + self.cmd) + self._exec("dcpatched", ["exec", "-e", "NOGOSU=True", self.service] + self.cmd) diff --git a/docky/common/api.py b/docky/common/api.py index 4907835..1e181b1 100644 --- a/docky/common/api.py +++ b/docky/common/api.py @@ -1,21 +1,19 @@ -# -*- coding: utf-8 -*- -# Copyright 2018 Akretion (http://www.akretion.com). +# Copyright 2018-TODAY Akretion (http://www.akretion.com). # @author Sébastien BEAU # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - import logging import sys # Optionnal code for colorized log from rainbow_logging_handler import RainbowLoggingHandler -logger = logging.getLogger('docky') +logger = logging.getLogger("docky") formatter = logging.Formatter("%(message)s") logger.setLevel(logging.INFO) handler = RainbowLoggingHandler( sys.stderr, - color_message_info=('green', None, True), + color_message_info=("green", None, True), ) handler.setFormatter(formatter) logger.addHandler(handler) diff --git a/docky/common/project.py b/docky/common/project.py index c1428b5..7c0c78d 100644 --- a/docky/common/project.py +++ b/docky/common/project.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# Copyright 2018 Akretion (http://www.akretion.com). +# Copyright 2018-TODAY Akretion (http://www.akretion.com). # @author Sébastien BEAU # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -16,10 +15,10 @@ class Project(object): def __init__(self): try: - self.project = command.project_from_options('.', {}) + self.project = command.project_from_options(".", {}) except ComposeFileNotFound: print("No docker-compose found, create one with :") - print('$ docky init') + print("$ docky init") exit(-1) self.name = self.project.name @@ -30,23 +29,23 @@ def _get_main_service(self, project): """main_service has docky.main.service defined in his label.""" for service in project.services: - labels = service.options.get('labels', {}) + labels = service.options.get("labels", {}) # service.labels() do not contain docky.main.service # see also compose.service.merge_labels - if labels.get('docky.main.service', False): + if labels.get("docky.main.service", False): return service.name def get_containers(self, service=None): - kwargs = {'one_off': OneOffFilter.include} + kwargs = {"one_off": OneOffFilter.include} if service: - kwargs['service_names'] = [service] + kwargs["service_names"] = [service] return self.project.containers(**kwargs) def display_service_tooltip(self): infos = self._get_services_info() for service in self.project.services: - labels = service.options.get('labels', {}) - if labels.get('docky.access.help'): + labels = service.options.get("labels", {}) + if labels.get("docky.access.help"): # TODO remove after some versions logger.warning( "'docky.access.help' is replaced by 'docky.help'. " @@ -55,8 +54,8 @@ def display_service_tooltip(self): # some applications provide extra parameters to access resource infos[service.name] += labels.get("docky.url_suffix", "") logger.info(infos[service.name]) - if labels.get('docky.help'): - logger.info(labels.get('docky.help')) + if labels.get("docky.help"): + logger.info(labels.get("docky.help")) def _get_services_info(self): """ Search IP and Port for each services @@ -94,7 +93,7 @@ def create_volume(self): docker-compose up do not attemps to create it so we have to do it ourselves""" for service in self.project.services: - for volume in service.options.get('volumes', []): + for volume in service.options.get("volumes", []): if volume.external: path = local.path(local.env.expand(volume.external)) if not path.exists(): @@ -105,6 +104,6 @@ def create_volume(self): def get_user(self, service_name): service = self.project.get_service(name=service_name) - labels = service.options.get('labels') + labels = service.options.get("labels") if labels: - return labels.get('docky.user', None) + return labels.get("docky.user", None) diff --git a/docky/dcpatched.py b/docky/dcpatched.py index 3659258..2e3119e 100644 --- a/docky/dcpatched.py +++ b/docky/dcpatched.py @@ -16,7 +16,7 @@ def get_run_container(self, number=1): # search for container running in background for container in self.containers( - labels=['{0}={1}'.format(LABEL_CONTAINER_NUMBER, number)]): + labels=["{0}={1}".format(LABEL_CONTAINER_NUMBER, number)]): return container # search for container running with "run" cmd diff --git a/setup.py b/setup.py index 6cdcd1f..0e12db1 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ def read(*parts): path = os.path.join(os.path.dirname(__file__), *parts) - with codecs.open(path, encoding='utf-8') as fobj: + with codecs.open(path, encoding="utf-8") as fobj: return fobj.read() @@ -20,26 +20,26 @@ def find_version(*file_paths): setup( - name='docky', + name="docky", version=find_version("docky", "cmd", "base.py"), - author='Akretion', - author_email='contact@akretion.com', - url='https://github.com/akretion/docky/', - description='Make developpement with docker simply', + author="Akretion", + author_email="contact@akretion.com", + url="https://github.com/akretion/docky/", + description="Make developpement with docker simply", license="AGPLv3+", - long_description=open('README.rst').read(), + long_description=open("README.rst").read(), classifiers=[ "Programming Language :: Python :: 3", "Operating System :: POSIX :: Linux", ], install_requires=[ - r.strip() for r in open('requirements.txt').read().splitlines()], + r.strip() for r in open("requirements.txt").read().splitlines()], entry_points=""" [console_scripts] docky=docky.main:main dcpatched=docky.dcpatched:main """, include_package_data=True, - packages=find_packages() + ['docky'], + packages=find_packages() + ["docky"], zip_safe=False, )