Skip to content

Commit 1f84f0f

Browse files
committed
appmenus: tweak style to match existing codebase conventions
1 parent 745c359 commit 1f84f0f

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

qubesappmenus/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,10 @@ def appmenus_remove(self, vm, refresh_cache=True):
510510

511511
@staticmethod
512512
def _remove_menu_files(vm):
513-
"""Remove leftover .menu files from ~/.config/menus/applications-merged/.
513+
"""Remove .menu files for a VM from ~/.config/menus/applications-merged/
514514
515-
xdg-desktop-menu uninstall may not clean these up reliably (errors are
516-
suppressed, and accumulated installs can leave residual entries).
517-
Explicitly remove the known .menu file paths for this VM.
515+
xdg-desktop-menu uninstall does not always clean these up (errors
516+
are suppressed, partial installs can leave entries behind).
518517
"""
519518
menus_dir = os.path.join(xdg.BaseDirectory.xdg_config_home,
520519
'menus', 'applications-merged')
@@ -523,11 +522,10 @@ def _remove_menu_files(vm):
523522
vm_name = str(vm)
524523
escaped = vm_name_escape(vm_name)
525524
for prefix in ('qubes-vm-directory', 'qubes-dispvm-directory'):
526-
# current format (escaped VM name)
527525
with contextlib.suppress(FileNotFoundError):
528526
os.unlink(os.path.join(menus_dir,
529527
'user-' + prefix + escaped + '.menu'))
530-
# old format (raw dash-separated name, pre-escaping era)
528+
# also try old format (before VM name escaping was introduced)
531529
with contextlib.suppress(FileNotFoundError):
532530
os.unlink(os.path.join(menus_dir,
533531
'user-' + prefix + '-' + vm_name + '.menu'))

qubesappmenus/tests.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import io
2626
import os
27+
import shutil
2728
import tempfile
2829
import sys
2930

@@ -728,7 +729,7 @@ def test_131_set_get_default_whitelist(self, mock_subprocess):
728729

729730

730731
@unittest.mock.patch('subprocess.check_call')
731-
def test_140_remove_appvm_cleans_menu_file(self, mock_subprocess):
732+
def test_140_remove_cleans_menu_files(self, mock_subprocess):
732733
tpl = TestVM('test-inst-tpl',
733734
klass='TemplateVM',
734735
virt_mode='pvh',
@@ -746,20 +747,20 @@ def test_140_remove_appvm_cleans_menu_file(self, mock_subprocess):
746747
self.ext.appmenus_init(appvm)
747748
self.ext.appmenus_create(appvm, refresh_cache=False)
748749

749-
# Simulate leftover .menu files left by xdg-desktop-menu install
750750
config_dir = tempfile.mkdtemp()
751751
try:
752752
menus_dir = os.path.join(config_dir, 'menus', 'applications-merged')
753753
os.makedirs(menus_dir)
754754
escaped = qubesappmenus.vm_name_escape(appvm.name)
755+
# current-format .menu file
755756
menu_file = os.path.join(menus_dir,
756-
'user-qubes-vm-directory' + escaped + '.menu')
757+
'user-qubes-vm-directory' + escaped + '.menu')
758+
# old-format .menu file (pre-escaping)
757759
old_menu_file = os.path.join(menus_dir,
758-
'user-qubes-vm-directory-' + appvm.name + '.menu')
759-
with open(menu_file, 'w', encoding='utf-8') as f:
760-
f.write('<Menu/>\n')
761-
with open(old_menu_file, 'w', encoding='utf-8') as f:
762-
f.write('<Menu/>\n')
760+
'user-qubes-vm-directory-' + appvm.name + '.menu')
761+
for path in (menu_file, old_menu_file):
762+
with open(path, 'w', encoding='utf-8') as f:
763+
f.write('<Menu/>\n')
763764

764765
with unittest.mock.patch('xdg.BaseDirectory.xdg_config_home',
765766
config_dir):

0 commit comments

Comments
 (0)