File: simple.py

package info (click to toggle)
gnome-python-extras 2.19.1-3.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,640 kB
  • ctags: 736
  • sloc: sh: 8,856; ansic: 5,031; xml: 1,319; python: 769; makefile: 460
file content (23 lines) | stat: -rw-r--r-- 596 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gksu2 as gksu
import gobject
import getpass

def ask_pass_func(context, prompt):
    try:
        return getpass.getpass("Enter root password: ")
    except KeyboardInterrupt:
        print
        err = gobject.GError("keyboard interrupt")
        err.code = gksu.ERROR_CANCELED
        err.domain = "libgksu"
        raise err

ctx = gksu.Context()
ctx.set_command("ls /root")
try:
    gksu.su_full(ctx, ask_pass=ask_pass_func)
except gobject.GError, error:
    if error.code == gksu.ERROR_CANCELED:
        print "Cancel:", error.message
    else:
        print "Error:", error.message