2 # -*- coding: utf-8 -*-
4 # (c) Copyright 2003-2009 Hewlett-Packard Development Company, L.P.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 __mod__ = 'hp-pkservice'
25 __title__ = 'Policy Kit Service'
39 from base import utils, module
41 USAGE = [ (__doc__, "", "name", True),
42 ("Usage: %s [MODE] [OPTIONS]" % __mod__, "", "summary", True),
44 utils.USAGE_INTERACTIVE_MODE,
47 utils.USAGE_LOGGING1, utils.USAGE_LOGGING2, utils.USAGE_LOGGING3,
52 mod = module.Module(__mod__, __title__, __version__, __doc__, USAGE,
53 (INTERACTIVE_MODE, ), run_as_root_ok=True)
55 mod.setUsage(module.USAGE_FLAG_NONE,
56 extra_options=[utils.USAGE_SPACE,
57 ("[OPTIONS] (General)", "", "header", False),
58 ("PolicyKit version:", "-v<version> or --version=<version>", "option", False)])
60 opts, device_uri, printer_name, mode, ui_toolkit, loc = \
61 mod.parseStdOpts('v:', ["version="])
63 user_pkit_version = None
66 if o in ('-v', '--version'):
68 user_pkit_version = int(a)
70 log.error("-v or --version require an integer argument")
72 if user_pkit_version < 0 or user_pkit_version > 1:
73 log.error("invalid PolicyKit version...use 0 or 1")
76 PKIT = utils.to_bool(sys_conf.get('configure', 'policy-kit'))
79 from base.pkit import *
80 pkit_version = policykit_version()
81 if not user_pkit_version is None:
82 pkit_version = user_pkit_version
84 from dbus.mainloop.glib import DBusGMainLoop
86 log.error("PolicyKit requires dbus")
89 log.error("Unable to load pkit...is HPLIP installed?")
92 log.error("PolicyKit support not installed")
95 DBusGMainLoop(set_as_default=True)
97 if not os.geteuid() == 0:
98 log.error("You must be root to run this utility.")
101 log.debug("using PolicyKit version %d" % pkit_version)
104 BackendService().run(pkit_version)
105 except dbus.DBusException, ex:
106 log.error("Unable to start service (%s)" % ex)