Skip to content

Commit

Permalink
Add a debug configuration option.
Browse files Browse the repository at this point in the history
  • Loading branch information
rjuju committed Apr 2, 2019
1 parent 77776c5 commit f011d37
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
3 changes: 2 additions & 1 deletion powa-collector.conf-dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"repository": {
"dsn": "postgresql://powa_user@localhost:5432/powa"
}
},
"debug": false
}
4 changes: 1 addition & 3 deletions powa-collector.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env python

from powa_collector import PowaCollector
import logging

# app = PowaCollector()
app = PowaCollector(loglevel=logging.DEBUG)
app = PowaCollector()
app.main()
7 changes: 6 additions & 1 deletion powa_collector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@


class PowaCollector():
def __init__(self, loglevel=logging.INFO):
def __init__(self):
self.workers = {}
self.logger = logging.getLogger("powa-collector")
self.stopping = False

raw_options = parse_options()
loglevel = logging.INFO
if (raw_options["debug"]):
loglevel = logging.DEBUG

extra = {'threadname': '-'}
logging.basicConfig(
format='%(asctime)s %(threadname)s %(levelname)-6s: %(message)s ',
Expand Down
25 changes: 24 additions & 1 deletion powa_collector/options.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
"""
Simple configuration file handling, as a JSON.
"""
import json


def get_full_config(conn):
"""
Return the full configuration, consisting of the information from the local
configuration file and the remote servers stored on the repository
database.
"""
return add_servers_config(conn, parse_options())


def add_servers_config(conn, config):
"""
Add the remote servers stored on the repository database to a given
configuration JSON.
"""
if ("servers" not in config):
config["servers"] = {}

Expand Down Expand Up @@ -39,8 +51,19 @@ def add_servers_config(conn, config):


def parse_options():
return parse_file('./powa-collector.conf')
"""
Parse the local configuration file and return the resulting JSON, also
adding the implicit values if needed.
"""
options = parse_file('./powa-collector.conf')
if ('debug' not in options):
options["debug"] = False

return options


def parse_file(filepath):
"""
Read a configuration file and return the JSON
"""
return json.load(open(filepath))

0 comments on commit f011d37

Please sign in to comment.