Permalink
Browse files

bug 511766 (check in code used by cruncher to update dirty profiles p…

…eriodically) updates generated places.sqlite dbs on cruncher p=anodelman r=bhearsum
  • Loading branch information...
1 parent c6d102d commit deaa4266fbc7f9203d772d6b4ccbb8e0f5efa125 Alice Nodelman committed Apr 30, 2010
Showing with 64 additions and 0 deletions.
  1. +64 −0 buildfarm/utils/updateGenerated.py
@@ -0,0 +1,64 @@
+import os
+import os.path
+import subprocess
+import zipfile
+import zlib
+
+SAVED_ENV = {}
+
+basePath = '/home/anodelman/public_html/'
+
+dirtyProfiles = ['places_generated_med/places.sqlite',
+ 'places_generated_min/places.sqlite']
+
+maxDirtyProfile = ['places_generated_max/places.sqlite']
+
+updateCmd = ['/usr/local/bin/python', '/home/anodelman/generator/places/builddb/increment_dates.py']
+
+profilesList = [['dirtyDBs.zip', dirtyProfiles],
+ ['dirtyMaxDBs.zip', maxDirtyProfile]]
+
+def setEnvironmentVar(key, val):
+ global SAVED_ENV
+ env = os.environ
+ if key in env:
+ SAVED_ENV[key] = env[key]
+ else:
+ SAVED_ENV[key] = ''
+ env[key] = val
+
+def restoreEnvironment():
+ global SAVED_ENV
+ for var in SAVED_ENV:
+ os.environ[var] = SAVED_ENV[var]
+ SAVED_ENV = {}
+
+def runCmd(cmd):
+ subprocess.call(cmd)
+
+def removeZip():
+ os.remove(zipName)
+
+def createZip(zipName):
+ zip = zipfile.ZipFile(basePath + zipName, 'w')
+ for val in profiles:
+ zip.write(basePath + val, val, compress_type=zipfile.ZIP_DEFLATED)
+ zip.close()
+
+
+def updateProfiles(profiles):
+ key = 'PLACES_DB_PATH'
+ for val in profiles:
+ setEnvironmentVar('PYTHONPATH', '$PYTHONPATH:/usr/local/bin:/home/anodelman/generator')
+ setEnvironmentVar('DJANGO_SETTINGS_MODULE', 'places.settings')
+ setEnvironmentVar(key, basePath + val)
+ print "\nUpdating " + val + "\n"
+ runCmd(updateCmd)
+ restoreEnvironment()
+
+
+if __name__=='__main__':
+ for name, profiles in profilesList:
+ updateProfiles(profiles)
+ createZip(name)
+

0 comments on commit deaa426

Please sign in to comment.