2013-03-16 17:23:22 +00:00
|
|
|
#!/usr/bin/python
|
2014-05-19 11:36:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-03-16 17:23:22 +00:00
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
|
|
|
# Copyright (C) 2011 Marek Marczykowski <marmarek@mimuw.edu.pl>
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
#
|
2015-08-02 12:43:17 +00:00
|
|
|
import optparse
|
2013-03-16 17:23:22 +00:00
|
|
|
|
|
|
|
import subprocess
|
|
|
|
import re
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import shutil
|
2014-05-19 11:36:02 +00:00
|
|
|
import pipes
|
|
|
|
|
2013-03-16 17:23:22 +00:00
|
|
|
from optparse import OptionParser
|
2015-05-02 18:13:28 +00:00
|
|
|
from qubes.qubes import QubesVmCollection, QubesException, system_path
|
2013-12-04 02:05:34 +00:00
|
|
|
from qubes.qubes import QubesHVm
|
2013-11-29 22:52:41 +00:00
|
|
|
from qubes.qubes import vm_files
|
2015-08-03 02:19:49 +00:00
|
|
|
from qubes.qubes import vmm
|
2013-03-16 17:23:22 +00:00
|
|
|
|
2015-12-17 22:44:27 +00:00
|
|
|
import qubesimgconverter
|
|
|
|
|
2013-03-16 17:23:22 +00:00
|
|
|
# fields required to be present (and verified) in retrieved desktop file
|
2015-05-02 18:13:28 +00:00
|
|
|
required_fields = ["Name", "Exec"]
|
2013-03-16 17:23:22 +00:00
|
|
|
|
2015-05-02 18:13:28 +00:00
|
|
|
# limits
|
2013-03-16 17:23:22 +00:00
|
|
|
appmenus_line_size = 1024
|
|
|
|
appmenus_line_count = 100000
|
|
|
|
|
|
|
|
# regexps for sanitization of retrieved values
|
2016-03-16 21:38:38 +00:00
|
|
|
std_re = re.compile(r"^[/a-zA-Z0-9.,:&()_ -]*$")
|
2013-03-16 17:23:22 +00:00
|
|
|
fields_regexp = {
|
|
|
|
"Name": std_re,
|
|
|
|
"GenericName": std_re,
|
|
|
|
"Comment": std_re,
|
2014-04-04 09:32:54 +00:00
|
|
|
"Categories": re.compile(r"^[a-zA-Z0-9/.;:'() -]*$"),
|
2015-05-16 22:07:01 +00:00
|
|
|
"Exec": re.compile(r"^[a-zA-Z0-9()_%&>/{}\"'\\:.= -]*$"),
|
2013-11-29 22:52:41 +00:00
|
|
|
"Icon": re.compile(r"^[a-zA-Z0-9/_.-]*$"),
|
2013-03-16 17:23:22 +00:00
|
|
|
}
|
|
|
|
|
2015-05-02 18:14:30 +00:00
|
|
|
CATEGORIES_WHITELIST = {
|
2014-05-08 09:40:45 +00:00
|
|
|
# Main Categories
|
|
|
|
# http://standards.freedesktop.org/menu-spec/1.1/apa.html 20140507
|
|
|
|
'AudioVideo', 'Audio', 'Video', 'Development', 'Education', 'Game',
|
|
|
|
'Graphics', 'Network', 'Office', 'Science', 'Settings', 'System',
|
|
|
|
'Utility',
|
|
|
|
|
|
|
|
# Additional Categories
|
|
|
|
# http://standards.freedesktop.org/menu-spec/1.1/apas02.html
|
|
|
|
'Building', 'Debugger', 'IDE', 'GUIDesigner', 'Profiling',
|
|
|
|
'RevisionControl', 'Translation', 'Calendar', 'ContactManagement',
|
|
|
|
'Database', 'Dictionary', 'Chart', 'Email', 'Finance', 'FlowChart', 'PDA',
|
|
|
|
'ProjectManagement', 'Presentation', 'Spreadsheet', 'WordProcessor',
|
|
|
|
'2DGraphics', 'VectorGraphics', 'RasterGraphics', '3DGraphics', 'Scanning',
|
|
|
|
'OCR', 'Photography', 'Publishing', 'Viewer', 'TextTools',
|
|
|
|
'DesktopSettings', 'HardwareSettings', 'Printing', 'PackageManager',
|
|
|
|
'Dialup', 'InstantMessaging', 'Chat', 'IRCClient', 'Feed', 'FileTransfer',
|
|
|
|
'HamRadio', 'News', 'P2P', 'RemoteAccess', 'Telephony', 'TelephonyTools',
|
|
|
|
'VideoConference', 'WebBrowser', 'WebDevelopment', 'Midi', 'Mixer',
|
|
|
|
'Sequencer', 'Tuner', 'TV', 'AudioVideoEditing', 'Player', 'Recorder',
|
|
|
|
'DiscBurning', 'ActionGame', 'AdventureGame', 'ArcadeGame', 'BoardGame',
|
|
|
|
'BlocksGame', 'CardGame', 'KidsGame', 'LogicGame', 'RolePlaying',
|
|
|
|
'Shooter', 'Simulation', 'SportsGame', 'StrategyGame', 'Art',
|
|
|
|
'Construction', 'Music', 'Languages', 'ArtificialIntelligence',
|
|
|
|
'Astronomy', 'Biology', 'Chemistry', 'ComputerScience',
|
|
|
|
'DataVisualization', 'Economy', 'Electricity', 'Geography', 'Geology',
|
|
|
|
'Geoscience', 'History', 'Humanities', 'ImageProcessing', 'Literature',
|
|
|
|
'Maps', 'Math', 'NumericalAnalysis', 'MedicalSoftware', 'Physics',
|
|
|
|
'Robotics', 'Spirituality', 'Sports', 'ParallelComputing', 'Amusement',
|
|
|
|
'Archiving', 'Compression', 'Electronics', 'Emulator', 'Engineering',
|
|
|
|
'FileTools', 'FileManager', 'TerminalEmulator', 'Filesystem', 'Monitor',
|
|
|
|
'Security', 'Accessibility', 'Calculator', 'Clock', 'TextEditor',
|
|
|
|
'Documentation', 'Adult', 'Core', 'KDE', 'GNOME', 'XFCE', 'GTK', 'Qt',
|
|
|
|
'Motif', 'Java', 'ConsoleOnly',
|
|
|
|
|
|
|
|
# Reserved Categories (not whitelisted)
|
|
|
|
# http://standards.freedesktop.org/menu-spec/1.1/apas03.html
|
2015-05-02 18:14:30 +00:00
|
|
|
# 'Screensaver', 'TrayIcon', 'Applet', 'Shell',
|
|
|
|
}
|
|
|
|
|
2014-05-08 09:40:45 +00:00
|
|
|
|
|
|
|
def sanitise_categories(untrusted_value):
|
|
|
|
untrusted_categories = (c.strip() for c in untrusted_value.split(';') if c)
|
|
|
|
categories = (c for c in untrusted_categories if c in CATEGORIES_WHITELIST)
|
|
|
|
|
|
|
|
return ';'.join(categories) + ';'
|
|
|
|
|
2015-05-02 18:13:28 +00:00
|
|
|
|
2013-12-04 02:05:34 +00:00
|
|
|
def fallback_hvm_appmenulist():
|
2015-05-02 18:13:28 +00:00
|
|
|
p = subprocess.Popen(["grep", "-rH", "=", "/usr/share/qubes-appmenus/hvm"],
|
|
|
|
stdout=subprocess.PIPE)
|
2013-12-04 02:05:34 +00:00
|
|
|
(stdout, stderr) = p.communicate()
|
|
|
|
return stdout.splitlines()
|
|
|
|
|
2015-05-02 18:13:28 +00:00
|
|
|
|
2013-03-16 17:23:22 +00:00
|
|
|
def get_appmenus(vm):
|
|
|
|
global appmenus_line_count
|
|
|
|
global appmenus_line_size
|
|
|
|
untrusted_appmenulist = []
|
|
|
|
if vm is None:
|
|
|
|
while appmenus_line_count > 0:
|
|
|
|
untrusted_line = sys.stdin.readline(appmenus_line_size)
|
|
|
|
if untrusted_line == "":
|
2014-02-16 19:14:00 +00:00
|
|
|
break
|
2013-03-16 17:23:22 +00:00
|
|
|
untrusted_appmenulist.append(untrusted_line.strip())
|
|
|
|
appmenus_line_count -= 1
|
|
|
|
if appmenus_line_count == 0:
|
|
|
|
raise QubesException("Line count limit exceeded")
|
|
|
|
else:
|
2015-03-10 22:59:30 +00:00
|
|
|
p = vm.run('QUBESRPC qubes.GetAppmenus dom0', passio_popen=True,
|
|
|
|
gui=False)
|
2013-03-16 17:23:22 +00:00
|
|
|
while appmenus_line_count > 0:
|
|
|
|
untrusted_line = p.stdout.readline(appmenus_line_size)
|
|
|
|
if untrusted_line == "":
|
2014-02-16 19:14:00 +00:00
|
|
|
break
|
2013-03-16 17:23:22 +00:00
|
|
|
untrusted_appmenulist.append(untrusted_line.strip())
|
|
|
|
appmenus_line_count -= 1
|
|
|
|
p.wait()
|
|
|
|
if p.returncode != 0:
|
2013-12-04 02:05:34 +00:00
|
|
|
if isinstance(vm, QubesHVm):
|
|
|
|
untrusted_appmenulist = fallback_hvm_appmenulist()
|
|
|
|
else:
|
|
|
|
raise QubesException("Error getting application list")
|
2013-03-16 17:23:22 +00:00
|
|
|
if appmenus_line_count == 0:
|
|
|
|
raise QubesException("Line count limit exceeded")
|
|
|
|
|
|
|
|
appmenus = {}
|
2015-05-02 18:13:28 +00:00
|
|
|
line_rx = re.compile(
|
|
|
|
r"([a-zA-Z0-9.()_-]+.desktop):([a-zA-Z0-9-]+(?:\[[a-zA-Z@_]+\])?)=(.*)")
|
2014-04-19 14:39:37 +00:00
|
|
|
ignore_rx = re.compile(r".*([a-zA-Z0-9._-]+.desktop):(#.*|\s+)$")
|
2013-03-16 17:23:22 +00:00
|
|
|
for untrusted_line in untrusted_appmenulist:
|
|
|
|
# Ignore blank lines and comments
|
|
|
|
if len(untrusted_line) == 0 or ignore_rx.match(untrusted_line):
|
2015-05-02 18:13:28 +00:00
|
|
|
continue
|
2013-03-16 17:23:22 +00:00
|
|
|
# use search instead of match to skip file path
|
|
|
|
untrusted_m = line_rx.search(untrusted_line)
|
|
|
|
if untrusted_m:
|
2014-04-19 14:46:03 +00:00
|
|
|
filename = untrusted_m.group(1)
|
2014-05-19 11:36:02 +00:00
|
|
|
assert '/' not in filename
|
|
|
|
assert '\0' not in filename
|
|
|
|
|
2013-03-16 17:23:22 +00:00
|
|
|
untrusted_key = untrusted_m.group(2)
|
2014-05-19 11:36:02 +00:00
|
|
|
assert '\0' not in untrusted_key
|
|
|
|
assert '\x1b' not in untrusted_key
|
|
|
|
assert '=' not in untrusted_key
|
|
|
|
|
2013-03-16 17:23:22 +00:00
|
|
|
untrusted_value = untrusted_m.group(3)
|
2014-05-19 11:36:02 +00:00
|
|
|
# TODO add key-dependent asserts
|
|
|
|
|
2013-03-16 17:23:22 +00:00
|
|
|
# Look only at predefined keys
|
2015-05-02 18:14:30 +00:00
|
|
|
if untrusted_key in fields_regexp:
|
2013-03-16 17:23:22 +00:00
|
|
|
if fields_regexp[untrusted_key].match(untrusted_value):
|
|
|
|
# now values are sanitized
|
|
|
|
key = untrusted_key
|
2014-05-08 09:40:45 +00:00
|
|
|
if key == 'Categories':
|
|
|
|
value = sanitise_categories(untrusted_value)
|
|
|
|
else:
|
|
|
|
value = untrusted_value
|
2013-03-16 17:23:22 +00:00
|
|
|
|
2015-05-02 18:14:30 +00:00
|
|
|
if filename not in appmenus:
|
2013-03-16 17:23:22 +00:00
|
|
|
appmenus[filename] = {}
|
|
|
|
|
2015-05-02 18:13:28 +00:00
|
|
|
appmenus[filename][key] = value
|
2013-03-16 17:23:22 +00:00
|
|
|
else:
|
2015-05-02 18:13:28 +00:00
|
|
|
print >> sys.stderr, \
|
|
|
|
"Warning: ignoring key %r of %s" % \
|
|
|
|
(untrusted_key, filename)
|
2013-03-16 17:23:22 +00:00
|
|
|
# else: ignore this key
|
|
|
|
|
|
|
|
return appmenus
|
|
|
|
|
|
|
|
|
|
|
|
def create_template(path, values):
|
|
|
|
# check if all required fields are present
|
|
|
|
for key in required_fields:
|
2015-05-02 18:14:30 +00:00
|
|
|
if key not in values:
|
2015-05-02 18:13:28 +00:00
|
|
|
print >> sys.stderr, "Warning: not creating/updating '%s' " \
|
|
|
|
"because of missing '%s' key" % (
|
|
|
|
path, key)
|
2013-03-16 17:23:22 +00:00
|
|
|
return
|
|
|
|
|
2015-04-28 10:45:29 +00:00
|
|
|
desktop_entry = ""
|
|
|
|
desktop_entry += "[Desktop Entry]\n"
|
|
|
|
desktop_entry += "Version=1.0\n"
|
|
|
|
desktop_entry += "Type=Application\n"
|
|
|
|
desktop_entry += "Terminal=false\n"
|
|
|
|
desktop_entry += "X-Qubes-VmName=%VMNAME%\n"
|
2013-11-29 22:52:41 +00:00
|
|
|
|
|
|
|
if 'Icon' in values:
|
|
|
|
icon_file = os.path.splitext(os.path.split(path)[1])[0] + '.png'
|
2015-04-28 10:45:29 +00:00
|
|
|
desktop_entry += "Icon={0}\n".format(os.path.join(
|
|
|
|
'%VMDIR%', vm_files['appmenus_icons_subdir'], icon_file))
|
2013-11-29 22:52:41 +00:00
|
|
|
else:
|
2015-04-28 10:45:29 +00:00
|
|
|
desktop_entry += "Icon=%XDGICON%\n"
|
2013-11-29 22:52:41 +00:00
|
|
|
|
2015-05-02 18:13:28 +00:00
|
|
|
for key in ["Name", "GenericName"]:
|
2015-05-02 18:14:30 +00:00
|
|
|
if key in values:
|
2015-04-28 10:45:29 +00:00
|
|
|
desktop_entry += "{0}=%VMNAME%: {1}\n".format(key, values[key])
|
2015-05-02 18:13:28 +00:00
|
|
|
|
2016-07-15 09:31:27 +00:00
|
|
|
# force category X-Qubes-VM
|
|
|
|
values["Categories"] = values.get("Categories", "") + "X-Qubes-VM;"
|
|
|
|
|
2015-05-02 18:13:28 +00:00
|
|
|
for key in ["Comment", "Categories"]:
|
2015-05-02 18:14:30 +00:00
|
|
|
if key in values:
|
2015-04-28 10:45:29 +00:00
|
|
|
desktop_entry += "{0}={1}\n".format(key, values[key])
|
2013-03-16 17:23:22 +00:00
|
|
|
|
2015-04-28 10:45:29 +00:00
|
|
|
desktop_entry += "Exec=qvm-run -q --tray -a %VMNAME% -- {0}\n".format(
|
|
|
|
pipes.quote(values['Exec']))
|
|
|
|
if not os.path.exists(path) or desktop_entry != open(path, "r").read():
|
|
|
|
desktop_file = open(path, "w")
|
|
|
|
desktop_file.write(desktop_entry)
|
|
|
|
desktop_file.close()
|
2013-03-16 17:23:22 +00:00
|
|
|
|
2015-05-02 18:13:28 +00:00
|
|
|
|
2013-03-16 17:23:22 +00:00
|
|
|
def main():
|
|
|
|
env_vmname = os.environ.get("QREXEC_REMOTE_DOMAIN")
|
2015-05-02 18:13:28 +00:00
|
|
|
usage = "usage: %prog [options] <vm-name>\n" \
|
|
|
|
"Update desktop file templates for given StandaloneVM or TemplateVM"
|
|
|
|
|
|
|
|
parser = OptionParser(usage)
|
|
|
|
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
|
|
|
|
default=False)
|
|
|
|
parser.add_option("--force-root", action="store_true", dest="force_root",
|
|
|
|
default=False,
|
|
|
|
help="Force to run, even with root privileges")
|
|
|
|
parser.add_option("--force-rpc", action="store_true", dest="force_rpc",
|
|
|
|
default=False,
|
|
|
|
help="Force to start a new RPC call, "
|
|
|
|
"even if called from existing one")
|
2015-08-02 12:43:17 +00:00
|
|
|
# Do not use any RPC call, expects data on stdin (in qubes.GetAppmenus
|
|
|
|
# format)
|
|
|
|
parser.add_option("--offline-mode", dest="offline_mode",
|
|
|
|
action="store_true", default=False,
|
|
|
|
help=optparse.SUPPRESS_HELP)
|
2015-05-02 18:13:28 +00:00
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
if (len(args) != 1) and env_vmname is None:
|
|
|
|
parser.error("You must specify at least the VM name!")
|
2013-03-16 17:23:22 +00:00
|
|
|
|
|
|
|
if env_vmname:
|
2015-05-02 18:13:28 +00:00
|
|
|
vmname = env_vmname
|
2013-03-16 17:23:22 +00:00
|
|
|
else:
|
2015-05-02 18:13:28 +00:00
|
|
|
vmname = args[0]
|
2013-03-16 17:23:22 +00:00
|
|
|
|
|
|
|
if os.geteuid() == 0:
|
|
|
|
if not options.force_root:
|
2015-05-02 18:13:28 +00:00
|
|
|
print >> sys.stderr, "*** Running this tool as root is strongly " \
|
|
|
|
"discouraged, this will lead you into " \
|
|
|
|
"permissions problems."
|
2013-03-16 17:23:22 +00:00
|
|
|
print >> sys.stderr, "Retry as unprivileged user."
|
|
|
|
print >> sys.stderr, "... or use --force-root to continue anyway."
|
|
|
|
exit(1)
|
|
|
|
|
2015-08-02 12:43:17 +00:00
|
|
|
if options.offline_mode:
|
|
|
|
vmm.offline_mode = True
|
2013-03-16 17:23:22 +00:00
|
|
|
qvm_collection = QubesVmCollection()
|
|
|
|
qvm_collection.lock_db_for_reading()
|
|
|
|
qvm_collection.load()
|
|
|
|
qvm_collection.unlock_db()
|
|
|
|
|
|
|
|
vm = qvm_collection.get_vm_by_name(vmname)
|
|
|
|
|
|
|
|
if vm is None:
|
2015-05-02 18:13:28 +00:00
|
|
|
print >> sys.stderr, "ERROR: A VM with the name '{0}' " \
|
|
|
|
"does not exist in the system.".format(
|
|
|
|
vmname)
|
2013-03-16 17:23:22 +00:00
|
|
|
exit(1)
|
|
|
|
|
|
|
|
if vm.template is not None:
|
2015-05-02 18:13:28 +00:00
|
|
|
print >> sys.stderr, "ERROR: To sync appmenus for template based VM, " \
|
|
|
|
"do it on template instead"
|
2013-03-16 17:23:22 +00:00
|
|
|
exit(1)
|
|
|
|
|
2015-08-02 12:43:17 +00:00
|
|
|
if not options.offline_mode and not vm.is_running():
|
2015-05-02 18:13:28 +00:00
|
|
|
print >> sys.stderr, "ERROR: Appmenus can be retrieved only from " \
|
|
|
|
"running VM - start it first"
|
2013-03-16 17:23:22 +00:00
|
|
|
exit(1)
|
|
|
|
|
2015-08-02 12:43:17 +00:00
|
|
|
if not options.offline_mode and env_vmname is None or options.force_rpc:
|
2013-03-16 17:23:22 +00:00
|
|
|
new_appmenus = get_appmenus(vm)
|
|
|
|
else:
|
|
|
|
options.verbose = False
|
|
|
|
new_appmenus = get_appmenus(None)
|
|
|
|
|
|
|
|
if len(new_appmenus) == 0:
|
2015-05-02 18:13:28 +00:00
|
|
|
print >> sys.stderr, "ERROR: No appmenus received, terminating"
|
2013-03-16 17:23:22 +00:00
|
|
|
exit(1)
|
|
|
|
|
2015-09-02 23:18:16 +00:00
|
|
|
os.umask(002)
|
|
|
|
|
2013-03-16 17:23:22 +00:00
|
|
|
if not os.path.exists(vm.appmenus_templates_dir):
|
|
|
|
os.mkdir(vm.appmenus_templates_dir)
|
|
|
|
|
2014-01-30 16:47:18 +00:00
|
|
|
if not os.path.exists(vm.appmenus_template_icons_dir):
|
|
|
|
os.mkdir(vm.appmenus_template_icons_dir)
|
|
|
|
|
2013-03-16 17:23:22 +00:00
|
|
|
# Create new/update existing templates
|
|
|
|
if options.verbose:
|
2015-05-02 18:13:28 +00:00
|
|
|
print >> sys.stderr, "--> Got {0} appmenus, storing to disk".format(
|
|
|
|
str(len(new_appmenus)))
|
2013-03-16 17:23:22 +00:00
|
|
|
for appmenu_file in new_appmenus.keys():
|
|
|
|
if options.verbose:
|
2015-05-02 18:13:28 +00:00
|
|
|
if os.path.exists(
|
|
|
|
os.path.join(vm.appmenus_templates_dir, appmenu_file)):
|
2013-03-16 17:23:22 +00:00
|
|
|
print >> sys.stderr, "---> Updating {0}".format(appmenu_file)
|
|
|
|
else:
|
|
|
|
print >> sys.stderr, "---> Creating {0}".format(appmenu_file)
|
2013-11-29 22:52:41 +00:00
|
|
|
|
2015-08-02 12:43:17 +00:00
|
|
|
# TODO: icons support in offline mode
|
|
|
|
if options.offline_mode:
|
|
|
|
new_appmenus[appmenu_file].pop('Icon', None)
|
2013-11-29 22:52:41 +00:00
|
|
|
if 'Icon' in new_appmenus[appmenu_file]:
|
|
|
|
# the following line is used for time comparison
|
2014-05-07 12:54:59 +00:00
|
|
|
icondest = os.path.join(vm.appmenus_template_icons_dir,
|
2015-05-02 18:13:28 +00:00
|
|
|
os.path.splitext(appmenu_file)[0] + '.png')
|
2014-05-07 12:54:59 +00:00
|
|
|
|
2013-11-29 22:52:41 +00:00
|
|
|
try:
|
2015-12-17 22:44:27 +00:00
|
|
|
icon = qubesimgconverter.Image. \
|
2015-05-02 18:13:28 +00:00
|
|
|
get_xdg_icon_from_vm(vm,
|
|
|
|
new_appmenus[
|
|
|
|
appmenu_file][
|
|
|
|
'Icon'])
|
2015-04-28 10:45:29 +00:00
|
|
|
if os.path.exists(icondest):
|
2015-12-17 22:44:27 +00:00
|
|
|
old_icon = qubesimgconverter.Image.load_from_file(icondest)
|
2015-04-28 10:45:29 +00:00
|
|
|
else:
|
|
|
|
old_icon = None
|
|
|
|
if old_icon is None or icon != old_icon:
|
|
|
|
icon.save(icondest)
|
2013-11-29 22:52:41 +00:00
|
|
|
except Exception, e:
|
2015-05-02 18:13:28 +00:00
|
|
|
print >> sys.stderr, '----> Failed to get icon for {0}: {1!s}'.\
|
|
|
|
format(appmenu_file, e)
|
2014-05-07 12:54:59 +00:00
|
|
|
|
|
|
|
if os.path.exists(icondest):
|
2015-05-02 18:13:28 +00:00
|
|
|
print >> sys.stderr, '-----> Found old icon, ' \
|
|
|
|
'using it instead'
|
2014-05-07 12:54:59 +00:00
|
|
|
else:
|
|
|
|
del new_appmenus[appmenu_file]['Icon']
|
2013-11-29 22:52:41 +00:00
|
|
|
|
|
|
|
create_template(os.path.join(vm.appmenus_templates_dir, appmenu_file),
|
2015-05-02 18:13:28 +00:00
|
|
|
new_appmenus[appmenu_file])
|
2013-03-16 17:23:22 +00:00
|
|
|
|
2013-12-04 02:05:34 +00:00
|
|
|
# Delete appmenus of removed applications
|
2013-03-16 17:23:22 +00:00
|
|
|
if options.verbose:
|
|
|
|
print >> sys.stderr, "--> Cleaning old files"
|
|
|
|
for appmenu_file in os.listdir(vm.appmenus_templates_dir):
|
2014-05-19 11:36:02 +00:00
|
|
|
if not appmenu_file.endswith('.desktop'):
|
2013-03-16 17:23:22 +00:00
|
|
|
continue
|
|
|
|
|
2015-05-02 18:14:30 +00:00
|
|
|
if appmenu_file not in new_appmenus:
|
2013-03-16 17:23:22 +00:00
|
|
|
if options.verbose:
|
|
|
|
print >> sys.stderr, "---> Removing {0}".format(appmenu_file)
|
2014-04-19 14:46:49 +00:00
|
|
|
os.unlink(os.path.join(vm.appmenus_templates_dir, appmenu_file))
|
2013-03-16 17:23:22 +00:00
|
|
|
|
2013-12-04 02:05:34 +00:00
|
|
|
if isinstance(vm, QubesHVm):
|
|
|
|
if not os.path.exists(os.path.join(vm.appmenus_templates_dir,
|
2015-05-02 18:13:28 +00:00
|
|
|
os.path.basename(system_path[
|
|
|
|
'appmenu_start_hvm_template']))):
|
|
|
|
shutil.copy(system_path['appmenu_start_hvm_template'],
|
|
|
|
vm.appmenus_templates_dir)
|
2013-12-04 02:05:34 +00:00
|
|
|
|
2015-05-02 19:07:57 +00:00
|
|
|
vm.appmenus_update()
|
2014-02-22 00:26:01 +00:00
|
|
|
if hasattr(vm, 'appvms'):
|
2015-01-26 02:59:22 +00:00
|
|
|
os.putenv('SKIP_CACHE_REBUILD', '1')
|
2014-02-22 00:26:01 +00:00
|
|
|
for child_vm in vm.appvms.values():
|
|
|
|
try:
|
2015-04-28 10:45:29 +00:00
|
|
|
child_vm.appmenus_update()
|
2014-02-22 00:26:01 +00:00
|
|
|
except Exception, e:
|
2015-05-02 18:13:28 +00:00
|
|
|
print >> sys.stderr, "---> Failed to recreate appmenus for " \
|
2014-02-22 00:26:01 +00:00
|
|
|
"'{0}': {1}".format(child_vm.name, str(e))
|
2015-07-08 03:56:38 +00:00
|
|
|
subprocess.call(['xdg-desktop-menu', 'forceupdate'])
|
2015-01-26 02:59:22 +00:00
|
|
|
if 'KDE_SESSION_UID' in os.environ:
|
2016-05-03 23:44:09 +00:00
|
|
|
subprocess.call(['kbuildsycoca' + os.environ.get('KDE_SESSION_VERSION', '4')])
|
2015-01-26 02:59:22 +00:00
|
|
|
os.unsetenv('SKIP_CACHE_REBUILD')
|
2014-02-22 00:26:01 +00:00
|
|
|
|