8def enable(oksfile, disable, resource, session_name):
9 """Script to enable or disable (-d) Resources from the first Session of the
10 specified OKS database file"""
12 if session_name == "":
13 session_dals = db.get_dals(class_name="Session")
14 if len(session_dals) == 0:
15 print(f"Error could not find any Session in file {oksfile}")
16 return
17 session = session_dals[0]
18 else:
19 try:
20 session = db.get_dal("Session", session_name)
21 except:
22 print(f"Error could not find Session {session_name} in file {oksfile}")
23 return
24 disabled = session.disabled
25 for res in resource:
26 try:
27 res_dal = db.get_dal("ResourceBase", res)
28 except:
29 print(f"Error could not find Resource {res} in file {oksfile}")
30 continue
31
32 if disable:
33 if res_dal in disabled:
34 print(
35 f"{res} is already in disabled relationship of Session {session.id}"
36 )
37 else:
38
39 print(f"Adding {res} to disabled relationship of Session {session.id}")
40 disabled.append(res_dal)
41 else:
42 if res_dal not in disabled:
43 print(f"{res} is not in disabled relationship of Session {session.id}")
44 else:
45
46 print(
47 f"Removing {res} from disabled relationship of Session {session.id}"
48 )
49 disabled.remove(res_dal)
50 session.disabled = disabled
51 db.update_dal(session)
52 db.commit()