From 0e8e8d98de53285d84c6327174ee3527048e4d8e Mon Sep 17 00:00:00 2001 From: WillyPillow Date: Thu, 9 Jul 2020 02:38:36 +0800 Subject: [PATCH] Better way of detecting VM. --- qubesadmin/tools/qvm_template.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/qubesadmin/tools/qvm_template.py b/qubesadmin/tools/qvm_template.py index 293690f..3d3ad0a 100644 --- a/qubesadmin/tools/qvm_template.py +++ b/qubesadmin/tools/qvm_template.py @@ -20,17 +20,12 @@ PACKAGE_NAME_PREFIX = 'qubes-template-' CACHE_DIR = os.path.join(xdg.BaseDirectory.xdg_cache_home, 'qvm-template') def qubes_release(): - try: - os_id = subprocess.check_output(['lsb_release', '-si'], - encoding='UTF-8').strip() - if os_id == 'Qubes': - return subprocess.check_output(['lsb_release', '-sr'], - encoding='UTF-8').strip() - except: - pass - with open('/usr/share/qubes/marker-vm', 'r') as f: - # Get last line (in the format `x.x`) - return f.readlines[-1].strip() + if os.path.exists('/usr/share/qubes/marker-vm'): + with open('/usr/share/qubes/marker-vm', 'r') as f: + # Get last line (in the format `x.x`) + return f.readlines()[-1].strip() + return subprocess.check_output(['lsb_release', '-sr'], + encoding='UTF-8').strip() parser = argparse.ArgumentParser(description='Qubes Template Manager') parser.add_argument('operation', type=str)