Devilzc0de Forum Follow @devilzc0de
  • Home
  • Hacking
  • Networking
  • Programming
  • O.S
  • Server
  • Tweets
  • Search
  • Member List
  • Calendar
Current time: 06-19-2013, 06:37 AM Hello There, Guest! (Login — Register)
Devilzc0de Forum › Information Technology › Programming › Python v
« Previous 1 2 3 4 Next »

Writing PolicyKit applications in Python without D-Bus

Home General Computer Multimedia Business Lounge

Post Reply 
Tweet
Threaded Mode | Linear Mode
Writing PolicyKit applications in Python without D-Bus
05-21-2011, 09:33 AM
Post: #1
mywisdom Offline
Administrator
*******
Administrators
Posts: 923
Joined: Dec 2009
Reputation: 51
Writing PolicyKit applications in Python without D-Bus
Source: http://blog.artfwo.net/2011/02/writing-p...ns-in.html

Code:
#! /usr/bin/env python

import sys, os
from gi.repository import GObject, Gio, Polkit

def on_tensec_timeout(loop):
  print("Ten seconds have passed. Now exiting.")
  loop.quit()
  return False

def check_authorization_cb(authority, res, loop):
    try:
        result = authority.check_authorization_finish(res)
        if result.get_is_authorized():
            print("Authorized")
        elif result.get_is_challenge():
            print("Challenge")
        else:
            print("Not authorized")
    except GObject.GError as error:
         print("Error checking authorization: %s" % error.message)
        
    print("Authorization check has been cancelled "
          "and the dialog should now be hidden.\n"
          "This process will exit in ten seconds.")
    GObject.timeout_add(10000, on_tensec_timeout, loop)

def do_cancel(cancellable):
    print("Timer has expired; cancelling authorization check")
    cancellable.cancel()
    return False

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("usage: %s <action_id>" % sys.argv[0])
        sys.exit(1)
    action_id = sys.argv[1]

    mainloop = GObject.MainLoop()
    authority = Polkit.Authority.get()
    subject = Polkit.UnixProcess.new(os.getppid())

    cancellable = Gio.Cancellable()
    GObject.timeout_add(10 * 1000, do_cancel, cancellable)

    authority.check_authorization(subject,
        action_id, #"org.freedesktop.policykit.exec",
        None,
        Polkit.CheckAuthorizationFlags.ALLOW_USER_INTERACTION,
        cancellable,
        check_authorization_cb,
        mainloop)

    mainloop.run()
Find all posts by this user
Quote this message in a reply
05-21-2011, 10:34 AM
Post: #2
Bunga.Mataharry Away
Devilzc0de Ambassador
***
Posts: 1,432
Joined: Jan 2011
Reputation: 90
RE: Writing PolicyKit applications in Python without D-Bus
(05-21-2011 09:33 AM)mywisdom Wrote:  Source: http://blog.artfwo.net/2011/02/writing-p...ns-in.html

Code:
#! /usr/bin/env python

import sys, os
from gi.repository import GObject, Gio, Polkit

def on_tensec_timeout(loop):
  print("Ten seconds have passed. Now exiting.")
  loop.quit()
  return False

def check_authorization_cb(authority, res, loop):
    try:
        result = authority.check_authorization_finish(res)
        if result.get_is_authorized():
            print("Authorized")
        elif result.get_is_challenge():
            print("Challenge")
        else:
            print("Not authorized")
    except GObject.GError as error:
         print("Error checking authorization: %s" % error.message)
        
    print("Authorization check has been cancelled "
          "and the dialog should now be hidden.\n"
          "This process will exit in ten seconds.")
    GObject.timeout_add(10000, on_tensec_timeout, loop)

def do_cancel(cancellable):
    print("Timer has expired; cancelling authorization check")
    cancellable.cancel()
    return False

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("usage: %s <action_id>" % sys.argv[0])
        sys.exit(1)
    action_id = sys.argv[1]

    mainloop = GObject.MainLoop()
    authority = Polkit.Authority.get()
    subject = Polkit.UnixProcess.new(os.getppid())

    cancellable = Gio.Cancellable()
    GObject.timeout_add(10 * 1000, do_cancel, cancellable)

    authority.check_authorization(subject,
        action_id, #"org.freedesktop.policykit.exec",
        None,
        Polkit.CheckAuthorizationFlags.ALLOW_USER_INTERACTION,
        cancellable,
        check_authorization_cb,
        mainloop)

    mainloop.run()

Ular kadut lagi... belajarbelajarbelajarbelajar

Pahlawan gak boleh gagal nahlukin ular kadut.. banggabangga
Visit this user's website Find all posts by this user
Quote this message in a reply
05-21-2011, 11:02 AM
Post: #3
mywisdom Offline
Administrator
*******
Administrators
Posts: 923
Joined: Dec 2009
Reputation: 51
RE: Writing PolicyKit applications in Python without D-Bus
hehehehe bukan itu tujuanya, ada suatu yg lebih dalam dari sekedar ular kadut ini ;))
Find all posts by this user
Quote this message in a reply
05-21-2011, 12:46 PM
Post: #4
yanzbatara Offline
./Devilz Commander
Posts: 434
Joined: Feb 2011
Reputation: 4
RE: Writing PolicyKit applications in Python without D-Bus
belajarbelajar

belom ngserti...prustasi
Visit this user's website Find all posts by this user
Quote this message in a reply
« Next Oldest | Next Newest »
Post Reply 


Topic Tools
Topic Link :
BBCode :
HTML Code :
View a Printable Version Send Thread to a Friend Subscribe to this thread
Submit Google Submit Face book Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
Thumbs Up Belajar Python GUI Gaya Baru candragati 20 839 05-18-2013 07:49 PM
Last Post: dewa-crot
  NGOPREK Bahasa Pemprograman (Python) Bunga.Mataharry 29 7,348 04-30-2013 06:07 PM
Last Post: pr4bu_51l1w4n61
  how to create login auth with django framework (python) 5ynL0rd 6 1,801 04-25-2013 08:06 AM
Last Post: dophponh
Star [Tutor] Materi DIC "Basic Programming Python" root31 20 495 04-23-2013 07:56 AM
Last Post: orochimadit
  [PYTHON] Install Python di Windows sang.sakaya 12 3,956 04-19-2013 03:40 PM
Last Post: fata
  [cloning] nembak cewek dengan python test 13 458 03-31-2013 11:58 AM
Last Post: 2easy4me
  Belajar bahasa pemrograman Python whitehat 17 5,442 03-03-2013 08:01 PM
Last Post: eM.eL
  [Tutor] [Share]Program Pencacah Pecahan dengan Python hitheir 5 372 02-24-2013 02:21 PM
Last Post: ghosthands
  [Tutor] Slideshare Disabled Python Looping Slide Download hitheir 9 227 01-27-2013 05:53 PM
Last Post: sotbot
  [cloning] Segitiga bolak balik di python test 5 246 12-15-2012 09:17 AM
Last Post: qpdll

Users Browsing
1 Guest(s)

  • Contact Us
  • devilzc0de
  • Return to Top
  • Mobile Version
  • RSS Syndication
  • Help
Current time: 06-19-2013, 06:37 AM Powered By MyBB, © 2002-2013 MyBB Group. Theme created by Justin S. | Mixed By Chaer.Newbie | Fixed By Aditya

USING THIS SITE INDICATES THAT YOU HAVE READ AND ACCEPT OUR TERMS. IF YOU DO NOT ACCEPT THESE TERMS, YOU ARE NOT AUTHORIZED TO USE THIS SITE