Skip to content

Instantly share code, notes, and snippets.

@Glutexo
Last active February 4, 2022 20:51
Show Gist options
  • Save Glutexo/a93d92d3fe51c477e4407cb7f0b47731 to your computer and use it in GitHub Desktop.
Save Glutexo/a93d92d3fe51c477e4407cb7f0b47731 to your computer and use it in GitHub Desktop.
Get Insights Core version from Insights Client RPM
from contextlib import contextmanager
from os.path import join
from rpmfile import open as rpm_open
from sys import argv
from zipfile import ZipFile
EGG_PATH = join(".", "etc", "insights-client", "rpm.egg")
VERSION_PATH = join("insights", "VERSION")
@contextmanager
def get_egg(rpm_path):
with rpm_open(rpm_path) as rpm_file:
yield rpm_file.extractfile(EGG_PATH)
def get_version(egg):
zip_file = ZipFile(egg)
version_bytes = zip_file.read(VERSION_PATH)
version_string = version_bytes.decode("utf-8")
return version_string.rstrip()
def main(rpm_path):
with get_egg(rpm_path) as egg:
version = get_version(egg)
print(version)
if __name__ == "__main__":
if len(argv) == 2:
rpm_path_arg = argv[1]
else:
raise ValueError("Invalid argument count.")
main(rpm_path_arg)
rpmfile ~= "1.0.8"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment