Skip to content

Commit

Permalink
Return to 88 chars/line & more
Browse files Browse the repository at this point in the history
  • Loading branch information
t0mab committed Jun 5, 2020
1 parent 191ea34 commit 2e9668f
Show file tree
Hide file tree
Showing 49 changed files with 2,023 additions and 1,081 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -51,3 +51,4 @@ docs/_build
htmlcov
.cache
.ropeproject
.vscode
57 changes: 36 additions & 21 deletions pydiploy/bottle.py
Expand Up @@ -14,30 +14,33 @@ def wrap_deploy():
yield
except SystemExit:
fabric.api.execute(rollback)
fabric.api.abort(fabric.colors.red(
"Deploy failed rollbacking process launched"))
fabric.api.abort(
fabric.colors.red("Deploy failed rollbacking process launched")
)


@do_verbose
def application_packages(update=False):
""" Installs all packages for the app """
fabtools.require.deb.packages(['gettext'], update=update)
if env.remote_python_version >= 3:
fabric.api.execute(pydiploy.require.system.check_python3_install,
version='python%s' % env.remote_python_version)
fabric.api.execute(
pydiploy.require.system.check_python3_install,
version='python%s' % env.remote_python_version,
)
fabric.api.execute(pydiploy.require.python.utils.python_pkg)
if 'extra_ppa_to_install' in env:
fabric.api.execute(
pydiploy.require.system.install_extra_ppa,
env.extra_ppa_to_install)
pydiploy.require.system.install_extra_ppa, env.extra_ppa_to_install
)
if 'extra_source_to_install' in env:
fabric.api.execute(
pydiploy.require.system.install_extra_source,
env.extra_source_to_install)
pydiploy.require.system.install_extra_source, env.extra_source_to_install
)
if 'extra_pkg_to_install' in env:
fabric.api.execute(
pydiploy.require.system.install_extra_packages,
env.extra_pkg_to_install)
pydiploy.require.system.install_extra_packages, env.extra_pkg_to_install
)


def pre_install_backend(commands='/usr/bin/rsync', upgrade_circus=False):
Expand All @@ -47,8 +50,7 @@ def pre_install_backend(commands='/usr/bin/rsync', upgrade_circus=False):
fabric.api.execute(pydiploy.require.system.set_timezone)
fabric.api.execute(pydiploy.require.system.update_pkg_index)
fabric.api.execute(application_packages)
fabric.api.execute(pydiploy.require.circus.circus_pkg,
update=upgrade_circus)
fabric.api.execute(pydiploy.require.circus.circus_pkg, update=upgrade_circus)
fabric.api.execute(pydiploy.require.python.virtualenv.virtualenv)
fabric.api.execute(pydiploy.require.circus.upstart)

Expand All @@ -67,11 +69,10 @@ def deploy_backend(upgrade_pkg=False, **kwargs):
fabric.api.execute(pydiploy.require.releases_manager.deploy_code)
fabric.api.execute(pydiploy.require.django.utils.deploy_wsgi_file)
fabric.api.execute(
pydiploy.require.python.utils.application_dependencies,
upgrade_pkg)
pydiploy.require.python.utils.application_dependencies, upgrade_pkg
)
# TODO PUT THIS METHOD IN OTHER PACKAGE
fabric.api.execute(pydiploy.require.bottle.utils.app_settings,
**kwargs)
fabric.api.execute(pydiploy.require.bottle.utils.app_settings, **kwargs)
fabric.api.execute(pydiploy.require.bottle.utils.deploy_environ_file)
fabric.api.execute(pydiploy.require.bottle.command.bottle_prepare)
fabric.api.execute(pydiploy.require.system.permissions)
Expand Down Expand Up @@ -122,7 +123,7 @@ def set_app_up():
fabric.api.execute(pydiploy.require.nginx.set_website_up)


def install_postgres_server(user=None,dbname=None,password=None):
def install_postgres_server(user=None, dbname=None, password=None):
""" Install postgres server & add user for postgres
if no parameters are provided using (if exists) ::
Expand All @@ -134,16 +135,30 @@ def install_postgres_server(user=None,dbname=None,password=None):
"""

if not (user and dbname and password):
if all([e in env.keys() for e in ('default_db_user', 'default_db_name', 'default_db_password')]):
if all(
[
e in env.keys()
for e in ('default_db_user', 'default_db_name', 'default_db_password')
]
):
user = env.default_db_user
dbname = env.default_db_name
password = env.default_db_password
else:
fabric.api.abort('Please provide user,dbname,password parameters for postgres.')
fabric.api.abort(
'Please provide user,dbname,password parameters for postgres.'
)

fabric.api.execute(pydiploy.require.databases.postgres.install_postgres_server)
fabric.api.execute(pydiploy.require.databases.postgres.add_postgres_user,user,password=password)
fabric.api.execute(pydiploy.require.databases.postgres.add_postgres_database,dbname,owner=user,locale=env.locale)
fabric.api.execute(
pydiploy.require.databases.postgres.add_postgres_user, user, password=password
)
fabric.api.execute(
pydiploy.require.databases.postgres.add_postgres_database,
dbname,
owner=user,
locale=env.locale,
)


def install_oracle_client():
Expand Down
17 changes: 13 additions & 4 deletions pydiploy/decorators.py
Expand Up @@ -4,6 +4,7 @@
import fabric
from fabric.api import env


"""
Decorators
Expand All @@ -18,11 +19,19 @@ def do_verbose(view_func):

@wraps(view_func)
def wrapper(*args, **kwargs):
custom_hide = ['running', 'stdout', 'stderr'] if 'verbose_output' in\
env and not env.verbose_output else []
custom_hide = (
['running', 'stdout', 'stderr']
if 'verbose_output' in env and not env.verbose_output
else []
)
with fabric.context_managers.hide(*custom_hide):
fabric.api.puts("%s : %s" % (view_func.__name__, fabric.colors.green("Executing")))
fabric.api.puts(
"%s : %s" % (view_func.__name__, fabric.colors.green("Executing"))
)
res = view_func(*args, **kwargs)
fabric.api.puts("%s : %s" % (view_func.__name__, fabric.colors.green("Done")))
fabric.api.puts(
"%s : %s" % (view_func.__name__, fabric.colors.green("Done"))
)
return res

return wrapper
51 changes: 35 additions & 16 deletions pydiploy/django.py
Expand Up @@ -22,8 +22,9 @@ def wrap_deploy():
yield
except SystemExit:
fabric.api.execute(rollback)
fabric.api.abort(fabric.colors.red(
"Deploy failed rollbacking process launched"))
fabric.api.abort(
fabric.colors.red("Deploy failed rollbacking process launched")
)


@do_verbose
Expand All @@ -32,18 +33,23 @@ def application_packages(update=False):
fabtools.require.deb.packages(['gettext'], update=update)

if env.remote_python_version >= 3:
fabric.api.execute(pydiploy.require.system.check_python3_install,
version='python%s' % env.remote_python_version)
fabric.api.execute(
pydiploy.require.system.check_python3_install,
version='python%s' % env.remote_python_version,
)
fabric.api.execute(pydiploy.require.python.utils.python_pkg)
if env.has_key('extra_ppa_to_install'):
fabric.api.execute(
pydiploy.require.system.install_extra_ppa, env.extra_ppa_to_install)
pydiploy.require.system.install_extra_ppa, env.extra_ppa_to_install
)
if env.has_key('extra_source_to_install'):
fabric.api.execute(
pydiploy.require.system.install_extra_source, env.extra_source_to_install)
pydiploy.require.system.install_extra_source, env.extra_source_to_install
)
if env.has_key('extra_pkg_to_install'):
fabric.api.execute(
pydiploy.require.system.install_extra_packages, env.extra_pkg_to_install)
pydiploy.require.system.install_extra_packages, env.extra_pkg_to_install
)


def pre_install_backend(commands='/usr/bin/rsync', upgrade_circus=False):
Expand Down Expand Up @@ -73,10 +79,9 @@ def deploy_backend(upgrade_pkg=False, **kwargs):
fabric.api.execute(pydiploy.require.django.utils.deploy_manage_file)
fabric.api.execute(pydiploy.require.django.utils.deploy_wsgi_file)
fabric.api.execute(
pydiploy.require.python.utils.application_dependencies,
upgrade_pkg)
fabric.api.execute(pydiploy.require.django.utils.app_settings,
**kwargs)
pydiploy.require.python.utils.application_dependencies, upgrade_pkg
)
fabric.api.execute(pydiploy.require.django.utils.app_settings, **kwargs)
fabric.api.execute(pydiploy.require.django.command.django_prepare)
fabric.api.execute(pydiploy.require.system.permissions)
fabric.api.execute(pydiploy.require.circus.app_reload)
Expand Down Expand Up @@ -136,7 +141,7 @@ def custom_manage_command(cmd):
fabric.api.execute(pydiploy.require.django.command.django_custom_cmd, cmd)


def install_postgres_server(user=None,dbname=None,password=None):
def install_postgres_server(user=None, dbname=None, password=None):
""" Install postgres server & add user for postgres
if no parameters are provided using (if exists) ::
Expand All @@ -148,16 +153,30 @@ def install_postgres_server(user=None,dbname=None,password=None):
"""

if not (user and dbname and password):
if all([e in env.keys() for e in ('default_db_user', 'default_db_name', 'default_db_password')]):
if all(
[
e in env.keys()
for e in ('default_db_user', 'default_db_name', 'default_db_password')
]
):
user = env.default_db_user
dbname = env.default_db_name
password = env.default_db_password
else:
fabric.api.abort('Please provide user,dbname,password parameters for postgres.')
fabric.api.abort(
'Please provide user,dbname,password parameters for postgres.'
)

fabric.api.execute(pydiploy.require.databases.postgres.install_postgres_server)
fabric.api.execute(pydiploy.require.databases.postgres.add_postgres_user,user,password=password)
fabric.api.execute(pydiploy.require.databases.postgres.add_postgres_database,dbname,owner=user,locale=env.locale)
fabric.api.execute(
pydiploy.require.databases.postgres.add_postgres_user, user, password=password
)
fabric.api.execute(
pydiploy.require.databases.postgres.add_postgres_database,
dbname,
owner=user,
locale=env.locale,
)


def install_oracle_client():
Expand Down
38 changes: 28 additions & 10 deletions pydiploy/php.py
Expand Up @@ -22,19 +22,22 @@ def wrap_deploy():
yield
except SystemExit:
fabric.api.execute(rollback)
fabric.api.abort(fabric.colors.red(
"Deploy failed rollbacking process launched"))
fabric.api.abort(
fabric.colors.red("Deploy failed rollbacking process launched")
)


@do_verbose
def application_packages(update=False):
""" Installs all packages for php webapp """
if env.has_key('extra_ppa_to_install'):
fabric.api.execute(
pydiploy.require.system.install_extra_ppa, env.extra_ppa_to_install)
pydiploy.require.system.install_extra_ppa, env.extra_ppa_to_install
)
if env.has_key('extra_pkg_to_install'):
fabric.api.execute(
pydiploy.require.system.install_extra_packages, env.extra_pkg_to_install)
pydiploy.require.system.install_extra_packages, env.extra_pkg_to_install
)


def pre_install_backend(commands='/usr/bin/rsync'):
Expand All @@ -44,7 +47,7 @@ def pre_install_backend(commands='/usr/bin/rsync'):
fabric.api.execute(pydiploy.require.system.set_timezone)
fabric.api.execute(pydiploy.require.system.update_pkg_index)
fabric.api.execute(pydiploy.require.apache.apache_pkg)
fabtools.require.deb.packages(['php5','libapache2-mod-php5'], update=True)
fabtools.require.deb.packages(['php5', 'libapache2-mod-php5'], update=True)
fabric.api.execute(application_packages)


Expand All @@ -56,6 +59,7 @@ def deploy_backend(upgrade_pkg=False, **kwargs):
fabric.api.execute(pydiploy.require.system.permissions)
fabric.api.execute(pydiploy.require.releases_manager.cleanup)


def post_install_backend():
fabric.api.execute(pydiploy.require.apache.web_configuration)
fabric.api.execute(pydiploy.require.apache.apache_restart)
Expand All @@ -82,7 +86,7 @@ def set_app_up():
fabric.api.execute(pydiploy.require.apache.set_website_up)


def install_postgres_server(user=None,dbname=None,password=None):
def install_postgres_server(user=None, dbname=None, password=None):
""" Install postgres server & add user for postgres
if no parameters are provided using (if exists) ::
Expand All @@ -94,16 +98,30 @@ def install_postgres_server(user=None,dbname=None,password=None):
"""

if not (user and dbname and password):
if all([e in env.keys() for e in ('default_db_user', 'default_db_name', 'default_db_password')]):
if all(
[
e in env.keys()
for e in ('default_db_user', 'default_db_name', 'default_db_password')
]
):
user = env.default_db_user
dbname = env.default_db_name
password = env.default_db_password
else:
fabric.api.abort('Please provide user,dbname,password parameters for postgres.')
fabric.api.abort(
'Please provide user,dbname,password parameters for postgres.'
)

fabric.api.execute(pydiploy.require.databases.postgres.install_postgres_server)
fabric.api.execute(pydiploy.require.databases.postgres.add_postgres_user,user,password=password)
fabric.api.execute(pydiploy.require.databases.postgres.add_postgres_database,dbname,owner=user,locale=env.locale)
fabric.api.execute(
pydiploy.require.databases.postgres.add_postgres_user, user, password=password
)
fabric.api.execute(
pydiploy.require.databases.postgres.add_postgres_database,
dbname,
owner=user,
locale=env.locale,
)


def install_oracle_client():
Expand Down

0 comments on commit 2e9668f

Please sign in to comment.