-
Notifications
You must be signed in to change notification settings - Fork 0
/
pfs_reporting.py
111 lines (90 loc) · 3.94 KB
/
pfs_reporting.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
import argparse
import runQuery
import sys
import io
import os
import configparser
import json
from datetime import datetime
def returnList(pList):
if ',' in pList:
return pList.split(',')
elif pList == 'None':
return []
else: return [pList]
def main():
"""
parser = argparse.ArgumentParser()
parser.add_argument("-r", "--request", help = "Show Output", nargs='?', const='')
parser.add_argument("-b", "--batch", help = "Show Output", nargs='?', const='')
parser.add_argument("-e", "--experiment", help = "Show Output", nargs='?', const='')
parser.add_argument("-f", "--from_test_date", help = "Show Output", nargs='?', const='')
parser.add_argument("-t", "--to_test_date", help = "Show Output", nargs='?', const='')
parser.add_argument("-o", "--options", help = "Show Output", nargs='?', const='')
parser.add_argument("-u", "--user", help = "Show Output")
parser.add_argument("-j", "--jaxstrain", help = "Show Output", nargs='?', const='')
args = parser.parse_args()
"""
public_config = configparser.ConfigParser()
public_config.read("./config/setup.cfg")
SERVICE_USERNAME = public_config["CORE LIMS"]["service username"]
private_config = configparser.ConfigParser()
private_config.read("./config/secret.cfg")
SERVICE_PASSWORD = private_config["CORE LIMS"]["service password"]
"""
if not(has_cba_access(args.user, SERVICE_USERNAME, SERVICE_PASSWORD)):
raise Exception("User %s does not have access to CBA" % args.user)
publishedBool = False
unpublishedBool = False
inactiveBool = False
summaryBool = False
jaxstrain = ''
for opt in args.options.split(","):
publishedBool = True if opt == 'p' else publishedBool
inactiveBool = True if opt == 'i' else inactiveBool
summaryBool = True if opt == 's' else summaryBool
unpublishedBool = True if opt == 'u' else unpublishedBool
cbbList = returnList(args.batch) if args.batch else []
requestList = returnList(args.request) if args.request else []
#raise Exception(str(requestList))
templateList = returnList(args.experiment) if args.experiment else []
if args.from_test_date:
f_from_test_date = datetime.strftime(datetime.strptime(args.from_test_date, '%m-%d-%Y'), '%Y-%m-%d')
else:
f_from_test_date = None
if args.to_test_date:
f_to_test_date = datetime.strftime(datetime.strptime(args.to_test_date, '%m-%d-%Y'), '%Y-%m-%d')
else:
f_to_test_date = None
if args.jaxstrain:
jaxstrain = args.jaxstrain
"""
cbbList = ['CBB1261','CBB1229']
requestList = ''
templateList = returnList('CBA_ROTAROD_EXPERIMENT')
f_from_test_date = None
f_to_test_date = None
publishedBool = None
unpublishedBool = None
inactiveBool = None
summaryBool = True
jaxstrain = 'JR000664'
newObj = runQuery.CBAAssayHandler(cbbList, requestList, templateList, \
f_from_test_date, f_to_test_date, publishedBool, unpublishedBool, inactiveBool, summaryBool, jaxstrain, SERVICE_USERNAME, SERVICE_PASSWORD) # Need to add unpublishedBool
dfList = (newObj.controller())
data = newObj.writeFile(dfList)
#dealie.seek(0)
#with open("output.txt", "wb") as f: #!works
# f.write(dealie.getbuffer())
sys.stdout.buffer.write(data.getbuffer())
def has_cba_access(user, service_username, service_password):
has_cba_access = False
check_access_query = runQuery.QueryHandler(service_username, service_password)
employee_string = f"EMPLOYEE?&expand=PROJECT&$filter=contains(CI_USERNAME, '{user.lower()}') and PROJECT/any(a:a/Name eq 'Center for Biometric Analysis')"
result_data = check_access_query.runQuery(check_access_query.queryBase + employee_string, 'xml')
json_data = json.loads(result_data)
if len(json_data['value']) > 0:
has_cba_access = True
return has_cba_access
if __name__ == "__main__":
main()