Bläddra i källkod

not even a running version yet
Added
- configuration file handling
- default value settings
- exit cleanup function
- external library functions



git-svn-id: svn://svn.siningsoft.de/myCar@4 4258477e-9397-4ceb-bd8a-6305f6291781

devnull 7 år sedan
förälder
incheckning
4595f2a25d
4 ändrade filer med 49 tillägg och 0 borttagningar
  1. 8 0
      lib/app_control.py
  2. 15 0
      lib/config.py
  3. 26 0
      myCar.py
  4. BIN
      static/add.png

+ 8 - 0
lib/app_control.py

@@ -0,0 +1,8 @@
+# this is the main cleanup function to cleanup the application once shutdonw
+def myCar_exit(config):
+    import configparser
+    with open('data/etc/myCar.conf', 'w') as configfile:
+        config.write(configfile)
+
+    print('system cleanup done')
+

+ 15 - 0
lib/config.py

@@ -0,0 +1,15 @@
+# return a configuration objects with default values
+def myCar_read_config_defaults(config):
+    import configparser
+    if not config.sections():
+    # there is nothing, lets setup default values
+        config['paths'] = { 'app' : '/opt/myCar',
+                            'log' : 'data/log',
+                            'record' : 'data/rec' }
+        config['connections'] = { 'bt_dev' : '/dev/rfcomm',
+                                  'gps_dev' : '/dev/ttyS1',
+                                  'wifi_pwd' : 'myCar123' }
+
+    # return a valid config object either 
+    # with or without default values
+    return config

+ 26 - 0
myCar.py

@@ -1,5 +1,23 @@
 #!/usr/bin/python3
 
+import configparser
+import lib.config
+import lib.app_control
+
+# we need to initially load the configuration file.
+# This is loaded via a local symlink
+myCar_config = configparser.ConfigParser()
+myCar_config.read('data/etc/myCar.conf')
+
+# fill in config values with defaults
+myCar_config = lib.config.myCar_read_config_defaults(myCar_config)
+
+
+import atexit
+atexit.register(lib.app_control.myCar_exit, myCar_config)
+
+
+
 from flask import Flask
 from flask import url_for
 from flask import render_template
@@ -71,3 +89,11 @@ def myCar_bluetooth_connect():
         ret = render_template('bluetooth/devices.html', bt_dev=bluew.devices(),bt_error='Bluetooth device ' + bt_dst_mac +' is not available')
 
     return ret
+
+#@app.route('/conf', methods=['POST'])
+#def myCar_conf():
+    # this method reads the configuration file
+    # !!! beware due to stupidity in my mind this method also holds the 
+    # !!! default vaules when the config file is not present
+
+    

BIN
static/add.png