def main(): try: # TODO vytvorit TMP slozku # Objekt pro ulozeni globalnich promennych a nastaveni o = Options() # Nactu konfiguracni soubor config.load(o) # Nactu a zpracuji arumenty args.parse(o) # Zaznamenam cas spusteni o.timeStart = datetime.now() say('Start at ' + str(o.timeStart), o) # Ziskam informace o statu parser.area(o) # Nactu informace z hlavicky parser.fileHeader(o) # Stahnu mapova data download.mapData(o) # Stahnu polygon download.polygon(o) # Zpracuji polygon polygon.load(o) # Vytvorim vrstevnice generator.contours(o) # Oriznu mapovy soubor generator.crop(o) # Generuji Garmin mapu generator.garmin(o) # TODO remove temp except KeyboardInterrupt: error("\nUkonceno uzivatelem") except Exception as e: error(str(e)) exit(1) finally: # Ukoncim generovani end(o)
def fileHeader(o): say(_('Ctu hlavicku souboru'), o) o.area.timestamp = None o.area.fileHeader = None if os.path.isfile(o.area.mapDataName): o.area.fileHeader = osmium.io.Reader( o.area.mapDataName, osmium.osm.osm_entity_bits.NOTHING).header() o.area.timestamp = o.area.fileHeader.get( "osmosis_replication_timestamp") try: o.area.timestamp = datetime.strptime(o.area.timestamp, "%Y-%m-%dT%H:%M:%SZ") o.area.timestamp = o.area.timestamp.replace(tzinfo=timezone.utc) except ValueError: error( _('Datum v hlavicce OSM souboru neni ve formatu ISO8601 (napr. 2015-12-24T08:08Z). Ignoruji' ), o) o.area.timestamp = None say(_("Soubor z ") + str(o.area.timestamp), o)
def fileHeader(o): say("Parsing file header", o) o.area.timestamp = None o.area.fileHeader = None if os.path.isfile(o.area.mapDataName): o.area.fileHeader = osmium.io.Reader( o.area.mapDataName, osmium.osm.osm_entity_bits.NOTHING).header() o.area.timestamp = o.area.fileHeader.get( "osmosis_replication_timestamp") try: o.area.timestamp = datetime.strptime(o.area.timestamp, "%Y-%m-%dT%H:%M:%SZ") o.area.timestamp = o.area.timestamp.replace(tzinfo=timezone.utc) except ValueError: error( "Date in OSM file header is not in ISO8601 format (e.g. 2015-12-24T08:08Z). Ignored", o) o.area.timestamp = None say("File from " + str(o.area.timestamp), o)
def run(program, o): program = ' '.join(program.split()) say(program, o, '[RUN] ') process = subprocess.Popen(program, universal_newlines=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) while True: output = process.stdout.readline() if output == '' and process.poll() is not None: break if output: say(output, o, '', '') log(output, o) if process.poll() != 0: error('stderr: ' + process.stderr.read(), o) raise ValueError(program + ' ' + _('vratil') + ' ' + str(process.poll()) + ' (ocekavana 0)')