UbuntuOneFilesNotes11.10

Attachment '3.py'

Download

   1 #!/usr/bin/python
   2 
   3 import sys
   4 
   5 _login_success = False
   6 def login():
   7   from gobject import MainLoop
   8   from dbus.mainloop.glib import DBusGMainLoop
   9   from ubuntuone.platform.credentials import CredentialsManagementTool
  10 
  11   global _login_success
  12   _login_success = False
  13 
  14   DBusGMainLoop(set_as_default=True)
  15   loop = MainLoop()
  16 
  17   def quit(result):
  18     global _login_success
  19     loop.quit()
  20     if result:
  21 	    _login_success = True
  22 
  23   cd = CredentialsManagementTool()
  24   d = cd.login()
  25   d.addCallbacks(quit)
  26   loop.run()
  27   if not _login_success:
  28     sys.exit(1)
  29 
  30 def logout():
  31   from gobject import MainLoop
  32   from dbus.mainloop.glib import DBusGMainLoop
  33   from ubuntuone.platform.credentials import CredentialsManagementTool
  34 
  35   DBusGMainLoop(set_as_default=True)
  36   loop = MainLoop()
  37 
  38   def quit(result):
  39     loop.quit()
  40 
  41   cd = CredentialsManagementTool()
  42   d = cd.clear_credentials()
  43   d.addCallbacks(quit)
  44   loop.run()
  45 
  46 def create_volume(path):
  47   import ubuntuone.couch.auth as auth
  48   import urllib
  49   base = "https://one.ubuntu.com/api/file_storage/v1/volumes/~/"
  50   auth.request(base + urllib.quote(path), http_method="PUT")
  51 
  52 if len(sys.argv) <= 1:
  53   print "Need more arguments"
  54   sys.exit(1)
  55 
  56 if sys.argv[1] == "login":
  57   login()
  58 elif sys.argv[1] == "logout":
  59   logout()
  60 elif sys.argv[1] == "create-volume":
  61   login()
  62   create_volume(sys.argv[2])

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2011-09-07 15:17:38, 0.1 KB) [[attachment:1.py]]
  • [get | view] (2011-09-07 15:17:44, 1.0 KB) [[attachment:2.py]]
  • [get | view] (2011-09-07 15:17:52, 1.3 KB) [[attachment:3.py]]
  • [get | view] (2011-09-07 15:18:00, 2.3 KB) [[attachment:4.py]]
  • [get | view] (2011-09-07 15:18:06, 2.8 KB) [[attachment:5.py]]
  • [get | view] (2011-09-07 15:18:12, 3.4 KB) [[attachment:6.py]]
  • [get | view] (2011-09-07 15:18:18, 3.8 KB) [[attachment:7.py]]
  • [get | view] (2011-09-07 15:18:24, 4.1 KB) [[attachment:u1file.py]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.