Permalink
Browse files

MB-100: refactored save_doc method

Change-Id: Id183804cf0028c12816c03971a29bf5c3dea5100
Reviewed-on: http://review.couchbase.org/18004
Tested-by: Pavel Paulau <pavel.paulau@gmail.com>
Reviewed-by: Bin Cui <bin.cui@gmail.com>
  • Loading branch information...
1 parent 9bc42d7 commit a14f2d25bedfd0f925202d1c6700344f8ff04742 @pavel-paulau pavel-paulau committed with pavel-paulau Jul 6, 2012
Showing with 12 additions and 16 deletions.
  1. +12 −16 docloader
View
@@ -42,23 +42,19 @@ class DocLoader:
print self.options, self.args
- def save_doc(self, bucket, dockey, fp, views):
- buf = fp.read()
- result = json.loads(buf)
- if isinstance(result, dict):
- if '_id' not in result:
- bucket.set(dockey, 0, 0, json.dumps(result))
+ def save_doc(self, bucket, dockey, datafile, views):
+ raw_data = datafile.read()
+ try:
+ doc = json.loads(raw_data)
+ if '_id' not in doc:
+ bucket.set(dockey, 0, 0, raw_data)
else:
- try:
- result['_id'] = result['_id'].encode('UTF-8')
- doc_id = bucket.save(result)
- print "just now saving %s" % doc_id
- except:
- doc_id = "_design/testing"
- if result['_id'] and 'views' in result:
- for key in result['views'].iterkeys():
- viewpath = result['_id'] + '/_view/' + key
- views.append(viewpath)
+ doc['_id'] = doc['_id'].encode('UTF-8')
+ bucket.save(doc)
+ for view in doc.get('views', []):
+ views.append(doc['_id'] + '/_view/' + view)
+ except ValueError, error:
+ print error
def gen_dockey(self, filename):
return os.path.basename(filename).split('.')[0]

0 comments on commit a14f2d2

Please sign in to comment.