python类copyfile()的实例源码

rotational_temp.py 文件源码 项目:sail 作者: GemHunt 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def create_single_lmdb(seed_image_id, filedata, test_id, multi_image_training=False, images_per_angle=500,
                       retraining=False):
    start_time = time.time()
    print 'create_single_lmdb for ' + str(seed_image_id)

    if retraining:
        weight_filename = 'snapshot_iter_16880.caffemodel'
        shutil.copyfile(train_dir + str(seed_image_id) + '/' + weight_filename, train_dir + weight_filename)
    else:
        weight_filename = 'starting-weights.caffemodel'
        shutil.copyfile(weight_filename, train_dir + weight_filename)

    lmdb_dir = train_dir + str(seed_image_id) + '/'

    create_lmdb_rotate_whole_image.create_lmdbs(filedata, lmdb_dir, images_per_angle, -1, True, False)
    copy_train_files(lmdb_dir, multi_image_training)
    create_train_script(lmdb_dir, train_dir + weight_filename, multi_image_training)
    print 'Done in %s seconds' % (time.time() - start_time,)
rotational.py 文件源码 项目:sail 作者: GemHunt 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def create_single_lmdb(seed_image_id, filedata, test_id, multi_image_training=False, images_per_angle=500,
                       retraining=False):
    start_time = time.time()
    print 'create_single_lmdb for ' + str(seed_image_id)

    if retraining:
        weight_filename = 'snapshot_iter_16880.caffemodel'
        shutil.copyfile(train_dir + str(seed_image_id) + '/' + weight_filename, train_dir + weight_filename)
    else:
        weight_filename = 'starting-weights.caffemodel'
        shutil.copyfile(weight_filename, train_dir + weight_filename)

    lmdb_dir = train_dir + str(seed_image_id) + '/'

    create_lmdb_rotate_whole_image.create_lmdbs(filedata, lmdb_dir, images_per_angle, True, False)
    copy_train_files(lmdb_dir, multi_image_training)
    create_train_script(lmdb_dir, train_dir + weight_filename, multi_image_training)
    print 'Done in %s seconds' % (time.time() - start_time,)
util.py 文件源码 项目:jira_worklog_scanner 作者: pgarneau 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def copy_file(self, infile, outfile, check=True):
        """Copy a file respecting dry-run and force flags.
        """
        self.ensure_dir(os.path.dirname(outfile))
        logger.info('Copying %s to %s', infile, outfile)
        if not self.dry_run:
            msg = None
            if check:
                if os.path.islink(outfile):
                    msg = '%s is a symlink' % outfile
                elif os.path.exists(outfile) and not os.path.isfile(outfile):
                    msg = '%s is a non-regular file' % outfile
            if msg:
                raise ValueError(msg + ' which would be overwritten')
            shutil.copyfile(infile, outfile)
        self.record_as_written(outfile)
archive_util.py 文件源码 项目:jira_worklog_scanner 作者: pgarneau 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def unpack_directory(filename, extract_dir, progress_filter=default_filter):
    """"Unpack" a directory, using the same interface as for archives

    Raises ``UnrecognizedFormat`` if `filename` is not a directory
    """
    if not os.path.isdir(filename):
        raise UnrecognizedFormat("%s is not a directory" % filename)

    paths = {
        filename: ('', extract_dir),
    }
    for base, dirs, files in os.walk(filename):
        src, dst = paths[base]
        for d in dirs:
            paths[os.path.join(base, d)] = src + d + '/', os.path.join(dst, d)
        for f in files:
            target = os.path.join(dst, f)
            target = progress_filter(src + f, target)
            if not target:
                # skip non-files
                continue
            ensure_directory(target)
            f = os.path.join(base, f)
            shutil.copyfile(f, target)
            shutil.copystat(f, target)
marionette.py 文件源码 项目:ave 作者: sonyxperiadev 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def generate_report(pretty, json_file):
    '''
    Generates a report from a static JSON result file
    '''
    # setup workspace
    ws = Workspace('test-files-marionette')
    ws_json_file = os.path.join(ws.make_tempdir(), json_file)
    # copy static json result file to workspace
    shutil.copyfile(os.path.join(TEST_DATA_PATH, json_file), ws_json_file)
    # create a random test name for decibel
    buff = []
    for i in range(10):
        buff.append(random.randint(0,9))
    name = ''.join(['%d' % i for i in buff])
    # create time stamp for report
    time = datetime.now()
    start_time = time.strftime("%Y-%m-%d %H:%M:%S")
    end_time = (time + timedelta(seconds=1)).strftime("%Y-%m-%d %H:%M:%S")
    # try to generate report.

    # delete workspace.
    ws.delete()
    # check if decibel reported 200 (ok) in response.

    return name, start_time, end_time
marionette.py 文件源码 项目:ave 作者: sonyxperiadev 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def generate_report(pretty, json_file):
    '''
    Generates a report from a static JSON result file
    '''
    # setup workspace
    ws = Workspace('test-files-marionette')
    ws_json_file = os.path.join(ws.make_tempdir(), json_file)
    # copy static json result file to workspace
    shutil.copyfile(os.path.join(TEST_DATA_PATH, json_file), ws_json_file)
    # create a random test name for decibel
    buff = []
    for i in range(10):
        buff.append(random.randint(0,9))
    name = ''.join(['%d' % i for i in buff])
    # create time stamp for report
    time = datetime.now()
    start_time = time.strftime("%Y-%m-%d %H:%M:%S")
    end_time = (time + timedelta(seconds=1)).strftime("%Y-%m-%d %H:%M:%S")
    # try to generate report.

    # delete workspace.
    ws.delete()
    # check if decibel reported 200 (ok) in response.

    return name, start_time, end_time
build_docs.py 文件源码 项目:aws-go-developer-guide 作者: awsdocs 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def copy_dir_contents_with_overwrite(input_dir_name, output_dir_name):
    """Copy the contents of a directory into another, overwriting files if they
    exist."""

    # if output_dir_name isn't a location, make it so.
    if not os.path.exists(output_dir_name):
        os.makedirs(output_dir_name)

    dir_entries = os.listdir(input_dir_name)

    for dir_entry in dir_entries:
        input_path = os.path.join(input_dir_name, dir_entry)
        output_path = os.path.join(output_dir_name, dir_entry)

        if os.path.isdir(input_path):
            copy_dir_contents_with_overwrite(input_path, output_path)
        else:
            shutil.copyfile(input_path, output_path)
manage.py 文件源码 项目:veneer-py 作者: flowmatters 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def overwrite_plugin_configuration(source_binaries,project_fn):
    plugin_fn = _find_plugins_file(project_fn)
    if not plugin_fn:
        # logger.warn('Unable to overwrite plugins. No Plugin.xml found')
        return
    print(plugin_fn)

    if os.path.isfile(source_binaries):
        source_binaries = os.path.join(os.path.dirname(source_binaries),'RiverSystem.Forms.exe')

    source_version = '.'.join([str(v) for v in _get_version_number(source_binaries)[00:-1]])
    print(source_version)

    plugin_dir = os.path.join('C:\\','Users',os.environ['USERNAME'],'AppData','Roaming','Source',source_version)
    if not os.path.exists(plugin_dir):
        os.makedirs(plugin_dir)
    plugin_dest_file = os.path.join(plugin_dir,'Plugins.xml')
    shutil.copyfile(plugin_fn,plugin_dest_file)
util.py 文件源码 项目:zanph 作者: zanph 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def copy_file(self, infile, outfile, check=True):
        """Copy a file respecting dry-run and force flags.
        """
        self.ensure_dir(os.path.dirname(outfile))
        logger.info('Copying %s to %s', infile, outfile)
        if not self.dry_run:
            msg = None
            if check:
                if os.path.islink(outfile):
                    msg = '%s is a symlink' % outfile
                elif os.path.exists(outfile) and not os.path.isfile(outfile):
                    msg = '%s is a non-regular file' % outfile
            if msg:
                raise ValueError(msg + ' which would be overwritten')
            shutil.copyfile(infile, outfile)
        self.record_as_written(outfile)
archive_util.py 文件源码 项目:zanph 作者: zanph 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def unpack_directory(filename, extract_dir, progress_filter=default_filter):
    """"Unpack" a directory, using the same interface as for archives

    Raises ``UnrecognizedFormat`` if `filename` is not a directory
    """
    if not os.path.isdir(filename):
        raise UnrecognizedFormat("%s is not a directory" % filename)

    paths = {
        filename: ('', extract_dir),
    }
    for base, dirs, files in os.walk(filename):
        src, dst = paths[base]
        for d in dirs:
            paths[os.path.join(base, d)] = src + d + '/', os.path.join(dst, d)
        for f in files:
            target = os.path.join(dst, f)
            target = progress_filter(src + f, target)
            if not target:
                # skip non-files
                continue
            ensure_directory(target)
            f = os.path.join(base, f)
            shutil.copyfile(f, target)
            shutil.copystat(f, target)
mccdl.py 文件源码 项目:mccdl 作者: jkoelndorfer 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def create(self, minecraft_version, forge_version, icon_path=None):
        self.logger.info("Creating MultiMC instance %s, Minecraft version %s, Forge version %s",
                         self.name, minecraft_version, forge_version)
        if os.path.exists(self.directory):
            errmsg = "MultiMC instance {} already exists".format(self.name)
            raise MultiMcInstanceExistsError(errmsg)
        os.makedirs(self.mods_directory)

        multimc_icon_key = None
        if icon_path is not None:
            multimc_icon_filename = "mccdl_" + os.path.basename(icon_path)
            multimc_icon_key = os.path.splitext(multimc_icon_filename)[0]
            shutil.copyfile(
                icon_path, os.path.join(self.instance_manager.multimc_directory, "icons", multimc_icon_filename)
            )
        self.configure(minecraft_version, forge_version, icon_key=multimc_icon_key)
util.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def copy_file(self, infile, outfile, check=True):
        """Copy a file respecting dry-run and force flags.
        """
        self.ensure_dir(os.path.dirname(outfile))
        logger.info('Copying %s to %s', infile, outfile)
        if not self.dry_run:
            msg = None
            if check:
                if os.path.islink(outfile):
                    msg = '%s is a symlink' % outfile
                elif os.path.exists(outfile) and not os.path.isfile(outfile):
                    msg = '%s is a non-regular file' % outfile
            if msg:
                raise ValueError(msg + ' which would be overwritten')
            shutil.copyfile(infile, outfile)
        self.record_as_written(outfile)
util.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def copy_file(self, infile, outfile, check=True):
        """Copy a file respecting dry-run and force flags.
        """
        self.ensure_dir(os.path.dirname(outfile))
        logger.info('Copying %s to %s', infile, outfile)
        if not self.dry_run:
            msg = None
            if check:
                if os.path.islink(outfile):
                    msg = '%s is a symlink' % outfile
                elif os.path.exists(outfile) and not os.path.isfile(outfile):
                    msg = '%s is a non-regular file' % outfile
            if msg:
                raise ValueError(msg + ' which would be overwritten')
            shutil.copyfile(infile, outfile)
        self.record_as_written(outfile)
pyGamitSession.py 文件源码 项目:Parallel.GAMIT 作者: demiangomez 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def copy_sestbl_procdef_atx(self):
        # copy process.defaults and sestbl.
        copyfile(self.GamitOpts['process_defaults'], os.path.join(self.pwd_tables, 'process.defaults'))
        copyfile(self.GamitOpts['atx'], os.path.join(self.pwd_tables, 'antmod.dat'))

        # change the scratch directory in the sestbl. file
        #copyfile(self.GamitOpts['sestbl'], os.path.join(self.pwd_tables, 'sestbl.'))

        with open(os.path.join(self.pwd_tables, 'sestbl.'), 'w') as sestbl:
            with open(self.GamitOpts['sestbl']) as orig_sestbl:
                for line in orig_sestbl:
                    if 'Scratch directory' in line:
                        # empty means local directory! LA RE PU...
                        sestbl.write('Scratch directory = \n')
                    else:
                        sestbl.write(line)

        return
test.py 文件源码 项目:meteos 作者: openstack 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __init__(self, db_session, db_migrate, sql_connection, sqlite_db,
                 sqlite_clean_db):
        self.sql_connection = sql_connection
        self.sqlite_db = sqlite_db
        self.sqlite_clean_db = sqlite_clean_db
        self.engine = db_session.get_engine()
        self.engine.dispose()
        conn = self.engine.connect()
        if sql_connection == "sqlite://":
            self.setup_sqlite(db_migrate)
        else:
            testdb = os.path.join(CONF.state_path, sqlite_db)
            db_migrate.upgrade('head')
            if os.path.exists(testdb):
                return
        if sql_connection == "sqlite://":
            conn = self.engine.connect()
            self._DB = "".join(line for line in conn.connection.iterdump())
            self.engine.dispose()
        else:
            cleandb = os.path.join(CONF.state_path, sqlite_clean_db)
            shutil.copyfile(testdb, cleandb)
base.py 文件源码 项目:gluon 作者: openstack 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, db_api, sql_connection,
                 sqlite_db, sqlite_clean_db):
        self.sql_connection = sql_connection
        self.sqlite_db = sqlite_db
        self.sqlite_clean_db = sqlite_clean_db
        self.engine = db_api.get_engine()
        self.engine.dispose()
        conn = self.engine.connect()
        if sql_connection == "sqlite://":
            self.setup_sqlite()
        elif sql_connection.startswith('sqlite:///'):
            testdb = paths.state_path_rel(sqlite_db)
            self.setup_sqlite()
        self.post_migrations()
        if sql_connection == "sqlite://":
            conn = self.engine.connect()
            self._DB = "".join(line for line in conn.connection.iterdump())
            self.engine.dispose()
        else:
            cleandb = paths.state_path_rel(sqlite_clean_db)
            try:
                shutil.copyfile(testdb, cleandb)
            except Exception:
                pass
util.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def copy_file(self, infile, outfile, check=True):
        """Copy a file respecting dry-run and force flags.
        """
        self.ensure_dir(os.path.dirname(outfile))
        logger.info('Copying %s to %s', infile, outfile)
        if not self.dry_run:
            msg = None
            if check:
                if os.path.islink(outfile):
                    msg = '%s is a symlink' % outfile
                elif os.path.exists(outfile) and not os.path.isfile(outfile):
                    msg = '%s is a non-regular file' % outfile
            if msg:
                raise ValueError(msg + ' which would be overwritten')
            shutil.copyfile(infile, outfile)
        self.record_as_written(outfile)
archive_util.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def unpack_directory(filename, extract_dir, progress_filter=default_filter):
    """"Unpack" a directory, using the same interface as for archives

    Raises ``UnrecognizedFormat`` if `filename` is not a directory
    """
    if not os.path.isdir(filename):
        raise UnrecognizedFormat("%s is not a directory" % filename)

    paths = {
        filename: ('', extract_dir),
    }
    for base, dirs, files in os.walk(filename):
        src, dst = paths[base]
        for d in dirs:
            paths[os.path.join(base, d)] = src + d + '/', os.path.join(dst, d)
        for f in files:
            target = os.path.join(dst, f)
            target = progress_filter(src + f, target)
            if not target:
                # skip non-files
                continue
            ensure_directory(target)
            f = os.path.join(base, f)
            shutil.copyfile(f, target)
            shutil.copystat(f, target)
util.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def copy_file(self, infile, outfile, check=True):
        """Copy a file respecting dry-run and force flags.
        """
        self.ensure_dir(os.path.dirname(outfile))
        logger.info('Copying %s to %s', infile, outfile)
        if not self.dry_run:
            msg = None
            if check:
                if os.path.islink(outfile):
                    msg = '%s is a symlink' % outfile
                elif os.path.exists(outfile) and not os.path.isfile(outfile):
                    msg = '%s is a non-regular file' % outfile
            if msg:
                raise ValueError(msg + ' which would be overwritten')
            shutil.copyfile(infile, outfile)
        self.record_as_written(outfile)
archive_util.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def unpack_directory(filename, extract_dir, progress_filter=default_filter):
    """"Unpack" a directory, using the same interface as for archives

    Raises ``UnrecognizedFormat`` if `filename` is not a directory
    """
    if not os.path.isdir(filename):
        raise UnrecognizedFormat("%s is not a directory" % filename)

    paths = {
        filename: ('', extract_dir),
    }
    for base, dirs, files in os.walk(filename):
        src, dst = paths[base]
        for d in dirs:
            paths[os.path.join(base, d)] = src + d + '/', os.path.join(dst, d)
        for f in files:
            target = os.path.join(dst, f)
            target = progress_filter(src + f, target)
            if not target:
                # skip non-files
                continue
            ensure_directory(target)
            f = os.path.join(base, f)
            shutil.copyfile(f, target)
            shutil.copystat(f, target)


问题


面经


文章

微信
公众号

扫码关注公众号