Ejemplo n.º 1
0
def createStateDatabase(path, fileListFileName):
    logger.info("Načítám stavovou databázi ze seznamu " + fileListFileName)
    GDALFileListNames = convertFileToDownloadLists(fileListFileName)
    downloadBatchFileName = buildDownloadBatch(fileListFileName, GDALFileListNames)

    call(downloadBatchFileName)
    deleteFilesInLists(path, GDALFileListNames, ".xml.gz")
    os.remove(downloadBatchFileName)
    renameFile(fileListFileName, "__")
    pass
Ejemplo n.º 2
0
def updateDatabase(updateFileList):

    def removeDataFiles():
        dataPath = pathWithLastSlash(os.path.split(updateFileList)[0])
        inFile = open(updateFileList, "r")
        try:
            for line in inFile:
                fileName = os.path.basename(line)
                if os.path.exists(dataPath + fileName):
                    os.remove(dataPath + fileName)
        finally:
            inFile.close()
        pass

    logger.info("Importing update data from " + updateFileList)

    (startDate, endDate, type) = extractDatesAndType(updateFileList)
    logger.info("\tPočáteční datum:" + startDate)
    logger.info("\tKonečné datum:" + endDate)
    logger.info("\tTyp dat:" + type)

    os4GeoPath = joinPaths(os.path.dirname(__file__), config.os4GeoPath)

    (VFRlogFileName, VFRerrFileName) = buildhtmllog.getLogFileNames(updateFileList)

    params = ' '.join([os4GeoPath, "vfr2pg",
                "--dbname", config.dbname,
                "--user ", config.user,
                "--passwd ", config.password,
                "--date", startDate + ":" + endDate,
                "--type", type])
    if config.layers != "": params += " --layer " + config.layers
    params += " >%s 2>%s" % (VFRlogFileName, VFRerrFileName)

    batchFileName = os.path.dirname(os.path.abspath(updateFileList)) + os.sep + "Import.bat"
    file = open(batchFileName, "w")
    file.write("cd " + os.path.dirname(os.path.abspath(updateFileList)) + "\n")
    file.write(params)
    file.close()

    call(batchFileName)
    os.remove(batchFileName)
    removeDataFiles()

    renameFile(updateFileList, "__")
    logger.info("Import update data done.")
    pass
Ejemplo n.º 3
0
def doImport(argv):
    logger.info("Importing VFR data to database.")
    config.loadFromCommandLine(argv, helpStr)

    osGeoPath = getOSGeoPath()
    if not os.path.exists(osGeoPath):
        print "Error: Batch file %s doesn't exist" % osGeoPath
        print "Download file http://geo1.fsv.cvut.cz/landa/vfr/OSGeo4W_vfr.zip, expand it and run script again."
        sys.exit()

    from RUIANDownloader.RUIANDownload import getDataDirFullPath
    rebuildAuxiliaryTables = processDownloadedDirectory(getDataDirFullPath())

    if config.buildServicesTables and rebuildAuxiliaryTables:
        from RUIANServices.services.auxiliarytables import buildAll, buildServicesTables
        if config.buildAutocompleteTables:
            buildAll()
        else:
            buildServicesTables()

    from RUIANServices.services.RUIANConnection import saveRUIANVersionDateToday
    saveRUIANVersionDateToday()
Ejemplo n.º 4
0
def _getRUIANVersionDate():
    result = "unassigned _getRUIANVersionDate"
    try:
        connection = psycopg2.connect(host=DATABASE_HOST, database=DATABASE_NAME, port= PORT, user=USER_NAME, password=PASSWORD)
        cursor = connection.cursor()
        try:
            query = 'select * from ruian_dates'
            cursor.execute(query)
            row = cursor.fetchone()
            result = row[1]
        except psycopg2.Error as e:
            result = "Error: Could not execute query to %s at %s:%s as %s:%s" % (DATABASE_NAME, DATABASE_HOST, PORT, USER_NAME, query)
            logger.info("Error: " + e.pgerror)
            return "ERROR:" + e.pgerror
        finally:
            cursor.close()
            connection.close()

    except psycopg2.Error as e:
        result = "Error: Could connect to %s at %s:%s as %s\n%s" % (DATABASE_NAME, DATABASE_HOST, PORT, USER_NAME, str(e))
        logger.info(result)

    return result
Ejemplo n.º 5
0
 def __init__(self):
     try:
         self.conection = psycopg2.connect(host = DATABASE_HOST, database = DATABASE_NAME, port = PORT, user = USER_NAME, password = PASSWORD)
     except psycopg2.Error as e:
         logger.info("Error: Could not connect to database %s at %s:%s as %s\n%s" % (DATABASE_NAME, DATABASE_HOST, PORT, USER_NAME, str(e)))
         self.conection = None
Ejemplo n.º 6
0
def processDownloadedDirectory(path):
    logger.info("Načítám stažené soubory do databáze...")
    logger.info("--------------------------------------")
    logger.info("Zdrojová data : " + path)

    path = pathWithLastSlash(path)
    stateFileList = ""
    updatesFileList = []
    for file in os.listdir(path):
        fileName = file.lower()
        if file.endswith(".txt"):
            if fileName.startswith("download_"):
                stateFileList = join(path, fileName)
            elif fileName.startswith("patch_"):
                updatesFileList.append(join(path, fileName))

    result = False
    if stateFileList != "":
        createStateDatabase(path, stateFileList)
        result = True
    else:
        logger.info("Stavová data nejsou obsahem zdrojových dat.")

    if len(updatesFileList) == 0:
        logger.info("Denní aktualizace nejsou obsahem zdrojových dat.")
    else:
        result = True
        for updateFileName in updatesFileList:
            updateDatabase(updateFileName)

    logger.info(u"Generuji sestavu importů.")
    buildhtmllog.buildHTMLLog()

    logger.info("Načítání stažených souborů do databáze - hotovo.")
    return result