Added .lugitorc configuration and hooked the config files into the connectors. Updates to HISTORY.rst, README.rst and AUTHORS.rst
parent
f327136c34
commit
e445368ef9
@ -1,27 +0,0 @@
|
||||
{
|
||||
"hosts": {
|
||||
"http://phab.lubuntu.me/": {
|
||||
"token": ""
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"default": "http://phab.lubunutu.me/api/"
|
||||
},
|
||||
"HMAC": i{
|
||||
"irc": "",
|
||||
},
|
||||
"irc": {
|
||||
"host": "irc.freenode.net",
|
||||
"port": "6697",
|
||||
"username": "",
|
||||
"password": "",
|
||||
"channel": "#lubuntu-devel"
|
||||
},
|
||||
"launchpad": {
|
||||
"application": "lugito",
|
||||
"staging": "production",
|
||||
"version": "devel",
|
||||
"supported_versions": ["Cosmic", "Bionic", "Xenial", "Trusty"]
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,65 @@
|
||||
# Lugito
|
||||
lugito
|
||||
======
|
||||
|
||||
This is Lubuntu's friendly IRC notifications bot, hooked up to our Phabricator instance at phab.lubuntu.me
|
||||
[![image](https://img.shields.io/pypi/v/lugito.svg)](https://pypi.python.org/pypi/lugito)
|
||||
|
||||
The code is licensed under the 3-clause BSD license, and is copyrighted by the Lubuntu team. More info available in LICENSE.
|
||||
[![image](https://img.shields.io/travis/doc-E-brown/lugito.svg)](https://travis-ci.org/doc-E-brown/lugito)
|
||||
|
||||
[![Documentation Status](https://readthedocs.org/projects/lugito/badge/?version=latest)](https://lugito.readthedocs.io/en/latest/?badge=latest)
|
||||
|
||||
Python Boilerplate contains all the boilerplate you need to create a
|
||||
Python package.
|
||||
|
||||
- Free software: 3 Clause BSD license
|
||||
- Documentation: <https://lugito.readthedocs.io>.
|
||||
|
||||
Temp - Example .lugitorc
|
||||
------------------------
|
||||
|
||||
```
|
||||
[phabricator]
|
||||
host = http://127.0.0.1:9091/api/
|
||||
token = api-nojs2ip33hmp4zn6u6cf72w7d6yh
|
||||
|
||||
[phabricator.hooks]
|
||||
irc = cqg42zdcuqysff632kc6rnsu4m3hjg6c
|
||||
commithook = znkyfflbcia5gviqx5ybad7s6uyfywxi
|
||||
|
||||
[connector.irc]
|
||||
host = irc.freenode.net
|
||||
port = 6697
|
||||
username = someusername
|
||||
password = somepassword
|
||||
channel = #somechannel
|
||||
|
||||
[connector.launchpad]
|
||||
application = lugito
|
||||
staging = production
|
||||
version = devel
|
||||
supported_versions =
|
||||
Cosmic
|
||||
Bionic
|
||||
Xenial
|
||||
Trusty
|
||||
|
||||
[connector.launchpad.package_names]
|
||||
rDEFAULTSETTINGS = lubuntu-default-settings
|
||||
rART = lubuntu-artwork
|
||||
rCALASETTINGS = calamares-settings-ubuntu
|
||||
rQTERMINALPACKAGING = qterminal
|
||||
rLXQTCONFIGPACKAGING = lxqt-config
|
||||
rNMTRAYPACKAGING = nm-tray
|
||||
```
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
- TODO
|
||||
|
||||
Credits
|
||||
-------
|
||||
|
||||
This package was created with
|
||||
[Cookiecutter](https://github.com/audreyr/cookiecutter) and the
|
||||
[audreyr/cookiecutter-pypackage](https://github.com/audreyr/cookiecutter-pypackage)
|
||||
project template.
|
||||
|
@ -0,0 +1,135 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# S.D.G
|
||||
|
||||
"""
|
||||
:mod:`lugito.config`
|
||||
======================================
|
||||
|
||||
Module to manage lugito configuration
|
||||
|
||||
.. currentmodule:: lugito.config
|
||||
"""
|
||||
|
||||
# Imports
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
|
||||
DEFAULT_CONFIG_FILE = os.path.join(
|
||||
os.getcwd(), '.lugitorc')
|
||||
|
||||
logger = logging.getLogger('lugito.config')
|
||||
|
||||
# Add log level
|
||||
ch = logging.StreamHandler()
|
||||
|
||||
formatter = logging.Formatter(
|
||||
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
|
||||
ch.setFormatter(formatter)
|
||||
logger.addHandler(ch)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
CONFIG = {}
|
||||
|
||||
|
||||
def update_config(config_file=DEFAULT_CONFIG_FILE):
|
||||
"""
|
||||
Update the system config from a config file
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
config_file: str
|
||||
The path of the lugito config file
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
||||
config: dictionary
|
||||
A dictionary of config parameters
|
||||
|
||||
"""
|
||||
config = configparser.ConfigParser()
|
||||
config.read(config_file)
|
||||
|
||||
# Make some basic assertions for minimum functionality
|
||||
if 'phabricator' not in config:
|
||||
raise ValueError('phabricator section missing from config file: %s' %\
|
||||
config_file)
|
||||
|
||||
if 'host' not in config['phabricator']:
|
||||
raise ValueError('host value missing from phabricator section in'\
|
||||
' config file: %s' % config_file)
|
||||
|
||||
if 'token' not in config['phabricator']:
|
||||
raise ValueError('token value missing from phabricator section in'\
|
||||
' config file: %s' % config_file)
|
||||
|
||||
CONFIG['phabricator'] = {}
|
||||
CONFIG['phabricator']['host'] = config['phabricator']['host']
|
||||
CONFIG['phabricator']['token'] = config['phabricator']['token']
|
||||
|
||||
CONFIG['phabricator']['hooks'] = {}
|
||||
|
||||
# Iterate through hooks for HMAC keys
|
||||
if 'phabricator.hooks' in config:
|
||||
|
||||
for key, value in config['phabricator.hooks'].items():
|
||||
CONFIG['phabricator']['hooks'][key] = value
|
||||
|
||||
CONFIG['connectors'] = {}
|
||||
|
||||
# Iterate through available connectors
|
||||
for key in config.keys():
|
||||
|
||||
# Is a connector section
|
||||
if ('connector.' in key) and (key.count('.') == 1) :
|
||||
connector = key.split('.')[1]
|
||||
|
||||
if 'connectors' not in CONFIG:
|
||||
CONFIG['connectors'] = {}
|
||||
|
||||
if connector not in CONFIG['connectors']:
|
||||
CONFIG['connectors'][connector] = {}
|
||||
|
||||
for param, value in config[key].items():
|
||||
|
||||
# Check for multiple values for a parameter
|
||||
if value.find('\n') >= 0:
|
||||
value = value[1:].split('\n')
|
||||
|
||||
CONFIG['connectors'][connector][param] = value
|
||||
|
||||
# Is a connector sub-section
|
||||
elif ('connector.' in key) and (key.count('.') > 1) :
|
||||
sections = key.split('.')
|
||||
connector = sections[1]
|
||||
subsection = sections[-1]
|
||||
|
||||
if 'connectors' not in CONFIG:
|
||||
CONFIG['connectors'] = {}
|
||||
|
||||
if connector not in CONFIG['connectors']:
|
||||
CONFIG['connectors'][connector] = {}
|
||||
|
||||
CONFIG['connectors'][connector][subsection] = {}
|
||||
|
||||
for param, value in config[key].items():
|
||||
|
||||
# Check for multiple values for a parameter
|
||||
if value.find('\n') >= 0:
|
||||
value = value[1:].split('\n')
|
||||
|
||||
# configparser reads the parameters as lower case
|
||||
# convert all but first character to upper case
|
||||
param = 'r{}'.format(param[1:].upper())
|
||||
CONFIG['connectors'][connector][subsection][param] = value
|
||||
|
||||
|
||||
try:
|
||||
update_config()
|
||||
except ValueError:
|
||||
# The config file is not present
|
||||
logging.warning('Default config file: %s not found' % DEFAULT_CONFIG_FILE)
|
@ -1,3 +1,11 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# S.D.G
|
||||
|
||||
from lugito.connectors.irc import (
|
||||
irc,
|
||||
)
|
||||
|
||||
from lugito.connectors.launchpad import (
|
||||
launchpad,
|
||||
)
|
||||
|
@ -1,4 +1,5 @@
|
||||
[pytest]
|
||||
timeout=100
|
||||
python_files = tests.py test_*.py *_tests.py
|
||||
pytest_plugins = "pytest_cov", "pep8"
|
||||
addopts = --doctest-modules --cov-config=.coveragerc --cov=lugito --cov-report=term-missing
|
||||
|
@ -0,0 +1,32 @@
|
||||
[phabricator]
|
||||
host = http://127.0.0.1:9091/api/
|
||||
token = api-nojs2ip33hmp4zn6u6cf72w7d6yh
|
||||
|
||||
[phabricator.hooks]
|
||||
diffhook = vglzi6t4gsumnilv27r27no7rs3vgs75
|
||||
commithook = znkyfflbcia5gviqx5ybad7s6uyfywxi
|
||||
|
||||
[connector.irc]
|
||||
host = irc.freenode.net
|
||||
port = 6697
|
||||
username = someusername
|
||||
password = somepassword
|
||||
channel = #somechannel
|
||||
|
||||
[connector.launchpad]
|
||||
application = lugito
|
||||
staging = production
|
||||
version = devel
|
||||
supported_versions =
|
||||
Cosmic
|
||||
Bionic
|
||||
Xenial
|
||||
Trusty
|
||||
|
||||
[connector.launchpad.package_names]
|
||||
rDEFAULTSETTINGS = lubuntu-default-settings
|
||||
rART = lubuntu-artwork
|
||||
rCALASETTINGS = calamares-settings-ubuntu
|
||||
rQTERMINALPACKAGING = qterminal
|
||||
rLXQTCONFIGPACKAGING = lxqt-config
|
||||
rNMTRAYPACKAGING = nm-tray
|
@ -0,0 +1,23 @@
|
||||
[phabricator]
|
||||
token = api-nojs2ip33hmp4zn6u6cf72w7d6yh
|
||||
|
||||
[phabricator.hooks]
|
||||
diffhook = vglzi6t4gsumnilv27r27no7rs3vgs75
|
||||
commithook = znkyfflbcia5gviqx5ybad7s6uyfywxi
|
||||
|
||||
[connector.irc]
|
||||
host = irc.freenode.net
|
||||
port = 6697
|
||||
username = someusername
|
||||
password = somepassword
|
||||
channel = #somechannel
|
||||
|
||||
[connector.launchpad]
|
||||
application = lugito
|
||||
staging = production
|
||||
version = devel
|
||||
supported_versions =
|
||||
Cosmic
|
||||
Bionic
|
||||
Xenial
|
||||
Trusty
|
@ -0,0 +1,20 @@
|
||||
[phabricator.hooks]
|
||||
diffhook = vglzi6t4gsumnilv27r27no7rs3vgs75
|
||||
commithook = znkyfflbcia5gviqx5ybad7s6uyfywxi
|
||||
|
||||
[connector.irc]
|
||||
host = irc.freenode.net
|
||||
port = 6697
|
||||
username = someusername
|
||||
password = somepassword
|
||||
channel = #somechannel
|
||||
|
||||
[connector.launchpad]
|
||||
application = lugito
|
||||
staging = production
|
||||
version = devel
|
||||
supported_versions =
|
||||
Cosmic
|
||||
Bionic
|
||||
Xenial
|
||||
Trusty
|
@ -0,0 +1,23 @@
|
||||
[phabricator]
|
||||
host = http://127.0.0.1/api/
|
||||
|
||||
[phabricator.hooks]
|
||||
diffhook = vglzi6t4gsumnilv27r27no7rs3vgs75
|
||||
commithook = znkyfflbcia5gviqx5ybad7s6uyfywxi
|
||||
|
||||
[connector.irc]
|
||||
host = irc.freenode.net
|
||||
port = 6697
|
||||
username = someusername
|
||||
password = somepassword
|
||||
channel = #somechannel
|
||||
|
||||
[connector.launchpad]
|
||||
application = lugito
|
||||
staging = production
|
||||
version = devel
|
||||
supported_versions =
|
||||
Cosmic
|
||||
Bionic
|
||||
Xenial
|
||||
Trusty
|
@ -0,0 +1 @@
|
||||
[lugito]
|
@ -0,0 +1,114 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# S.D.G
|
||||
|
||||
"""Test config values
|
||||
|
||||
|
||||
:author: Ben Johnston
|
||||
|
||||
"""
|
||||
|
||||
# Imports
|
||||
import os
|
||||
import pytest
|
||||
import lugito.config
|
||||
|
||||
TEST_FILE = os.path.join(
|
||||
os.path.dirname(__file__),
|
||||
'.lugitorc')
|
||||
|
||||
|
||||
TEST_FILE_NO_PHAB = os.path.join(
|
||||
os.path.dirname(__file__),
|
||||
'.lugitorc_no_phab')
|
||||
|
||||
|
||||
TEST_FILE_NO_HOST = os.path.join(
|
||||
os.path.dirname(__file__),
|
||||
'.lugitorc_no_host')
|
||||
|
||||
|
||||
TEST_FILE_NO_TOKEN = os.path.join(
|
||||
os.path.dirname(__file__),
|
||||
'.lugitorc_no_token')
|
||||
|
||||
|
||||
def test_loading_config_hooks():
|
||||
"""Test loading config"""
|
||||
|
||||
lugito.config.update_config(TEST_FILE)
|
||||
CONFIG = lugito.config.CONFIG
|
||||
|
||||
assert(CONFIG['phabricator']['host'] == 'http://127.0.0.1:9091/api/')
|
||||
assert(CONFIG['phabricator']['token'] == 'api-nojs2ip33hmp4zn6u6cf72w7d6yh')
|
||||
|
||||
# Hooks
|
||||
assert(CONFIG['phabricator']['hooks']['diffhook'] ==\
|
||||
'vglzi6t4gsumnilv27r27no7rs3vgs75')
|
||||
assert(CONFIG['phabricator']['hooks']['commithook'] ==\
|
||||
'znkyfflbcia5gviqx5ybad7s6uyfywxi')
|
||||
|
||||
|
||||
def test_loading_config_connectors():
|
||||
"""Test loading config connectors"""
|
||||
|
||||
|
||||
lugito.config.update_config(TEST_FILE)
|
||||
CONFIG = lugito.config.CONFIG
|
||||
|
||||
# Connectors
|
||||
assert(CONFIG['connectors']['irc'] == {
|
||||
'host': 'irc.freenode.net',
|
||||
'port': '6697',
|
||||
'username': 'someusername',
|
||||
'password':'somepassword',
|
||||
'channel': '#somechannel',
|
||||
})
|
||||
|
||||
if not (CONFIG['connectors']['launchpad'] == {
|
||||
'application': 'lugito',
|
||||
'staging': 'production',
|
||||
'version': 'devel',
|
||||
'supported_versions': ['Cosmic', 'Bionic', 'Xenial', 'Trusty'],
|
||||
'package_names': {
|
||||
'rDEFAULTSETTINGS': 'lubuntu-default-settings',
|
||||
'rART': 'lubuntu-artwork',
|
||||
'rCALASETTINGS': 'calamares-settings-ubuntu',
|
||||
'rQTERMINALPACKAGING': 'qterminal',
|
||||
'rLXQTCONFIGPACKAGING': 'lxqt-config',
|
||||
'rNMTRAYPACKAGING': 'nm-tray',
|
||||
},
|
||||
}):
|
||||
import pdb;pdb.set_trace()
|
||||
|
||||
|
||||
|
||||
|
||||
def test_load_config_no_phab():
|
||||
"""Test loading config to load phabricator"""
|
||||
|
||||
with pytest.raises(ValueError) as err:
|
||||
|
||||
lugito.config.update_config(TEST_FILE_NO_PHAB)
|
||||
|
||||
assert('phabricator section missing from config file' in str(err))
|
||||
|
||||
|
||||
def test_load_config_no_host():
|
||||
"""Test loading config to load phabricator"""
|
||||
|
||||
with pytest.raises(ValueError) as err:
|
||||
lugito.config.update_config(TEST_FILE_NO_HOST)
|
||||
|
||||
assert('host value missing from phabricator section config file' in str(err))
|
||||
|
||||
|
||||
def test_load_config_no_token():
|
||||
"""Test loading config to load phabricator"""
|
||||
|
||||
with pytest.raises(ValueError) as err:
|
||||
|
||||
lugito.config.update_config(TEST_FILE_NO_TOKEN)
|
||||
|
||||
assert('host value missing from phabricator conffig file' in str(err))
|
Loading…
Reference in new issue