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,)
python类copyfile()的实例源码
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,)
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)
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)
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
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
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)
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)
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)
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)
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)
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)
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)
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
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)
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
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)
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)
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)
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)