Merge remote-tracking branch 'qubesos/pr/4'
* qubesos/pr/4: Add qvm-appmenu-replace tool.
This commit is contained in:
commit
fc2e8264d4
@ -84,6 +84,14 @@ def QubesVm_get_appmenus_icons_dir(self):
|
|||||||
QubesVm.appmenus_icons_dir = property(QubesVm_get_appmenus_icons_dir)
|
QubesVm.appmenus_icons_dir = property(QubesVm_get_appmenus_icons_dir)
|
||||||
|
|
||||||
|
|
||||||
|
def get_whitelist_names(vm):
|
||||||
|
return (whitelist for whitelist in (
|
||||||
|
vm_files["appmenus_whitelist"],
|
||||||
|
'vm-' + vm_files["appmenus_whitelist"],
|
||||||
|
'netvm-' + vm_files["appmenus_whitelist"])
|
||||||
|
if os.path.exists(os.path.join(vm.dir_path, whitelist)))
|
||||||
|
|
||||||
|
|
||||||
def QubesVm_appmenus_create(self, verbose=False, source_template=None):
|
def QubesVm_appmenus_create(self, verbose=False, source_template=None):
|
||||||
if source_template is None:
|
if source_template is None:
|
||||||
source_template = self.template
|
source_template = self.template
|
||||||
@ -148,6 +156,19 @@ def QubesVm_appmenus_cleanup(self):
|
|||||||
os.unlink(os.path.join(self.appmenus_dir, appmenu))
|
os.unlink(os.path.join(self.appmenus_dir, appmenu))
|
||||||
|
|
||||||
|
|
||||||
|
def QubesVm_appmenus_replace_entry(self, old_name, new_name):
|
||||||
|
for whitelist in get_whitelist_names(self):
|
||||||
|
whitelist_path = os.path.join(self.dir_path, whitelist)
|
||||||
|
with open(whitelist_path) as f:
|
||||||
|
old_lines = f.readlines()
|
||||||
|
new_lines = [
|
||||||
|
(new_name + '\n' if l == old_name + '\n' else l)
|
||||||
|
for l in old_lines]
|
||||||
|
if new_lines != old_lines:
|
||||||
|
with open(whitelist_path, 'w') as f:
|
||||||
|
f.write(''.join(new_lines))
|
||||||
|
|
||||||
|
|
||||||
def QubesVm_appicons_create(self, srcdir=None):
|
def QubesVm_appicons_create(self, srcdir=None):
|
||||||
if srcdir is None:
|
if srcdir is None:
|
||||||
srcdir = self.appmenus_template_icons_dir
|
srcdir = self.appmenus_template_icons_dir
|
||||||
@ -277,16 +298,12 @@ def QubesVm_clone_disk_files(self, src_vm, verbose):
|
|||||||
shutil.copytree(src_vm.appmenus_template_icons_dir,
|
shutil.copytree(src_vm.appmenus_template_icons_dir,
|
||||||
self.appmenus_template_icons_dir)
|
self.appmenus_template_icons_dir)
|
||||||
|
|
||||||
for whitelist in (
|
for whitelist in get_whitelist_names(src_vm):
|
||||||
vm_files["appmenus_whitelist"],
|
if verbose:
|
||||||
'vm-' + vm_files["appmenus_whitelist"],
|
print >> sys.stderr, "--> Copying whitelisted apps list: {0}". \
|
||||||
'netvm-' + vm_files["appmenus_whitelist"]):
|
format(whitelist)
|
||||||
if os.path.exists(os.path.join(src_vm.dir_path, whitelist)):
|
shutil.copy(os.path.join(src_vm.dir_path, whitelist),
|
||||||
if verbose:
|
os.path.join(self.dir_path, whitelist))
|
||||||
print >> sys.stderr, "--> Copying whitelisted apps list: {0}". \
|
|
||||||
format(whitelist)
|
|
||||||
shutil.copy(os.path.join(src_vm.dir_path, whitelist),
|
|
||||||
os.path.join(self.dir_path, whitelist))
|
|
||||||
|
|
||||||
# Create appmenus
|
# Create appmenus
|
||||||
self.appicons_create()
|
self.appicons_create()
|
||||||
@ -362,6 +379,7 @@ QubesVm.appmenus_remove = QubesVm_appmenus_remove
|
|||||||
QubesVm.appmenus_cleanup = QubesVm_appmenus_cleanup
|
QubesVm.appmenus_cleanup = QubesVm_appmenus_cleanup
|
||||||
QubesVm.appmenus_recreate = QubesVm_appmenus_recreate
|
QubesVm.appmenus_recreate = QubesVm_appmenus_recreate
|
||||||
QubesVm.appmenus_update = QubesVm_appmenus_update
|
QubesVm.appmenus_update = QubesVm_appmenus_update
|
||||||
|
QubesVm.appmenus_replace_entry = QubesVm_appmenus_replace_entry
|
||||||
QubesVm.appicons_create = QubesVm_appicons_create
|
QubesVm.appicons_create = QubesVm_appicons_create
|
||||||
QubesVm.appicons_cleanup = QubesVm_appicons_cleanup
|
QubesVm.appicons_cleanup = QubesVm_appicons_cleanup
|
||||||
QubesVm.appicons_remove = QubesVm_appicons_remove
|
QubesVm.appicons_remove = QubesVm_appicons_remove
|
||||||
|
56
appmenus-scripts/qvm-appmenu-replace
Normal file
56
appmenus-scripts/qvm-appmenu-replace
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# The Qubes OS Project, http://www.qubes-os.org
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
import sys
|
||||||
|
from qubes.qubes import QubesVmCollection
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if len(sys.argv) != 4:
|
||||||
|
print >> sys.stderr, \
|
||||||
|
'Usage: qvm-appmenu-replace VM_NAME OLD_NAME.desktop NEW_NAME.desktop'
|
||||||
|
sys.exit(1)
|
||||||
|
vm_name = sys.argv[1]
|
||||||
|
old_name = sys.argv[2]
|
||||||
|
new_name = sys.argv[3]
|
||||||
|
|
||||||
|
qvm_collection = QubesVmCollection()
|
||||||
|
qvm_collection.lock_db_for_reading()
|
||||||
|
qvm_collection.load()
|
||||||
|
qvm_collection.unlock_db()
|
||||||
|
|
||||||
|
vm = qvm_collection.get_vm_by_name(vm_name)
|
||||||
|
|
||||||
|
if vm is None:
|
||||||
|
print >> sys.stderr, "ERROR: A VM with the name '{0}' " \
|
||||||
|
"does not exist in the system.".format(
|
||||||
|
vm_name)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
if vm.template is not None:
|
||||||
|
print >> sys.stderr, "ERROR: To replace appmenu for template based VM, " \
|
||||||
|
"do it on template instead"
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
vm.appmenus_replace_entry(old_name, new_name)
|
||||||
|
if hasattr(vm, 'appvms'):
|
||||||
|
for child_vm in vm.appvms.values():
|
||||||
|
child_vm.appmenus_replace_entry(old_name, new_name)
|
||||||
|
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user