File: map-client

package info (click to toggle)
obexd 0.46-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,616 kB
  • sloc: ansic: 25,341; sh: 11,307; python: 423; makefile: 153
file content (62 lines) | stat: -rwxr-xr-x 1,912 bytes parent folder | download
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python

import gobject

import dbus
import dbus.mainloop.glib
from optparse import OptionParser

def parse_options():
    parser.add_option("-d", "--device", dest="device",
                      help="Device to connect", metavar="DEVICE")
    parser.add_option("-c", "--chdir", dest="new_dir",
                      help="Change current directory to DIR", metavar="DIR")
    parser.add_option("-l", "--lsdir", action="store_true", dest="ls_dir",
                      help="List folders in current directory")
    parser.add_option("-v", "--verbose", action="store_true", dest="verbose")
    parser.add_option("-L", "--lsmsg", action="store", dest="ls_msg",
                      help="List messages in supplied CWD subdir")

    return parser.parse_args()

def set_folder(session, new_dir):
    for node in new_dir.split("/"):
        session.SetFolder(node)

if  __name__ == '__main__':

    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

    parser = OptionParser()

    (options, args) = parse_options()

    if not options.device:
        parser.print_help()
        exit(0)

    bus = dbus.SessionBus()
    mainloop = gobject.MainLoop()

    client = dbus.Interface(bus.get_object("org.openobex.client", "/"),
                            "org.openobex.Client")

    session_path = client.CreateSession({ "Destination": options.device,
                                          "Target": "map"})

    session = dbus.Interface(bus.get_object("org.openobex.client", session_path),
                 "org.openobex.Session")

    map = dbus.Interface(bus.get_object("org.openobex.client", session_path),
                 "org.openobex.MessageAccess")

    if options.new_dir:
        set_folder(map, options.new_dir)

    if options.ls_dir:
        print map.GetFolderListing(dict())

    if options.ls_msg is not None:
	print map.GetMessageListing(options.ls_msg, dict())

    mainloop.run()