Publishing a folder with Ubuntu One

Ubuntu One has the concept of publishing a file — that is, giving a file in your personal cloud a URL so that anyone can download it, if you tell them the URL — but you can’t currently do that with a whole folder of files. Since that’d be quite a useful thing to be able to do, and it’s not yet supported by U1 itself, I wrote a little script to do it, u1-publish-folder (the script needs you to be on Ubuntu 12.04, which is released next week). Simply do u1-publish-folder /path/to/synced/folder and it’ll give you a URL for the index for that folder; a handy way to get a bunch of files to someone without a U1 account* where they can pick and choose the ones they want (rather than sending them a zip file, or sharing a folder with them).

The way it actually works is to publish all the files in the folder, then create an HTML index file linking to all those published files, then sync and publish the index. So you get a directory listing, like Apache gives you when you browse a folder: List of files in testpublishfolder.

The thing I found nicest about this is working with SyncDaemonTool, the Python U1 controller. Combined with Twisted’s defer.inlineCallbacks stuff, it makes dealing with U1 really easy:

@defer.inlineCallbacks
def dosomething():
    sd = SyncDaemonTool()
    metadata = yield sd.get_metadata("/home/aquarius/Documents/somefile")
    print metadata

Normally, dealing with async stuff is hard, but it’s just dead easy this way; simply throw in a yield and you can write code as if it’s normally synchronous but it’s actually async, so your program doesn’t block while it’s working and you don’t need to invent a zillion “callback” functions (whether they’re anonymous functions or not). I like this.

11 thoughts on “Publishing a folder with Ubuntu One

  1. Michael says:

    hi.. thanks for the nice script.. but there is one error:

    Examining folder /home/wolf/bla
    Unhandled error in Deferred:
    Unhandled Error
    Traceback (most recent call last):
    File “/usr/lib/python2.7/dist-packages/twisted/internet/defer.py”, line 361, in callback
    self._startRunCallbacks(result)
    File “/usr/lib/python2.7/dist-packages/twisted/internet/defer.py”, line 455, in _startRunCallbacks
    self._runCallbacks()
    File “/usr/lib/python2.7/dist-packages/twisted/internet/defer.py”, line 542, in _runCallbacks
    current.result = callback(current.result, *args, **kw)
    File “/usr/lib/python2.7/dist-packages/twisted/internet/defer.py”, line 1076, in gotResult
    _inlineCallbacks(r, g, deferred)

    File “/usr/lib/python2.7/dist-packages/twisted/internet/defer.py”, line 1020, in _inlineCallbacks
    result = g.send(result)
    File “./Desktop/u1-publish-folder”, line 103, in process_folder
    publicfiles = yield sd.get_public_files()
    exceptions.AttributeError: ‘SyncDaemonTool’ object has no attribute ‘get_public_files’

    Do I do something wrong?
    Thanks for reply.

  2. sil says:

    Michael,

    Ah, good catch: this will likely require Ubuntu 12.04. I’ll update the main post.

  3. Eduard Gotwig says:

    Please, report that bug for ubuntu one and upload your patch on the bug report. SO it may get upstream, soon!

    I thank you for that, but I only install software (except my own) that is packaged.

  4. monica håkansson says:

    varför kan jag inte spela city vill på facebook staden försvinner

  5. Konsta Karioja says:

    Nice script! Makes life easier.

    Nonetheless, I’d like to know is there an easy way to stop publishing a folder? Of course I can delete/unpublish the created html index, but the files remain published this way. Is there any other trick than making them unpublished one by one?

  6. sil says:

    Konsta: there isn’t an easy way to unpublish all the files already, but another script to do so (“for file in directory: unpublish(file)”) wouldn’t be too hard :)

  7. Alberto says:

    Wow, awesome! Thanks!!!

  8. Fred says:

    Is here any way to let the script provide https links in the index file. This to prevent restrictive content scanning on some proxy systems and overall, less snooping on my internet line (Data Retention and so on). I know Ubuntu One supports this, just replace the http with the https afterwards, but it would be nice to have it in one script.

  9. Guzmán says:

    Thanks!!! It’s great!!!

  10. talisman says:

    Thank you very much, this is really cool. I see a really cool future for u1

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>