Browse Source

Added host and port settings to configuration file

Óscar García Amor 4 years ago
parent
commit
be6abd68e8
3 changed files with 12 additions and 3 deletions
  1. 6 0
      sysdweb.conf
  2. 3 3
      sysdweb/main.py
  3. 3 0
      sysdweb/server.py

+ 6 - 0
sysdweb.conf

@@ -24,6 +24,12 @@
 # - user. for control systemd user units
 scope = system
 
+# Can configure listen address host and port. If not present, default values
+# will be used. Take note that you can pass this values via args and they
+# prevail over this configuration.
+#host = 127.0.0.1
+#port = 10080
+
 # Some sample entries
 [ngx]
 title = Nginx

+ 3 - 3
sysdweb/main.py

@@ -12,9 +12,9 @@ import argparse
 
 def main():
     parser = argparse.ArgumentParser()
-    parser.add_argument('-c', '--config', metavar='value', default=None, help='Custom configuration file path')
-    parser.add_argument('-l', '--listen', metavar='value', default='127.0.0.1', help='listen address (host or ip), default: 127.0.0.1')
-    parser.add_argument('-p', '--port', metavar='value', default='10080', help='listen port, default: 10080')
+    parser.add_argument('-c', '--config', metavar='value', help='Custom configuration file path')
+    parser.add_argument('-l', '--listen', metavar='value', help='listen address (host or ip), default: 127.0.0.1')
+    parser.add_argument('-p', '--port', metavar='value', help='listen port, default: 10080')
     args = parser.parse_args()
 
     start (args.config, args.listen, args.port)

+ 3 - 0
sysdweb/server.py

@@ -100,5 +100,8 @@ def start(config_file, host, port):
     global config
     config = checkConfig(config_file)
 
+    if host == None: host = config.get('DEFAULT', 'host', fallback='127.0.0.1')
+    if port == None: port = config.get('DEFAULT', 'port', fallback='10080')
+
     # Run webserver
     run(host=host, port=port)