Skip to content

Commit 01d4f62

Browse files
committed
STY: formatted with ruff
1 parent 6445868 commit 01d4f62

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed
File renamed without changes.
File renamed without changes.

src/save_and_restore_api/tools/upload.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import httpx
1+
import getpass
22
import logging
33
import pprint
4-
import json
5-
import getpass
4+
5+
import httpx
66

77
logger = logging.getLogger(__name__)
88

99
BASE_URL = "http://epics-services-hxn.nsls2.bnl.local:20381/save-restore"
1010
timeout = 2
1111
file_name = "auto_settings.sav"
1212

13-
class SaveRestoreAPI:
1413

14+
class SaveRestoreAPI:
1515
def __init__(self, *, base_url, timeout):
1616
self._base_url = base_url
1717
self._timeout = timeout
@@ -45,27 +45,26 @@ def set_username_password(self, username=None, password=None):
4545
self._username = username
4646
self._password = password
4747

48-
4948
def login(self, *, username=None, password=None):
50-
params = dict(username=self._username, password=self._password)
49+
params = {"username": self._username, "password": self._password}
5150
self.send_request("POST", "/login", json=params)
5251

5352
def send_request(self, method, url, **kwargs):
5453
response = self._client.request(method, url, **kwargs)
5554

5655
print(f"{response.request.url=}")
57-
print(f"{response.headers.get("content-type")=}")
56+
print(f"{response.headers.get('content-type')=}")
5857

5958
if response.status_code != 200:
6059
print(f"Request failed: status code {response.status_code}")
6160
print(f"Error message: {response.text}")
6261
raise Exception(f"Request failed with code {response.status_code}")
63-
62+
6463
if response.headers.get("content-type") == "application/json":
6564
data = response.json()
6665
else:
6766
data = {}
68-
67+
6968
return data
7069

7170
def get_node(self, node_uid):
@@ -83,7 +82,7 @@ def create_config(self, parent_node_uid, name, pv_list):
8382
},
8483
"configurationData": {
8584
"pvList": pv_list,
86-
}
85+
},
8786
}
8887
print(f"config_dict=\n{pprint.pformat(config_dict)}")
8988
return self.send_request("PUT", f"/config?parentNodeId={parent_node_uid}", json=config_dict)
@@ -98,39 +97,38 @@ def update_config(self, node_uid, name, pv_list):
9897
},
9998
"configurationData": {
10099
"pvList": pv_list,
101-
}
100+
},
102101
}
103102
print(f"config_dict=\n{pprint.pformat(config_dict)}")
104103
# return self.send_request("POST", f"/config/{node_uid}", json=config_dict)
105-
return self.send_request("POST", f"/config", json=config_dict)
104+
return self.send_request("POST", "/config", json=config_dict)
105+
106106

107107
def add_to_pv_list(pv_list, *, pv_name):
108-
pv_list.append(dict(pvName=pv_name))
108+
pv_list.append({"pvName": pv_name})
109+
109110

110111
def load_pvs_from_autosave_file(file_name):
111112
pv_names = []
112-
with open(file_name, 'r') as f:
113+
with open(file_name) as f:
113114
for line in f:
114-
l = line.strip()
115-
if l.startswith("#") or l.startswith("<"):
115+
ln = line.strip()
116+
if ln.startswith("#") or ln.startswith("<"):
116117
continue
117-
pv_name = l.split(" ")[0]
118+
pv_name = ln.split(" ")[0]
118119
if pv_name:
119120
pv_names.append(pv_name)
120121
return pv_names
121122

122123

123-
# if __name__ == "__main__":
124-
125124
def main():
126125
logging.basicConfig(level=logging.WARNING)
127126
# logging.getLogger("bluesky_queueserver").setLevel("INFO")
128127

129128
SR = SaveRestoreAPI(base_url=BASE_URL, timeout=timeout)
130129
try:
131-
132130
pv_names = load_pvs_from_autosave_file(file_name)
133-
131+
134132
SR.set_username_password()
135133
SR.open()
136134
SR.login()
@@ -153,4 +151,4 @@ def main():
153151
print(f"data=\n{pprint.pformat(data)}")
154152

155153
finally:
156-
SR.close()
154+
SR.close()

0 commit comments

Comments
 (0)