22
22
23
23
BULK_SIZE = 1000
24
24
25
- def dump_docs (envelope , docs ):
25
+ def dump_docs (envelope , db , docs ):
26
26
for doc in docs :
27
27
28
28
print >> sys .stderr , 'Dumping document %r' % doc .id
@@ -35,14 +35,19 @@ def dump_docs(envelope, docs):
35
35
'ETag' : '"%s"' % doc .rev
36
36
})
37
37
parts .add ('application/json' , jsondoc )
38
-
39
38
for name , info in attachments .items ():
39
+
40
40
content_type = info .get ('content_type' )
41
41
if content_type is None : # CouchDB < 0.8
42
42
content_type = info .get ('content-type' )
43
- parts .add (content_type , b64decode (info ['data' ]), {
44
- 'Content-ID' : name
45
- })
43
+
44
+ if 'data' not in info :
45
+ data = db .get_attachment (doc , name ).read ()
46
+ else :
47
+ data = b64decode (info ['data' ])
48
+
49
+ parts .add (content_type , data , {'Content-ID' : name })
50
+
46
51
parts .close ()
47
52
48
53
else :
@@ -62,7 +67,8 @@ def dump_db(dburl, username=None, password=None, boundary=None,
62
67
start , num = 0 , db .info ()['doc_count' ]
63
68
while start < num :
64
69
opts = {'limit' : bulk_size , 'skip' : start , 'include_docs' : True }
65
- dump_docs (envelope , [row .doc for row in db .view ('_all_docs' , ** opts )])
70
+ docs = (row .doc for row in db .view ('_all_docs' , ** opts ))
71
+ dump_docs (envelope , db , docs )
66
72
start += bulk_size
67
73
68
74
envelope .close ()
0 commit comments