def pdfcomments(infilename: str, outfilename: Optional[str] = None) -> int: severities = load_comments(infilename) if outfilename is None: outfilename = extsep.join([Path(infilename).stem, OUT_EXT]) save_comments(severities, outfilename) return EX_OK
def get_show_keys(): ''' Gets contents of show_keys result file ''' filename = ospath.join( RESULT_DIR, extsep.join(['show_keys', 'txt', ]), ) with open(filename) as fhandle: return fhandle.read()
def joinext(root, ext): """ Roughly the reverse of os.path.splitext. :type root: string :param root: part of the filename before the extension :type root: string :param ext: the extension :rtype: string :returns: ``root`` joined with ``ext`` separated by a single ``os.extsep`` """ return extsep.join([root.rstrip(extsep), ext.lstrip(extsep)])
def get_test_result(key): ''' Read data and result for given key ''' filename = ospath.join( RESULT_DIR, extsep.join([key, 'yaml', ]), ) with open(filename) as fhandle: result = load(fhandle) return result
def get_show_keys(): ''' Gets contents of show_keys result file ''' filename = ospath.join( RESULT_DIR, extsep.join([ 'show_keys', 'txt', ]), ) with open(filename) as fhandle: return fhandle.read()
def test_module(subclass, directory=False): '''Executes subclass and outputs data :param subclass: key to subclass under test :param directory: optional - indicates that input data is a directory ''' subclass.read() data = ospath.join(SUBDIR, 'data') result = ospath.join(SUBDIR, 'result') # make raw data directory for i in (data, result): try: mkdir(i) except OSError as ex: if ex.errno != errno.EEXIST: raise # write raw data for later inspection # ignore if input is a directory # (PidFd class) or no data found if not directory: try: with open( ospath.join(data, subclass.key), 'wt' ) as fd: fd.write(subclass.data) fd.write('\n') except (AttributeError, TypeError): pass # write result dictionary for later inspection with open( extsep.join([ ospath.join(result, subclass.key), 'yaml', ]), 'wt' ) as fd: yaml.dump( subclass.normalize(), stream=fd, indent=2, width=80, default_flow_style=False )
def get_test_result(key): ''' Read data and result for given key ''' filename = ospath.join( RESULT_DIR, extsep.join([ key, 'yaml', ]), ) with open(filename) as fhandle: result = load(fhandle) return result
def write_result(key, result): ''' Sometimes we want to actially write the result dictionary ''' filename = ospath.join( RESULT_DIR, extsep.join([key, 'yaml', ]), ) with open(filename) as fhandle: result = dump( result, fhandle, indent=2, width=80, default_flow_style=False )
def write_result(key, result): ''' Sometimes we want to actially write the result dictionary ''' filename = ospath.join( RESULT_DIR, extsep.join([ key, 'yaml', ]), ) with open(filename) as fhandle: result = dump(result, fhandle, indent=2, width=80, default_flow_style=False)
def run(): parser = argparse.ArgumentParser(usage=__doc__) parser.add_argument('--hla-dir', required=True) parser.add_argument('--maf-dir', required=True) args = parser.parse_args() hla_dir_out = args.hla_dir + "_cleaned" maf_dir_out = args.maf_dir + "_cleaned" shutil.rmtree(hla_dir_out, ignore_errors=True) shutil.rmtree(maf_dir_out, ignore_errors=True) makedirs(hla_dir_out) makedirs(maf_dir_out) maf_set = set() both_set = set() maf_exts = [] for maf_filename in listdir(args.maf_dir): maf_parts = maf_filename.split(extsep) if "maf" in maf_parts: maf_set.add(maf_parts[0]) maf_exts.append(extsep + extsep.join(maf_parts[1:])) for hla_filename in listdir(args.hla_dir): hla_basename, hla_ext = path.splitext(hla_filename) hla_stripped_basename = hla_basename[:NUM_CHARS_HLA] hla_stripped_filename = hla_stripped_basename + hla_ext if ".hla" == hla_ext and hla_stripped_basename in maf_set: both_set.add(hla_stripped_basename) hla_filepath = path.join(args.hla_dir, hla_filename) lines = [strip_info(line) for line in open(hla_filepath)] hla_filepath_new = path.join(hla_dir_out, hla_stripped_filename) with open(hla_filepath_new, 'a') as nf: output = '\n'.join(lines) nf.write(output) maf_dirpath = path.abspath(args.maf_dir) maf_dirpath_out = path.abspath(maf_dir_out) for basename in both_set: maf_filepath_original = path.join(maf_dirpath, basename) + maf_exts[0] maf_basepath = path.join(maf_dirpath_out, basename) maf_filepath = maf_basepath + maf_exts[0] maf_filepath_new = maf_basepath + ".maf" shutil.copyfile(maf_filepath_original, maf_filepath) rename(maf_filepath, maf_filepath_new)
def get_output_filename (self): return self.output \ if self.output is not None \ else extsep.join((self.task_name.replace(' ', extsep), 'csv'))
def extjoin(*args): return extsep.join(args)