~ubuntu-branches/ubuntu/trusty/plainbox-provider-checkbox/trusty

« back to all changes in this revision

Viewing changes to bin/obex_send

  • Committer: Package Import Robot
  • Author(s): Zygmunt Krynicki
  • Date: 2014-04-07 19:00:31 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20140407190031-rf836grml6oilfyt
Tags: 0.4-1
* New upstream release. List of bugfixes:
  https://launchpad.net/plainbox-provider-checkbox/14.04/0.4
* debian/watch: look for new releases on launchpad
* debian/rules: stop using pybuild and use manage.py
  {i18n,build,install,validate} instead. This also drops dependency on
  python3-distutils-extra and replaces that with intltool
* debian/control: drop X-Python3-Version
* debian/control: make plainbox-provider-checkbox depend on python and
  python2.7 (for some scripts) rather than suggesting them.
* debian/upstream/signing-key.asc: Use armoured gpg keys to avoid having to
  keep binary files in Debian packaging. Also, replace that with my key
  since I made the 0.3 release upstream.
* debian/source/lintian-overrides: add an override for warning about no
  source for flash movie with reference to a bug report that discusses that
  issue.
* debian/source/include-binaries: drop (no longer needed)
* debian/patches: drop (no longer needed)
* debian/plainbox-provider-checkbox.lintian-overrides: drop (no longer
  needed)
* Stop being a python3 module, move to from DPMT to PAPT

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3
 
2
 
 
3
import os
 
4
import sys
 
5
import time
 
6
import dbus
 
7
import dbus.service
 
8
import dbus.mainloop.glib
 
9
 
 
10
from gi.repository import GObject
 
11
 
 
12
class Agent(dbus.service.Object):
 
13
    def __init__(self, conn=None, obj_path=None):
 
14
        dbus.service.Object.__init__(self, conn, obj_path)
 
15
 
 
16
    @dbus.service.method("org.openobex.Agent",
 
17
                         in_signature="o", out_signature="s")
 
18
    def Request(self, path):
 
19
        print("Transfer Request")
 
20
        self.transfer = dbus.Interface(bus.get_object("org.openobex.client",
 
21
                                                      path),
 
22
                                       "org.openobex.Transfer")
 
23
        properties = self.transfer.GetProperties()
 
24
        for key in list(properties.keys()):
 
25
            print("  %s = %s" % (key, properties[key]))
 
26
        self.start = True
 
27
        return ""
 
28
 
 
29
    @dbus.service.method("org.openobex.Agent",
 
30
                         in_signature="ot", out_signature="")
 
31
    def Progress(self, path, transferred):
 
32
        if (self.start):
 
33
            print("Transfer Started")
 
34
            properties = self.transfer.GetProperties()
 
35
            self.transfer_size = properties['Size']
 
36
            self.start_time = time.time()
 
37
            self.start = False
 
38
        else:
 
39
            speed = transferred / abs((time.time() - self.start_time) * 1000)
 
40
            progress = ("(" + str(transferred) + "/" + str(self.transfer_size)
 
41
                        + " bytes) @ " + str(int(speed)) + " kB/s")
 
42
            out = "\rTransfer progress " + progress
 
43
            sys.stdout.write(out)
 
44
            sys.stdout.flush()
 
45
        return
 
46
 
 
47
    @dbus.service.method("org.openobex.Agent",
 
48
                         in_signature="o", out_signature="")
 
49
    def Complete(self, path):
 
50
        print("\nTransfer finished")
 
51
        return
 
52
 
 
53
    @dbus.service.method("org.openobex.Agent",
 
54
                         in_signature="os", out_signature="")
 
55
    def Error(self, path, error):
 
56
        print("\nTransfer finished with an error: %s" % (error))
 
57
        return
 
58
 
 
59
    @dbus.service.method("org.openobex.Agent",
 
60
                         in_signature="", out_signature="")
 
61
    def Release(self):
 
62
        mainloop.quit()
 
63
        return
 
64
 
 
65
if __name__ == '__main__':
 
66
    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
 
67
 
 
68
    bus = dbus.SessionBus()
 
69
    client = dbus.Interface(bus.get_object("org.openobex.client", "/"),
 
70
                            "org.openobex.Client")
 
71
 
 
72
    if (len(sys.argv) < 3):
 
73
        print("Usage: %s <device> <file> [file*]" % (sys.argv[0]))
 
74
        sys.exit(1)
 
75
 
 
76
    path = "/test/agent"
 
77
    agent = Agent(bus, path)
 
78
 
 
79
    mainloop = GObject.MainLoop()
 
80
    files = [os.path.realpath(f) for f in sys.argv[2:]]
 
81
 
 
82
    client.SendFiles({"Destination": sys.argv[1]}, files, path)
 
83
 
 
84
    mainloop.run()