changeset 117:c5c877d6c1e3

Load and create default database for installed scripts Load default database from current dir if default dabase exists. If not load or create a default database in $HOME/.getan/
author Björn Ricks <bjoern.ricks@intevation.de>
date Mon, 12 Dec 2011 09:48:20 +0100
parents 67a89439e10d
children 5f26c5c50243
files getan/main.py
diffstat 1 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/getan/main.py	Mon Dec 12 09:37:39 2011 +0100
+++ b/getan/main.py	Mon Dec 12 09:48:20 2011 +0100
@@ -12,6 +12,9 @@
 
 import logging
 import sys
+import os
+import os.path
+
 from optparse import OptionParser
 
 import getan.config  as config
@@ -44,8 +47,16 @@
         backend = Backend(args[0])
         logging.info("Use database '%s'." % args[0])
     else:
-        backend = Backend()
-        logging.info("Use database '%s'." % DEFAULT_DATABASE)
+        if os.path.isfile(DEFAULT_DATABASE):
+            database = os.path.abspath(DEFAULT_DATABASE)
+        else:
+            getan_dir = os.path.expanduser(os.path.join("~", ".getan"))
+            if not os.path.exists(getan_dir):
+                os.mkdir(getan_dir)
+            database = os.path.join(getan_dir, DEFAULT_DATABASE)
+
+        backend = Backend(database)
+        logging.info("Use database '%s'." % database)
 
     controller = GetanController(backend, ProjectList, EntryList)
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)