General code cleanup
This commit is contained in:
parent
0bad386fbe
commit
88f7c7994e
@ -10,6 +10,8 @@ Version 1.6.1
|
|||||||
|
|
||||||
* Add --force-update option to script
|
* Add --force-update option to script
|
||||||
|
|
||||||
|
* General code cleanup
|
||||||
|
|
||||||
Version 1.6.0
|
Version 1.6.0
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
36
bin/pug2
36
bin/pug2
@ -58,16 +58,19 @@ def retrieve_gist_info(gist_id):
|
|||||||
:returns: data read from gist
|
:returns: data read from gist
|
||||||
:rtype: bytes
|
:rtype: bytes
|
||||||
"""
|
"""
|
||||||
return subprocess.run(f"gist --read {gist_id}", capture_output=True).stdout
|
return subprocess.run(
|
||||||
|
["gist", "--read", gist_id], capture_output=True, text=True
|
||||||
|
|
||||||
def package_lists_match(gist_id):
|
|
||||||
"""Compare local package list to that of pacman and gist, return if they match."""
|
|
||||||
local_packages = subprocess.run(["pacman", "-Qqen"], capture_output=True).stdout
|
|
||||||
gist_packages = subprocess.run(
|
|
||||||
["gist", "--read", gist_id], capture_output=True
|
|
||||||
).stdout
|
).stdout
|
||||||
return local_packages == gist_packages
|
|
||||||
|
|
||||||
|
def package_lists_match(gist_id, package_list):
|
||||||
|
"""Compare local package list to that of pacman and gist, return if they match.
|
||||||
|
:param gist_id: ID of the gist to read from
|
||||||
|
:param package_list: Newline separated list of packages installed on the system
|
||||||
|
:type gist_id: str
|
||||||
|
:type package_list: str
|
||||||
|
"""
|
||||||
|
return retrieve_gist_info(gist_id) == package_list
|
||||||
|
|
||||||
|
|
||||||
# ========== Main Script ==========
|
# ========== Main Script ==========
|
||||||
@ -99,15 +102,20 @@ if __name__ == "__main__":
|
|||||||
gist_description = config.get(CONFIG_SECTION, CONFIG_OPTION_DESCRIPTION)
|
gist_description = config.get(CONFIG_SECTION, CONFIG_OPTION_DESCRIPTION)
|
||||||
gist_filename = config.get(CONFIG_SECTION, CONFIG_OPTION_FILENAME)
|
gist_filename = config.get(CONFIG_SECTION, CONFIG_OPTION_FILENAME)
|
||||||
gist_id = config.get(CONFIG_SECTION, CONFIG_OPTION_ID)
|
gist_id = config.get(CONFIG_SECTION, CONFIG_OPTION_ID)
|
||||||
|
gist_opts = ["--filename", gist_filename, "--description", gist_description]
|
||||||
|
|
||||||
|
packages = subprocess.run(
|
||||||
|
["pacman", "-Qqen"], capture_output=True, text=True
|
||||||
|
).stdout
|
||||||
|
|
||||||
if gist_id == "":
|
if gist_id == "":
|
||||||
try:
|
try:
|
||||||
print("No gist ID detected, creating new.")
|
print("No gist ID detected, creating new.")
|
||||||
gist_process = subprocess.run(
|
gist_process = subprocess.run(
|
||||||
f"pacman -Qqen | gist --filename {gist_filename} --description {gist_description}",
|
["gist", *gist_opts],
|
||||||
|
input=packages,
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
shell=True,
|
|
||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
@ -124,12 +132,12 @@ if __name__ == "__main__":
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
print("Package lists differ, updating.")
|
print("Updating package list.")
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
f"pacman -Qqen | gist --update {gist_id} --filename {gist_filename} --description {gist_description}",
|
["gist", "--update", gist_id, *gist_opts],
|
||||||
|
input=packages,
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
shell=True,
|
|
||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user