Fab files format changed

This commit is contained in:
Omkar Pakki 2019-07-09 21:52:45 +05:30
parent e07cd1462e
commit 408c033338
3 changed files with 55 additions and 48 deletions

View File

@ -15,9 +15,9 @@ from fabvenv import virtualenv
FABRIC_ROOT = os.path.dirname(__file__) FABRIC_ROOT = os.path.dirname(__file__)
PROJECT_ROOT = os.path.dirname(FABRIC_ROOT) project_root = os.path.dirname(FABRIC_ROOT)
VENV_ROOT = os.path.expanduser(os.path.join('~', '.virtualenvs', 'pybitmessage-devops')) VENV_ROOT = os.path.expanduser(os.path.join('~', '.virtualenvs', 'pybitmessage-devops'))
PYTHONPATH = os.path.join(PROJECT_ROOT, 'src',) PYTHONPATH = os.path.join(project_root, 'src', )
def coerce_list(value): def coerce_list(value):
@ -72,7 +72,7 @@ def filelist_from_git(rev=None):
else: else:
cmd += ' -r {}'.format(rev) cmd += ' -r {}'.format(rev)
with cd(PROJECT_ROOT): with cd(project_root):
with hide('running', 'stdout'): with hide('running', 'stdout'):
results = [] results = []
ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]') ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]')
@ -92,7 +92,7 @@ def pycodestyle(path_to_file):
return run( return run(
'pycodestyle --config={0} {1}'.format( 'pycodestyle --config={0} {1}'.format(
os.path.join( os.path.join(
PROJECT_ROOT, project_root,
'setup.cfg', 'setup.cfg',
), ),
path_to_file, path_to_file,
@ -108,7 +108,7 @@ def flake8(path_to_file):
return run( return run(
'flake8 --config={0} {1}'.format( 'flake8 --config={0} {1}'.format(
os.path.join( os.path.join(
PROJECT_ROOT, project_root,
'setup.cfg', 'setup.cfg',
), ),
path_to_file, path_to_file,
@ -125,7 +125,7 @@ def pylint(path_to_file):
return run( return run(
'pylint --rcfile={0} {1}'.format( 'pylint --rcfile={0} {1}'.format(
os.path.join( os.path.join(
PROJECT_ROOT, project_root,
'setup.cfg', 'setup.cfg',
), ),
path_to_file, path_to_file,

View File

@ -15,7 +15,7 @@ from fabric.contrib.project import rsync_project
from fabvenv import virtualenv from fabvenv import virtualenv
from fabfile.lib import ( from fabfile.lib import (
autopep8, PROJECT_ROOT, VENV_ROOT, coerce_bool, flatten, filelist_from_git, default_hosts, autopep8, project_root, VENV_ROOT, coerce_bool, flatten, filelist_from_git, default_hosts,
get_filtered_pycodestyle_output, get_filtered_flake8_output, get_filtered_pylint_output, get_filtered_pycodestyle_output, get_filtered_flake8_output, get_filtered_pylint_output,
) )
@ -28,16 +28,17 @@ def get_tool_results(file_list):
results = [] results = []
for path_to_file in file_list: for path_to_file in file_list:
result = {} result = {
result['pycodestyle_violations'] = get_filtered_pycodestyle_output(path_to_file) 'pycodestyle_violations': get_filtered_pycodestyle_output(path_to_file),
result['flake8_violations'] = get_filtered_flake8_output(path_to_file) 'flake8_violations': get_filtered_flake8_output(path_to_file),
result['pylint_violations'] = get_filtered_pylint_output(path_to_file) 'pylint_violations': get_filtered_pylint_output(path_to_file),
result['path_to_file'] = path_to_file 'path_to_file': path_to_file,
result['total_violations'] = sum([ 'total_violations': sum([
len(result['pycodestyle_violations']), len(result['pycodestyle_violations']),
len(result['flake8_violations']), len(result['flake8_violations']),
len(result['pylint_violations']), len(result['pylint_violations']),
]) ])
}
results.append(result) results.append(result)
return results return results
@ -46,13 +47,13 @@ def print_results(results, top, verbose, details):
"""Print an item with the appropriate verbosity / detail""" """Print an item with the appropriate verbosity / detail"""
if verbose and results: if verbose and results:
print ''.join( print(''.join(
[ [
os.linesep, os.linesep,
'total pycodestyle flake8 pylint path_to_file', 'total pycodestyle flake8 pylint path_to_file',
os.linesep, os.linesep,
] ]
) ))
for item in sort_and_slice(results, top): for item in sort_and_slice(results, top):
@ -66,22 +67,22 @@ def print_results(results, top, verbose, details):
) )
else: else:
line = item['path_to_file'] line = item['path_to_file']
print line print(line)
if details: if details:
print "pycodestyle:" print("pycodestyle:")
for detail in flatten(item['pycodestyle_violations']): for detail in flatten(item['pycodestyle_violations']):
print detail print(detail)
print print
print "flake8:" print("flake8:")
for detail in flatten(item['flake8_violations']): for detail in flatten(item['flake8_violations']):
print detail print(detail)
print print
print "pylint:" print("pylint:")
for detail in flatten(item['pylint_violations']): for detail in flatten(item['pylint_violations']):
print detail print(detail)
print print
@ -107,13 +108,13 @@ def generate_file_list(filename):
if filename: if filename:
filename = os.path.abspath(filename) filename = os.path.abspath(filename)
if not os.path.exists(filename): if not os.path.exists(filename):
print "Bad filename, specify a Python file" print("Bad filename, specify a Python file")
sys.exit(1) sys.exit(1)
else: else:
file_list = [filename] file_list = [filename]
else: else:
with cd(PROJECT_ROOT): with cd(project_root):
file_list = [ file_list = [
os.path.abspath(i.rstrip('\r')) os.path.abspath(i.rstrip('\r'))
for i in run('find . -name "*.py"').split(os.linesep) for i in run('find . -name "*.py"').split(os.linesep)
@ -137,15 +138,15 @@ def create_dependency_graphs():
with hide('running', 'stdout'): with hide('running', 'stdout'):
# .. todo:: consider a better place to put this, use a particular commit # .. todo:: consider a better place to put this, use a particular commit
with cd(PROJECT_ROOT): with cd(project_root):
with settings(warn_only=True): with settings(warn_only=True):
if run('stat pyan').return_code: if run('stat pyan').return_code:
run('git clone https://github.com/davidfraser/pyan.git') run('git clone https://github.com/davidfraser/pyan.git')
with cd(os.path.join(PROJECT_ROOT, 'pyan')): with cd(os.path.join(project_root, 'pyan')):
run('git checkout pre-python3') run('git checkout pre-python3')
# .. todo:: Use better settings. This is MVP to make a diagram # .. todo:: Use better settings. This is MVP to make a diagram
with cd(PROJECT_ROOT): with cd(project_root):
file_list = run("find . -type f -name '*.py' ! -path './src/.eggs/*'").split('\r\n') file_list = run("find . -type f -name '*.py' ! -path './src/.eggs/*'").split('\r\n')
for cmd in [ for cmd in [
'neato -Goverlap=false -Tpng > deps-neato.png', 'neato -Goverlap=false -Tpng > deps-neato.png',
@ -215,7 +216,7 @@ def code_quality(verbose=True, details=False, fix=False, filename=None, top=10,
def test(): def test():
"""Run tests on the code""" """Run tests on the code"""
with cd(PROJECT_ROOT): with cd(project_root):
with virtualenv(VENV_ROOT): with virtualenv(VENV_ROOT):
run('pip uninstall -y pybitmessage') run('pip uninstall -y pybitmessage')
@ -264,14 +265,14 @@ def build_docs(dep_graph=False, apidoc=True):
apidoc_result = 0 apidoc_result = 0
if apidoc: if apidoc:
run('mkdir -p {}'.format(os.path.join(PROJECT_ROOT, 'docs', 'autodoc'))) run('mkdir -p {}'.format(os.path.join(project_root, 'docs', 'autodoc')))
with cd(os.path.join(PROJECT_ROOT, 'docs', 'autodoc')): with cd(os.path.join(project_root, 'docs', 'autodoc')):
with settings(warn_only=True): with settings(warn_only=True):
run('rm *.rst') run('rm *.rst')
with cd(os.path.join(PROJECT_ROOT, 'docs')): with cd(os.path.join(project_root, 'docs')):
apidoc_result = run('sphinx-apidoc -o autodoc ..').return_code apidoc_result = run('sphinx-apidoc -o autodoc ..').return_code
with cd(os.path.join(PROJECT_ROOT, 'docs')): with cd(os.path.join(project_root, 'docs')):
make_result = run('make html').return_code make_result = run('make html').return_code
return_code = apidoc_result + make_result return_code = apidoc_result + make_result
@ -294,16 +295,16 @@ def push_docs(path=None):
""" """
# Making assumptions # Making assumptions
WEB_ROOT = path if path is not None else os.path.join('var', 'www', 'html', 'pybitmessage', 'en', 'latest') web_root = path if path is not None else os.path.join('var', 'www', 'html', 'pybitmessage', 'en', 'latest')
VERSION_ROOT = os.path.join(os.path.dirname(WEB_ROOT), softwareVersion) version_root = os.path.join(os.path.dirname(web_root), softwareVersion)
rsync_project( rsync_project(
remote_dir=VERSION_ROOT, remote_dir=version_root,
local_dir=os.path.join(PROJECT_ROOT, 'docs', '_build', 'html') local_dir=os.path.join(project_root, 'docs', '_build', 'html')
) )
result = run('ln -sf {0} {1}'.format(WEB_ROOT, VERSION_ROOT)) result = run('ln -sf {0} {1}'.format(web_root, version_root))
if result.return_code: if result.return_code:
print 'Linking the new release failed' print('Linking the new release failed')
# More assumptions # More assumptions
sudo('systemctl restart apache2') sudo('systemctl restart apache2')
@ -314,5 +315,5 @@ def push_docs(path=None):
def clean(): def clean():
"""Clean up files generated by fabric commands.""" """Clean up files generated by fabric commands."""
with hide('running', 'stdout'): with hide('running', 'stdout'):
with cd(PROJECT_ROOT): with cd(project_root):
run(r"find . -name '*.pyc' -exec rm '{}' \;") run(r"find . -name '*.pyc' -exec rm '{}' \;")

View File

@ -7,18 +7,20 @@ import xmlrpclib
pybmurl = "" pybmurl = ""
api = "" api = ""
def init_callback(): def init_callback():
global api global api
api = xmlrpclib.ServerProxy(pybmurl) api = xmlrpclib.ServerProxy(pybmurl)
collectd.info('pybitmessagestatus.py init done') collectd.info('pybitmessagestatus.py init done')
def config_callback(ObjConfiguration):
def config_callback(obj_configuration):
global pybmurl global pybmurl
apiUsername = "" apiUsername = ""
apiPassword = "" apiPassword = ""
apiInterface = "127.0.0.1" apiInterface = "127.0.0.1"
apiPort = 8445 apiPort = 8445
for node in ObjConfiguration.children: for node in obj_configuration.children:
key = node.key.lower() key = node.key.lower()
if key.lower() == "apiusername" and node.values: if key.lower() == "apiusername" and node.values:
apiUsername = node.values[0] apiUsername = node.values[0]
@ -31,14 +33,17 @@ def config_callback(ObjConfiguration):
pybmurl = "http://" + apiUsername + ":" + apiPassword + "@" + apiInterface+ ":" + str(int(apiPort)) + "/" pybmurl = "http://" + apiUsername + ":" + apiPassword + "@" + apiInterface+ ":" + str(int(apiPort)) + "/"
collectd.info('pybitmessagestatus.py config done') collectd.info('pybitmessagestatus.py config done')
def read_callback(): def read_callback():
try: try:
clientStatus = json.loads(api.clientStatus()) client_status = json.loads(api.clientStatus())
except: except:
collectd.info("Exception loading or parsing JSON") collectd.info("Exception loading or parsing JSON")
return return
for i in ["networkConnections", "numberOfPubkeysProcessed", "numberOfMessagesProcessed", "numberOfBroadcastsProcessed"]: con_data = ["networkConnections", "numberOfPubkeysProcessed",
"numberOfMessagesProcessed", "numberOfBroadcastsProcessed"]
for i in con_data:
metric = collectd.Values() metric = collectd.Values()
metric.plugin = "pybitmessagestatus" metric.plugin = "pybitmessagestatus"
if i[0:6] == "number": if i[0:6] == "number":
@ -47,11 +52,12 @@ def read_callback():
metric.type = 'gauge' metric.type = 'gauge'
metric.type_instance = i.lower() metric.type_instance = i.lower()
try: try:
metric.values = [clientStatus[i]] metric.values = [client_status[i]]
except: except:
collectd.info("Value for %s missing" % (i)) collectd.info("Value for %s missing" % (i))
metric.dispatch() metric.dispatch()
if __name__ == "__main__": if __name__ == "__main__":
main() main()
else: else: