Ver código fonte

implement config file. fixes #9

George C. Privon 8 anos atrás
pai
commit
0e0df00cca
2 arquivos alterados com 18 adições e 3 exclusões
  1. 8 0
      CHANGELOG.md
  2. 10 3
      manage_database.py

+ 8 - 0
CHANGELOG.md

@@ -1,5 +1,13 @@
 # Changelog
 
+## 0.4 Series
+
+### 0.4.0
+
+#### Enhancements
+
+* add a configuration file specifying the database location
+
 ## 0.3 Series
 
 ### 0.3.3 (21 February 2018)

+ 10 - 3
manage_database.py

@@ -33,9 +33,16 @@ def loadConfig(cfile):
 
     if not os.path.isfile(cfile):
         sys.stderr.write("Error: could not find configuration file '" + cfile + "'\n")
-        sys.exit()
-
-    config = configparser.read(cfile)
+        if os.path.isfile('CarcassonneScore.conf.example'):
+            sys.stderr.write("Copying 'CarcassonneScore.conf.example' to 'CarcassonneScore.conf'.\n")
+            import shutil
+            shutil.copyfile('CarcassonneScore.conf.example',
+                            'CarcassonneScore.conf')
+        else:
+            sys.stderr.write("Error: cannot find default configuration file 'CarcassonneScore.conf.example' to copy.\n")
+
+    config = configparser.RawConfigParser()
+    config.read(cfile)
 
     return config