Skip to content

Commit

Permalink
1.7.3
Browse files Browse the repository at this point in the history
Changelog:
*  Add Popen args and kwargs to `on_execute` hook message.
*  Fix doc styles static.

See merge request polemarch/ce!193
  • Loading branch information
onegreyonewhite committed May 8, 2020
2 parents 30e5981 + 471dbb0 commit bcdaf2a
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=unexpected-keyword-arg,no-name-in-module,useless-super-delegation,len-as-condition,super-init-not-called,keyword-arg-before-vararg,no-else-return,no-self-argument,inconsistent-return-statements,unsubscriptable-object,too-many-branches,deprecated-lambda,old-style-class,no-init,expression-not-assigned,broad-except,logging-format-interpolation,model-no-explicit-unicode,too-many-ancestors,bad-continuation,bad-whitespace,redefined-builtin,missing-docstring,redefined-variable-type,no-self-use,line-too-long,suppressed-message,cmp-method,no-absolute-import,xrange-builtin,using-cmp-argument,basestring-builtin,backtick,unpacking-in-except,old-raise-syntax,getslice-method,long-builtin,print-statement,reduce-builtin,filter-builtin-not-iterating,import-star-module-level,unichr-builtin,dict-iter-method,range-builtin-not-iterating,file-builtin,old-division,standarderror-builtin,coerce-builtin,setslice-method,old-ne-operator,long-suffix,execfile-builtin,oct-method,metaclass-assignment,intern-builtin,apply-builtin,dict-view-method,raw_input-builtin,raising-string,coerce-method,unicode-builtin,next-method-called,hex-method,nonzero-method,round-builtin,cmp-builtin,reload-builtin,buffer-builtin,useless-suppression,zip-builtin-not-iterating,indexing-exception,map-builtin-not-iterating,delslice-method,old-octal-literal,input-builtin,parameter-unpacking,model-has-unicode,bare-except,too-few-public-methods,fixme,dangerous-default-value,attribute-defined-outside-init,pointless-string-statement,too-many-instance-attributes,arguments-differ,binary-op-exception,bad-classmethod-argument,locally-disabled,file-ignored,multiple-statements,superfluous-parens,bad-mcs-classmethod-argument,useless-object-inheritance
disable=logging-fstring-interpolation,unexpected-keyword-arg,no-name-in-module,useless-super-delegation,len-as-condition,super-init-not-called,keyword-arg-before-vararg,no-else-return,no-self-argument,inconsistent-return-statements,unsubscriptable-object,too-many-branches,deprecated-lambda,old-style-class,no-init,expression-not-assigned,broad-except,logging-format-interpolation,model-no-explicit-unicode,too-many-ancestors,bad-continuation,bad-whitespace,redefined-builtin,missing-docstring,redefined-variable-type,no-self-use,line-too-long,suppressed-message,cmp-method,no-absolute-import,xrange-builtin,using-cmp-argument,basestring-builtin,backtick,unpacking-in-except,old-raise-syntax,getslice-method,long-builtin,print-statement,reduce-builtin,filter-builtin-not-iterating,import-star-module-level,unichr-builtin,dict-iter-method,range-builtin-not-iterating,file-builtin,old-division,standarderror-builtin,coerce-builtin,setslice-method,old-ne-operator,long-suffix,execfile-builtin,oct-method,metaclass-assignment,intern-builtin,apply-builtin,dict-view-method,raw_input-builtin,raising-string,coerce-method,unicode-builtin,next-method-called,hex-method,nonzero-method,round-builtin,cmp-builtin,reload-builtin,buffer-builtin,useless-suppression,zip-builtin-not-iterating,indexing-exception,map-builtin-not-iterating,delslice-method,old-octal-literal,input-builtin,parameter-unpacking,model-has-unicode,bare-except,too-few-public-methods,fixme,dangerous-default-value,attribute-defined-outside-init,pointless-string-statement,too-many-instance-attributes,arguments-differ,binary-op-exception,bad-classmethod-argument,locally-disabled,file-ignored,multiple-statements,superfluous-parens,bad-mcs-classmethod-argument,useless-object-inheritance


[REPORTS]
Expand Down
29 changes: 29 additions & 0 deletions doc/_static/ce-docs.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.text-logo {
margin-left: auto;
width: 165px;
float: inherit;
}

.sidebar-collapse .text-logo {
display: none;
}

.sidebar-collapse .main-sidebar:hover .text-logo {
display: inline-block;
}

#indices-and-tables > h1 {
font-size: 140%;
}
.post {
border-bottom: none;
}

.main-footer {
display: flex;
justify-content: space-between;
}

.social {
font-size: 20px;
}
6 changes: 3 additions & 3 deletions doc/polemarch-sphinx-theme/layout.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% extends "vst-sphinx-theme/layout.html" %}

{%- block scripts %}
{{- super() }}
<script src="{{ pathto('_static/polemarch/doc.js', 1) }}"></script>
{%- block css %}
{{- super() }}
<link rel="stylesheet" href="{{ pathto('_static/ce-docs.css', 1) }}" type="text/css" />
{%- endblock %}

{% block logo %}
Expand Down
16 changes: 0 additions & 16 deletions frontend_src/doc.css

This file was deleted.

2 changes: 0 additions & 2 deletions frontend_src/doc.js

This file was deleted.

2 changes: 1 addition & 1 deletion polemarch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"VST_ROOT_URLCONF": os.getenv("VST_ROOT_URLCONF", 'vstutils.urls'),
}

__version__ = "1.7.2"
__version__ = "1.7.3"

prepare_environment(**default_settings)
10 changes: 7 additions & 3 deletions polemarch/main/hooks/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ def execute(self, script, when, file) -> str:
)
except BaseException as err:
logger.error(traceback.format_exc())
logger.error("Details:\nSCRIPT:{}\nWHEN:{}\nCWD:{}\n".format(
script, when, self.conf['HOOKS_DIR']
))
logger.error(
f'Details:\n'
f'SCRIPT:{script}\n'
f'WHEN:{when}\n'
f'CWD:{self.conf["HOOKS_DIR"]}\n'
f'ERR:{str(err)}\n'
)
return str(err)

def setup(self, **kwargs):
Expand Down
8 changes: 5 additions & 3 deletions polemarch/main/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _verbose_output(self, value: Text, level: int = 3) -> NoReturn:
def _get_tmp_name(self) -> Text:
return os.path.join(self.cwd, 'project_sources')

def _send_hook(self, when: Text) -> NoReturn:
def _send_hook(self, when: Text, **kwargs) -> NoReturn:
msg = OrderedDict()
msg['execution_type'] = self.history.kind
msg['when'] = when
Expand All @@ -220,6 +220,7 @@ def _send_hook(self, when: Text) -> NoReturn:
msg['target']['inventory'] = inventory
msg['target']['project'] = self.project.get_hook_data(when)
msg['history'] = self.history.get_hook_data(when)
msg['extra'] = kwargs
self.project.hook(when, msg)

def __generate_arg_file(self, value: Text) -> Tuple[Text, List[tmp_file]]:
Expand Down Expand Up @@ -391,11 +392,12 @@ def error_handler(self, exception: BaseException) -> NoReturn:
def execute(self, target: Text, inventory: Any, history: History, project: Project, **extra_args) -> NoReturn:
try:
self.prepare(target, inventory, history, project)
self._send_hook('on_execution')
self.history.status = "OK"
extra = self.__parse_extra_args(**extra_args)
args = self.get_args(self.target, extra.args)
self.executor.execute(args, **self.get_kwargs(self.target, extra.args))
kwargs = self.get_kwargs(self.target, extra.args)
self._send_hook('on_execution', args=args, kwargs=kwargs)
self.executor.execute(args, **kwargs)
except Exception as exception:
logger.error(traceback.format_exc())
self.error_handler(exception)
Expand Down
13 changes: 10 additions & 3 deletions polemarch/main/tests/_base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import json # noqa: F401

import os
import stat
from pathlib import Path
from vstutils.tests import BaseTestCase as VSTBaseTestCase
from ...main import models

hook_data = '''
echo "OK"
hook_data = '''#!/bin/bash
echo "OK";
echo $(cat -);
# exit 1;
'''


Expand All @@ -32,8 +37,10 @@ def tearDown(self):
pass

def create_hook(self, hook):
with open(self.get_hook_path(hook), 'w') as hook_fd:
hook_path = Path(self.get_hook_path(hook))
with hook_path.open('w') as hook_fd:
hook_fd.write(hook_data)
hook_path.chmod(hook_path.stat().st_mode | stat.S_IEXEC)
self.hooks.append(hook)

def generate_hooks(self, hooks):
Expand Down
13 changes: 12 additions & 1 deletion polemarch/main/tests/hosts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import logging
from subprocess import check_output
from ._base import BaseTestCase, json


logger = logging.getLogger('polemarch')


class InvBaseTestCase(BaseTestCase):
def setUp(self):
super(InvBaseTestCase, self).setUp()
Expand Down Expand Up @@ -155,9 +160,15 @@ def test_hosts(self):
self.generate_hooks(scripts)
self.mass_create_bulk('hook', data)
##

def side_effect_for_hooks(*args, **kwargs):
result = check_output(*args, **kwargs)
logger.debug(result)
return result

with self.patch('subprocess.check_output') as mock:
iterations = 3 * len(scripts)
mock.side_effect = [''] * iterations
mock.side_effect = side_effect_for_hooks
results = self.make_bulk(bulk_data, 'put')
self.assertEqual(mock.call_count, iterations)
self.assertEqual(results[0]['status'], 201)
Expand Down
3 changes: 1 addition & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ function setMode() {
const config = {
mode: setMode(),
entry: {
pmlib: entrypoints_dir + "/main.js",
doc: entrypoints_dir + "/doc.js"
pmlib: entrypoints_dir + "/main.js"
},
output: {
path: __dirname + "/polemarch/static/polemarch",
Expand Down

0 comments on commit bcdaf2a

Please sign in to comment.