Index: /main/waeup.stress/trunk/src/waeup/stress/scripts.py
===================================================================
--- /main/waeup.stress/trunk/src/waeup/stress/scripts.py	(revision 8749)
+++ /main/waeup.stress/trunk/src/waeup/stress/scripts.py	(revision 8750)
@@ -1,2 +1,4 @@
+"""Helpers when inside an instance context.
+"""
 import os
 import sys
@@ -9,4 +11,22 @@
 #: will be put into the root folder
 APP_NAME = 'stress_app'
+
+IMPORTERS = {
+    'faculties.csv': 'facultyprocessor',
+    'departments.csv': 'departmentprocessor',
+    'courses.csv': 'courseprocessor',
+    'certificates.csv': 'certificateprocessor',
+    'certificatecourses.csv': 'certificatecourseprocessor',
+    'applicantcontainers.csv': 'applicants container processor',
+    'applicants.csv': 'applicantprocessor',
+    }
+
+def configure(instance_path=''):
+    config_file = os.path.join(
+        instance_path, 'parts', 'etc', 'site.zcml')
+    print "WAEUP.STRESS: configuring ZODB from %s" % (
+        config_file,)
+    context = config(config_file)
+    return context
 
 def open_zodb(instance_path=''):
@@ -23,11 +43,7 @@
     to this DB and the root folder.
     """
-    config_file = os.path.join(
-        instance_path, 'parts', 'etc', 'site.zcml')
+    print "WAEUP.STRESS: opening ZODB"
     zodb_file = os.path.join(
         instance_path, 'var', 'filestorage', 'Data.fs')
-    print "WAEUP.STRESS: configuring ZODB from %s / %s" % (
-        config_file, zodb_file)
-    context = config(config_file)
     db = database(zodb_file)
     conn = db.open()
@@ -62,8 +78,49 @@
     the root folder of an opened, writable ZODB.
     """
-    print [x for x in root_folder]
-    root_folder['stress_app'] = University()
-    print "WAEUP.STRESS.SCRIPTS: created 'stress_app' in root folder."
+    root_folder[APP_NAME] = University()
+    print "WAEUP.STRESS.SCRIPTS: created '%s' in root folder." % APP_NAME
     return
 
-create_app()
+@zodb
+def import_files(root_folder, *args):
+    from zope.component.hooks import setSite
+    from zope.component import getUtility
+    from waeup.kofa.interfaces import IBatchProcessor
+    setSite(root_folder[APP_NAME])
+    for path in args:
+        if not os.path.isfile(path):
+            print "WAEUP.STRESS.SCRIPTS: no such file: %s" % path
+            continue
+        basename = os.path.basename(path)
+        util_name = IMPORTERS.get(basename, None)
+        if util_name is None:
+            print "WAEUP.STRESS.SCRIPTS: not a valid import filename: %s" % (
+                basename)
+            print "  valid names: %s" % IMPORTERS.keys()
+            continue
+        util = getUtility(IBatchProcessor, name=util_name)
+        for line in open(path, 'rb'):
+            break
+        headerfields = line.strip().split(',')
+        print "WAEUP.STRESS.SCRIPTS: importing %s" % os.path.basename(path)
+        results = util.doImport(path, headerfields)
+        print "WAEUP.STRESS.SCRIPTS: import done."
+    return
+
+def main(cmd, *args, **kw):
+    if cmd == 'install_app':
+        configure()
+        create_app()
+        return
+    elif cmd == 'import_csv':
+        configure()
+        create_app()
+        import_files(*args)
+        return
+
+if __name__ == '__main__':
+    cmd = sys.argv[1]
+    args = []
+    if len(sys.argv) > 2:
+        args = sys.argv[2:]
+    main(cmd, *args)
