| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
import os,sys |
| 4 |
import argparse |
| 5 |
import logging.config |
| 6 |
|
| 7 |
from biomaj_core.utils import Utils |
| 8 |
|
| 9 |
def main(): |
| 10 |
|
| 11 |
parser = argparse.ArgumentParser() |
| 12 |
|
| 13 |
parser.add_argument('-s', '--scan', dest="directory",help="Directory to scan") |
| 14 |
parser.add_argument('--type', dest="ftype",help="Files type") |
| 15 |
parser.add_argument('--tags', dest="tags", action="append", default=[], |
| 16 |
help="tags, format key:value, can be repeated multiple times") |
| 17 |
|
| 18 |
args = parser.parse_args() |
| 19 |
|
| 20 |
if not os.path.exists(args.directory): |
| 21 |
sys.exit(1) |
| 22 |
|
| 23 |
res = {} |
| 24 |
for (path, dirs, files) in os.walk(args.directory): |
| 25 |
for file in files: |
| 26 |
filename = os.path.join(path, file) |
| 27 |
(file_format, mime) = Utils.detect_format(filename) |
| 28 |
if file_format is not None: |
| 29 |
file_format = file_format.replace('application/','') |
| 30 |
filename = filename.replace(args.directory+'/','') |
| 31 |
if file_format is not None: |
| 32 |
if file_format not in res: |
| 33 |
res[file_format] = [filename] |
| 34 |
else: |
| 35 |
res[file_format].append(filename) |
| 36 |
|
| 37 |
f_type = '' |
| 38 |
if args.ftype: |
| 39 |
f_type = args.ftype |
| 40 |
tags = '' |
| 41 |
if args.tags: |
| 42 |
tags = ','.join(args.tags) |
| 43 |
for fformat in res.keys(): |
| 44 |
print('##BIOMAJ#'+fformat+'#'+f_type+'#'+tags+'#'+','.join(res[fformat])) |
| 45 |
|
| 46 |
|
| 47 |
if __name__ == '__main__': |
| 48 |
main() |