Commits

kunstmusik committed 78feb4d

initial work implementing commands for init (to create .cspm file when creating a module) and info (to look up information about a package); added error function for easy error message formatting, as well as test SERVER that defaults to current dir + testRepo

Comments (0)

Files changed (1)

 #!/usr/bin/env python
 
+import os
+import sys
+import sqlite3
+
+SERVER = "file://" + os.getcwd() + os.sep + "testRepo" # temporary local test repo
 VERSION = "1.0 Alpha"
 
+def error(msg):
+    print "cspm - error: ", msg
 
 class Command(object):
     def __init__(self, commandName, description, processFunction):
     def process(self, args):
         """Function for Command to do work"""
         return self.processFunction(args)
-    
+
 def dummyFunc(args):
-    print "Command not implemented"
+    print "Command not implemented: Args %s"%args
     return True
-    
-commands = [Command("install", "Installs a list of packages.", dummyFunc ),
-            Command("update", "Update list of known packages.", dummyFunc),
-            Command("list", "List packages matching a search string.", dummyFunc),
-            Command("info", "Display detailed information about a particular package.", dummyFunc),
-            Command("init", "Create a default .cspm file in the current directory.", dummyFunc)
-
-             ]    
-
 
 def usage():
     message = """Csound Package Manager - version %s
         
     return message
 
+# INIT COMMAND ####################################
+
+def initCspmFile(args):
+    descriptor = """Name:package-name
+Version:1.0
+Author:authorName
+Maintainer:maintainer.email@website.com
+#Website:
+#License:
+#Copyright:
+#Depends:"""
+
+    
+    f = open('package.cspm', 'w')
+    f.write(descriptor)
+    f.flush()
+    f.close()
+    
+    print "Created example package.cspm file"
+
+
+# INFO COMMAND ####################################
+
+def findPackage(pkgName):
+    return None
+
+def packageInfo(args):
+    if(len(args) != 1):
+        error("info command requires one and only one package name to lookup information")
+        print usage()
+        sys.exit(1)
+    pkgname = args[0]
+    pkginfo = findPackage(pkgname)
+    if(pkginfo == None):
+        print "No package information for package: %s"%pkgname
+        sys.exit(0)
+    print "Package Information: %s\n"%pkgname
+
+# COMMANDS LIST ####################################
+    
+commands = [Command("install", "Installs a list of packages.", dummyFunc ),
+            Command("update", "Update list of known packages.", dummyFunc),
+            Command("list", "List packages matching a search string.", dummyFunc),
+            Command("info", "Display detailed information about a particular package.", packageInfo),
+            Command("init", "Create a default .cspm file in the current directory.", initCspmFile)
+
+             ]    
+
+
+
+
+
+# MAIN FUNCTION ####################################
     
 if __name__ == '__main__':
-    print usage()
+    if(len(sys.argv) == 1):
+        print usage()
+        sys.exit(1)
+    commandName = sys.argv[1]
+    command = None
+    for c in commands:
+        if(commandName == c.commandName):
+            command = c
+            break
+    if(command == None):
+        error("unknown command '%s'\n"%commandName)
+        print usage()
+        sys.exit(1)
+    args = sys.argv[2:]
+    #print "cspm - Command: %s Args %s\n"%(commandName, args)
+    command.process(args)
+
+        
+
+