Browse Source

add dh-python as build dependency, change configuration file format to json

Helmut Pozimski 8 years ago
parent
commit
e79600a074
9 changed files with 34 additions and 34 deletions
  1. 1 0
      Changelog
  2. 0 1
      TODO
  3. 7 0
      debian/changelog
  4. 1 1
      debian/control
  5. 1 1
      debian/stdd.init
  6. 1 0
      debian/stdd.install
  7. 12 12
      doc/stdd.1
  8. 2 2
      setup.py
  9. 9 17
      stddlib/configuration.py

+ 1 - 0
Changelog

@@ -2,6 +2,7 @@
 
     changed the init script to create a separate directory for the PID file
     create the PID file in the separate directory and rename it to stdd.pid
+    changed the main configuration file to json format
 
 2014-07-12  Helmut Pozimski  <helmut@pozimski.eu>
 

+ 0 - 1
TODO

@@ -1,4 +1,3 @@
 * Add stdd.postrm?
 * Check code with pylint and improve it
 * Make code pep8 clean
-* Change configuration file to json

+ 7 - 0
debian/changelog

@@ -1,3 +1,10 @@
+stdd (0.9.4-1) unstable; urgency=low
+
+  * New upstream release
+  * Add dh-python as build dependency
+
+ -- Helmut Pozimski <helmut@pozimski.eu>  Sun, 02 Aug 2015 12:44:00 +0200
+
 stdd (0.9.3-1) unstable; urgency=low
 
   * New upstream release

+ 1 - 1
debian/control

@@ -4,7 +4,7 @@ Maintainer: Helmut Pozimski <helmut@pozimski.eu>
 Homepage: https://dev.intranet.helmut-pozimski.de/stdd
 Section: python
 Priority: optional
-Build-Depends: python (>= 2.6), debhelper (>= 9)
+Build-Depends: python (>= 2.6), debhelper (>= 9), dh-python
 Standards-Version: 3.9.6
 
 Package: stdd

+ 1 - 1
debian/stdd.init

@@ -22,7 +22,7 @@ DAEMON=/usr/bin/$NAME
 # Read configuration variable file if it is present
 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
 
-DAEMON_ARGS="-d -c /etc/stdd.conf -u $STDD_USER -g $STDD_GROUP"
+DAEMON_ARGS="-d -c /etc/stdd.json -u $STDD_USER -g $STDD_GROUP"
 SCRIPTNAME=/etc/init.d/$NAME
 
 if [ -d /run ]; then

+ 1 - 0
debian/stdd.install

@@ -1 +1,2 @@
 default/stdd /etc/default/
+config/stdd.json /etc/

+ 12 - 12
doc/stdd.1

@@ -37,32 +37,32 @@ define the path to your stdd configuration file. This is usually needed to start
 print version information and exit.
 .SH EXAMPLES
 .TP
-.B stdd -c /etc/stdd.conf
+.B stdd -c /etc/stdd.json
 minimal example using the default configuration file
 .TP
-.B stdd -c /etc/stdd.conf -u i2cuser -g i2c -d
+.B stdd -c /etc/stdd.json -u i2cuser -g i2c -d
 start with the privileges of user i2cuser, group i2c and run as daemon
 .SH CONFIGURATION
-The following options can and should be set in the configuration file:
+The configuration file is in json format and usually found in /etc/stdd.json. The following options can and should be set in the configuration file:
 .P
-HW_ADDRESS:	hardware address for your display, a common value is "0x70" use i2cdetect to find yours if it doesn't match
+hw_address:	hardware address for your display, a common value is "0x70" use i2cdetect to find yours if it doesn't match
 .P
-BLINK_COLON:	define if you want the middle colon to blink, 0 = off, 1 = on
+blink_colon:	define if you want the middle colon to blink, false = off, true = on
 .P
-BRIGHTNESS_HIGH:	value used for "high" brightness, valid values are 0-15
+brightness_high:	value used for "high" brightness, valid values are 0-15
 .P
-BRIGHTNESS_LOW:	value used for "low" brightness, valid values are 0-15
+brightness_low:	value used for "low" brightness, valid values are 0-15
 .P
-SET_BRIGHTNESS_LOW:	value used for "low" brightness, valid values are 0-15
+set_brightness_low:	time of the day to change the brightness from high to low
 .P
-SET_BRIGHTNESS_HIGH:	time of the day to change the brightness from low to high
+set_brightness_high:	time of the day to change the brightness from low to high
 .P
-SYSLOG_LEVEL:	maximum syslog level to log, stdd uses debug, info and error
+syslog_level:	maximum syslog level to log, stdd uses debug, info and error
 .P
-SYSLOG_FACILITY:	syslog facility to use for logging (default: user, can also be daemon)
+syslog_facility:	syslog facility to use for logging (default: user, can also be daemon)
 .SH FILES
 .TP
-.B /etc/stdd.conf
+.B /etc/stdd.json
 the default path to the configuration file
 .SH "SEE ALSO"
 .TP 

+ 2 - 2
setup.py

@@ -10,7 +10,7 @@ from distutils.core import setup
 
 setup(
     name="stdd",
-    version="0.9.3",
+    version="0.9.4",
     author_email="helmut@pozimski.eu",
     description="stdd, simple time display daemon",
     long_description=("stdd is a small daemon written in python which displays"
@@ -19,5 +19,5 @@ setup(
     license="3-clause BSD license",
     packages=["adafruit_7segment", "stddlib"],
     scripts=["stdd"],
-    data_files=[('/etc', ['config/stdd.conf'])]
+    data_files=[('/etc', ['config/stdd.json']), ('/etc/default', ['default/stdd'])  ]
 )

+ 9 - 17
stddlib/configuration.py

@@ -5,7 +5,7 @@
 # licensed under the 3-clause BSD license
 
 import datetime
-
+import json
 
 class Conf(object):
     def __init__(self):
@@ -34,19 +34,14 @@ class Conf(object):
         self.syslog_level = ""
         self.syslog_facility = ""
 
-    def Read(self, file_path="/etc/stdd.conf"):
+    def Read(self, file_path="/etc/stdd.json"):
         """reads the configuration file from the path given to the function,
         default to /etc/stdd.conf if empty"""
         self.__conffile = open(file_path, "r")
-        for line in self.__conffile:
-            if "#" in line:
-                continue
-            else:
-                self.__line_stripped = line.strip()
-                if self.__line_stripped != "":
-                    self.__tmpvalue = self.__line_stripped.split("=")
-                    self.__values[self.__tmpvalue[0].lower()] =\
-                        self.__tmpvalue[1]
+        config_read = json.load(self.__conffile)
+        for value in config_read:
+            if value:
+                self.__values[value] = config_read[value]
         self.__conffile.close()
 
     def Analyze(self):
@@ -55,12 +50,9 @@ class Conf(object):
 
         """
         self.hw_address = int(self.__values["hw_address"], 16)
-        if self.__values["blink_colon"] == "1":
-            self.blink_colon = True
-        else:
-            self.blink_colon = False
-        self.brightness_high = int(self.__values["brightness_high"])
-        self.brightness_low = int(self.__values["brightness_low"])
+        self.blink_colon = self.__values["blink_colon"]
+        self.brightness_high = self.__values["brightness_high"]
+        self.brightness_low = self.__values["brightness_low"]
         self.__timetemp = self.__values["set_brightness_high"].split(":")
         self.set_brightness_high = datetime.time(int(self.__timetemp[0]),
                                                  int(self.__timetemp[1]))