Skip to content

Commit 14b5313

Browse files
author
Mohan Sahu
committed
remove duplicate get_machine_types call, replace if with elif, chnage the way exceptions were logged, add data type for check_kw, removed v0 endpoints
1 parent b3e6f03 commit 14b5313

4 files changed

Lines changed: 10 additions & 21 deletions

File tree

smsdk/client_v0.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,10 @@ def inner(self, machine_source, types=[], return_mtype=False, **kwargs):
440440
return
441441
try:
442442
stats = self.get_machine_types(normalize=False, _limit=1, source_type=machine_type)
443-
stats = self.get_machine_types(normalize=False, _limit=1, source_type=machine_type)['stats'][0]
444443
except KeyError:
445444
# explicitly embed string to machine type names esp JCP
446445
machine_type = f"'{machine_type}'"
447-
stats = self.get_machine_types(normalize=False, _limit=1, source_type=machine_type)['stats'][0]
446+
stats = self.get_machine_types(normalize=False, _limit=1, source_type=machine_type)
448447
except Exception as ex:
449448
print(f"Exception in getting machine type stats {ex}")
450449
kwargs['stats'] = stats

smsdk/config/api_endpoints.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,22 @@
33
"url": "/auth/password/login"
44
},
55
"Cycle": {
6-
"url_v1": "/v1/datatab/cycle",
7-
"url": "/api/cycle",
8-
"alt_url": "/api/cycle"
6+
"url_v1": "/v1/datatab/cycle"
97
},
108
"Factory": {
11-
"url" : "/api/factory",
129
"url_v1" : "/v1/obj/factory"
1310
},
1411
"MachineType": {
15-
"url" : "/api/machinetype",
1612
"url_v1" : "/v1/obj/machine_type"
1713
},
1814
"Machine": {
19-
"url" : "/api/machine",
2015
"url_v1" : "/v1/obj/machine"
2116
},
2217
"Parts": {
23-
"url" : "/api/part",
2418
"url_v1": "/v1/datatab/part",
2519
"part_schema": "/v1/obj/part_type"
2620
},
2721
"Downtime": {
28-
"url" : "/api/downtime",
2922
"url_v1" : "/v1/datatab/downtime"
3023

3124
},

smsdk/ma_session.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ def dict_to_df(data, normalize=True):
4848
if len(df) > 0:
4949
if '_id' in df.columns:
5050
df.set_index('_id', inplace=True)
51-
52-
if 'id' in df.columns:
51+
elif 'id' in df.columns:
5352
df.set_index('id', inplace=True)
5453
return df
5554

@@ -125,9 +124,8 @@ def _get_records(
125124
return records
126125
_offset += this_loop_limit
127126

128-
except:
129-
import traceback
130-
log.error(traceback.print_exc())
127+
except Exception as e:
128+
log.exception(str(e), exc_info=1)
131129
return records
132130

133131
def _get_schema(
@@ -230,10 +228,8 @@ def _get_records_v1(
230228
return records
231229
offset += this_loop_limit
232230

233-
except:
234-
import traceback
235-
236-
log.error(traceback.print_exc())
231+
except Exception as e:
232+
log.exception(str(e), exc_info=1)
237233
return records
238234

239235
def get_json_headers(self):

smsdk/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def get_url(protocol, tenant, site_domain):
2828

2929
return "{}://{}.{}".format(protocol, tenant, site_domain)
3030

31-
def check_kw(kw) -> bool:
31+
def check_kw(kw: str) -> bool:
32+
print(f"type of kw is {type(kw)}")
3233
for key in [
3334
"machine_type",
3435
"Machine",
@@ -38,6 +39,6 @@ def check_kw(kw) -> bool:
3839
"Start Time",
3940
"starttime"
4041
]:
41-
if kw[0] == "_" or key in kw:
42+
if kw.startswith("_") or key in kw:
4243
return False
4344
return True

0 commit comments

Comments
 (0)