-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetadump.py
61 lines (52 loc) · 1.73 KB
/
metadump.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
PyMDECO - Python Meta Data Extractor and Collection Organizer
Extract file metadata from a directory with files
"""
from __future__ import print_function
# internal Python modules
import os
import sys
import json
import argparse
#
from pymdeco.services import FileMetadataService
from pymdeco.exceptions import GeneralException
def main(arg=None):
parser = argparse.ArgumentParser(
description =
'Crawl through directory tree and collects file metadata',
epilog='author: Todor Bukov, [email protected], ver.: ' + \
os.path.basename(sys.argv[0])
)
parser.add_argument(
'-v','--verbose',
action='store_true',
help='Print verbose information'
)
parser.add_argument(
'-p','--path',
action='store',
required=True,
help='Starting point (directory path)'
)
if arg is None:
arguments = parser.parse_args()
else:
arguments = parser.parse_args(arg)
root_path = arguments.path
scan_service = FileMetadataService() # use the defaults
# print("Services:", scan_service.available_scanners())
for root, dirs, files in os.walk(root_path):
for afile in files:
fpath = os.path.join(root, afile)
print ("processing file:", fpath)
try:
finfo = scan_service.get_metadata(fpath)
except GeneralException as ex:
print("ERROR: Exception occured:\n" + str(ex))
meta_json = json.dumps(finfo, ensure_ascii=False, indent=2)
print ("Meta data (JSON):\n", meta_json)
if __name__ == '__main__':
main()