20
20
from .user import PpmsUser
21
21
from .system import PpmsSystem
22
22
from .booking import PpmsBooking
23
+ from .exceptions import NoDataError
23
24
24
25
25
26
class PpmsConnection :
@@ -133,7 +134,7 @@ def __authenticate(self):
133
134
)
134
135
self .status ["auth_state" ] = "attempting"
135
136
response = self .request ("auth" )
136
- log .debug (f"Authenticate response: { response .text } " )
137
+ log .trace (f"Authenticate response: { response .text } " )
137
138
self .status ["auth_response" ] = response .text
138
139
self .status ["auth_httpstatus" ] = response .status_code
139
140
@@ -166,8 +167,11 @@ def __authenticate(self):
166
167
log .error (msg )
167
168
raise requests .exceptions .ConnectionError (msg )
168
169
169
- log .info (f"Authentication succeeded, response=[{ response .text } ]" )
170
- log .debug (f"HTTP Status: { response .status_code } " )
170
+ log .info (
171
+ "Authentication succeeded, response=[{}], http_status=[{}]" ,
172
+ response .text ,
173
+ response .status_code ,
174
+ )
171
175
self .status ["auth_state" ] = "good"
172
176
173
177
def request (self , action , parameters = {}, skip_cache = False ):
@@ -249,14 +253,14 @@ def __interception_path(self, req_data, create_dir=False):
249
253
action = req_data ["action" ]
250
254
251
255
if self .cache_users_only and action != "getuser" :
252
- log .debug (f"NOT caching '{ action } ' (cache_users_only is set)" )
256
+ log .trace (f"NOT caching '{ action } ' (cache_users_only is set)" )
253
257
return None
254
258
255
259
intercept_dir = os .path .join (self .cache_path , action )
256
260
if create_dir and not os .path .exists (intercept_dir ): # pragma: no cover
257
261
try :
258
262
os .makedirs (intercept_dir )
259
- log .debug (f"Created dir to store response: { intercept_dir } " )
263
+ log .trace (f"Created dir to store response: { intercept_dir } " )
260
264
except Exception as err : # pylint: disable-msg=broad-except
261
265
log .warning (f"Failed creating [{ intercept_dir } ]: { err } " )
262
266
return None
@@ -316,7 +320,10 @@ def __init__(self, text, status_code):
316
320
317
321
with open (intercept_file , "r" , encoding = "utf-8" ) as infile :
318
322
text = infile .read ()
319
- log .debug (f"Read intercepted response text from [{ intercept_file } ]" )
323
+ log .debug (
324
+ "Read intercepted response text from [{}]" ,
325
+ intercept_file [len (str (self .cache_path )) :],
326
+ )
320
327
321
328
status_code = 200
322
329
status_file = os .path .splitext (intercept_file )[0 ] + "_status-code.txt"
@@ -590,12 +597,14 @@ def get_running_sheet(self, core_facility_ref, date, ignore_uncached_users=False
590
597
response = self .request ("getrunningsheet" , parameters )
591
598
try :
592
599
entries = parse_multiline_response (response .text , graceful = False )
600
+ except NoDataError :
601
+ # in case no bookings exist the response will be empty!
602
+ log .debug ("Runningsheet for the given day was empty!" )
603
+ return []
593
604
except Exception as err : # pylint: disable-msg=broad-except
594
605
log .error ("Parsing runningsheet details failed: {}" , err )
595
- # NOTE: in case no future bookings exist the response will be empty!
596
- log .error ("Possibly the runningsheet is empty as no bookings exist?" )
597
- log .debug ("Runningsheet PUMPAI response was: {}" , response .text )
598
- return bookings
606
+ log .debug ("Runningsheet PUMPAI response was: >>>{}<<<" , response .text )
607
+ return []
599
608
600
609
for entry in entries :
601
610
full = entry ["User" ]
@@ -702,7 +711,7 @@ def get_systems_matching(self, localisation, name_contains):
702
711
systems = self .get_systems ()
703
712
for sys_id , system in systems .items ():
704
713
if loc .lower () not in str (system .localisation ).lower ():
705
- log .debug (
714
+ log .trace (
706
715
"System [{}] location ({}) is NOT matching ({}), ignoring" ,
707
716
system .name ,
708
717
system .localisation ,
@@ -715,7 +724,7 @@ def get_systems_matching(self, localisation, name_contains):
715
724
# system.name, loc, name_contains)
716
725
for valid_name in name_contains :
717
726
if valid_name in system .name :
718
- log .debug ("System [{}] matches all criteria" , system .name )
727
+ log .trace ("System [{}] matches all criteria" , system .name )
719
728
system_ids .append (sys_id )
720
729
break
721
730
0 commit comments