-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrvt_xml_sys_to_user_path.py
64 lines (57 loc) · 2.77 KB
/
rvt_xml_sys_to_user_path.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
62
63
64
import os
import sys
# Parameters
# you can use the same paths for all three dirs if you wish to overwrite xml files and py files are in that directory
# directory with rft.xml files (the ones with system paths).
xml_dir = r"D:\example_path"
# output directory where new rft.xml files will be saved (if same as xml_dir it overwrites files)
new_xml_dir = r"D:\example_path"
# directory to be replaced to in xml (directory where py files are stored)
change_to_dir = r"D:\example_path"
# If len(sys.argv) > 1 if we input arguments, they are used as parameters otherwise top ones are used.
if len(sys.argv) > 1:
for i_arg in range(len(sys.argv)):
if sys.argv[i_arg] == "-xml_dir":
if i_arg + 1 > len(sys.argv):
raise Exception("Wrong input parameters!")
elif sys.argv[i_arg + 1][0] == "-":
raise Exception("Wrong input parameters!")
else:
xml_dir = r'{}'.format(sys.argv[i_arg + 1])
if sys.argv[i_arg] == "-new_xml_dir":
if i_arg + 1 > len(sys.argv):
raise Exception("Wrong input parameters!")
elif sys.argv[i_arg + 1][0] == "-":
raise Exception("Wrong input parameters!")
else:
new_xml_dir = r'{}'.format(sys.argv[i_arg + 1])
if sys.argv[i_arg] == "-change_to_dir":
if i_arg + 1 > len(sys.argv):
raise Exception("Wrong input parameters!")
elif sys.argv[i_arg + 1][0] == "-":
raise Exception("Wrong input parameters!")
else:
change_to_dir = r'{}'.format(sys.argv[i_arg + 1])
if not os.path.isdir(xml_dir):
raise Exception("rvt_xml_sys_to_user_path: Directory xml_dir doesn't exists!")
if not os.path.isdir(new_xml_dir):
raise Exception("rvt_xml_sys_to_user_path: Directory new_xml_dir doesn't exists!")
if not os.path.isdir(change_to_dir):
raise Exception("rvt_xml_sys_to_user_path: Directory change_to_dir doesn't exists! "
"Can't change paths in xmls if directory doesn't exist!")
path_to_replace = r"[functions]Custom\rvt-arcgis-pro"
xml_files_list = [f for f in os.listdir(xml_dir) if f.endswith('.rft.xml')] # all .rft.xml files from xml_dir
if xml_files_list == []:
raise Exception("rvt_xml_sys_to_user_path: There is no .rft.xml files in xml_dir!")
for xml_file in xml_files_list:
in_file_path = os.path.abspath(os.path.join(xml_dir, xml_file))
out_file_path = os.path.abspath(os.path.join(new_xml_dir, xml_file))
dat_in = open(in_file_path, "r")
out_str = ""
for line in dat_in:
out_str += (line.replace(path_to_replace, change_to_dir))
dat_in.close()
dat_out = open(out_file_path, "w")
dat_out.write(out_str)
dat_out.close()
input("Press any key to close...")