Python os.mkdir() Examples
The following are 30
code examples of os.mkdir().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os
, or try the search function
.
Example #1
Source File: train_models.py From Turku-neural-parser-pipeline with Apache License 2.0 | 8 votes |
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
Example #2
Source File: create_joint_gs.py From CAMISIM with Apache License 2.0 | 6 votes |
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
Example #3
Source File: payday.py From payday with GNU General Public License v2.0 | 6 votes |
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 ### ###############################
Example #4
Source File: _7zip.py From multibootusb with GNU General Public License v2.0 | 6 votes |
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)
Example #5
Source File: imdb.py From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 | 6 votes |
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)
Example #6
Source File: utils.py From dc_tts with Apache License 2.0 | 6 votes |
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)
Example #7
Source File: pretrain.py From OpenNRE with MIT License | 6 votes |
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.')
Example #8
Source File: config.py From pytorch_NER_BiLSTM_CNN_CRF with Apache License 2.0 | 6 votes |
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'))
Example #9
Source File: strainsimulationwrapper.py From CAMISIM with Apache License 2.0 | 6 votes |
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)
Example #10
Source File: can_haz_image.py From macops with Apache License 2.0 | 6 votes |
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)
Example #11
Source File: can_haz_image.py From macops with Apache License 2.0 | 6 votes |
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]))
Example #12
Source File: _qemu.py From ALF with Apache License 2.0 | 6 votes |
def _remote_init(working_dir): global pickle import pickle import sys import shutil import os if not os.path.isdir(working_dir): os.mkdir(working_dir) sys.path.append(working_dir) shutil.move("_common.py", working_dir) shutil.move("_gdb.py", working_dir) shutil.move("cmds.gdb", working_dir) # setup CERT exploitable exp_lib_dir = os.path.join(working_dir, "exploitable", "lib") os.makedirs(exp_lib_dir) shutil.move("exploitable.py", os.path.join(working_dir, "exploitable")) shutil.move("__init__.py", exp_lib_dir) shutil.move("analyzers.py", exp_lib_dir) shutil.move("classifier.py", exp_lib_dir) shutil.move("elf.py", exp_lib_dir) shutil.move("gdb_wrapper.py", exp_lib_dir) shutil.move("rules.py", exp_lib_dir) shutil.move("tools.py", exp_lib_dir) shutil.move("versions.py", exp_lib_dir) os.chdir(working_dir) global _common global _gdb import _common import _gdb
Example #13
Source File: pascal_voc.py From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 | 6 votes |
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()
Example #14
Source File: download.py From arm_now with MIT License | 6 votes |
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)
Example #15
Source File: test_delocating.py From delocate with BSD 2-Clause "Simplified" License | 6 votes |
def test_dyld_library_path_lookups(): # Test that DYLD_LIBRARY_PATH can be used to find libs during # delocation with TempDirWithoutEnvVars('DYLD_LIBRARY_PATH') as tmpdir: # Copy libs into a temporary directory subtree = pjoin(tmpdir, 'subtree') all_local_libs = _make_libtree(subtree) liba, libb, libc, test_lib, slibc, stest_lib = all_local_libs # move libb and confirm that test_lib doesn't work hidden_dir = 'hidden' os.mkdir(hidden_dir) new_libb = os.path.join(hidden_dir, os.path.basename(LIBB)) shutil.move(libb, new_libb) assert_raises(RuntimeError, back_tick, [test_lib]) # Update DYLD_LIBRARY_PATH and confirm that we can now # successfully delocate test_lib os.environ['DYLD_LIBRARY_PATH'] = hidden_dir delocate_path('subtree', 'deplibs') back_tick(test_lib)
Example #16
Source File: test_delocating.py From delocate with BSD 2-Clause "Simplified" License | 6 votes |
def test_dyld_library_path_beats_basename(): # Test that we find libraries on DYLD_LIBRARY_PATH before basename with TempDirWithoutEnvVars('DYLD_LIBRARY_PATH') as tmpdir: # Copy libs into a temporary directory subtree = pjoin(tmpdir, 'subtree') all_local_libs = _make_libtree(subtree) liba, libb, libc, test_lib, slibc, stest_lib = all_local_libs # Copy liba into a subdirectory subdir = os.path.join(subtree, 'subdir') os.mkdir(subdir) new_libb = os.path.join(subdir, os.path.basename(LIBB)) shutil.copyfile(libb, new_libb) # Without updating the environment variable, we find the lib normally predicted_lib_location = search_environment_for_lib(libb) # tmpdir can end up in /var, and that can be symlinked to # /private/var, so we'll use realpath to resolve the two assert_equal(predicted_lib_location, os.path.realpath(libb)) # Updating shows us the new lib os.environ['DYLD_LIBRARY_PATH'] = subdir predicted_lib_location = search_environment_for_lib(libb) assert_equal(predicted_lib_location, new_libb)
Example #17
Source File: test_delocating.py From delocate with BSD 2-Clause "Simplified" License | 6 votes |
def test_dyld_fallback_library_path_loses_to_basename(): # Test that we find libraries on basename before DYLD_FALLBACK_LIBRARY_PATH with TempDirWithoutEnvVars('DYLD_FALLBACK_LIBRARY_PATH') as tmpdir: # Copy libs into a temporary directory subtree = pjoin(tmpdir, 'subtree') all_local_libs = _make_libtree(subtree) liba, libb, libc, test_lib, slibc, stest_lib = all_local_libs # Copy liba into a subdirectory subdir = 'subdir' os.mkdir(subdir) new_libb = os.path.join(subdir, os.path.basename(LIBB)) shutil.copyfile(libb, new_libb) os.environ['DYLD_FALLBACK_LIBRARY_PATH'] = subdir predicted_lib_location = search_environment_for_lib(libb) # tmpdir can end up in /var, and that can be symlinked to # /private/var, so we'll use realpath to resolve the two assert_equal(predicted_lib_location, os.path.realpath(libb))
Example #18
Source File: download_glue.py From BERT-Classification-Tutorial with Apache License 2.0 | 6 votes |
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)
Example #19
Source File: test_tools.py From delocate with BSD 2-Clause "Simplified" License | 6 votes |
def test_find_package_dirs(): # Test utility for finding package directories with InTemporaryDirectory(): os.mkdir('to_test') a_dir = pjoin('to_test', 'a_dir') b_dir = pjoin('to_test', 'b_dir') c_dir = pjoin('to_test', 'c_dir') for dir in (a_dir, b_dir, c_dir): os.mkdir(dir) assert_equal(find_package_dirs('to_test'), set([])) _write_file(pjoin(a_dir, '__init__.py'), "# a package") assert_equal(find_package_dirs('to_test'), {a_dir}) _write_file(pjoin(c_dir, '__init__.py'), "# another package") assert_equal(find_package_dirs('to_test'), {a_dir, c_dir}) # Not recursive assert_equal(find_package_dirs('.'), set()) _write_file(pjoin('to_test', '__init__.py'), "# base package") # Also - strips '.' for current directory assert_equal(find_package_dirs('.'), {'to_test'})
Example #20
Source File: test_scripts.py From delocate with BSD 2-Clause "Simplified" License | 6 votes |
def test_fuse_wheels(): # Some tests for wheel fusing with InTemporaryDirectory(): zip2dir(PLAT_WHEEL, 'to_wheel') zip2dir(PLAT_WHEEL, 'from_wheel') dir2zip('to_wheel', 'to_wheel.whl') dir2zip('from_wheel', 'from_wheel.whl') code, stdout, stderr = run_command( ['delocate-fuse', 'to_wheel.whl', 'from_wheel.whl']) assert_equal(code, 0) zip2dir('to_wheel.whl', 'to_wheel_fused') assert_same_tree('to_wheel_fused', 'from_wheel') # Test output argument os.mkdir('wheels') code, stdout, stderr = run_command( ['delocate-fuse', 'to_wheel.whl', 'from_wheel.whl', '-w', 'wheels']) zip2dir(pjoin('wheels', 'to_wheel.whl'), 'to_wheel_refused') assert_same_tree('to_wheel_refused', 'from_wheel')
Example #21
Source File: engine.py From PickTrue with MIT License | 5 votes |
def ensure_dir(self): if not os.path.exists(self.save_dir): os.mkdir(self.save_dir)
Example #22
Source File: data_utils.py From DOTA_models with Apache License 2.0 | 5 votes |
def maybe_download(directory, filename, url): """Download filename from url unless it's already in directory.""" if not os.path.exists(directory): print("Creating directory %s" % directory) os.mkdir(directory) filepath = os.path.join(directory, filename) if not os.path.exists(filepath): print("Downloading %s to %s" % (url, filepath)) filepath, _ = urllib.request.urlretrieve(url, filepath) statinfo = os.stat(filepath) print("Successfully downloaded", filename, statinfo.st_size, "bytes") return filepath
Example #23
Source File: pascal_voc.py From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 | 5 votes |
def cache_path(self): """ make a directory to store all caches Returns: --------- cache path """ cache_path = os.path.join(os.path.dirname(__file__), '..', 'cache') if not os.path.exists(cache_path): os.mkdir(cache_path) return cache_path
Example #24
Source File: seq2seq_attention_decode.py From DOTA_models with Apache License 2.0 | 5 votes |
def __init__(self, outdir): self._cnt = 0 self._outdir = outdir if not os.path.exists(self._outdir): os.mkdir(self._outdir) self._ref_file = None self._decode_file = None
Example #25
Source File: setup.py From sqliv with GNU General Public License v3.0 | 5 votes |
def install(file_path, exec_path): """full installation of SQLiv to the system""" os.mkdir(file_path) copy2("sqliv.py", file_path) copy2("requirements.txt", file_path) copy2("LICENSE", file_path) copy2("README.md", file_path) os.mkdir(file_path + "/src") copy_tree("src", file_path + "/src") os.mkdir(file_path + "/lib") copy_tree("lib", file_path + "/lib") # python dependencies with pip dependencies("install") # add executable with open(exec_path, 'w') as installer: installer.write('#!/bin/bash\n') installer.write('\n') installer.write('python2 {}/sqliv.py "$@"\n'.format(file_path)) # S_IRWXU = rwx for owner # S_IRGRP | S_IXGRP = rx for group # S_IROTH | S_IXOTH = rx for other os.chmod(exec_path, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
Example #26
Source File: modelzoo.py From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 | 5 votes |
def download_model(model_name, dst_dir='./', meta_info=None): if meta_info is None: meta_info = _default_model_info meta_info = dict(meta_info) if model_name not in meta_info: return (None, 0) if not os.path.isdir(dst_dir): os.mkdir(dst_dir) meta = dict(meta_info[model_name]) assert 'symbol' in meta, "missing symbol url" model_name = os.path.join(dst_dir, model_name) download_file(meta['symbol'], model_name+'-symbol.json') assert 'params' in meta, "mssing parameter file url" download_file(meta['params'], model_name+'-0000.params') return (model_name, 0)
Example #27
Source File: text_cnn.py From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 | 5 votes |
def save_model(): if not os.path.exists("checkpoint"): os.mkdir("checkpoint") return mx.callback.do_checkpoint("checkpoint/checkpoint", args.save_period)
Example #28
Source File: text_cnn.py From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 | 5 votes |
def save_model(): if not os.path.exists("checkpoint"): os.mkdir("checkpoint") return mx.callback.do_checkpoint("checkpoint/checkpoint", args.save_period)
Example #29
Source File: Preprocessing.py From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 | 5 votes |
def mkdir(fname): try: os.mkdir(fname) except: pass
Example #30
Source File: pastebin_crawler.py From pastebin-monitor with GNU General Public License v2.0 | 5 votes |
def save_result ( self, paste_url, paste_id, file, directory ): timestamp = get_timestamp() with open ( file, 'a' ) as matching: matching.write ( timestamp + ' - ' + paste_url + '\n' ) try: os.mkdir(directory) except KeyboardInterrupt: raise except: pass with open( directory + '/' + timestamp.replace('/','_').replace(':','_').replace(' ','__') + '_' + paste_id.replace('/','') + '.txt', mode='w' ) as paste: paste_txt = PyQuery(url=paste_url)('#paste_code').text() paste.write(paste_txt + '\n')