Skip to content
Browse files

CBD-514: Avoid using temporary files

Instead, extracting files to a temp location and upload files
on temp directory. It will speed up the uploading process.

Change-Id: I5298dc84ef4000a86ed6586bcab0073c2463fd5f
Reviewed-on: http://review.couchbase.org/19788
Reviewed-by: Steve Yen <steve.yen@gmail.com>
Tested-by: Bin Cui <bin.cui@gmail.com>
  • Loading branch information...
1 parent 10913bb commit 2399ac0baf421579bc023fee484f690e3348b969 @bcui6611 bcui6611 committed Aug 17, 2012
Showing with 5 additions and 16 deletions.
  1. +5 −16 cbdocloader
View
21 cbdocloader
@@ -6,6 +6,7 @@ import time
import zipfile
import os
import os.path
+import shutil
import simplejson as json
from tempfile import TemporaryFile
from optparse import OptionParser
@@ -117,22 +118,10 @@ class DocLoader:
def unzip_file_and_upload(self):
zfobj = zipfile.ZipFile(self.args[0])
- for name in zfobj.namelist():
- if not name.endswith('/') and name.find("design_docs") < 0:
- self.upload_file(zfobj, name)
- #upload design docs after all other docs
- for name in zfobj.namelist():
- if not name.endswith('/') and name.find("design_docs") >= 0:
- self.upload_file(zfobj, name)
-
- def upload_file(self, zfobj, name):
- print 'working with %s' % name
- dockey = self.gen_dockey(name)
- temp_file = TemporaryFile()
- temp_file.write(zfobj.read(name))
- temp_file.seek(0)
- self.save_doc(dockey, temp_file)
- temp_file.close()
+ working_dir = os.path.join(os.path.dirname(sys.argv[0]), '_working')
+ zfobj.extractall(working_dir)
+ self.list_files(working_dir)
+ shutil.rmtree(working_dir)
def populate_docs(self):
cb = client.Couchbase(self.options.node,

0 comments on commit 2399ac0

Please sign in to comment.
Something went wrong with that request. Please try again.