-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_test.py
53 lines (42 loc) · 1.44 KB
/
parse_test.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
from lxml import etree
import pickle
dfxml_output = 'Z:/TEST/files/30000152020792-dfxml.xml'
temp_dir = 'Z:/UAC/ingest/20190819/30000152020792/temp'
file_stats = []
counter = 0
for event, element in etree.iterparse(dfxml_output, events = ("end",), tag="fileobject"):
counter =+ 1
print('\nWorking on item ', counter)
file_dict = {}
good = True
mt = False
mtime = 'undated'
for child in element:
if child.tag == "filename":
target = child.text
if child.tag == "name_type":
if child.text != "r":
element.clear()
good = False
break
if child.tag == "alloc":
if child.text != "1":
good = False
element.clear()
break
if child.tag == "filesize":
size = child.text
if child.tag == "hashdigest":
checksum = child.text
if child.tag == "mtime":
mtime = child.text
mt = True
if child.tag == "crtime" and mt == False:
mtime = child.text
if good:
file_dict = { 'name' : target, 'size' : size, 'mtime' : mtime, 'checksum' : checksum}
file_stats.append(file_dict)
element.clear()
checksums = os.path.join(temp_dir, 'checksums.txt')
with open (checksums, 'wb') as f:
pickle.dump(file_stats, f)