|
|
|
@ -27,7 +27,8 @@ import sys
|
|
|
|
|
import fnmatch
|
|
|
|
|
import shutil
|
|
|
|
|
from optparse import OptionParser
|
|
|
|
|
from qubes.qubes import QubesVmCollection,QubesException
|
|
|
|
|
from qubes.qubes import QubesVmCollection,QubesException,system_path
|
|
|
|
|
from qubes.qubes import QubesHVm
|
|
|
|
|
|
|
|
|
|
# fields required to be present (and verified) in retrieved desktop file
|
|
|
|
|
required_fields = [ "Name", "Exec" ]
|
|
|
|
@ -43,9 +44,15 @@ fields_regexp = {
|
|
|
|
|
"GenericName": std_re,
|
|
|
|
|
"Comment": std_re,
|
|
|
|
|
"Categories": re.compile(r"^[a-zA-Z0-9/.; -]*$"),
|
|
|
|
|
"Exec": re.compile(r"^[a-zA-Z0-9%>/:.= -]*$"),
|
|
|
|
|
"Exec": re.compile(r"^[a-zA-Z0-9%>/\\:.= -]*$"),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def fallback_hvm_appmenulist():
|
|
|
|
|
p = subprocess.Popen(["grep", "-rH", "=", "/usr/share/qubes-appmenus/hvm"],
|
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
|
(stdout, stderr) = p.communicate()
|
|
|
|
|
return stdout.splitlines()
|
|
|
|
|
|
|
|
|
|
def get_appmenus(vm):
|
|
|
|
|
global appmenus_line_count
|
|
|
|
|
global appmenus_line_size
|
|
|
|
@ -69,7 +76,10 @@ def get_appmenus(vm):
|
|
|
|
|
appmenus_line_count -= 1
|
|
|
|
|
p.wait()
|
|
|
|
|
if p.returncode != 0:
|
|
|
|
|
raise QubesException("Error getting application list")
|
|
|
|
|
if isinstance(vm, QubesHVm):
|
|
|
|
|
untrusted_appmenulist = fallback_hvm_appmenulist()
|
|
|
|
|
else:
|
|
|
|
|
raise QubesException("Error getting application list")
|
|
|
|
|
if appmenus_line_count == 0:
|
|
|
|
|
raise QubesException("Line count limit exceeded")
|
|
|
|
|
|
|
|
|
@ -144,6 +154,8 @@ def main():
|
|
|
|
|
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")
|
|
|
|
|
|
|
|
|
|
(options, args) = parser.parse_args ()
|
|
|
|
|
if (len (args) != 1) and env_vmname is None:
|
|
|
|
@ -181,7 +193,7 @@ def main():
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
new_appmenus = {}
|
|
|
|
|
if env_vmname is None:
|
|
|
|
|
if env_vmname is None or options.force_rpc:
|
|
|
|
|
new_appmenus = get_appmenus(vm)
|
|
|
|
|
else:
|
|
|
|
|
options.verbose = False
|
|
|
|
@ -205,7 +217,7 @@ def main():
|
|
|
|
|
print >> sys.stderr, "---> Creating {0}".format(appmenu_file)
|
|
|
|
|
create_template(vm.appmenus_templates_dir + '/' + appmenu_file, new_appmenus[appmenu_file])
|
|
|
|
|
|
|
|
|
|
# Delete appmenus of remove applications
|
|
|
|
|
# Delete appmenus of removed applications
|
|
|
|
|
if options.verbose:
|
|
|
|
|
print >> sys.stderr, "--> Cleaning old files"
|
|
|
|
|
for appmenu_file in os.listdir(vm.appmenus_templates_dir):
|
|
|
|
@ -217,4 +229,9 @@ def main():
|
|
|
|
|
print >> sys.stderr, "---> Removing {0}".format(appmenu_file)
|
|
|
|
|
os.unlink(vm.appmenus_templates_dir + '/' + appmenu_file)
|
|
|
|
|
|
|
|
|
|
if isinstance(vm, QubesHVm):
|
|
|
|
|
if not os.path.exists(os.path.join(vm.appmenus_templates_dir,
|
|
|
|
|
os.path.basename(system_path['appmenu_start_hvm_template']))):
|
|
|
|
|
shutil.copy(system_path['appmenu_start_hvm_template'], vm.appmenus_templates_dir)
|
|
|
|
|
|
|
|
|
|
main()
|
|
|
|
|