Browse Source

Added an example of config variable interp0lation and made some val00s optional

Wazakindjes 1 year ago
parent
commit
5820815d86
2 changed files with 28 additions and 3 deletions
  1. 15 1
      muhconf.ini.example
  2. 13 2
      temps.py

+ 15 - 1
muhconf.ini.example

@@ -1,18 +1,31 @@
 [main]
 # Basically, when this is set to false you'll have no output except for errors, which is desired when running cronned ;]
+# This is optional and defaults to false
 debug = false
 
+# Do almost everything as usual (connect to SQL, read temperature) but don't actually insert into the database
+# This is optional and defaults to false
+#dryrun = false
+
+# You can also use variable interpolation to make dryrun automatically go into effect when debug == true
+# This doesn't work if --debug is specified from the command line, you'd need to do both --debug and --dryrun ;]
+dryrun = %(debug)s
+
 # Specify the sensor's sysfs directory name (should be the <SENSOR> in: /sys/bus/w1/devices/<SENSOR>/w1_slave)
 # If you have multiple sensors simply specify multiple "sensor = xxx" lines ;]
 sensor = 28-02155265b0ff
 
 # For every sample, try to read the sensor this many times until it produces some expected output (should usually take only 1 attempt but still ;])
+# This is optional and defaults to 5
 sample_maxattempts = 5
 
 [mysql]
 # Should be obvious lmao
-host = 127.0.0.1
+# This is optional and defaults to 3306
 port = 3306
+
+# All of deez nuts are required yo
+host = 127.0.0.1
 user = ayylmao
 pass = gottem
 db = turds
@@ -20,4 +33,5 @@ table = temperature
 column = temp
 
 # MySQL must be explicitly configured for SSL/TLS and is usually implemented in the form of STARTTLS (explicit TLS, running on the same port as plaintext)
+# This is optional and defaults to false
 tls = false

+ 13 - 2
temps.py

@@ -37,13 +37,24 @@ def try_db_cleanup(db, cursor):
 		pass
 
 def show_version():
-	printem("temps v{0}, written by: {1}".format(__version__, __author__))
+	printem("temps.py v{0}, written by: {1}".format(__version__, __author__))
 
 def readem_conf():
 	err = False
 
 	try:
-		cfg = ConfigParser.ConfigParser()
+		cfg = ConfigParser.SafeConfigParser({
+			# Some variables are optional ;]
+
+			# [main] section
+			"debug": "false",
+			"dryrun": "false",
+			"sample_maxattempts": "5",
+
+			# [mysql] section
+			"port": 3306,
+			"tls": "false",
+		})
 		cfg.read("{0}/muhconf.ini".format(os.path.dirname(os.path.realpath(__file__))))
 
 		### [main] section BEGIN