Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MB-100: don't open temp. file second time

Change-Id: I80f0fe4897ba035510da53482adc6d627ebf94bb
Reviewed-on: http://review.couchbase.org/17987
Reviewed-by: Bin Cui <bin.cui@gmail.com>
Tested-by: Pavel Paulau <pavel.paulau@gmail.com>
  • Loading branch information...
commit 95f59b064d65783635936cbcac8a2635999bf2c6 1 parent 4793fb9
@pavel-paulau pavel-paulau authored
Showing with 6 additions and 12 deletions.
  1. +6 −12 docloader
View
18 docloader
@@ -6,7 +6,7 @@ import zipfile
import os
import os.path
import simplejson as json
-import tempfile
+from tempfile import TemporaryFile
import re
from optparse import OptionParser
@@ -96,17 +96,11 @@ class DocLoader:
if not name.endswith('/'):
print 'working with ', name
dockey = self.gen_dockey(name)
- temp = tempfile.NamedTemporaryFile()
- fname = temp.name
- temp.write(zfobj.read(name))
- temp.flush()
- try:
- fp = open(fname, 'r')
- self.save_doc(bucket, dockey, fp, views)
- fp.close()
- except IOError, error:
- print error
- temp.close()
+ temp_file = TemporaryFile()
+ temp_file.write(zfobj.read(name))
+ temp_file.seek(0)
+ self.save_doc(bucket, dockey, temp_file, views)
+ temp_file.close()
def populate_docs(self, bucket, views):
if self.args[0].endswith('.zip'):
Please sign in to comment.
Something went wrong with that request. Please try again.