Changeset 8750 for main/waeup.stress
- Timestamp:
- 18 Jun 2012, 10:22:32 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.stress/trunk/src/waeup/stress/scripts.py
r8654 r8750 1 """Helpers when inside an instance context. 2 """ 1 3 import os 2 4 import sys … … 9 11 #: will be put into the root folder 10 12 APP_NAME = 'stress_app' 13 14 IMPORTERS = { 15 'faculties.csv': 'facultyprocessor', 16 'departments.csv': 'departmentprocessor', 17 'courses.csv': 'courseprocessor', 18 'certificates.csv': 'certificateprocessor', 19 'certificatecourses.csv': 'certificatecourseprocessor', 20 'applicantcontainers.csv': 'applicants container processor', 21 'applicants.csv': 'applicantprocessor', 22 } 23 24 def configure(instance_path=''): 25 config_file = os.path.join( 26 instance_path, 'parts', 'etc', 'site.zcml') 27 print "WAEUP.STRESS: configuring ZODB from %s" % ( 28 config_file,) 29 context = config(config_file) 30 return context 11 31 12 32 def open_zodb(instance_path=''): … … 23 43 to this DB and the root folder. 24 44 """ 25 config_file = os.path.join( 26 instance_path, 'parts', 'etc', 'site.zcml') 45 print "WAEUP.STRESS: opening ZODB" 27 46 zodb_file = os.path.join( 28 47 instance_path, 'var', 'filestorage', 'Data.fs') 29 print "WAEUP.STRESS: configuring ZODB from %s / %s" % (30 config_file, zodb_file)31 context = config(config_file)32 48 db = database(zodb_file) 33 49 conn = db.open() … … 62 78 the root folder of an opened, writable ZODB. 63 79 """ 64 print [x for x in root_folder] 65 root_folder['stress_app'] = University() 66 print "WAEUP.STRESS.SCRIPTS: created 'stress_app' in root folder." 80 root_folder[APP_NAME] = University() 81 print "WAEUP.STRESS.SCRIPTS: created '%s' in root folder." % APP_NAME 67 82 return 68 83 69 create_app() 84 @zodb 85 def import_files(root_folder, *args): 86 from zope.component.hooks import setSite 87 from zope.component import getUtility 88 from waeup.kofa.interfaces import IBatchProcessor 89 setSite(root_folder[APP_NAME]) 90 for path in args: 91 if not os.path.isfile(path): 92 print "WAEUP.STRESS.SCRIPTS: no such file: %s" % path 93 continue 94 basename = os.path.basename(path) 95 util_name = IMPORTERS.get(basename, None) 96 if util_name is None: 97 print "WAEUP.STRESS.SCRIPTS: not a valid import filename: %s" % ( 98 basename) 99 print " valid names: %s" % IMPORTERS.keys() 100 continue 101 util = getUtility(IBatchProcessor, name=util_name) 102 for line in open(path, 'rb'): 103 break 104 headerfields = line.strip().split(',') 105 print "WAEUP.STRESS.SCRIPTS: importing %s" % os.path.basename(path) 106 results = util.doImport(path, headerfields) 107 print "WAEUP.STRESS.SCRIPTS: import done." 108 return 109 110 def main(cmd, *args, **kw): 111 if cmd == 'install_app': 112 configure() 113 create_app() 114 return 115 elif cmd == 'import_csv': 116 configure() 117 create_app() 118 import_files(*args) 119 return 120 121 if __name__ == '__main__': 122 cmd = sys.argv[1] 123 args = [] 124 if len(sys.argv) > 2: 125 args = sys.argv[2:] 126 main(cmd, *args)
Note: See TracChangeset for help on using the changeset viewer.