代码教程:使你的应用与 Ubuntu One 同步

  • Ubuntu 9.10 and Ubuntu One: Canonical released Ubuntu 9.10 in October and launched Ubuntu One, a cloud storage solution for synchronizing files and app data. Only a few apps use its capabilities.

    • Ubuntu One architecture: It has separate file and app synchronization features. The app data synchronization is powered by CouchDB, which is conducive to replication. Ubuntu One client pairs with Canonical's servers, enabling data replication between local and remote CouchDB instances. Desktop CouchDB creates per-session instances on random ports and uses D-Bus for activation and exposing port numbers. It requires OAuth credentials for security. Users can use Desktop CouchDB without Ubuntu One.
  • Accessing Desktop CouchDB with Python: Ubuntu One developers created a Python library to wrap Desktop CouchDB. It handles authentication and hides other details. CouchDB stores data as JSON documents. The Python library allows using dictionary objects to describe database items. Examples show how to connect to CouchDB, create records, and put them into the database. Futon can be used to inspect the data. Record type URLs are used for interoperability between applications.
  • A simple real-world example: A script called LinkCollector uses D-Bus to monitor Pidgin and XChat messages for links. It extracts links and stores them in Desktop CouchDB, which is propagated to other computers via Ubuntu One. The script uses regex to extract links and creates CouchDB records.
  • Working with CouchDB views: CouchDB uses views for filtering JSON data. Views have map and reduce functions. A simple view example shows how to emit data based on specific fields. Another example filters IRC links by a specific user and time. Python code is used to create and filter views.
  • Adding CouchDB support to existing software: Adding sync support to an existing application like GTG by creating a new backend that stores data in Desktop CouchDB. GTG is modular and designed for pluggable backends. The CouchDB backend has methods to set, get, and remove tasks. However, GTG's architecture has limitations that prevent full use of CouchDB's potential performance advantages. There are also issues with ID values and the deletion behavior of the Desktop CouchDB Python library. Workarounds were implemented in the GTG backend.
  • Conclusion: Desktop CouchDB is powerful and brings value to the Linux desktop. Python bindings are easy to use for experimentation, and the synchronization functionality is seamless and addictive.
阅读 7
0 条评论