当前位置: 首页>>代码示例>>Python>>正文


Python genericpath.exists方法代码示例

本文整理汇总了Python中genericpath.exists方法的典型用法代码示例。如果您正苦于以下问题:Python genericpath.exists方法的具体用法?Python genericpath.exists怎么用?Python genericpath.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在genericpath的用法示例。


在下文中一共展示了genericpath.exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: prepare_auto_configure

# 需要导入模块: import genericpath [as 别名]
# 或者: from genericpath import exists [as 别名]
def prepare_auto_configure(main, config_file, repo_path):
    """
    Instructions for auto configurations.
    http://www.sax.de/unix-stammtisch/docs/autotools/autotools.html
    http://www.aireadfun.com/blog/2012/12/03/study-automake/
    libtoolize && aclocal && autoheader && automake --add-missing && autoconf

    :param main: the detector object
    :param repo_path: path to the cloned repo
    """
    logger.info("executing %s", config_file)

    exec_command('libtoolize', ["libtoolize"], cwd=repo_path, timeout=main.CONFIGURE_TIMEOUT)
    exec_command('aclocal', ["aclocal"], cwd=repo_path, timeout=main.CONFIGURE_TIMEOUT)
    exec_command('autoheader', ["autoheader"], cwd=repo_path, timeout=main.CONFIGURE_TIMEOUT)
    exec_command('automake', ["automake", "--add-missing"], cwd=repo_path, timeout=main.CONFIGURE_TIMEOUT)
    exec_command('autoconf', ["autoconf"], cwd=repo_path, timeout=main.CONFIGURE_TIMEOUT)

    generated_configure = join(repo_path, 'configure')
    if exists(generated_configure):
        prepare_configure(main=main, config_file=generated_configure, repo_path=repo_path)
    else:
        logger.error("autoconf for %s failed!", config_file) 
开发者ID:osssanitizer,项目名称:osspolice,代码行数:25,代码来源:signature.py

示例2: load_ratings_csv

# 需要导入模块: import genericpath [as 别名]
# 或者: from genericpath import exists [as 别名]
def load_ratings_csv(prev_ratings_file):
    """Reads ratings from a CSV file into a dict.

    Format expected in each line:
    subject_id,ratings,notes

    """

    if pexists(prev_ratings_file):
        csv_values = [line.strip().split(',') for line in
                      open(prev_ratings_file).readlines()]
        ratings = {item[0]: item[1] for item in csv_values}
        notes = {item[0]: item[2] for item in csv_values}
    else:
        ratings = dict()
        notes = dict()

    return ratings, notes 
开发者ID:raamana,项目名称:visualqc,代码行数:20,代码来源:utils.py

示例3: save_ratings_to_disk

# 需要导入模块: import genericpath [as 别名]
# 或者: from genericpath import exists [as 别名]
def save_ratings_to_disk(ratings, notes, qcw):
    """Save ratings before closing shop."""

    ratings_file, prev_ratings_backup = get_ratings_path_info(qcw)

    if pexists(ratings_file):
        copyfile(ratings_file, prev_ratings_backup)

    lines = '\n'.join(['{},{},{}'.format(sid, rating, notes[sid])
                       for sid, rating in ratings.items()])
    try:
        with open(ratings_file, 'w') as cf:
            cf.write(lines)
    except:
        raise IOError('Error in saving ratings to file!!\n'
                      'Backup might be helpful at:\n\t{}'
                      ''.format(prev_ratings_backup))

    return 
开发者ID:raamana,项目名称:visualqc,代码行数:21,代码来源:utils.py

示例4: check_bids_dir

# 需要导入模块: import genericpath [as 别名]
# 或者: from genericpath import exists [as 别名]
def check_bids_dir(dir_path):
    """Checks if its a BIDS folder or not"""

    descr_file_name = 'dataset_description.json'
    descr_path = pjoin(dir_path, descr_file_name)
    if not pexists(descr_path):
        raise ValueError('There is no {} file at the root\n '
                         'Ensure folder is formatted according to BIDS spec.'
                         ''.format(descr_file_name))

    try:
        import json
        with open(descr_path) as df:
            descr = json.load(df)
    except:
        raise IOError('{} could not be read'.format(descr_path))

    ver_tag = 'BIDSVersion'
    if 'BIDSVersion' not in descr:
        raise IOError('There is no field {} in \n\t {}'.format(ver_tag, descr_path))

    in_dir = realpath(dir_path)
    dir_type = 'BIDSVersion:'+descr['BIDSVersion']

    return in_dir, dir_type 
开发者ID:raamana,项目名称:visualqc,代码行数:27,代码来源:utils.py

示例5: cached_file_reader

# 需要导入模块: import genericpath [as 别名]
# 或者: from genericpath import exists [as 别名]
def cached_file_reader(dir, flat, flon):
    # https://wiki.openstreetmap.org/wiki/SRTM
    # The official 3-arc-second and 1-arc-second data for versions 2.1 and 3.0 are divided into 1°×1° data tiles.
    # The tiles are distributed as zip files containing HGT files labeled with the coordinate of the southwest cell.
    # For example, the file N20E100.hgt contains data from 20°N to 21°N and from 100°E to 101°E inclusive.
    root = '%s%02d%s%03d' % ('S' if flat < 0 else 'N', abs(flat), 'W' if flon < 0 else 'E', abs(flon))
    hgt_file = root + '.hgt'
    hgt_path = join(dir, hgt_file)
    zip_path = join(dir, root + EXTN)
    if exists(hgt_path):
        log.debug(f'Reading {hgt_path}')
        with open(hgt_path, 'rb') as input:
            data = input.read()
    elif exists(zip_path):
        log.debug(f'Reading {zip_path}')
        with open(zip_path, 'rb') as input:
            zip = ZipFile(input)
            log.debug(f'Found {zip.filelist}')
            data = zip.open(hgt_file).read()
    else:
        # i tried automating download, but couldn't get ouath2 to work
        log.warning(f'Download {BASE_URL + root + EXTN}')
        raise Exception(f'Missing {hgt_file}')
    return np.flip(np.frombuffer(data, np.dtype('>i2'), SAMPLES * SAMPLES).reshape((SAMPLES, SAMPLES)), 0) 
开发者ID:andrewcooke,项目名称:choochoo,代码行数:26,代码来源:file.py

示例6: prepare_configure

# 需要导入模块: import genericpath [as 别名]
# 或者: from genericpath import exists [as 别名]
def prepare_configure(main, config_file, repo_path):
    logger.debug("%s exists. making it executable", config_file)

    # make sure "configure" is executable
    st = os.stat(os.path.join(repo_path, config_file))
    os.chmod(os.path.join(repo_path, config_file), st.st_mode | stat.S_IEXEC)

    logger.info("executing %s", config_file)

    # get ndk toolchain path
    ndk_toolchain = os.environ["NDK_TOOLCHAIN"]
    if not ndk_toolchain:
        raise Exception("$NDK_TOOLCHAIN environ variable not defined!")

    # configure exists, good to go
    args = ["sh", config_file, "--host=arm-linux-androideabi", "--with-sysroot=" + ndk_toolchain + "/sysroot"]
    retcode = exec_command(config_file, args, cwd=repo_path, timeout=main.CONFIGURE_TIMEOUT)
    if retcode:
        logger.error("configure %s failed", config_file)

        # failed with args, try with no args
        args = ["sh", config_file]
        retcode = exec_command(config_file, args, cwd=repo_path, timeout=main.CONFIGURE_TIMEOUT)

        # check if the makefile was generated
        if retcode or not os.path.isfile(os.path.join(repo_path, "Makefile")):
            logger.error("configure %s failed", config_file)
        else:
            # makefile successfully generated
            logger.info("%s finished! executing generated makefile", config_file)

            # execute make to generate any build dependent headers
            args = ["make"]
            retcode = exec_command("makefile", args, cwd=repo_path, timeout=5)
            if retcode:
                logger.error("make failed")
            else:
                logger.info("make done or timed out") 
开发者ID:osssanitizer,项目名称:osspolice,代码行数:40,代码来源:signature.py

示例7: repo_scanned

# 需要导入模块: import genericpath [as 别名]
# 或者: from genericpath import exists [as 别名]
def repo_scanned(redis, repo_id, branch=None):
    try:
        if branch:
            branch_id = get_typed_key(typ=repo_id, key=branch)
            exists = redis.exists(get_typed_key('branch', branch_id))
        else:
            exists = redis.exists(get_typed_key('repo', repo_id))
        if exists:
            logger.debug("repo %s branch %s already indexed", repo_id, branch)
            return True
        return False

    except Exception as e:
        logger.error("repo_scanned: error %s", str(e))
        return False 
开发者ID:osssanitizer,项目名称:osspolice,代码行数:17,代码来源:signature.py

示例8: setup

# 需要导入模块: import genericpath [as 别名]
# 或者: from genericpath import exists [as 别名]
def setup():
    os.environ['XDG_DATA_HOME'] = TEST_TEMP_DIR_PATH

    # start every test from a clean state
    if exists(TEST_TEMP_DBFILE_PATH):
        os.remove(TEST_TEMP_DBFILE_PATH) 
开发者ID:jarun,项目名称:buku,代码行数:8,代码来源:test_bukuDb.py

示例9: setUp

# 需要导入模块: import genericpath [as 别名]
# 或者: from genericpath import exists [as 别名]
def setUp(self):
        os.environ['XDG_DATA_HOME'] = TEST_TEMP_DIR_PATH

        # start every test from a clean state
        if exists(TEST_TEMP_DBFILE_PATH):
            os.remove(TEST_TEMP_DBFILE_PATH)

        self.bookmarks = TEST_BOOKMARKS
        self.bdb = BukuDb() 
开发者ID:jarun,项目名称:buku,代码行数:11,代码来源:test_bukuDb.py

示例10: test_initdb

# 需要导入模块: import genericpath [as 别名]
# 或者: from genericpath import exists [as 别名]
def test_initdb(self):
        if exists(TEST_TEMP_DBFILE_PATH):
            os.remove(TEST_TEMP_DBFILE_PATH)
        self.assertIs(False, exists(TEST_TEMP_DBFILE_PATH))
        conn, curr = BukuDb.initdb()
        self.assertIsInstance(conn, sqlite3.Connection)
        self.assertIsInstance(curr, sqlite3.Cursor)
        self.assertIs(True, exists(TEST_TEMP_DBFILE_PATH))
        curr.close()
        conn.close() 
开发者ID:jarun,项目名称:buku,代码行数:12,代码来源:test_bukuDb.py

示例11: refreshdb_fixture

# 需要导入模块: import genericpath [as 别名]
# 或者: from genericpath import exists [as 别名]
def refreshdb_fixture():
    # Setup
    os.environ['XDG_DATA_HOME'] = TEST_TEMP_DIR_PATH

    # start every test from a clean state
    if exists(TEST_TEMP_DBFILE_PATH):
        os.remove(TEST_TEMP_DBFILE_PATH)

    bdb = BukuDb()

    yield bdb

    # Teardown
    os.environ['XDG_DATA_HOME'] = TEST_TEMP_DIR_PATH 
开发者ID:jarun,项目名称:buku,代码行数:16,代码来源:test_bukuDb.py

示例12: read_image

# 需要导入模块: import genericpath [as 别名]
# 或者: from genericpath import exists [as 别名]
def read_image(img_spec,
               error_msg='image',
               num_dims=3,
               reorient_canonical=True):
    """Image reader. Removes stray values close to zero (smaller than 5 %ile)."""

    if isinstance(img_spec, str):
        if pexists(realpath(img_spec)):
            hdr = nib.load(img_spec)
            # trying to stick to an orientation
            if reorient_canonical:
                hdr = nib.as_closest_canonical(hdr)
            img = hdr.get_data()
        else:
            raise IOError('Given path to {} does not exist!\n\t{}'
                          ''.format(error_msg, img_spec))
    elif isinstance(img_spec, np.ndarray):
        img = img_spec
    else:
        raise ValueError('Invalid input specified! '
                         'Input either a path to image data, '
                         'or provide 3d Matrix directly.')

    if num_dims == 3:
        img = check_image_is_3d(img)
    elif num_dims == 4:
        check_image_is_4d(img)
    else:
        raise ValueError('Requested check for {} dims - allowed: 3 or 4!')

    if not np.issubdtype(img.dtype, np.float64):
        img = img.astype('float32')

    return img 
开发者ID:raamana,项目名称:visualqc,代码行数:36,代码来源:utils.py

示例13: restore_previous_ratings

# 需要导入模块: import genericpath [as 别名]
# 或者: from genericpath import exists [as 别名]
def restore_previous_ratings(qcw):
    """Creates a separate folder for ratings, backing up any previous sessions."""

    # making a copy
    incomplete_list = list(qcw.id_list)
    prev_done = []  # empty list

    ratings_file, backup_name_ratings = get_ratings_path_info(qcw)

    if pexists(ratings_file):
        ratings, notes = load_ratings_csv(ratings_file)
        # finding the remaining
        prev_done = set(ratings.keys())
        incomplete_list = list(set(qcw.id_list) - prev_done)
    else:
        ratings = dict()
        notes = dict()

    if len(prev_done) > 0:
        print('\nRatings for {}/{} subjects were restored.'.format(len(prev_done),
                                                                   len(qcw.id_list)))

    if len(incomplete_list) < 1:
        print('No subjects to review/rate - exiting.')
        sys.exit(0)
    else:
        print('To be reviewed : {}\n'.format(len(incomplete_list)))

    return ratings, notes, incomplete_list 
开发者ID:raamana,项目名称:visualqc,代码行数:31,代码来源:utils.py

示例14: get_ratings_path_info

# 需要导入模块: import genericpath [as 别名]
# 或者: from genericpath import exists [as 别名]
def get_ratings_path_info(qcw):
    """Common routine to construct the same names"""

    ratings_dir = pjoin(qcw.out_dir, cfg.suffix_ratings_dir)
    if not pexists(ratings_dir):
        makedirs(ratings_dir)

    file_name_ratings = '{}_{}_{}'.format(qcw.vis_type, qcw.suffix, cfg.file_name_ratings)
    ratings_file = pjoin(ratings_dir, file_name_ratings)
    prev_ratings_backup = pjoin(ratings_dir,
                                '{}_{}'.format(cfg.prefix_backup, file_name_ratings))

    return ratings_file, prev_ratings_backup 
开发者ID:raamana,项目名称:visualqc,代码行数:15,代码来源:utils.py

示例15: check_input_dir

# 需要导入模块: import genericpath [as 别名]
# 或者: from genericpath import exists [as 别名]
def check_input_dir(fs_dir, user_dir, vis_type,
                    freesurfer_install_required=True):
    """Ensures proper input is specified."""

    in_dir = fs_dir
    if fs_dir is None and user_dir is None:
        raise ValueError('At least one of --fs_dir or --user_dir must be specified.')

    if fs_dir is not None:
        if user_dir is not None:
            raise ValueError('Only one of --fs_dir or --user_dir can be specified.')

        if freesurfer_install_required and not freesurfer_installed():
            raise EnvironmentError('Freesurfer functionality is requested (e.g. '
                                   'visualizing annotations), but is not installed!')

    if fs_dir is None and vis_type in freesurfer_vis_types:
        raise ValueError('vis_type depending on Freesurfer organization is specified,'
                         ' but --fs_dir is not provided.')

    if user_dir is None:
        if not pexists(fs_dir):
            raise IOError('Freesurfer directory specified does not exist!')
        else:
            in_dir = fs_dir
            type_of_features = 'freesurfer'
    elif fs_dir is None:
        if not pexists(user_dir):
            raise IOError('User-specified input directory does not exist!')
        else:
            in_dir = user_dir
            type_of_features = 'generic'

    if not pexists(in_dir):
        raise IOError('Invalid specification - check proper combination '
                      'of --fs_dir and --user_dir')

    return in_dir, type_of_features 
开发者ID:raamana,项目名称:visualqc,代码行数:40,代码来源:utils.py


注:本文中的genericpath.exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。