-
Notifications
You must be signed in to change notification settings - Fork 2
/
RunOrInstall
executable file
·42 lines (36 loc) · 1.31 KB
/
RunOrInstall
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#! /usr/bin/python
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 autoindent syntax=python
# -*- Mode: Python; py-indent-offset: 4 -*-
import sys, os, os.path
if len(sys.argv[1:]) < 2:
print "SYNTAX: pkg1,pkg2... /path/to/bin args..."
exit(-1)
pkgs, fn, args = sys.argv[1].split(','), sys.argv[2], sys.argv[3:]
if os.path.exists(fn):
args.insert(0, fn)
os.execv(fn, args) # env=os.environ.copy(); os.execve(fn, args, env)
exit(0) # never reached
# if this is reached this mean fn does not exists, pkgs should be installed
import dbus
from dbus.mainloop.glib import DBusGMainLoop
bus = dbus.SessionBus()
nopk = False
try:
pk_proxy = bus.get_object('org.freedesktop.PackageKit', '/org/freedesktop/PackageKit')
pk_iface = dbus.Interface(pk_proxy, 'org.freedesktop.PackageKit.Modify')
except dbus.DBusException, e:
nopk=True
def install_packages(pkgs):
if not pkgs or nopk: return
# options are show/hide-*: confirm-search confirm-deps confirm-install progress finished warning
try:
r = pk_iface.InstallPackageNames(dbus.UInt32(0),
pkgs,
"hide-confirm-search,show-confirm-install,show-progress,show-finished")
except dbus.DBusException, e:
return -1
return r
if not nopk:
install_packages(pkgs)
else:
exit(-1)