def main(): parser = argparse.ArgumentParser() parser.add_argument('-s', '--scan', dest="directory", help="Directory to scan") parser.add_argument('--type', dest="ftype", help="Files type") parser.add_argument( '--tags', dest="tags", action="append", default=[], help="tags, format key:value, can be repeated multiple times") args = parser.parse_args() if not os.path.exists(args.directory): sys.exit(1) res = {} for (path, dirs, files) in os.walk(args.directory): for file in files: filename = os.path.join(path, file) (file_format, mime) = Utils.detect_format(filename) if file_format is not None: file_format = file_format.replace('application/', '') filename = filename.replace(args.directory + '/', '') if file_format is not None: if file_format not in res: res[file_format] = [filename] else: res[file_format].append(filename) f_type = '' if args.ftype: f_type = args.ftype tags = '' if args.tags: tags = ','.join(args.tags) for fformat in res.keys(): print '##BIOMAJ#' + fformat + '#' + f_type + '#' + tags + '#' + ','.join( res[fformat])
def main(): parser = argparse.ArgumentParser() parser.add_argument("-s", "--scan", dest="directory", help="Directory to scan") parser.add_argument("--type", dest="ftype", help="Files type") parser.add_argument( "--tags", dest="tags", action="append", default=[], help="tags, format key:value, can be repeated multiple times", ) args = parser.parse_args() if not os.path.exists(args.directory): sys.exit(1) res = {} for (path, dirs, files) in os.walk(args.directory): for file in files: filename = os.path.join(path, file) (file_format, mime) = Utils.detect_format(filename) if file_format is not None: file_format = file_format.replace("application/", "") filename = filename.replace(args.directory + "/", "") if file_format is not None: if file_format not in res: res[file_format] = [filename] else: res[file_format].append(filename) f_type = "" if args.ftype: f_type = args.ftype tags = "" if args.tags: tags = ",".join(args.tags) for fformat in res.keys(): print "##BIOMAJ#" + fformat + "#" + f_type + "#" + tags + "#" + ",".join(res[fformat])
def test_mimes(self): fasta_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'bank/test2.fasta') (mime, encoding) = Utils.detect_format(fasta_file) self.assertTrue('application/fasta' == mime)
def test_mimes(self): fasta_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),'bank/test2.fasta') (mime, encoding) = Utils.detect_format(fasta_file) self.assertTrue('application/fasta' == mime)