-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_for_existing.py
63 lines (44 loc) · 1.78 KB
/
check_for_existing.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
""" Compare two .xml files and write the difference (for attribute 'path' in filelist.xml and parset.xml) to a new one
"""
import xml.etree.ElementTree as etree
import os
import search_dir
class Manipulate(object):
def __init__(self,filelist_old, params_old, rootdir):
self.fl_old = filelist_old
self.pm_old = params_old
self.rootdir = rootdir
def append_calc(self):
search_dir.SearchDir(['info.xml'], self.rootdir, True).search()
f = etree.parse(self.fl_old)
p = etree.parse(self.pm_old)
root_f = f.getroot()
paths_f = root_f.getiterator('dir')
path_p = []
path_f = []
root_p = p.getroot()
paths_p = root_p.getiterator('set')
for paths in paths_p:
path_p.append(self.rootdir + paths.get('path'))
for paths in paths_f:
path_f.append(paths.get('path'))
diff = set(path_p) - set(path_f)
for pathp in paths_p:
if (self.rootdir + pathp.get('path')) not in diff:
try:
root_p.remove(pathp)
except:
continue
fname = self.pm_old
p.write(fname)
root_p = p.getroot()
new = root_p.getiterator('set')
combined = etree.parse(self.rootdir + 'parset.xml')
root_combined = combined.getroot()
for element in new:
root_combined.append(element)
combined.write(self.rootdir + 'parset.xml')
print 'written new parameterfile to ' + self.pm_old
##usage:
#test = Manipulate('/fshome/tde/cluster/Ti_convergence_ngridk/calc_filelist.xml', '/fshome/tde/cluster/Ti_convergence_ngridk/parset.xml')
#test.append_calc()