Skip to content

Commit

Permalink
All linted
Browse files Browse the repository at this point in the history
  • Loading branch information
brickbots committed Jun 11, 2024
1 parent 7b90ba6 commit 9545a1f
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 74 deletions.
12 changes: 6 additions & 6 deletions python/PiFinder/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ def send_image(filename):
return static_file(filename, root="views/images", mimetype="image/png")

@app.route("/js/<filename>")
def send_static(filename):
def send_js(filename):
return static_file(filename, root="views/js")

@app.route("/css/<filename>")
def send_static(filename):
def send_css(filename):
return static_file(filename, root="views/css")

@app.route("/")
Expand Down Expand Up @@ -219,7 +219,7 @@ def gps_update():

@app.route("/network/add", method="post")
@auth_required
def network_update():
def network_add():
ssid = request.forms.get("ssid")
psk = request.forms.get("psk")
if len(psk) < 8:
Expand Down Expand Up @@ -282,7 +282,7 @@ def system_restart():

@app.route("/system/restart_pifinder")
@auth_required
def system_restart():
def pifinder_restart():
"""
Restarts just the PiFinder software
"""
Expand Down Expand Up @@ -347,14 +347,14 @@ def tools():
@app.route("/tools/backup")
@auth_required
def tools_backup():
backup_file = sys_utils.backup_userdata()
_backup_file = sys_utils.backup_userdata()

# Assumes the standard backup location
return static_file("PiFinder_backup.zip", "/home/pifinder/PiFinder_data")

@app.route("/tools/restore", method="post")
@auth_required
def tools_backup():
def tools_restore():
sys_utils.remove_backup()
backup_file = request.files.get("backup_file")
backup_file.filename = "PiFinder_backup.zip"
Expand Down
90 changes: 44 additions & 46 deletions python/PiFinder/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def insert_catalog_max_sequence(catalog_name):
def resolve_object_images():
# This is the list of catalogs to search for
# objects to match against image names
conn, db_c = objects_db.get_conn_cursor()
_conn, db_c = objects_db.get_conn_cursor()
resolution_priority = db_c.execute(
"""
SELECT catalog_code
Expand Down Expand Up @@ -209,11 +209,10 @@ def _load_deepmap_600():
]
obj_list = []
with open(data_path, "r") as deepmap:
field_index = 0
for l in deepmap:
for line in deepmap:
obj_rec = {}
l = l.strip()
ll = l.split("\t")
line = line.strip()
ll = line.split("\t")
for i, v in enumerate(ll):
obj_rec[field_list[i]] = v
obj_list.append(obj_rec)
Expand All @@ -228,7 +227,7 @@ def load_egc():
"""
logging.info("Loading EGC")
catalog = "EGC"
conn, db_c = objects_db.get_conn_cursor()
conn, _db_c = objects_db.get_conn_cursor()
delete_catalog_from_database(catalog)

insert_catalog(catalog, Path(utils.astro_data_dir, "EGC.desc"))
Expand All @@ -237,8 +236,8 @@ def load_egc():
with open(egc, "r") as df:
# skip title line
df.readline()
for l in tqdm(list(df)):
dfs = l.split("\t")
for line in tqdm(list(df)):
dfs = line.split("\t")
sequence = dfs[0]
other_names = dfs[1].split(",")

Expand All @@ -265,7 +264,7 @@ def load_egc():
object_id = object_finder.get_object_id(name)

# Assuming all the parsing logic is done and all variables are available...
if object_id == None:
if object_id is None:
obj_type = "Gb"
object_id = objects_db.insert_object(
obj_type, ra_deg, dec_deg, const, size, mag
Expand All @@ -283,7 +282,7 @@ def load_egc():
def load_collinder():
logging.info("Loading Collinder")
catalog = "Col"
conn, db_c = objects_db.get_conn_cursor()
conn, _db_c = objects_db.get_conn_cursor()
delete_catalog_from_database(catalog)
insert_catalog(catalog, Path(utils.astro_data_dir, "collinder.desc"))
object_finder = ObjectFinder()
Expand All @@ -304,8 +303,8 @@ def load_collinder():
c_dict = {}
with open(coll, "r") as df:
df.readline()
for l in tqdm(list(df)):
dfs = l.split("\t")
for line in tqdm(list(df)):
dfs = line.split("\t")
sequence = dfs[0].split(" ")[0]
other_names = dfs[1]
if other_names.isnumeric():
Expand Down Expand Up @@ -354,8 +353,8 @@ def load_collinder():
with open(coll2, "r") as df:
duplicate_names = set()
df.readline()
for l in tqdm(list(df)):
dfs = l.split("\t")
for line in tqdm(list(df)):
dfs = line.split("\t")
sequence = dfs[0].split(" ")[1]
obj_type = type_trans.get(dfs[4], "OC")
mag = dfs[6].strip().split(" ")[0]
Expand Down Expand Up @@ -409,8 +408,8 @@ def load_bright_stars():
# skip header
df.readline()
obj_type = "* "
for l in tqdm(list(df)):
dfs = l.split(",")
for line in tqdm(list(df)):
dfs = line.split(",")
dfs = [d.strip() for d in dfs]
other_names = dfs[1:3]
sequence = int(dfs[0]) + 1
Expand Down Expand Up @@ -460,8 +459,8 @@ def load_herschel400():
with open(hcat, "r") as df:
# skip column headers
df.readline()
for l in tqdm(list(df)):
dfs = l.split("\t")
for line in tqdm(list(df)):
dfs = line.split("\t")
dfs = [d.strip() for d in dfs]
NGC_sequence = dfs[0]
h_name = dfs[7]
Expand Down Expand Up @@ -491,8 +490,8 @@ def load_sac_asterisms():
with open(saca, "r") as df:
df.readline()
obj_type = "Ast"
for l in tqdm(list(df)):
dfs = l.split("|")
for line in tqdm(list(df)):
dfs = line.split("|")
dfs = [d.strip() for d in dfs]
other_names = dfs[1].strip()
if other_names == "":
Expand Down Expand Up @@ -550,8 +549,8 @@ def load_sac_multistars():
with open(saca, "r") as df:
df.readline()
obj_type = "D*"
for l in tqdm(list(df)):
dfs = l.split("|")
for line in tqdm(list(df)):
dfs = line.split("|")
dfs = [d.strip() for d in dfs]
name = [dfs[2].strip()]
other_names = dfs[6].strip().split(";")
Expand Down Expand Up @@ -618,8 +617,8 @@ def load_sac_redstars():
with open(sac, "r") as df:
df.readline()
obj_type = "D*"
for l in tqdm(list(df)):
dfs = l.split("|")
for line in tqdm(list(df)):
dfs = line.split("|")
dfs = [d.strip() for d in dfs]
name = [dfs[1].strip()]
other_names = dfs[2].strip().split(";")
Expand Down Expand Up @@ -773,8 +772,8 @@ def load_caldwell():
object_finder = ObjectFinder()
data = Path(utils.astro_data_dir, "caldwell.dat")
with open(data, "r") as df:
for l in tqdm(list(df)):
dfs = l.split("\t")
for line in tqdm(list(df)):
dfs = line.split("\t")
sequence = dfs[0].strip()
logging.debug(f"<----------------- Caldwell {sequence=} ----------------->")
other_names = add_space_after_prefix(dfs[1])
Expand Down Expand Up @@ -1079,7 +1078,7 @@ def load_abell():

def load_ngc_catalog():
logging.info("Loading NGC catalog")
conn, db_c = objects_db.get_conn_cursor()
conn, _db_c = objects_db.get_conn_cursor()
object_id_desc_dict = {}

ngc_dat_files = [
Expand All @@ -1096,25 +1095,25 @@ def load_ngc_catalog():

for ngc_dat in ngc_dat_files:
with open(ngc_dat, "r") as ngc:
for l in tqdm(list(ngc)):
sequence = int(l[1:5])
for line in tqdm(list(ngc)):
sequence = int(line[1:5])
# add = True
catalog = l[0:1]
catalog = line[0:1]
if catalog == " " or catalog == "N":
catalog = "NGC"
if catalog == "I":
catalog = "IC"
obj_type = l[6:9].strip()
rah = int(l[10:12])
ram = float(l[13:17])
des = l[19:20]
ded = int(l[20:22])
dem = int(l[23:25])
const = l[29:32]
l_size = l[32:33]
size = l_size + l[33:38]
mag = l[40:44]
desc = l[46:].strip()
obj_type = line[6:9].strip()
rah = int(line[10:12])
ram = float(line[13:17])
des = line[19:20]
ded = int(line[20:22])
dem = int(line[23:25])
const = line[29:32]
line_size = line[32:33]
size = line_size + line[33:38]
mag = line[40:44]
desc = line[46:].strip()

dec = ded + (dem / 60)
if des == "-":
Expand All @@ -1136,22 +1135,21 @@ def load_ngc_catalog():
seen = set()
for name_dat in tqdm(name_dat_files):
with open(name_dat, "r") as names:
for l in names:
for line in names:
m_sequence = ""
common_name = l[0:35]
common_name = line[0:35]
if common_name.startswith("M "):
m_sequence = common_name[2:].strip()
common_name = "M" + m_sequence
catalog = l[36:37]
catalog = line[36:37]
if catalog == " ":
catalog = "N"
if catalog == "N":
catalog = "NGC"
if catalog == "I":
catalog = "IC"

ngc_ic_sequence = l[37:41].strip()
comment = l[42:]
ngc_ic_sequence = line[37:41].strip()

if ngc_ic_sequence != "":
obj = objects_db.get_catalog_object_by_sequence(
Expand Down
32 changes: 16 additions & 16 deletions python/PiFinder/sys_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def populate_wifi_networks(self):
with open("/etc/wpa_supplicant/wpa_supplicant.conf", "r") as wpa_conf:
network_id = 0
in_network_block = False
for l in wpa_conf:
if l.startswith("network={"):
for line in wpa_conf:
if line.startswith("network={"):
in_network_block = True
network_dict = {
"id": network_id,
Expand All @@ -38,13 +38,13 @@ def populate_wifi_networks(self):
"key_mgmt": None,
}

elif l.strip() == "}" and in_network_block:
elif line.strip() == "}" and in_network_block:
in_network_block = False
self._wifi_networks.append(network_dict)
network_id += 1

elif in_network_block:
key, value = l.strip().split("=")
key, value = line.strip().split("=")
network_dict[key] = value.strip('"')

def get_wifi_networks(self):
Expand All @@ -61,12 +61,12 @@ def delete_wifi_network(self, network_id):

with open("/etc/wpa_supplicant/wpa_supplicant.conf", "w") as wpa_conf:
in_networks = False
for l in wpa_contents:
for line in wpa_contents:
if not in_networks:
if l.startswith("network={"):
if line.startswith("network={"):
in_networks = True
else:
wpa_conf.write(l)
wpa_conf.write(line)

for network in self._wifi_networks:
ssid = network["ssid"]
Expand Down Expand Up @@ -103,20 +103,20 @@ def add_wifi_network(self, ssid, key_mgmt, psk=None):

def get_ap_name(self):
with open("/etc/hostapd/hostapd.conf", "r") as conf:
for l in conf:
if l.startswith("ssid="):
return l[5:-1]
for line in conf:
if line.startswith("ssid="):
return line[5:-1]
return "UNKN"

def set_ap_name(self, ap_name):
if ap_name == self.get_ap_name():
return
with open("/tmp/hostapd.conf", "w") as new_conf:
with open("/etc/hostapd/hostapd.conf", "r") as conf:
for l in conf:
if l.startswith("ssid="):
l = f"ssid={ap_name}\n"
new_conf.write(l)
for line in conf:
if line.startswith("ssid="):
line = f"ssid={ap_name}\n"
new_conf.write(line)
sh.sudo("cp", "/tmp/hostapd.conf", "/etc/hostapd/hostapd.conf")

def get_host_name(self):
Expand All @@ -137,7 +137,7 @@ def get_connected_ssid(self):
def set_host_name(self, hostname):
if hostname == self.get_host_name():
return
result = sh.sudo("hostnamectl", "set-hostname", hostname)
_result = sh.sudo("hostnamectl", "set-hostname", hostname)

def wifi_mode(self):
return self._wifi_mode
Expand All @@ -159,7 +159,7 @@ def local_ip(self):
try:
s.connect(("192.255.255.255", 1))
ip = s.getsockname()[0]
except:
except Exception:
ip = "NONE"
finally:
s.close()
Expand Down
1 change: 0 additions & 1 deletion python/PiFinder/sys_utils_fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def get_connected_ssid(self):
def set_host_name(self, hostname):
if hostname == self.get_host_name():
return
result = "UNKN"

def wifi_mode(self):
return "UNKN"
Expand Down
4 changes: 2 additions & 2 deletions python/PiFinder/ui/nearby.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def create_locate_text(self) -> List[Tuple[str, TextLayouterSimple]]:
_, obj_dist = self.space_calculator.calculate_spaces(
obj_name, distance, empty_if_exceeds=False, trunc_left=True
)
obj_mag, obj_color = self._obj_to_mag_color(obj)
_obj_mag, obj_color = self._obj_to_mag_color(obj)
entry = self.simpleTextLayout(
obj_dist,
font=self.fonts.base,
Expand All @@ -253,7 +253,7 @@ def create_name_text(self) -> List[Tuple[str, TextLayouterSimple]]:
obj_name, full_name, empty_if_exceeds=False, trunc_left=False
)

obj_mag, obj_color = self._obj_to_mag_color(obj)
_obj_mag, obj_color = self._obj_to_mag_color(obj)
entry = self.simpleTextLayout(
obj_dist,
font=self.fonts.base,
Expand Down
Loading

0 comments on commit 9545a1f

Please sign in to comment.