Changeset 2466
- Timestamp:
- 02/15/09 22:25:57 (4 years ago)
- File:
-
- 1 edited
-
alternc-apps/trunk/bin/update_apps.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
alternc-apps/trunk/bin/update_apps.py
r2463 r2466 1 1 #!/usr/bin/python 2 2 3 import adodb, os 3 import adodb, os, sys, getopt 4 4 5 5 alterncapps = "/var/alternc/apps" … … 7 7 database = "alternc" 8 8 username = "alternc" 9 password = " "9 password = "nJWuYCgj0K" 10 10 11 def usage(): 12 print "update_apps.py usage:" 13 print " -c --cron cron mode" 14 print " -u [appname] --update=[appname] update installation of appname" 11 15 12 def generateFileList( application):16 def generateFileList(path): 13 17 directories = [] 14 18 fileslist = [] 15 for root, dirs, files in os.walk( alterncapps + "/" + application):16 root = root.replace( alterncapps + "/" + application, "")19 for root, dirs, files in os.walk(path): 20 root = root.replace(path , "") 17 21 18 22 if root != '': … … 36 40 os.symlink(fromfile, tofile) 37 41 42 def updateFiles(fromfiles,tofiles,frompath,path): 43 # we recreate the directories 44 for dir in fromfiles['dirs']: 45 if dir not in tofiles['dirs']: 46 createDirIfNotExist(os.path.normpath(path + "/" + dir)) 47 48 for file in fromfiles['files']: 49 if file not in tofiles['files']: 50 installFile(os.path.normpath(frompath + "/" + file),os.path.normpath(path + "/" + file)) 51 52 for file in tofiles['files']: 53 filepath = os.path.normpath(path + "/" + file) 54 if not os.path.exists(filepath): 55 os.unlink(filepath) 56 38 57 def installApplication(application, path): 39 files = generateFileList(application) 58 fromfiles = generateFileList(alterncapps + "/" + application) 59 tofiles = generateFileList(path) 60 print tofiles 40 61 for dir in files['dirs']: 41 62 createDirIfNotExist(path + dir) … … 44 65 installFile(alterncapps + "/" + application + "/" + file, path + "/" + file) 45 66 46 conn = adodb.NewADOConnection('mysql') 47 conn.Connect(host, username, password,database); 67 def updateApplication(appname): 68 print "Upgrading : " + appname 48 69 49 for row in conn.Execute('SELECT uid, application, path FROM applications WHERE installed = 0'): 50 uid = row[0] 51 application = row[1] 52 path = row[2] 53 installApplication(application,path) 54 conn.Execute('UPDATE applications SET installed = 1 WHERE uid = %s AND application = %s AND path = %s',(uid,application,path)) 70 conn = adodb.NewADOConnection('mysql') 71 conn.Connect(host, username, password,database); 55 72 73 files = generateFileList(alterncapps + "/" + appname) 74 75 for row in conn.Execute('SELECT uid, application, path FROM applications WHERE application = %s AND installed = 1',(appname)): 76 tofiles = generateFileList(row[2]) 77 updateFiles(files, tofiles, os.path.normpath(alterncapps + "/" + appname), row[2]) 78 79 80 def runCron(): 81 conn = adodb.NewADOConnection('mysql') 82 conn.Connect(host, username, password,database); 83 84 for row in conn.Execute('SELECT uid, application, path FROM applications WHERE installed = 0'): 85 uid = row[0] 86 application = row[1] 87 path = row[2] 88 installApplication(application,path) 89 conn.Execute('UPDATE applications SET installed = 1 WHERE uid = %s AND application = %s AND path = %s',(uid,application,path)) 90 91 try: 92 optlist, args = getopt.getopt(sys.argv[1:],'cu:', ["cron","update="]) 93 for option, arg in optlist: 94 if option in ("--cron","-c"): 95 runCron() 96 elif option in ("--update","-u"): 97 updateApplication(arg) 98 else: 99 usage() 100 exit(2) 101 102 except getopt.GetoptError, err: 103 print str(err) 104 usage() 105 sys.exit(2) 106 107
Note: See TracChangeset
for help on using the changeset viewer.
