Example #1
0
def convert_pstoascii():
    """Konvertiert die PDF-Dokumente in schlechtes Ascii. Unixspezifisch,
       verwendet Systemaufruf fuer das Programm: pstoascii. """
    
    import ebkus.db.sql
    sql.opendb()
    
    dokl = DokumentList(where = 'mtyp = %s'
                        % cc('mimetyp', 'pdf'), order = 'fall_id,id')
    grdokl = GruppendokumentList(where = 'mtyp = %s'
                                 % cc('mimetyp', 'pdf'), order = 'gruppe_id,id')
    
    for d in grdokl:
        gruppe_path = get_gruppe_path(d['gruppe_id'])
        dateil = os.listdir('%s' % gruppe_path)
        if '%s.txt' % d['id'] not in dateil and '%s.pdf' % d['id'] in dateil:
            os.system('ps2ascii %s/%s.pdf %s/%s.txt'
                      % (gruppe_path,d['id'],gruppe_path,d['id']))
            
    for d in dokl:
        fall = Fall(d['fall_id'])
        akte_path = get_akte_path(fall['akte_id'])
        dateil = os.listdir('%s' % akte_path)
        if '%s.txt' % d['id'] not in dateil and '%s.pdf' % d['id'] in dateil:
            os.system('ps2ascii %s/%s.pdf %s/%s.txt'
                      % (akte_path,d['id'],akte_path,d['id']))
            
    sql.closedb()
Example #2
0
 def __init__(self):
     # Protokoll stoert
     from ebkus.app.protocol import temp_off
     temp_off()
     # Sollversion ist immer die Major-Version der Software (4.1, 4.4, ...)
     from ebkus import Version
     self.ist_sw = Version
     # Minor-Version spielt keine Rolle
     vt = Version.split('.')
     self.soll_db = "%s.%s" % (vt[0], vt[1])
     try:
         opendb()
     except:
         # Zum Update muss die Datenbank verfügbar sein.
         # Daher:
         self.abort("Fuer das Update muss die Datenbank verfuegbar sein!",
                    exc_info=True)
     # Ist-Version der Datenbank feststellen
     self.tables = getDBHandle().listtables()
     try:
         ist_db = self.get_version()
         vt = ist_db.split('.')
         self.ist_db = "%s.%s" % (vt[0], vt[1])
     except:
         self.ist_db = None
Example #3
0
def convert_pstoascii():
    """Konvertiert die PDF-Dokumente in schlechtes Ascii. Unixspezifisch,
       verwendet Systemaufruf fuer das Programm: pstoascii. """

    import ebkus.db.sql

    sql.opendb()

    dokl = DokumentList(where="mtyp = %s" % cc("mimetyp", "pdf"), order="fall_id,id")
    grdokl = GruppendokumentList(where="mtyp = %s" % cc("mimetyp", "pdf"), order="gruppe_id,id")

    for d in grdokl:
        gruppe_path = get_gruppe_path(d["gruppe_id"])
        dateil = os.listdir("%s" % gruppe_path)
        if "%s.txt" % d["id"] not in dateil and "%s.pdf" % d["id"] in dateil:
            os.system("ps2ascii %s/%s.pdf %s/%s.txt" % (gruppe_path, d["id"], gruppe_path, d["id"]))

    for d in dokl:
        fall = Fall(d["fall_id"])
        akte_path = get_akte_path(fall["akte_id"])
        dateil = os.listdir("%s" % akte_path)
        if "%s.txt" % d["id"] not in dateil and "%s.pdf" % d["id"] in dateil:
            os.system("ps2ascii %s/%s.pdf %s/%s.txt" % (akte_path, d["id"], akte_path, d["id"]))

    sql.closedb()
Example #4
0
def dbexport(mit_id):
    opendb()
    site = ebapi.getDBSite()
    site_id = ebapi.cc('dbsite', site)
    export_time = int(time.time())
    export_time_string = time.strftime('%d%m%y-%H%M%S', time.localtime(export_time))
    exportprot = ebapi.Exportprotokoll()
    exportprot.new()
    export_id = exportprot['id']
    this_export_dir = os.path.join(config.INSTANCE_HOME, 'daten', 'export',
                                   'export-%s-%s-%s' %
                                   (site, export_id, export_time_string))
    os.mkdir(this_export_dir,0700)
    
    print "Daten exportieren nach: '%s' ..." % this_export_dir
    
    def dump(klass, dir = this_export_dir, where = '', order = 'id'):
        name = klass.resultClass.table
        # Tabelle aus der Datenbank holen (Tupelliste, *keine* dicts Feldname:Wert)
        table = klass().getTable(where = where, order = order)
        # In eine Datei schreiben
        f = open('%s/%s' % (dir, name), 'wb')
        marshal.dump(table, f)
        f.close()
        
    if site == config.MASTER_SITE:
        dump(ebapi.MitarbeiterList)
        dump(ebapi.CodeList)
    else:
        dump(ebapi.AkteList)
        dump(ebapi.FallList)
        dump(ebapi.BezugspersonList)
        dump(ebapi.EinrichtungskontaktList)
        dump(ebapi.LeistungList)
        dump(ebapi.AnmeldungList)
        dump(ebapi.ZustaendigkeitList)
        dump(ebapi.FachstatistikList)
        dump(ebapi.FachstatistikleistungList)
        dump(ebapi.FachstatistikkindproblemList)
        dump(ebapi.FachstatistikelternproblemList)
        dump(ebapi.JugendhilfestatistikList)
        
    dump(ebapi.ImportprotokollList, where = 'dbsite = %s' % site_id)
    exportprot['dbsite'] = site_id
    exportprot['zeit'] = export_time
    exportprot['mit_id'] = mit_id
    exportprot.insert()
    dump(ebapi.ExportprotokollList, where = 'dbsite = %s' % site_id)
    f = open(os.path.join(this_export_dir, 'export.inf'), 'w')
    f.write("%s\n%s\n%s\n" % (site, str(export_id), str(export_time)))
    f.close()
    print 'Ok'
Example #5
0
def _dbimport(mit_id, dir, export_site, export_id, export_time):
    print '_dbimport', dir, export_site, export_id
    opendb()
    site = ebapi.getDBSite()
    site_id = ebapi.cc('dbsite', site)
    exp_site = ebapi.cc('dbsite', export_site)
    if site_id == exp_site:
        print "Kein Import von '%s', da selbe Stelle" % dir
        return
    importprot = ebapi.ImportprotokollList(where = "exp_id = %s" % export_id)
    if len(importprot) > 0:
        print "Bereits importiert aus: '%s'" % dir
        return
    print "Daten Importieren aus: '%s' ... " % dir
    
    def load(klass, dir = dir):
        name = klass.resultClass.table
        f = open(os.path.join(dir, name), 'rb')
        table = marshal.load(f)
        klass().updateOrInsertTable(table)
        
    import_time = int(time.time())
    if export_site == config.MASTER_SITE:
        load(ebapi.MitarbeiterList)
        load(ebapi.CodeList)
    else:
        load(ebapi.AkteList)
        load(ebapi.FallList)
        load(ebapi.BezugspersonList)
        load(ebapi.EinrichtungskontaktList)
        load(ebapi.LeistungList)
        load(ebapi.AnmeldungList)
        load(ebapi.ZustaendigkeitList)
        load(ebapi.FachstatistikList)
        load(ebapi.FachstatistikleistungList)
        load(ebapi.FachstatistikkindproblemList)
        load(ebapi.FachstatistikelternproblemList)
        load(ebapi.JugendhilfestatistikList)
        load(ebapi.ImportprotokollList)
    load(ebapi.ExportprotokollList)
    importprot = ebapi.Importprotokoll()
    importprot['exp_id'] = export_id
    importprot['dbsite'] = site_id
    importprot['zeit'] = import_time
    importprot['mit_id'] = mit_id
    importprot.new()
    importprot.insert()
    print 'Ok'
Example #6
0
 def __init__(self):
     # Protokoll stoert
     from ebkus.app.protocol import temp_off
     temp_off()
     # Sollversion ist immer die Version der Software
     from ebkus import Version
     self.soll = Version
     try:
         opendb()
     except:
         # Zum Update muss die Datenbank verfügbar sein.
         # Daher:
         self.abort("Für das Update muss die Datenbank verfügbar sein!",
                    exc_info=True)
     # Ist-Version feststellen
     self.tables = getDBHandle().listtables()
     self.ist = self.get_version()
def read_strkat(file_name, opendb=False):
    dyn_pos = 0
    gesamt_pos = 0
    if opendb:
        sql.opendb()
    line = None
    neuliste = []
    if file_name.lower().endswith('.gz'):
        import gzip
        f = gzip.GzipFile(file_name)
    else:
        f = open(file_name)
    del_old_strkat()
    while line != '':
        line = f.readline()
        line = re.sub(r'\'', '\\\'', line)
        line = re.sub(r'\"', '\'', line)
        if line != '':
            neuliste = schreibe_daten(line)
            str_nr = neuliste[0]
            str_name = neuliste[1]
            hsnr = neuliste[2]
            if hsnr == '':
                hsnr = '\'---\''
            bez = neuliste[4]
            plz = neuliste[9]
            planungsr = neuliste[20]
            write_strassen_to_db(str_nr, str_name, hsnr, bez, plz, planungsr)
            dyn_pos = dyn_pos + 1
            if dyn_pos == 10000:
                gesamt_pos = gesamt_pos + 10000
                print "      Status: " + str(gesamt_pos) + " von ca. 385000 Datensaetzen fertig importiert."
                dyn_pos = 0
    #print "Strassenkatalog wurde erfolgreich importiert."
    ##*************************************************************************
    ## Anlegen eines Indexes für die schnellere Suche im Strassenkat
    ## Index wird über 10 Zeichen des Strassennamens angelegt. Wunsch von Huber.
    ## brehmea 15.08.2002
    ##*************************************************************************
    #print "Lege Index fuer Strassenkatalog an."
    sql_query = "ALTER TABLE strassenkat ADD INDEX (str_name(10))"
    sql.execute(sql_query)
    #print "Index fuer Strassenkatalog wurde erfolgreich angelegt."
    f.close()
    if opendb:
        sql.closedb()
Example #8
0
 def __init__(self):
     self.functions = getFunctionsToBePublished()
     self.classes = getClassesToBePublished()
     logging.info("EBKuS Version %s", Version)
     logging.info("EBKuS-Konfigurationsdatei: %s", config.ebkus_conf)
     if config.instance_conf:
         logging.info("Instanz-Konfigurationsdatei: %s", config.instance_conf)
     logging.debug("Aktuelle Konfiguration:\n%s>>>>\n%s\n<<<<%s", '-'*50,
                   config.dump(), '-'*50)
     try:
         sql.opendb()
     except:
         # geloggt wird in ebkus.dbadapter.connect
         # Der Start des Servers sollte aber hier
         # nicht scheitern, die Datenbank könnt ja
         # später wieder hochkommen.
         pass
Example #9
0
def update():
    try:
        opendb()
    except:
        # Zum Update muss die Datenbank verfügbar sein.
        # Daher:
        logging.critical("Für das Update muss die Datenbank verfügbar sein!", exc_info=True)
        logging.shutdown()
        sys.exit(1)
    if needs_update():
        logging.info("Update von EBKuS 3.2 auf 3.3 (neue gesetzliche Statistik) beginnt")
        try:
            do_update()
            logging.info("Update von EBKuS 3.2 auf 3.3 erfolgreich")
        except Exception, e:
            t = sys.exc_info()[0]
            logging.exception("%s: %s", t, e)
            logging.critical("Update von EBKuS 3.2 auf 3.3 misslungen")
            logging.shutdown()
            sys.exit(1)
Example #10
0
 def process(self, REQUEST, RESPONSE):
     global _current_request
     try:
         # Dieser Server ist single-threaded. Es gibt also zu jedem
         # Zeitpunkt nur einen einzigen Reqest, der hier global über
         # getRequest() zur Verfügung steht.
         # Der Grund für diesen Hack besteht darin, dass beim SQL-Protokollieren
         # (DBAdapter.query()) user und ip benötigt wird.
         # Eine bessere Lösung setzte eine umfangreiche Umstrukturierung voraus,
         # die man vornehmen müsste, wenn man multi-threaded arbeiten wollte.
         _current_request = self
         self.REQUEST = REQUEST
         self.RESPONSE = RESPONSE
         self.ip = REQUEST.environ.get("REMOTE_ADDR")
         # wenn etwas protokolliert wird bevor der Benutzer bekannt ist
         self.user = "******"
         try:
             self.form = self.REQUEST.form
             opendb()
             self.checkAuth()
             # print 'FORM: ', self.form
             return self.processForm(REQUEST, RESPONSE)
         except NichtIdentifiziert:
             return self.nichtIdentifiziert(REQUEST, RESPONSE)
         except KeineZugriffsberechtigung:
             return self.keineZugriffsberechtigung(REQUEST, RESPONSE)
         except (DatabaseError, DBAppError, SQLError), e:
             # ist nie von Anwender zu verantworten, also ein interner Fehler
             t = sys.exc_info()[0]
             logging.exception("Datenbankfehler: %s: %s", t, e)
             self.last_error_message = "Datenbankfehler: \n%s" % get_traceback()
             RESPONSE.setStatus("InternalError")
             return self.EBKuSInternalError(REQUEST, RESPONSE)
         except EBUpdateDataError, e:
             # in der Regel ausgelöst durch die Eingaben des Anwenders
             logging.debug("Eingabefehler: %s", e)
             self.last_error_message = str(e)
             return self.EBKuSError(REQUEST, RESPONSE)
Example #11
0
def update():
    try:
        opendb()
    except:
        # Zum Update muss die Datenbank verfügbar sein.
        # Daher:
        logging.critical("Für das Update muss die Datenbank verfügbar sein!",
                         exc_info=True)
        logging.shutdown()
        sys.exit(1)
    if not update_is_possible():
        sys.exit(1)
    if needs_update():
        logging.info("Update von EBKuS 4.0 auf 4.0.2 beginnt")
        try:
            do_update()
            logging.info("Update von EBKuS 4.0 auf 4.0.2 erfolgreich")
        except Exception, e:
            t = sys.exc_info()[0]
            logging.exception("%s: %s", t, e)
            logging.critical("Update von EBKuS 4.0 auf 4.0.2 misslungen")
            logging.shutdown()
            sys.exit(1)
Example #12
0
        andauernd = sys.argv[2]
        if andauernd.startswith('a'):
            andauernd = True
        else:
            print "***Fehler: Zweiter Parameter muss mit 'a' (fuer andauernd) beginnen"
            sys.exit(1)
    except IndexError:
        andauernd = False
    print
    print "Export der Jugendhilfestatistik fuer Instanz '%s'" % init.INSTANCE_NAME
    print "   (Pfad %s)" % init.INSTANCE_HOME
    print
    print "Jahr: %s  (%s)" % (jahr, andauernd and "andauernde Faelle" or "abgeschlossene Faelle" )
    print
    from ebkus.db.sql import opendb
    opendb()
    daten_saetze, log_daten_saetze = jghexport(jahr, andauernd)

    datei_name = get_export_datei_name(jahr, False, andauernd)
    f = open(datei_name, "w")
    f.write(daten_saetze)
    f.close()
    print "ausgegeben: %s" % datei_name 

    log_datei_name = get_export_datei_name(jahr, True, andauernd)
    f = open(log_datei_name, "w")
    f.write(log_daten_saetze)
    f.close()
    print "ausgegeben: %s" % log_datei_name
    print
    
Example #13
0
def generate_schema(schema_str, test):
    opendb()
    init_new_db(schema_str, test)
    closedb()
Example #14
0
def generate_schema(schema_str, test):
    from ebkus.db.sql import opendb, closedb
    opendb()
    init_new_db(schema_str, test)
    closedb()
Example #15
0
#!/usr/local/bin/python
# coding: latin-1

from ebkus.app import ebapi
from ebkus.db import dbapp, sql

sql.opendb()
sql.debug=0
dbapp.cache_off()

ebapi.Akte()._test_consistency()
ebapi.Leistung()._test_consistency()
ebapi.Einrichtungskontakt()._test_consistency()
ebapi.Anmeldung()._test_consistency()
ebapi.Bezugsperson()._test_consistency()
ebapi.Zustaendigkeit()._test_consistency()
ebapi.Fall()._test_consistency()
ebapi.Mitarbeiter()._test_consistency()
ebapi.Dokument()._test_consistency()
ebapi.Gruppe()._test_consistency()
ebapi.Gruppendokument()._test_consistency()
ebapi.FallGruppe()._test_consistency()
ebapi.BezugspersonGruppe()._test_consistency()
ebapi.MitarbeiterGruppe()._test_consistency()

ebapi.Code()._test_consistency()
ebapi.Kategorie()._test_consistency()
ebapi.Jugendhilfestatistik()._test_consistency()
ebapi.Fachstatistik()._test_consistency()
ebapi.Fachstatistikleistung()._test_consistency()
ebapi.Fachstatistikkindproblem()._test_consistency()
Example #16
0
def generate_ebapi(schema_str):
    opendb()
    f = gen_api(schema_str)
    closedb()
    # f ist StringIO Objekt
    return f