Skip to content

Commit

Permalink
qvm-template-postprocess: treat missing appmenus files as warnings only
Browse files Browse the repository at this point in the history
Do not fail if *-whitelisted-appmenus.list files are not included in the
template package, only log an error.

While at it, use pathlib there to make the code a bit nicer.
  • Loading branch information
marmarek committed Feb 19, 2021
1 parent e6360da commit bcf5957
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions qubesadmin/tools/qvm_template_postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import asyncio
import glob
import os
import pathlib

import shutil
import subprocess
Expand Down Expand Up @@ -166,16 +167,26 @@ def import_appmenus(vm, source_dir, skip_generate=True):
# store the whitelists in VM features
# separated by spaces should be ok as there should be no spaces in the file
# name according to the FreeDesktop spec
with open(os.path.join(source_dir, 'vm-whitelisted-appmenus.list'), 'r') \
as fd:
vm.features['default-menu-items'] = ' '.join([x.rstrip() for x in fd])
with open(os.path.join(source_dir, 'whitelisted-appmenus.list'), 'r') \
as fd:
vm.features['menu-items'] = ' '.join([x.rstrip() for x in fd])
with open(
os.path.join(source_dir, 'netvm-whitelisted-appmenus.list'), 'r') \
as fd:
vm.features['netvm-menu-items'] = ' '.join([x.rstrip() for x in fd])
source_dir = pathlib.Path(source_dir)
try:
with open(source_dir / 'vm-whitelisted-appmenus.list', 'r') as fd:
vm.features['default-menu-items'] = \
' '.join([x.rstrip() for x in fd])
except FileNotFoundError as e:
vm.log.warning('Cannot set default-menu-items, %s not found',
e.filename)
try:
with open(source_dir / 'whitelisted-appmenus.list', 'r') as fd:
vm.features['menu-items'] = ' '.join([x.rstrip() for x in fd])
except FileNotFoundError as e:
vm.log.warning('Cannot set menu-items, %s not found',
e.filename)
try:
with open(source_dir / 'netvm-whitelisted-appmenus.list', 'r') as fd:
vm.features['netvm-menu-items'] = ' '.join([x.rstrip() for x in fd])
except FileNotFoundError as e:
vm.log.warning('Cannot set netvm-menu-items, %s not found',
e.filename)

if skip_generate:
return
Expand All @@ -184,11 +195,11 @@ def import_appmenus(vm, source_dir, skip_generate=True):
# implemented
try:
subprocess.check_call(cmd_prefix + ['qvm-appmenus',
'--set-default-whitelist={}'.format(os.path.join(source_dir,
'vm-whitelisted-appmenus.list')), vm.name])
'--set-default-whitelist={!s}'.format(
source_dir / 'vm-whitelisted-appmenus.list'), vm.name])
subprocess.check_call(cmd_prefix + ['qvm-appmenus',
'--set-whitelist={}'.format(os.path.join(source_dir,
'whitelisted-appmenus.list')), vm.name])
'--set-whitelist={!s}'.format(
source_dir / 'whitelisted-appmenus.list'), vm.name])
except subprocess.CalledProcessError as e:
vm.log.warning('Failed to set default application list: %s', e)

Expand Down

0 comments on commit bcf5957

Please sign in to comment.