Back to index

plone3  3.1.7
createData.py
Go to the documentation of this file.
00001 import transaction
00002 import sys
00003 import os
00004 from os.path import realpath
00005 import math
00006 
00007 from ZODB import DB
00008 from ZODB.FileStorage import FileStorage
00009 
00010 from common import Root, Dummy
00011 
00012 
00013 epi_path = '/'.join(realpath(os.getcwd()).split('/')[:-1])
00014 sys.path.insert(0, epi_path)
00015 from ExtendedPathIndex import ExtendedPathIndex
00016 LIMIT = 500
00017 DEPTHLIMIT = 5
00018 
00019 
00020 storage = FileStorage(file_name='EPI.fs', create=True)
00021 db = DB(storage)
00022 
00023 transaction.begin()
00024 conn = db.open()
00025 root = conn.root()
00026 
00027 index = ExtendedPathIndex( 'path' )
00028 
00029 # Based on Pan Junyong's code
00030 # this is synthetic and not evenly distributed
00031 def buildTree(index, f1=20, f2=20, f3=1):
00032     count = 0
00033     for i in range(f1):
00034         f1id = 'f-%d' % i
00035         folder1 = Dummy("/plone/%s" % f1id)
00036         count += 1
00037         index.index_object(count, folder1)
00038 
00039         for j in range(f2):
00040             transaction.commit(1)
00041             f2id = 'f-%d-%d' % (i, j)
00042             folder2 = Dummy("/plone/%s/%s" % (f1id, f2id))
00043             count += 1
00044             index.index_object(count, folder2)
00045 
00046             for k in range(f3):
00047                 f3id = 'f-%d-%d-%d' % (i, j, k)
00048                 folder3 = Dummy("/plone/%s/%s/%s" % (f1id, f2id, f3id))
00049                 count += 1
00050                 index.index_object(count, folder3)
00051 
00052                 for m in range(500):
00053                     docid = 'f-%d-%d-%d-%d' % (i, j, k, m)
00054                     doc = Dummy("/plone/%s/%s/%s/%s" % (f1id, f2id, f3id, docid))
00055                     count += 1
00056                     index.index_object(count, doc)
00057     print 'Created %s entries' % count
00058 
00059 buildTree(index, 20,20)
00060 
00061 plone = Root('plone')
00062 plone.index = index
00063 root['plone'] = plone
00064 
00065 transaction.commit()
00066 conn.close()
00067 
00068 db.close()
00069 storage.close()
00070 #storage.cleanup() # For removing all files