Ubuntu One API

Registered by Ken VanDine

Create a convenience API around the existing dbus API to simplify integration with desktop applications.

Blueprint information

Status:
Not started
Approver:
Sebastien Bacher
Priority:
Undefined
Drafter:
Ken VanDine
Direction:
Needs approval
Assignee:
Ken VanDine
Definition:
New
Series goal:
None
Implementation:
Unknown
Milestone target:
None

Related branches

Sprints

Whiteboard

== Notes from a brainstorming session between kenvandine and sil ==

ubuntuone/public.py

def File(object):
  def __init__(self, filename):
    self.filename = filename
    self.publish_callbacks = []
    self.error_callbacks = []
    try:
      self.metadata = dbuscall.getmetadata(filename)
    except:
      raise FileIsNotInAnUbuntuOneFolderException

  def publish(self, callback, error_callback, simpleurl=True):
    self.publish_callbacks.append(callback)
    self.error_callbacks.append(error_callback)
    # is file synced?
    if self.metadata["node_id"]:
      # yes, yes it is
      self._publish(self.metadata, simpleurl)
    else:
      dbussignalwatch("FileSynced", self. _watchFileSynced, simpleurl)
      gobject.timeout_add(self._fileSyncWaitTimeout, 5000)

  def _fileSyncWaitTimeout(self):
    for callback in self.error_callbacks:
      callback("file sync didn't complete before the timeout. Try again.")
    dbussignalwatch("FileSynced").delete()

  def _watchFileSynced(self, fileThatHasBeenSynced, simpleurl):
    if fileThatHasBeenSynced == self.filename:
      # file is now synced, yay!
      self._publish(self.metadata, simpleurl)

  def _publish(self, metadata, simpleurl):
    dbussignalwatch("FilePublished", self._watchFilePublished)
    dbuscall("changePublicAccess", metadata["share_id"],
         metadata["node_id"], True, simpleurl)
    gobject.timeout_add(self._filePublishWaitTimeout, 5000)

  def _filePublishWaitTimeout(self):
    for callback in self.error_callbacks:
      callback("file publish didn't complete before the timeout. Try again.")
    dbussignalwatch("FilePublished").delete()

  def _watchFilePublished(self, fileThatHasBeenPublished, publicurl):
    if fileThatHasBeenPublished == self.filename:
      for callback in self.public_callbacks:
        callback(publicurl)

example.py
import ubuntuone.public, gtk

def displayPublicURL(publicURL):
  print "The URL is", publicURL
  gtk.main_quit()

try:
    f = ubuntuone.public.File(somefile)
    f.publish(displayPublicURL)
except FileIsNotInAnUbuntuOneEnabledFolderException as e:
    #copy file to U1, etc and retry
    pass

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.