-
Notifications
You must be signed in to change notification settings - Fork 0
/
bob_update.py
128 lines (112 loc) · 4.56 KB
/
bob_update.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#
# *******************************************************************************
# Copyright (c) 2020 by CEA.
# The full license specifying the redistribution, modification, usage and other rights
# and obligations is included with the distribution of this project in the file "license.txt"
#
# THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, NOT EVEN
#
# THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR OF THIS SOFTWARE
# ASSUMES NO RESPONSIBILITY FOR ANY CONSEQUENCE RESULTING FROM THE USE,
# MODIFICATION, OR REDISTRIBUTION OF THIS SOFTWARE.
# ******************************************************************************
# C.E.A. IRFU/DIS/LDISC
#
#
#Script for recursively converting CSS opi files into Phoebus bob files
#Created on 24 May 2023
#
#author: Antoine Choquet
#email: antoine.choquet@cea.fr
#
#contributor: Lea Perez
#contributor : Mathis Huriez
import xml.etree.ElementTree as ET
import logging
import os
def bob_updating(bob_file, bob_dirname, log):
tree = ET.parse(bob_file)
root = tree.getroot()
bob_file_name = os.path.basename(bob_file)
if log :
format = '%(asctime)s - %(levelname)-8s - %(message)s'
logfile = bob_dirname + os.sep + "Conversion_opi_to_bob.log"
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.DEBUG)
logging.basicConfig(format=format, level=logging.DEBUG, datefmt='%m/%d/%Y %I:%M:%S', force=True, handlers=[logging.FileHandler(logfile, mode='a'), stream_handler])
logging.info(f"Updating: {bob_file_name} ")
i = 0
j = 0
k = 0
l = 0
same_bob = ""
#update the link to other Phoebus bob
for file in root.iter('file'):
if file is not None:
opi = str(file.text)
bob = str(opi.replace("opi","bob"))
file.text = bob
if same_bob == bob:
i += 1
same_bob = bob
elif same_bob != "":
if log :
if i == 0 or i == 1:
logging.debug(f"the link to the graphical interface: {same_bob} has been updated")
else:
logging.debug(f"the link to the graphical interface: {same_bob} have been updated {i} times")
same_bob = bob
i = 0
else:
i += 1
same_bob = bob
if same_bob != "":
if log :
if i == 0 or i == 1:
logging.debug(f"the link to the graphical interface: {same_bob} has been updated")
else:
logging.debug(f"the link to the graphical interface: {same_bob} have been updated {i} times")
#Delete gridLayout widget
for gridLayout in root.findall('widget'):
if gridLayout is not None and gridLayout.get('typeId') == "org.csstudio.opibuilder.widgets.gridLayout":
root.remove(gridLayout)
i += 1
for widget in root.iter('widget'):
for gridLayout in widget.findall('widget'):
if gridLayout is not None and gridLayout.get('typeId') == "org.csstudio.opibuilder.widgets.gridLayout":
widget.remove(gridLayout)
i += 1
#update the color property name of polyline widget
if widget.get('type') == "polyline":
for rule in widget.findall('./rules/rule'):
if rule is not None:
rule.set('prop_id', 'line_color')
k += 1
if widget.get('type') == "xyplot":
l += 1
for script in root.iter('script'):
if script is not None:
script = script.get('file')
if log :
if "changeMacroValue.js" in script:
logging.warning(f"the script: {script} can be remplaced by a simpler embedded script")
else:
logging.warning(f"the script: {script} may not work")
if log :
if j !=0:
logging.debug(f"{i} gridLayout widgets have been removed")
if k !=0:
logging.debug(f"{k} polyline widgets have been updated")
if l !=0:
if l ==1:
logging.warning(f"there is 1 xyplot that might have a different behavior")
else:
logging.warning(f"there are {l} xyplot that might have a different behavior")
tree.write(bob_file, xml_declaration=True, method='xml', encoding='UTF-8')
while True:
try:
tree = ET.parse(bob_file)
break
except Exception:
print("Error:", {bob_file}, "is corrupted")
break