qvm-template-postprocess: treat missing appmenus files as warnings only
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.
This commit is contained in:
parent
e6360da22e
commit
bcf59579f1
@ -23,6 +23,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
|
import pathlib
|
||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -166,16 +167,26 @@ def import_appmenus(vm, source_dir, skip_generate=True):
|
|||||||
# store the whitelists in VM features
|
# store the whitelists in VM features
|
||||||
# separated by spaces should be ok as there should be no spaces in the file
|
# separated by spaces should be ok as there should be no spaces in the file
|
||||||
# name according to the FreeDesktop spec
|
# name according to the FreeDesktop spec
|
||||||
with open(os.path.join(source_dir, 'vm-whitelisted-appmenus.list'), 'r') \
|
source_dir = pathlib.Path(source_dir)
|
||||||
as fd:
|
try:
|
||||||
vm.features['default-menu-items'] = ' '.join([x.rstrip() for x in fd])
|
with open(source_dir / 'vm-whitelisted-appmenus.list', 'r') as fd:
|
||||||
with open(os.path.join(source_dir, 'whitelisted-appmenus.list'), 'r') \
|
vm.features['default-menu-items'] = \
|
||||||
as fd:
|
' '.join([x.rstrip() for x in fd])
|
||||||
vm.features['menu-items'] = ' '.join([x.rstrip() for x in fd])
|
except FileNotFoundError as e:
|
||||||
with open(
|
vm.log.warning('Cannot set default-menu-items, %s not found',
|
||||||
os.path.join(source_dir, 'netvm-whitelisted-appmenus.list'), 'r') \
|
e.filename)
|
||||||
as fd:
|
try:
|
||||||
vm.features['netvm-menu-items'] = ' '.join([x.rstrip() for x in fd])
|
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:
|
if skip_generate:
|
||||||
return
|
return
|
||||||
@ -184,11 +195,11 @@ def import_appmenus(vm, source_dir, skip_generate=True):
|
|||||||
# implemented
|
# implemented
|
||||||
try:
|
try:
|
||||||
subprocess.check_call(cmd_prefix + ['qvm-appmenus',
|
subprocess.check_call(cmd_prefix + ['qvm-appmenus',
|
||||||
'--set-default-whitelist={}'.format(os.path.join(source_dir,
|
'--set-default-whitelist={!s}'.format(
|
||||||
'vm-whitelisted-appmenus.list')), vm.name])
|
source_dir / 'vm-whitelisted-appmenus.list'), vm.name])
|
||||||
subprocess.check_call(cmd_prefix + ['qvm-appmenus',
|
subprocess.check_call(cmd_prefix + ['qvm-appmenus',
|
||||||
'--set-whitelist={}'.format(os.path.join(source_dir,
|
'--set-whitelist={!s}'.format(
|
||||||
'whitelisted-appmenus.list')), vm.name])
|
source_dir / 'whitelisted-appmenus.list'), vm.name])
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
vm.log.warning('Failed to set default application list: %s', e)
|
vm.log.warning('Failed to set default application list: %s', e)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user