Skip to content

Commit

Permalink
Merge pull request #17 from bibajz/patch-1
Browse files Browse the repository at this point in the history
Replace usages of `list.insert(0, ...)`
  • Loading branch information
dgeo authored Sep 11, 2024
2 parents 30b4856 + 327fcc9 commit c6e10a0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 28 deletions.
4 changes: 2 additions & 2 deletions iocage_cli/df.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ def cli(header, _long, _sort):
jail_list.sort(key=sort)

if header:
jail_list.insert(0, ["NAME", "CRT", "RES", "QTA", "USE", "AVA"])
table.header(["NAME", "CRT", "RES", "QTA", "USE", "AVA"])
# We get an infinite float otherwise.
table.set_cols_dtype(["t", "t", "t", "t", "t", "t"])
table.add_rows(jail_list)
table.add_rows(jail_list, header=False)

ioc_common.logit({"level": "INFO", "message": table.draw()})
else:
Expand Down
4 changes: 2 additions & 2 deletions iocage_cli/snaplist.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def cli(header, jail, _long, _sort):
snap_list = ioc.IOCage(jail=jail).snap_list(_long, _sort)

if header:
snap_list.insert(0, ["NAME", "CREATED", "RSIZE", "USED"])
table.header(["NAME", "CREATED", "RSIZE", "USED"])
# We get an infinite float otherwise.
table.set_cols_dtype(["t", "t", "t", "t"])
table.add_rows(snap_list)
table.add_rows(snap_list, header=False)
ioc_common.logit({
"level" : "INFO",
"message": table.draw()
Expand Down
9 changes: 3 additions & 6 deletions iocage_lib/ioc_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,19 +487,16 @@ def sort_release(releases, split=False, fetch_releases=False):
pass

ordered_r_dict = collections.OrderedDict(sorted(r_dict.items()))
index = 0

for r, t in ordered_r_dict.items():
if split:
r = r.rsplit('_')[0] # Remove the enumeration
if t:
release_list.insert(index, [f"{r}-{t}"])
release_list.append([f"{r}-{t}"])
else:
release_list.insert(index, [r])
index += 1
release_list.append([r])
else:
release_list.insert(index, f"{r}-{t}")
index += 1
release_list.append(f"{r}-{t}")

return release_list

Expand Down
5 changes: 2 additions & 3 deletions iocage_lib/ioc_fstab.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,8 @@ def fstab_list(self):

# We get an infinite float otherwise.
table.set_cols_dtype(["t", "t"])
flat_fstab.insert(0, ["INDEX", "FSTAB ENTRY"])

table.add_rows(flat_fstab)
table.header(["INDEX", "FSTAB ENTRY"])
table.add_rows(flat_fstab, header=False)

return table.draw()

Expand Down
23 changes: 10 additions & 13 deletions iocage_lib/ioc_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,8 @@ def list_all_quick(self, jails):

# We get an infinite float otherwise.
table.set_cols_dtype(["t", "t"])
jail_list.insert(0, ["NAME", "IP4"])

table.add_rows(jail_list)
table.header(["NAME", "IP4"])
table.add_rows(jail_list, header=False)

return table.draw()

Expand Down Expand Up @@ -443,23 +442,21 @@ def list_all(self, jails):
table.set_cols_dtype(["t", "t", "t", "t", "t", "t", "t", "t",
"t", "t", "t"])

jail_list.insert(0, ["JID", "NAME", "BOOT", "STATE", "TYPE",
"RELEASE", "IP4", "IP6", "TEMPLATE",
"PORTAL", "DOC_URL"])
table.header(["JID", "NAME", "BOOT", "STATE", "TYPE", "RELEASE",
"IP4", "IP6", "TEMPLATE", "PORTAL", "DOC_URL"])
else:
# We get an infinite float otherwise.
table.set_cols_dtype(["t", "t", "t", "t", "t", "t", "t", "t",
"t", "t"])

jail_list.insert(0, ["JID", "NAME", "BOOT", "STATE", "TYPE",
"RELEASE", "IP4", "IP6", "TEMPLATE",
'BASEJAIL'])
table.header(["JID", "NAME", "BOOT", "STATE", "TYPE", "RELEASE",
"IP4", "IP6", "TEMPLATE", 'BASEJAIL'])
else:
# We get an infinite float otherwise.
table.set_cols_dtype(["t", "t", "t", "t", "t"])
jail_list.insert(0, ["JID", "NAME", "STATE", "RELEASE", "IP4"])
table.header(["JID", "NAME", "STATE", "RELEASE", "IP4"])

table.add_rows(jail_list)
table.add_rows(jail_list, header=False)

return table.draw()

Expand All @@ -474,8 +471,8 @@ def list_bases(self, datasets):

return flat_base

base_list.insert(0, ["Bases fetched"])
table.add_rows(base_list)
table.header(["Bases fetched"])
table.add_rows(base_list, header=False)
# We get an infinite float otherwise.
table.set_cols_dtype(["t"])

Expand Down
4 changes: 2 additions & 2 deletions iocage_lib/ioc_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,9 @@ def fetch_plugin_index(
)
for p in plugin_list
]
plugin_list.insert(0, list_header)

table.add_rows(plugin_list)
table.header(list_header)
table.add_rows(plugin_list, header=False)

return table.draw()

Expand Down

0 comments on commit c6e10a0

Please sign in to comment.