예제 #1
0
def fare2ed(instance_config, filename, job_id):
    """ launch fare2ed """

    job = models.Job.query.get(job_id)
    instance = job.instance
    lock = redis.lock('tyr.lock|' + instance.name)
    if not lock.acquire(blocking=False):
        fare2ed.retry(countdown=300, max_retries=10)

    logger = get_instance_logger(instance)
    try:
        working_directory = os.path.dirname(filename)

        zip_file = zipfile.ZipFile(filename)
        zip_file.extractall(path=working_directory)

        res = launch_exec("fare2ed", ['-f', working_directory,
                                      '--connection-string',
                                      make_connection_string(instance_config)],
                          logger)
        if res != 0:
            #@TODO: exception
            raise ValueError('fare2ed failed')
    except:
        logger.exception('')
        job.state = 'failed'
        models.db.session.commit()
        raise
    finally:
        lock.release()
예제 #2
0
def synonym2ed(instance_config, filename, job_id):
    """ launch synonym2ed """

    job = models.Job.query.get(job_id)
    instance = job.instance
    lock = redis.lock('tyr.lock|' + instance.name)
    if not lock.acquire(blocking=False):
        synonym2ed.retry(countdown=300, max_retries=10)

    logger = get_instance_logger(instance)
    try:
        connection_string = make_connection_string(instance_config)
        res = launch_exec('synonym2ed',
                ["-i", filename, "--connection-string", connection_string],
                logger)
        if res != 0:
            #@TODO: exception
            raise ValueError('synonym2ed failed')
    except:
        logger.exception('')
        job.state = 'failed'
        models.db.session.commit()
        raise
    finally:
        lock.release()
예제 #3
0
def nav2rt(instance_config, job_id):
    """ Launch nav2rt"""
    job = models.Job.query.get(job_id)
    instance = job.instance
    lock = redis.lock('tyr.lock|' + instance.name)
    if not lock.acquire(blocking=False):
        nav2rt.retry(countdown=300, max_retries=10)

    logger = get_instance_logger(instance)
    try:
        source_filename = instance_config.tmp_file
        target_filename = instance_config.target_file
        connection_string = make_connection_string(instance_config)
        res = launch_exec('nav2rt',
                    ["-i", source_filename, "-o", target_filename,
                        "--connection-string", connection_string],
                    logger)
        if res != 0:
            raise ValueError('nav2rt failed')
    except:
        logger.exception('')
        job.state = 'failed'
        models.db.session.commit()
        raise
    finally:
        lock.release()
예제 #4
0
def fare2ed(self, instance_config, filename, job_id):
    """ launch fare2ed """

    job = models.Job.query.get(job_id)
    instance = job.instance

    logger = get_instance_logger(instance)
    try:
        working_directory = os.path.dirname(filename)

        zip_file = zipfile.ZipFile(filename)
        zip_file.extractall(path=working_directory)

        res = launch_exec("fare2ed", ['-f', working_directory,
                                      '--connection-string',
                                      make_connection_string(instance_config)],
                          logger)
        if res != 0:
            #@TODO: exception
            raise ValueError('fare2ed failed')
    except:
        logger.exception('')
        job.state = 'failed'
        models.db.session.commit()
        raise
예제 #5
0
def ed2nav(self, instance_config, job_id, custom_output_dir):
    """ Launch ed2nav"""
    job = models.Job.query.get(job_id)
    instance = job.instance

    logger = get_instance_logger(instance)
    try:
        output_file = instance_config.target_file

        if custom_output_dir:
            # we change the target_filename to store it in a subdir
            target_path = os.path.join(os.path.dirname(output_file), custom_output_dir)
            output_file = os.path.join(target_path, os.path.basename(output_file))
            if not os.path.exists(target_path):
                os.makedirs(target_path)


        connection_string = make_connection_string(instance_config)
        argv = ["-o", output_file, "--connection-string", connection_string]
        if 'CITIES_DATABASE_URI' in current_app.config and current_app.config['CITIES_DATABASE_URI']:
            argv.extend(["--cities-connection-string", current_app.config['CITIES_DATABASE_URI']])

        res = launch_exec('ed2nav', argv, logger)
        if res != 0:
            raise ValueError('ed2nav failed')
    except:
        logger.exception('')
        job.state = 'failed'
        models.db.session.commit()
        raise
예제 #6
0
def gtfs2ed(self, instance_config, gtfs_filename, job_id):
    """ Unzip gtfs file launch gtfs2ed """

    job = models.Job.query.get(job_id)
    instance = job.instance

    logger = get_instance_logger(instance)
    try:
        working_directory = os.path.dirname(gtfs_filename)

        zip_file = zipfile.ZipFile(gtfs_filename)
        zip_file.extractall(path=working_directory)

        params = ["-i", working_directory]
        if instance_config.aliases_file:
            params.append("-a")
            params.append(instance_config.aliases_file)

        if instance_config.synonyms_file:
            params.append("-s")
            params.append(instance_config.synonyms_file)

        connection_string = make_connection_string(instance_config)
        params.append("--connection-string")
        params.append(connection_string)
        res = launch_exec("gtfs2ed", params, logger)
        if res != 0:
            raise ValueError('gtfs2ed failed')
    except:
        logger.exception('')
        job.state = 'failed'
        models.db.session.commit()
        raise
예제 #7
0
def cities(osm_path):
    """ launch cities """
    res = -1
    try:
        res = launch_exec("cities", [
            '-i', osm_path, '--connection-string',
            current_app.config['CITIES_DATABASE_URI']
        ], logging)
        if res != 0:
            logging.error('cities failed')
    except:
        logging.exception('')
    logging.info('Import of cities finished')
    return res
예제 #8
0
def synonym2ed(self, instance_config, filename, job_id):
    """ launch synonym2ed """

    job = models.Job.query.get(job_id)
    instance = job.instance

    logger = get_instance_logger(instance)
    try:
        connection_string = make_connection_string(instance_config)
        res = launch_exec('synonym2ed',
                ["-i", filename, "--connection-string", connection_string],
                logger)
        if res != 0:
            #@TODO: exception
            raise ValueError('synonym2ed failed')
    except:
        logger.exception('')
        job.state = 'failed'
        models.db.session.commit()
        raise
예제 #9
0
def fusio2ed(instance_config, filename, job_id):
    """ Unzip fusio file and launch fusio2ed """

    job = models.Job.query.get(job_id)
    instance = job.instance
    lock = redis.lock('tyr.lock|' + instance.name)
    if not lock.acquire(blocking=False):
        fusio2ed.retry(countdown=300, max_retries=10)

    logger = get_instance_logger(instance)
    try:
        working_directory = os.path.dirname(filename)

        zip_file = zipfile.ZipFile(filename)
        zip_file.extractall(path=working_directory)

        params = ["-i", working_directory]
        if instance_config.aliases_file:
            params.append("-a")
            params.append(instance_config.aliases_file)

        if instance_config.synonyms_file:
            params.append("-s")
            params.append(instance_config.synonyms_file)

        connection_string = make_connection_string(instance_config)
        params.append("--connection-string")
        params.append(connection_string)
        res = launch_exec("fusio2ed", params, logger)
        if res != 0:
            raise ValueError('fusio2ed failed')
    except:
        logger.exception('')
        job.state = 'failed'
        models.db.session.commit()
        raise
    finally:
        lock.release()