~flimm/python-snippets/gtkcrashhandler

« back to all changes in this revision

Viewing changes to desktopcouch/addattachment.py

  • Committer: Jono Bacon
  • Date: 2010-04-10 19:47:35 UTC
  • mfrom: (81.3.1 add_attachment)
  • Revision ID: jono@ubuntu.com-20100410194735-leg9t0xnmwuwofv6
Attach something to a DesktopCouch entry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# [SNIPPET_NAME: Add an attachment to a Desktopcouch Record]
 
2
# [SNIPPET_CATEGORIES: DesktopCouch]
 
3
# [SNIPPET_DESCRIPTION: Shows how to add an attachment to a Desktopcouch Record that will be stored and replicated by CouchDB]
 
4
# [SNIPPET_AUTHOR: Manuel de la Pena <mandel@themacaque.com>]
 
5
# [SNIPPET_DOCS: http://www.themacaque.com/wiki/doku.php?id=desktopcouch:create_attachments]
 
6
# [SNIPPET_LICENSE: GPL]
 
7
import sys
 
8
from desktopcouch.records.record import Record
 
9
from desktopcouch.records.server import CouchDatabase
 
10
 
 
11
# get the jpg to add from the command line
 
12
 
 
13
if len(sys.argv) > 1:
 
14
    path = sys.argv[0]
 
15
    db = CouchDatabase("addattachment", create=True)
 
16
    record = Record(record_type="url")
 
17
    record.attach(path, "blob", "image/jpg")
 
18
    db.put_record(record)
 
19
else:
 
20
    print "Please pass the path of the jpg to add."
 
21
 
 
22
# got to /home/$USER/.local/share/desktop-couch/couchdb.html to see the 
 
23
# attached file