I have millions of files in the Google cloud storage's bucket. I want to search within files with a .index extension and retrieve the contents.
This is currently what I am doing, but the time required for overall process is large. Is there any better and faster way to do this?
class storage():
...
self.indexFile = []
self.indexFileIndex = []
...
def get_content(self,param1,param2):
c_n = []
for value, index in zip(param1, param2):
object_contents = StringIO.StringIO()
srcObjURI = boto.storage_uri(value, self.storage)
srcObjURI.get_key().get_file(object_contents)
c_n.append(object_contents.getvalue())
object_contents.close()
return c_n
def get_PATHs(self):
paths=[]
#pts=open("paths.txt","w")
pts_log=open("paths_log.txt","a")
pts_log.write("-"*20+time.ctime()+"-"*20+"\n")
indexFileContents = self.get_content(self.indexFile, self.indexFileIndex)
for c,d in zip(indexFileContents,self.indexFile):
regx = r"(.*)\/" + r"(.*?)\|"
patternPathList = re.compile(regx)
for match in patternPathList.finditer(c):
p=match.group(1).strip() + "/"+ match.group(2).strip()
tst_exst=""
if p in paths:
tst_exst="Already exist !"
else:
tst_exst="Added to PATHs list"
paths.append(p)
#pts.write(p)
#pts.write("\n")
pts_log.write("FROM : %s --> %s %s"%(d,p,tst_exst))
pts_log.write("\n")
#pts.close()
pts_log.close()
return paths
The files that I am trying to search varies from 200KB to 1MB and sometimes has Unicode characters.