Python源码示例:distutils.dir.mkpath()
示例1
def run(self):
"""Run the command"""
srcdir = os.path.join('docs', 'man')
manpages = os.listdir(srcdir)
self._outfiles = []
for man in manpages:
src_man = os.path.join(srcdir, man)
section = os.path.splitext(man)[1][1:]
dest_dir = os.path.join(self.prefix, 'man' + section)
self.mkpath(dest_dir) # Could be different section
dest_man = os.path.join(dest_dir, man)
self.copy_file(src_man, dest_man)
self._outfiles.append(dest_man)
# Disabled, done in the RPM spec
# self._write_record()
示例2
def make_name(opt, prefix="", eval_=False, is_dir=True, set_epoch=None,
do_epoch=True):
string = prefix
string += "{}-{}".format(opt.dataset, opt.exp)
string += "/"
string += "{}-{}-{}".format(opt.trainer, opt.cycle, opt.iters)
string += "/"
string += opt.model
if opt.mle:
string += "-{}".format(opt.mle)
string += "/"
string += make_name_string(opt.data) + "/"
string += make_name_string(opt.net) + "/"
string += make_name_string(opt.train.static) + "/"
if eval_:
string += make_name_string(opt.eval) + "/"
# mkpath caches whether a directory has been created
# In IPython, this can be a problem if the kernel is
# not reset after a dir is deleted. Trying to recreate
# that dir will be a problem because mkpath will think
# the directory already exists
if not is_dir:
mkpath(string)
string += make_name_string(
opt.train.dynamic, True, do_epoch, set_epoch)
if is_dir:
mkpath(string)
return string
示例3
def generate_config_files(type_, key, name="base", eval_mode=False):
with open("config/default.json".format(type_), "r") as f:
base_config = json.load(f)
with open("config/{}/default.json".format(type_), "r") as f:
base_config_2 = json.load(f)
if eval_mode:
with open("config/{}/eval_changes.json".format(type_), "r") as f:
changes_by_machine = json.load(f)
else:
with open("config/{}/changes.json".format(type_), "r") as f:
changes_by_machine = json.load(f)
base_config.update(base_config_2)
if name in changes_by_machine:
changes = changes_by_machine[name]
else:
changes = changes_by_machine["base"]
# for param in changes[key]:
# base_config[param] = changes[key][param]
replace_params(base_config, changes[key])
mkpath("config/{}".format(type_))
with open("config/{}/config_{}.json".format(type_, key), "w") as f:
json.dump(base_config, f, indent=4)
示例4
def mkpath(self, name, mode=0777):
dir_util.mkpath(name, mode, dry_run=self.dry_run)
示例5
def _copy_files(self, filelist):
self.outfiles = []
if not filelist:
return
self.mkpath(self.install_dir)
for f in filelist:
self.copy_file(f, self.install_dir)
self.outfiles.append(os.path.join(self.install_dir, f))
示例6
def mkpath(self, name, mode=0777):
mkpath(name, mode, dry_run=self.dry_run)
# class CCompiler
# Map a sys.platform/os.name ('posix', 'nt') to the default compiler
# type for that platform. Keys are interpreted as re match
# patterns. Order is important; platform mappings are preferred over
# OS names.
示例7
def mkpath(self, name, mode=0777):
dir_util.mkpath(name, mode, dry_run=self.dry_run)
示例8
def _copy_files(self, filelist):
self.outfiles = []
if not filelist:
return
self.mkpath(self.install_dir)
for f in filelist:
self.copy_file(f, self.install_dir)
self.outfiles.append(os.path.join(self.install_dir, f))
示例9
def mkpath(self, name, mode=0777):
mkpath(name, mode, dry_run=self.dry_run)
# class CCompiler
# Map a sys.platform/os.name ('posix', 'nt') to the default compiler
# type for that platform. Keys are interpreted as re match
# patterns. Order is important; platform mappings are preferred over
# OS names.
示例10
def mkpath(self, name, mode=0777):
dir_util.mkpath(name, mode, dry_run=self.dry_run)
示例11
def _copy_files(self, filelist):
self.outfiles = []
if not filelist:
return
self.mkpath(self.install_dir)
for f in filelist:
self.copy_file(f, self.install_dir)
self.outfiles.append(os.path.join(self.install_dir, f))
示例12
def mkpath(self, name, mode=0777):
mkpath(name, mode, dry_run=self.dry_run)
# class CCompiler
# Map a sys.platform/os.name ('posix', 'nt') to the default compiler
# type for that platform. Keys are interpreted as re match
# patterns. Order is important; platform mappings are preferred over
# OS names.
示例13
def mkpath(self, name, mode=0777):
dir_util.mkpath(name, mode, dry_run=self.dry_run)
示例14
def _copy_files(self, filelist):
self.outfiles = []
if not filelist:
return
self.mkpath(self.install_dir)
for f in filelist:
self.copy_file(f, self.install_dir)
self.outfiles.append(os.path.join(self.install_dir, f))
示例15
def mkpath(self, name, mode=0777):
mkpath(name, mode, dry_run=self.dry_run)
# class CCompiler
# Map a sys.platform/os.name ('posix', 'nt') to the default compiler
# type for that platform. Keys are interpreted as re match
# patterns. Order is important; platform mappings are preferred over
# OS names.
示例16
def mkpath(self, name, mode=0777):
dir_util.mkpath(name, mode, dry_run=self.dry_run)
示例17
def _copy_files(self, filelist):
self.outfiles = []
if not filelist:
return
self.mkpath(self.install_dir)
for f in filelist:
self.copy_file(f, self.install_dir)
self.outfiles.append(os.path.join(self.install_dir, f))
示例18
def mkpath(self, name, mode=0777):
mkpath(name, mode, dry_run=self.dry_run)
# class CCompiler
# Map a sys.platform/os.name ('posix', 'nt') to the default compiler
# type for that platform. Keys are interpreted as re match
# patterns. Order is important; platform mappings are preferred over
# OS names.
示例19
def pack(self, dst_path):
'''Pack pipeline to zip file.
Args:
dst_path: Path to store zipfile. E.g 'test/my_cool_pipe.zip'
'''
# Do everything relative from pipeline definition file path.
tmp = dict()
used_lib_paths = dict()
used_static_paths = dict()
tmp_path = os.path.abspath('tmp_pipe_packer')
tmp['root'] = os.path.join(tmp_path, self.pipe['name'])
dst = os.path.abspath(dst_path)
oldwd = os.getcwd()
os.chdir(self.pipe_template_path)
for pe_j in self.pipe['elements']:
if 'script' in pe_j:
element_j = pe_j['script']
script = parse_script(element_j)
src_script_dir_path = os.path.split(script.path)[0]
# Calculate all paths
tmp['script.rel'] = os.path.splitext(os.path.basename(script.path))[0]
tmp['script.abs'] = os.path.join(tmp['root'], tmp['script.rel'])
# Create folder structure
if not os.path.exists(tmp['script.abs']):
dir_util.mkpath(tmp['script.abs'])
# Copy files
dir_util.copy_tree(src_script_dir_path, tmp['script.abs'])
logging.info("Copyed script from %s to %s"%(src_script_dir_path,
tmp['script.abs']))
script_name = os.path.basename(script.path)
# Write new paths to back to json dict
element_j['path'] = script_name
with open(join(tmp['root'], os.path.basename(self.json_path)), 'w') as outfile:
json.dump(self.pipe, outfile)
fm.zipdir(src=tmp['root'], dst=dst)
dir_util.remove_tree(tmp_path)
os.chdir(oldwd) # Change dir back to old working directory.
示例20
def mkpath(self, name, mode=0o777):
dir_util.mkpath(name, mode, dry_run=self.dry_run)
示例21
def _copy_files(self, filelist):
self.outfiles = []
if not filelist:
return
self.mkpath(self.install_dir)
for f in filelist:
self.copy_file(f, self.install_dir)
self.outfiles.append(os.path.join(self.install_dir, f))
示例22
def mkpath(self, name, mode=0o777):
dir_util.mkpath(name, mode, dry_run=self.dry_run)
示例23
def _copy_files(self, filelist):
self.outfiles = []
if not filelist:
return
self.mkpath(self.install_dir)
for f in filelist:
self.copy_file(f, self.install_dir)
self.outfiles.append(os.path.join(self.install_dir, f))
示例24
def mkpath(self, name, mode=0o777):
dir_util.mkpath(name, mode, dry_run=self.dry_run)
示例25
def mkpath (self, name, mode=0o777):
mkpath(name, mode, dry_run=self.dry_run)
# Map a sys.platform/os.name ('posix', 'nt') to the default compiler
# type for that platform. Keys are interpreted as re match
# patterns. Order is important; platform mappings are preferred over
# OS names.
示例26
def mkpath(self, name, mode=0o777):
dir_util.mkpath(name, mode, dry_run=self.dry_run)
示例27
def _copy_files(self, filelist):
self.outfiles = []
if not filelist:
return
self.mkpath(self.install_dir)
for f in filelist:
self.copy_file(f, self.install_dir)
self.outfiles.append(os.path.join(self.install_dir, f))
示例28
def mkpath (self, name, mode=0o777):
mkpath(name, mode, dry_run=self.dry_run)
# Map a sys.platform/os.name ('posix', 'nt') to the default compiler
# type for that platform. Keys are interpreted as re match
# patterns. Order is important; platform mappings are preferred over
# OS names.
示例29
def mkpath(self, name, mode=0777):
dir_util.mkpath(name, mode, dry_run=self.dry_run)
示例30
def _copy_files(self, filelist):
self.outfiles = []
if not filelist:
return
self.mkpath(self.install_dir)
for f in filelist:
self.copy_file(f, self.install_dir)
self.outfiles.append(os.path.join(self.install_dir, f))