本文整理汇总了Python中os.mkdir方法的典型用法代码示例。如果您正苦于以下问题:Python os.mkdir方法的具体用法?Python os.mkdir怎么用?Python os.mkdir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.mkdir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_model_directory
# 需要导入模块: import os [as 别名]
# 或者: from os import mkdir [as 别名]
def create_model_directory(args):
# create necessary directories
if os.path.isdir("models_{name}".format(name=args.name)):
print("Directory models_{name} already exists, old files will be overwritten".format(name=args.name), file=sys.stderr)
else:
os.mkdir("models_{name}".format(name=args.name))
os.mkdir("models_{name}/Data".format(name=args.name))
os.mkdir("models_{name}/Tokenizer".format(name=args.name))
# copy necessary files
if args.embeddings: # embeddings
copyfile(args.embeddings, "models_{name}/Data/embeddings.vectors".format(name=args.name))
copyfile("{config}/pipelines.yaml".format(config=args.config_directory), "models_{name}/pipelines.yaml".format(name=args.name))
process_morpho(args) # train/dev files for tagger/parser
process_config(args) # configs for tagger/parser
示例2: main
# 需要导入模块: import os [as 别名]
# 或者: from os import mkdir [as 别名]
def main(arguments):
parser = argparse.ArgumentParser()
parser.add_argument('--data_dir', help='directory to save data to', type=str, default='glue_data')
parser.add_argument('--tasks', help='tasks to download data for as a comma separated string',
type=str, default='all')
parser.add_argument('--path_to_mrpc',
help='path to directory containing extracted MRPC data, msr_paraphrase_train.txt and msr_paraphrase_text.txt',
type=str, default='')
args = parser.parse_args(arguments)
if not os.path.isdir(args.data_dir):
os.mkdir(args.data_dir)
tasks = get_tasks(args.tasks)
for task in tasks:
if task == 'MRPC':
format_mrpc(args.data_dir, args.path_to_mrpc)
elif task == 'diagnostic':
download_diagnostic(args.data_dir)
else:
download_and_extract(task, args.data_dir)
示例3: download
# 需要导入模块: import os [as 别名]
# 或者: from os import mkdir [as 别名]
def download(url, filename, cache_directory):
filename_cache = url.split('/')[-1]
filename_cache = ''.join([c for c in filename_cache if c.isdigit() or c.isalpha()])
filename_cache = cache_directory + "/" + filename_cache
if os.path.exists(filename):
return
elif os.path.exists(filename_cache):
print("Already downloaded")
shutil.copyfile(filename_cache, filename)
else:
print("\nDownloading {} from {}".format(filename, url))
os.mkdir(cache_directory)
# wget.download(url, out=filename_cache)
obj = SmartDL(url, filename_cache)
obj.start()
shutil.copyfile(filename_cache, filename)
示例4: plot_alignment
# 需要导入模块: import os [as 别名]
# 或者: from os import mkdir [as 别名]
def plot_alignment(alignment, gs, dir=hp.logdir):
"""Plots the alignment.
Args:
alignment: A numpy array with shape of (encoder_steps, decoder_steps)
gs: (int) global step.
dir: Output path.
"""
if not os.path.exists(dir): os.mkdir(dir)
fig, ax = plt.subplots()
im = ax.imshow(alignment)
fig.colorbar(im)
plt.title('{} Steps'.format(gs))
plt.savefig('{}/alignment_{}.png'.format(dir, gs), format='png')
plt.close(fig)
示例5: test_extraction
# 需要导入模块: import os [as 别名]
# 或者: from os import mkdir [as 别名]
def test_extraction():
import shutil
src = 'c:/Users/shinj/Downloads/clonezilla-live-2.5.2-31-amd64.iso'
tmp_dir = 'c:/Users/shinj/Documents/tmp'
for subdir, pattern in [
('single_string', 'EFI/'),
('single_list', ['EFI/']),
('multi', ['EFI/', 'syslinux/']),
('all', None) ]:
dest_dir = os.path.join(tmp_dir, subdir)
if os.path.exists(dest_dir):
shutil.rmtree(dest_dir)
os.mkdir(dest_dir)
args = [src, dest_dir]
if pattern is not None:
args.append(pattern)
print ('Calling extract_iso(%s)' % args)
extract_iso(*args)
示例6: merge_bam_files
# 需要导入模块: import os [as 别名]
# 或者: from os import mkdir [as 别名]
def merge_bam_files(bams_per_genome, out, threads):
"""
Merges (+sort +index) all given bam files per genome (exact paths, single sample/multiple runs or multiple samples)
"""
out_path = os.path.join(out,"bam")
os.mkdir(out_path)
for genome in bams_per_genome:
list_of_bam = " ".join(bams_per_genome[genome]) # can be used as input to samtools immediately
header = fix_headers(genome, bams_per_genome[genome], out_path)
if header is not None:
for bam in bams_per_genome[genome]: # add new header to all bam files
cmd = "samtools reheader {header} {bam} >> {out}/out.bam; mv {out}/out.bam {bam}".format(
header = header,
out = out_path,
bam = bam
)
subprocess.call([cmd],shell=True)
cmd = "samtools merge -@ {threads} - {bam_files} | samtools sort -@ {threads} - {path}/{genome}; samtools index {path}/{genome}.bam".format(
threads = threads,
bam_files = list_of_bam,
path = out_path,
genome = genome
)
subprocess.call([cmd],shell=True) # this runs a single command at a time (but that one multi threaded)
return out_path
示例7: _prepare_simulation_subfolder
# 需要导入模块: import os [as 别名]
# 或者: from os import mkdir [as 别名]
def _prepare_simulation_subfolder(self, directory_strains):
"""
Create strain directory and copy templates and parameter file into it.
@param directory_strains: Directory for the simulated strains
@type directory_strains: str | unicode
@return: Nothing
@rtype: None
"""
if not os.path.exists(directory_strains):
os.mkdir(directory_strains)
for filename in self._directory_template_filenames:
src = os.path.join(self._directory_template, filename)
dst = os.path.join(directory_strains, filename)
shutil.copy(src, dst)
示例8: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import mkdir [as 别名]
def __init__(self, config_file):
# config = ConfigParser()
super().__init__()
self.test = None
self.train = None
config = myconf()
config.read(config_file)
self._config = config
self.config_file = config_file
print('Loaded config file sucessfully.')
for section in config.sections():
for k, v in config.items(section):
print(k, ":", v)
if not os.path.isdir(self.save_direction):
os.mkdir(self.save_direction)
config.write(open(config_file, 'w'))
示例9: get_payload_output
# 需要导入模块: import os [as 别名]
# 或者: from os import mkdir [as 别名]
def get_payload_output(payload_output_dir):
""" Builds directory structure if output option is supplied """
output_dir = payload_output_dir
# check to see if the trailing slash has been added to the path : ie /root/path
if not output_dir.endswith("/"):
output_dir = output_dir + "/"
# creates the structure if it doesn't exist
if not os.path.isdir(output_dir):
print(yellowtxt("[!] Creating output directory structure"))
os.mkdir(output_dir)
os.chdir(output_dir)
os.mkdir('handlers')
return output_dir
###############################
### Helper Function ###
###############################
示例10: evaluate_detections
# 需要导入模块: import os [as 别名]
# 或者: from os import mkdir [as 别名]
def evaluate_detections(self, detections):
"""
top level evaluations
Parameters:
----------
detections: list
result list, each entry is a matrix of detections
Returns:
----------
None
"""
# make all these folders for results
result_dir = os.path.join(self.devkit_path, 'results')
if not os.path.exists(result_dir):
os.mkdir(result_dir)
year_folder = os.path.join(self.devkit_path, 'results', 'VOC' + self.year)
if not os.path.exists(year_folder):
os.mkdir(year_folder)
res_file_folder = os.path.join(self.devkit_path, 'results', 'VOC' + self.year, 'Main')
if not os.path.exists(res_file_folder):
os.mkdir(res_file_folder)
self.write_pascal_results(detections)
self.do_python_eval()
示例11: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import mkdir [as 别名]
def __init__(self, name, root_path):
"""
basic information about an image database
:param root_path: root path store cache and proposal data
"""
self._name = name
self._root_path = root_path
# abstract attributes
self._classes = []
self._roidb = []
# create cache
cache_folder = os.path.join(self._root_path, 'cache')
if not os.path.exists(cache_folder):
os.mkdir(cache_folder)
示例12: copy_dependencies
# 需要导入模块: import os [as 别名]
# 或者: from os import mkdir [as 别名]
def copy_dependencies(f):
config_path = '/etc/yangcatalog/yangcatalog.conf'
config = ConfigParser.ConfigParser()
config._interpolation = ConfigParser.ExtendedInterpolation()
config.read(config_path)
yang_models = config.get('Directory-Section', 'save-file-dir')
tmp = config.get('Directory-Section', 'temp')
out = f.getvalue()
letters = string.ascii_letters
suffix = ''.join(random.choice(letters) for i in range(8))
dep_dir = '{}/yangvalidator-dependencies-{}'.format(tmp, suffix)
os.mkdir(dep_dir)
dependencies = out.split(':')[1].strip().split(' ')
for dep in dependencies:
for file in glob.glob(r'{}/{}*.yang'.format(yang_models, dep)):
shutil.copy(file, dep_dir)
return dep_dir
示例13: download
# 需要导入模块: import os [as 别名]
# 或者: from os import mkdir [as 别名]
def download(name, root_path=default_root_path):
if not os.path.exists(os.path.join(root_path, 'benchmark')):
os.mkdir(os.path.join(root_path, 'benchmark'))
if not os.path.exists(os.path.join(root_path, 'pretrain')):
os.mkdir(os.path.join(root_path, 'pretrain'))
if name == 'nyt10':
download_nyt10(root_path=root_path)
elif name == 'semeval':
download_semeval(root_path=root_path)
elif name == 'wiki80':
download_wiki80(root_path=root_path)
elif name == 'glove':
download_glove(root_path=root_path)
elif name == 'bert_base_uncased':
download_bert_base_uncased(root_path=root_path)
else:
raise Exception('Cannot find corresponding data.')
示例14: GetBaseImage
# 需要导入模块: import os [as 别名]
# 或者: from os import mkdir [as 别名]
def GetBaseImage(self, baseimage=None):
"""Downloads the base installer dmg."""
baseos_path = os.path.join(self.cwd, BUILD,
'BaseOS')
baseos_dmg = os.path.join(self.cwd, BUILD,
'BaseOS/Mac OS X Install DVD.dmg')
try:
os.mkdir(baseos_path)
except OSError:
pass
if not os.path.exists(baseos_dmg):
print 'Base image not found, getting latest one.'
if not baseimage:
src = os.path.join(self.webserver, 'osx_base',
'%s-default-base.dmg' % self.os_version)
else:
src = baseimage
tgt = os.path.join(self.cwd, BUILD, 'BaseOS/Mac OS X Install DVD.dmg')
self.DownloadFile(src, tgt)
示例15: GetBuildPackages
# 需要导入模块: import os [as 别名]
# 或者: from os import mkdir [as 别名]
def GetBuildPackages(self):
"""Downloads the packages to be installed."""
package_path = os.path.join(self.cwd, BUILD, 'Packages/')
try:
os.mkdir(package_path)
except OSError:
pass
catalogs = [os.path.join(self.cwd, 'base%s_new.catalog' % self.os_version),
os.path.join(self.cwd,
'thirdparty%s_new.catalog' % self.os_version)]
for catalog in catalogs:
f = open(catalog, 'r')
packages = f.readlines()
for line in packages:
shutil.copy(os.path.join(TMPDIR, line.split()[0]),
os.path.join(package_path, line.split()[0]))