Skip to content

Commit

Permalink
Merge pull request #158 from akretion/UPD-v8_0_0
Browse files Browse the repository at this point in the history
[UPD+REF] Update for version 8.0.0
  • Loading branch information
hparfr authored Jul 11, 2024
2 parents 7d81eaf + 6d99697 commit 251612b
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 54 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ venv/
ENV/
env.bak/
venv.bak/

# Backup files
*~
*.swp
14 changes: 6 additions & 8 deletions docky/cmd/base.py
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
# 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
Expand All @@ -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):
Expand All @@ -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:
Expand Down
7 changes: 3 additions & 4 deletions docky/cmd/forward.py
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand All @@ -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])
Expand All @@ -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")
Expand Down
5 changes: 2 additions & 3 deletions docky/cmd/kill.py
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand All @@ -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"})
16 changes: 7 additions & 9 deletions docky/cmd/run_open.py
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
# 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
Expand All @@ -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
Expand Down Expand Up @@ -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)


Expand All @@ -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)
8 changes: 3 additions & 5 deletions docky/common/api.py
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
# 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)
Expand Down
29 changes: 14 additions & 15 deletions docky/common/project.py
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand All @@ -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
Expand All @@ -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'. "
Expand All @@ -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
Expand Down Expand Up @@ -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():
Expand All @@ -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)
2 changes: 1 addition & 1 deletion docky/dcpatched.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand All @@ -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='[email protected]',
url='https://github.com/akretion/docky/',
description='Make developpement with docker simply',
author="Akretion",
author_email="[email protected]",
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,
)

0 comments on commit 251612b

Please sign in to comment.