Ejemplo n.º 1
0
def _get_platform_list(urls, platid=None):
    if not os.path.exists(CROSS_PLATFORM_PATH):
        logging.info('Create cross platforms path: %s', CROSS_PLATFORM_PATH)
        os.makedirs(CROSS_PLATFORM_PATH)

    filename = os.path.join(PLATFORM_PATH, platform_config)
    logging.info('Load platform list from %s', filename)
    with open(filename) as f:
        cfg = json_loads(f.read())

    ver = cfg.get('version')
    if not ver.split('.')[0] == core_version.split('.')[0]:
        logging.warning(
            'The core library excepted version is %s, '
            'but got %s from platform list file %s', core_version,
            cfg.get('version'), filename)
    urls[:] = [x.format(version=ver) for x in urls]

    if platid is not None:
        logging.info('Search library for platform: %s', platid)

    return cfg.get('platforms', []) if platid is None \
        else [x for x in cfg.get('platforms', [])
              if (platid is None
                  or (x['id'] == platid)
                  or (x['id'].find(platid + '.') == 0)
                  or (x['path'] == platid))]
Ejemplo n.º 2
0
def _get_platform_list(platid=None):
    filename = os.path.join(PLATFORM_PATH, platform_config)
    logging.debug('Load platform list from %s', filename)

    if not os.path.exists(filename):
        urls = [x.format(version=core_version) for x in platform_urls]
        res = _get_remote_file(urls, 'index.json', timeout=5.0)
        if res is None:
            raise RuntimeError('No platform list file %s found' % filename)
        logging.info('Write cached platform list file %s' % filename)
        with open(filename, 'wb') as f:
            f.write(res.read())

    with open(filename) as f:
        cfg = json_loads(f.read())

    ver = cfg.get('version')
    if not ver.split('.')[0] == core_version.split('.')[0]:
        logging.warning(
            'The core library excepted version is %s, '
            'but got %s from platform list file %s', core_version,
            cfg.get('version'), filename)

    return cfg.get('platforms', []) if platid is None \
        else [x for x in cfg.get('platforms', [])
              if (platid is None
                  or (x['id'] == platid)
                  or (x['id'].find(platid + '.') == 0)
                  or (x['path'] == platid))]