Commits

kunstmusik committed 98094c0

added initialization code for CSPM: creates $HOME/.cspm folder and cspm.db within it

Comments (0)

Files changed (1)

 import sqlite3
 
 SERVER = "file://" + os.getcwd() + os.sep + "testRepo" # temporary local test repo
+HOME_FOLDER = os.getenv('HOME')
+SETTINGS_FOLDER = HOME_FOLDER + os.sep + ".cspm"
+DB_FILE = SETTINGS_FOLDER + os.sep + "cspm.db"
 VERSION = "1.0 Alpha"
+conn = None
+
+# DB FUNCTIONS ####################################
+
+def db_init():
+    if(os.path.isfile(DB_FILE)):
+        return
+    message("initializing cspm.db database\n")
+    conn = sqlite3.connect(DB_FILE)
+    # do table creates here
+    
+def db_connect():
+    if(conn != None):
+        conn = sqlite3.connect(DB_FILE)
+    
+        
+        
+# PROGRAM FUNCTIONS ####################################
+
 
 def error(msg):
-    print "cspm - error: ", msg
+    print "cspm: error: ", msg
+    
+def message(msg):
+    print "cspm: ", msg
 
 class Command(object):
     def __init__(self, commandName, description, processFunction):
         return self.processFunction(args)
 
 def dummyFunc(args):
-    print "Command not implemented: Args %s"%args
+    message("Command not implemented: Args %s"%args)
     return True
 
 def usage():
         
     return message
 
+def init_CSPM():
+    if(os.path.isdir(SETTINGS_FOLDER)):
+        return
+    message("Initializing .cspm folder: " + SETTINGS_FOLDER)
+    os.mkdir(SETTINGS_FOLDER)
+    db_init()
+
 # INIT COMMAND ####################################
 
 def initCspmFile(args):
 # MAIN FUNCTION ####################################
     
 if __name__ == '__main__':
+    init_CSPM()
     if(len(sys.argv) == 1):
         print usage()
         sys.exit(1)
         error("unknown command '%s'\n"%commandName)
         print usage()
         sys.exit(1)
+    db_connect()
     args = sys.argv[2:]
     #print "cspm - Command: %s Args %s\n"%(commandName, args)
     command.process(args)