Example #1
0
def _path():
    _PATHS = {
        _CACHE_RWIS: os.path.join(get_path('cache'), _CACHE_RWIS),
        _CACHE_FAIL: os.path.join(get_path('cache'), _CACHE_FAIL)
    }

    for v in _PATHS.values():
        if not os.path.exists(v):
            os.mkdir(v)

    return _PATHS
def _path():
    PATHS = {
        CACHE_TYPE_DET: os.path.join(get_path('cache'), 'det'),
        CACHE_TYPE_FAIL: os.path.join(get_path('cache'), 'fail')
    }
    for v in PATHS.values():
        if not os.path.exists(v):
            try:
                os.mkdir(v)
            except FileExistsError:
                pass

    return PATHS
def download_metro_file():
    """ load_data metro xml file from IRIS

    :return: metro file path
    """
    logger.debug("loading metro.xml information from : " + cfg.CONFIG_XML_URL)

    logger.debug("loading file from IRIS server")
    try:
        res = urllib.request.urlopen(cfg.CONFIG_XML_URL)
    except urllib.error.HTTPError as e:
        logger.debug(
            'cannot get the remote file (reason={}, http_code={})'.format(
                str(e.reason), e.code))
        logger.debug('file : {}'.format(cfg.CONFIG_XML_URL))
        raise Exception('cannot load_data metro network information')
    except urllib.error.URLError as e:
        logger.critical('cannot connect to the server (reason={})'.format(
            str(e.reason)))
        raise Exception('cannot load_data metro network information')

    logger.debug("unzipping the downloaded xml file")

    mem_file = io.BytesIO(res.read())
    tmp_zip = gzip.GzipFile(fileobj=mem_file)
    metro_file = '{0}{1}{2}.xml'.format(get_path('metro'), os.sep,
                                        datetime.date.today())
    with open(metro_file, 'w') as mfile:
        mfile.write(tmp_zip.read().decode('utf-8'))

    return metro_file
Example #4
0
def _path():

    _PATHS = {
        _CACHE_TYPE: os.path.join(get_path('cache'), _CACHE_TYPE),
        _CACHE_RAIN: os.path.join(get_path('cache'), _CACHE_RAIN),
        _CACHE_FAIL: os.path.join(get_path('cache'), _CACHE_FAIL)
    }

    for v in _PATHS.values():
        if not os.path.exists(v):
            try:
                os.mkdir(v)
            except FileExistsError:
                pass

    return _PATHS
Example #5
0
def get_file_path(route_name, **kwargs):
    """
    :type route_name: str
    :rtype: str
    """
    name_based = kwargs.get('name_based', True)
    if name_based:
        uid = uuid.uuid3(uuid.NAMESPACE_DNS, route_name)
    else:
        uid = uuid.uuid4()

    name = str(uid)
    filepath = os.path.join(ticas.get_path('route'), name)
    if not name_based and os.path.exists(filepath):
        return get_file_path(route_name, **kwargs)

    return os.path.join(ticas.get_path('route'), name)
Example #6
0
def load_routes():
    """
    :rtype: list[Route]
    """
    routes = []
    for file in util.file_list(ticas.get_path('route')):
        r = load_route(file)
        if r:
            routes.append(r)
    return routes
Example #7
0
def connect(DB_INFO):
    """
    :rtype: (sqlalchemy.engine.Engine, sqlalchemy.engine.Connection, sqlalchemy.orm.scoped_session)
    """
    logger = getLogger(__name__)
    logger.info('creating database connection...')
    # for SQLite
    engine = create_engine('sqlite:///' + os.path.join(get_path('db'), DB_INFO['filename']))
    connection = engine.connect()
    model.Base.metadata.bind = engine
    session_factory = sessionmaker(bind=engine)
    Session = scoped_session(session_factory)

    return (engine, connection, Session)
def list_metro_files():
    """

    :return: metro file list
    """
    return util.file_list(get_path('metro'))
 def get_path(cls, sub_dir, **kwargs):
     return ticas.get_path(sub_dir, **kwargs)