-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
67 lines (63 loc) · 2.62 KB
/
script.py
File metadata and controls
67 lines (63 loc) · 2.62 KB
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
62
63
64
65
66
67
import string
import os.path as op
import olefile
import re
import os
import streamlit as st
def get_rvt_file_version(rvt_file):
if op.exists(rvt_file):
if olefile.isOleFile(rvt_file):
rvt_ole = olefile.OleFileIO(rvt_file)
bfi = rvt_ole.openstream("BasicFileInfo")
file_info_bytes = bfi.read() # read the stream once
bfi_text = str(file_info_bytes.decode("ascii", "ignore"))
# get the Central Model Path, Locale when saved Format, and the Build Number
bfi_text = ''.join(filter(lambda x: x in string.printable, bfi_text))
# print(bfi_text.splitlines())
cmp = re.search(r"Central Model Path: (.*)", bfi_text)
print(cmp.group(1))
if ".rvt" in cmp.group(1):
cmp_data = "Central Model Path: " + cmp.group(1)
else:
cmp = re.search(r"Last Save Path: (.*)", bfi_text)
if ".rvt" in cmp.group(1):
cmp_data = "Central Model Path: " + cmp.group(1).split("\\")[-1]
else:
cmp_data = "Central Model Path: None"
locale = re.search(r"Locale when saved: (.*)", bfi_text)
if locale:
locale_data = "Locale when saved: " + locale.group(1)
else:
locale_data = "Locale when saved: None"
build = re.search(r"Build: (.*)", bfi_text)
if build:
build_data = "Build Number: " + build.group(1)
else:
build_data = "Build Number: None"
rvt_format = re.search(r"Format: (.*)", bfi_text)
if rvt_format:
rvt_format_data = "Format: " + rvt_format.group(1)
else:
rvt_format_data = "Format: None"
return cmp_data + "\n" + locale_data + "\n" + build_data + "\n" + rvt_format_data
else:
pass
else:
pass
if __name__ == "__main__":
folder = st.text_input("Enter folder path to search for rvt files")
# walk the folder and find rvt files
st.write(folder)
files = st.file_selector(folder)
st.write(files)
for root, dirs, files in os.walk(folder):
st.write(root)
for files in files:
st.write(files)
if files.endswith(".rvt"):
st.write(files)
rvt_file = os.path.join(folder, files)
# test if file exists
if op.exists(rvt_file):
st.write(files)
st.write(get_rvt_file_version(rvt_file))