~aptdaemon-developers/aptdaemon/1.x

« back to all changes in this revision

Viewing changes to doc/examples/chained.py

  • Committer: sebi at glatzor
  • Date: 2010-09-09 11:43:00 UTC
  • mto: (449.2.39 0.3)
  • mto: This revision was merged to the branch mainline in revision 484.
  • Revision ID: sebi@glatzor.de-20100909114300-jb80dr57ejhcp16y
Add an example script

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import dbus
 
4
import gobject
 
5
 
 
6
from aptdaemon.client import AptClient
 
7
from aptdaemon.defer import inline_callbacks
 
8
from aptdaemon import policykit1
 
9
 
 
10
loop = gobject.MainLoop()
 
11
 
 
12
def on_finished(trans, exit):
 
13
    loop.quit()
 
14
    print exit
 
15
 
 
16
@inline_callbacks
 
17
def main():
 
18
    repo = ["deb", "http://packages.glatzor.de/silly-packages", "sid", ["main"],
 
19
            "Silly packages", "silly.list"]
 
20
    aptclient = AptClient()
 
21
    bus = dbus.SystemBus()
 
22
    name = bus.get_unique_name()
 
23
    # high level auth
 
24
    try:
 
25
        # Preauthentication
 
26
        action = policykit1.PK_ACTION_INSTALL_PURCHASED_PACKAGES
 
27
        flags = policykit1.CHECK_AUTH_ALLOW_USER_INTERACTION
 
28
        yield policykit1.check_authorization_by_name(name, action, flags=flags)
 
29
        # Setting up transactions
 
30
        trans_add = yield aptclient.add_repository(*repo, defer=True)
 
31
        trans_update = yield aptclient.update_cache("silly.list", defer=True)
 
32
        trans_inst = yield aptclient.install_packages(["silly-base"],
 
33
                                                      defer=True)
 
34
        yield trans_inst.set_allow_unauthenticated(True, defer=True)
 
35
        # Check when the last transaction was done
 
36
        trans_inst.connect("finished", on_finished)
 
37
        # Chaining transactions
 
38
        yield trans_update.run_after(trans_add, defer=True)
 
39
        yield trans_inst.run_after(trans_update, defer=True)
 
40
        yield trans_add.run(defer=True)
 
41
    except Exception, error:
 
42
        print error
 
43
        loop.quit()
 
44
 
 
45
if __name__ == "__main__":
 
46
    main()
 
47
    loop.run()