version 1.80.2.17, 2008/01/14 19:15:33
|
version 1.84, 2008/09/25 13:41:58
|
Line 21 from ZPublisher.HTTPRequest import HTTPR
|
Line 21 from ZPublisher.HTTPRequest import HTTPR
|
from ZPublisher.HTTPResponse import HTTPResponse |
from ZPublisher.HTTPResponse import HTTPResponse |
from ZPublisher.BaseRequest import RequestContainer |
from ZPublisher.BaseRequest import RequestContainer |
import threading |
import threading |
from BTrees.OOBTree import OOBTree |
from BTrees.OOBTree import OOBTree, OOTreeSet |
import logging |
import logging |
import transaction |
import transaction |
import copy |
import copy |
import codecs |
import codecs |
import sys |
import sys |
|
from BTrees.IOBTree import IOBTree |
import cdliSplitter |
import cdliSplitter |
|
from sets import Set |
|
import md5 |
|
|
def unicodify(s): |
def unicodify(s): |
"""decode str (utf-8 or latin-1 representation) into unicode object""" |
"""decode str (utf-8 or latin-1 representation) into unicode object""" |
Line 108 def formatAtfFullLineNum(txt, nolemma=Tr
|
Line 109 def formatAtfFullLineNum(txt, nolemma=Tr
|
surf = line.replace(words[0],surfaces[words[0]]).strip() |
surf = line.replace(words[0],surfaces[words[0]]).strip() |
|
|
elif words[0] == '@column': |
elif words[0] == '@column': |
col = words[1] |
col = ' '.join(words[1:]) |
|
|
elif line and line[0] in '123456789': |
elif line and line[0] in '123456789': |
# ordinary line -> add line number |
# ordinary line -> add line number |
Line 925 class CDLIBasketContainer(OrderedFolder)
|
Line 926 class CDLIBasketContainer(OrderedFolder)
|
if not ids: |
if not ids: |
ids=self.REQUEST.SESSION['fileIds'] |
ids=self.REQUEST.SESSION['fileIds'] |
|
|
if type(ids) is not ListType: |
if (type(ids) is not ListType) and (not isinstance(ids,Set)): |
ids=[ids] |
ids=[ids] |
|
|
|
if isinstance(ids,Set): |
|
ids=list(ids) |
|
|
if (submit.lower()=="store in new basket") or (submit.lower()=="new basket"): |
if (submit.lower()=="store in new basket") or (submit.lower()=="new basket"): |
basketRet=self.addBasket(newBasketName) |
basketRet=self.addBasket(newBasketName) |
self.setActiveBasket(basketRet.getId()) |
self.setActiveBasket(basketRet.getId()) |
Line 941 class CDLIBasketContainer(OrderedFolder)
|
Line 945 class CDLIBasketContainer(OrderedFolder)
|
|
|
if fromFileList: |
if fromFileList: |
|
|
return self.cdli_main.findObjectsFromList(list=self.REQUEST.SESSION['fileIds'],basketName=basket.title,numberOfObjects=added) |
return self.cdli_main.findObjectsFromList(list=ids,basketName=basket.title,numberOfObjects=added) |
|
|
if RESPONSE: |
if RESPONSE: |
|
|
Line 1177 class CDLIBasket(Folder,CatalogAware):
|
Line 1181 class CDLIBasket(Folder,CatalogAware):
|
|
|
def addObjects(self,ids,deleteOld=None,username=None): |
def addObjects(self,ids,deleteOld=None,username=None): |
"""generate a new version of the basket with objects added""" |
"""generate a new version of the basket with objects added""" |
|
|
|
def swap(x): |
|
return (x[1],x[0]) |
|
|
logging.info("add to basket (%s)"%(self.getId())) |
logging.info("add to basket (%s)"%(self.getId())) |
lastVersion=self.getLastVersion() |
lastVersion=self.getLastVersion() |
|
|
Line 1188 class CDLIBasket(Folder,CatalogAware):
|
Line 1196 class CDLIBasket(Folder,CatalogAware):
|
if deleteOld: |
if deleteOld: |
oldContent=[] |
oldContent=[] |
|
|
newContent=[] |
|
added=0 |
added=0 |
for id in ids: |
# for id in ids: |
try: |
# logging.debug("adding:"+id) |
founds=self.CDLICatalog.search({'title':id}) |
# try: |
except: |
# founds=self.CDLICatalog.search({'title':id}) |
founds=[] |
# except: |
|
# founds=[] |
|
# |
|
# for found in founds: |
|
# if found.getObject() not in oldContent: |
|
# #TODO: was passiert wenn, man eine Object dazufgt, das schon da ist aber eine neuere version |
|
# newContent.append((found.getObject().getLastVersion(),found.getObject())) |
|
# added+=1 |
|
|
|
hash = md5.new(repr(self.makelist(ids))).digest() # erzeuge hash als identification |
|
#logging.debug("JJJJJJJ:"+repr(self.makelist(ids))) |
|
logging.debug("JJJJJJJ:"+repr(hash)) |
|
|
|
if hasattr(self.cdliRoot,'_v_tmpStore') and self.cdliRoot._v_tmpStore.has_key(hash): |
|
logging.debug("from store!") |
|
newContent=Set(map(swap,self.cdliRoot._v_tmpStore[hash])) |
|
|
for found in founds: |
else: |
if found.getObject() not in oldContent: |
logging.debug("not from store!") |
#TODO: was passiert wenn, man eine Object dazufgt, das schon da ist aber eine neuere version |
newContent=Set([(self.getFileObjectLastVersion(x),self.getFileObject(x)) for x in ids]) |
newContent.append((found.getObject().getLastVersion(),found.getObject())) |
|
added+=1 |
|
|
|
content=oldContent+newContent |
|
|
content=Set(oldContent).union(newContent) |
|
added = len(content)-len(oldContent) |
if not username: |
if not username: |
user=self.getActualUserName() |
user=self.getActualUserName() |
else: |
else: |
user = username |
user = username |
|
|
ob=manage_addCDLIBasketVersion(self,user,comment="",basketContent=content) |
#logging.debug("content:"+repr(list(content))) |
|
ob=manage_addCDLIBasketVersion(self,user,comment="",basketContent=list(content)) |
logging.info("add to basket (%s) done"%(self.getId())) |
logging.info("add to basket (%s) done"%(self.getId())) |
return added |
return added |
|
|
Line 1392 class CDLIBasketVersion(Implicit,Persist
|
Line 1415 class CDLIBasketVersion(Implicit,Persist
|
|
|
|
|
for object in self.content.getContent(): |
for object in self.content.getContent(): |
|
logging.error("ret:"+repr(object[0])) |
|
logging.error(" -"+repr(procedure)) |
|
logging.error(" -"+repr(object[1].lockedBy)) |
|
|
if (procedure=="downloadAll") or (object[1].lockedBy=='') or (object[1].lockedBy==self.REQUEST['AUTHENTICATED_USER']): |
if (procedure=="downloadAll") or (object[1].lockedBy=='') or (object[1].lockedBy==self.REQUEST['AUTHENTICATED_USER']): |
|
logging.error("ret1") |
if current=="no": #version as they are in the basket |
if current=="no": #version as they are in the basket |
|
logging.error("ret2") |
ret+=str(object[0].getData())+"\n" |
ret+=str(object[0].getData())+"\n" |
elif current=="yes": |
elif current=="yes": |
|
logging.error("ret3") |
#search current object |
#search current object |
founds=self.CDLICatalog.search({'title':object[1].getId().split(".")[0]}) |
founds=self.CDLICatalog.search({'title':object[1].getId().split(".")[0]}) |
if len(founds)>0: |
if len(founds)>0: |
Line 1931 class CDLIFileFolder(extVersionedFileFol
|
Line 1960 class CDLIFileFolder(extVersionedFileFol
|
|
|
return ret |
return ret |
|
|
def findObjectsFromList(self,enterList=None,display=False,start=None,upload=None,list=None,basketName=None,numberOfObjects=None,RESPONSE=None): |
def expandFile(self,fileId,fileTree): |
"""findObjectsFromList (, TAB oder LINE separated)""" |
"""wildcard in fileID suche alle Treffer""" |
|
founds=self.CDLICatalog({'title':fileId}) |
|
for found in founds: |
|
fileTree.add(found.getId) |
|
logging.debug("ADDD:"+found.getId) |
|
|
|
def findObjectsFromList(self,enterList=None,display=False,start=None,upload=None,list=None,basketName=None,numberOfObjects=None,RESPONSE=None,REQUEST=None): |
|
"""findObjectsFromList (, TAB oder LINE separated)""" |
|
|
|
logging.debug("start: findObjectsFromList") |
if upload: # list from file upload |
if upload: # list from file upload |
txt=upload.read() |
txt=upload.read() |
|
|
Line 1966 class CDLIFileFolder(extVersionedFileFol
|
Line 2002 class CDLIFileFolder(extVersionedFileFol
|
return pt(basketName=basketName,numberOfObjects=numberOfObjects) |
return pt(basketName=basketName,numberOfObjects=numberOfObjects) |
|
|
if list is not None: # got already a list |
if list is not None: # got already a list |
|
|
|
logging.debug(" ----List version") |
ret=[] |
ret=[] |
|
fileTree=Set() |
|
|
for fileId in list: |
for fileId in list: |
if fileId.find("*"): #check for wildcards |
|
fileId=fileId |
if fileId.find("*")>-1: #check for wildcards |
|
self.expandFile(fileId,fileTree) |
|
|
elif len(fileId.split("."))==1: |
elif len(fileId.split("."))==1: |
fileId=fileId+".atf" |
fileId=fileId+".atf" |
|
fileTree.add(fileId) |
|
#logging.debug(" -----:"+fileId) |
|
#ret+=self.CDLICatalog({'title':fileId}) |
|
#x =self.getFileObject(fileId) |
|
#if x is not None: |
|
# ret.append(x) |
|
|
|
|
|
|
|
ids = fileTree & self.v_file_ids |
|
|
|
|
|
hash = md5.new(repr(self.makelist(ids))).digest() # erzeuge hash als identification |
|
#TODO: do I need garbage collection for _v_tmpStore ? |
|
#logging.debug("list:"+repr(self.makelist(ids))) |
|
#logging.debug("Hash:"+repr(hash)) |
|
if hasattr(self.cdliRoot,'_v_tmpStore') and self.cdliRoot._v_tmpStore.has_key(hash): |
|
logging.debug("asking for storage") |
|
return self.cdliRoot._v_tmpStore[hash] |
|
|
ret+=self.CDLICatalog({'title':fileId}) |
|
#TODO: get rid of one of these.. |
#TODO: get rid of one of these.. |
ids=[x.getObject().getId() for x in ret] |
#ids=[x.getObject().getId() for x in ret] |
self.REQUEST.SESSION['fileIds']=ids#store fieldIds in session for further usage |
ret=[(self.getFileObject(x),self.getFileObjectLastVersion(x)) for x in ids] |
|
|
|
#self.REQUEST.SESSION['fileIds']=ids#store fieldIds in session for further usage |
|
#self.REQUEST.SESSION['searchList']=self.REQUEST.SESSION['fileIds'] |
|
self.REQUEST.SESSION['fileIds']=list#store fieldIds in session for further usage |
self.REQUEST.SESSION['searchList']=self.REQUEST.SESSION['fileIds'] |
self.REQUEST.SESSION['searchList']=self.REQUEST.SESSION['fileIds'] |
|
|
if display: |
if display: |
Line 1984 class CDLIFileFolder(extVersionedFileFol
|
Line 2048 class CDLIFileFolder(extVersionedFileFol
|
|
|
return pt(search=ids) |
return pt(search=ids) |
else: |
else: |
|
#self.REQUEST.SESSION['hash'] = ret # store in session |
|
if not hasattr(self,'_v_tmpStore'): |
|
self.cdliRoot._v_tmpStore={} |
|
#logging.debug("HHHHHHNEU:"+repr(self.makelist(ids))) |
|
#logging.debug("HHHHHHNEU:"+repr(hash)) |
|
self.cdliRoot._v_tmpStore[hash] = ret # store in session |
return ret |
return ret |
|
|
|
|
Line 1991 class CDLIFileFolder(extVersionedFileFol
|
Line 2061 class CDLIFileFolder(extVersionedFileFol
|
if start: |
if start: |
RESPONSE.redirect("filelist.html?start:int="+str(start)) |
RESPONSE.redirect("filelist.html?start:int="+str(start)) |
|
|
|
def makelist(self,mySet): |
|
x = list(mySet) |
|
x.sort() |
|
return x |
|
|
security.declareProtected('Manage','createAllFilesAsSingleFile') |
security.declareProtected('Manage','createAllFilesAsSingleFile') |
def createAllFilesAsSingleFile(self,RESPONSE=None): |
def createAllFilesAsSingleFile(self,RESPONSE=None): |
Line 2119 class CDLIRoot(Folder):
|
Line 2193 class CDLIRoot(Folder):
|
'graphemes':cdliSplitter.graphemeSplitter()} |
'graphemes':cdliSplitter.graphemeSplitter()} |
|
|
|
|
|
def getFileObject(self,fileId): |
|
x=self.v_files.get(fileId) |
|
#logging.debug(x) |
|
return x |
|
|
|
def getFileObjectLastVersion(self,fileId): |
|
x=self.v_files_lastVersion.get(fileId) |
|
#logging.debug(x) |
|
return x |
|
|
|
def generateFileBTree(self): |
|
"""erzeuge einen Btree aus allen Files""" |
|
self.v_files = OOBTree() |
|
self.v_files_lastVersion = OOBTree() |
|
self.v_file_ids = Set() |
|
|
|
for x in self.CDLICatalog.searchResults(): |
|
|
|
self.v_files.update({x.getId:x.getObject()}) |
|
self.v_files_lastVersion.update({x.getId:x.getObject().getLastVersion()}) |
|
self.v_file_ids.add(x.getId) |
|
logging.debug("add:"+x.getId+"XXX"+repr(x.getObject())) |
|
|
|
return "done" |
def deleteFiles(self,ids): |
def deleteFiles(self,ids): |
"""delete files""" |
"""delete files""" |
for id in ids: |
for id in ids: |
Line 2157 class CDLIRoot(Folder):
|
Line 2255 class CDLIRoot(Folder):
|
return f[0].getObject().getData() |
return f[0].getObject().getData() |
|
|
|
|
|
|
def showFile(self,fileId,wholePage=False): |
def showFile(self,fileId,wholePage=False): |
"""show a file |
"""show a file |
@param fileId: P-Number of the document to be displayed |
@param fileId: P-Number of the document to be displayed |
Line 2296 class CDLIRoot(Folder):
|
Line 2393 class CDLIRoot(Folder):
|
return dict([(id,self.tagWordInFile(id, word, indexName, regExp)) for id in fileIds]) |
return dict([(id,self.tagWordInFile(id, word, indexName, regExp)) for id in fileIds]) |
|
|
|
|
|
def getFileVersionList(self, pnum): |
|
"""get the version history as a list for the translit file with the given pnum""" |
|
f = getattr(self, self.file_catalog).search({'textid':pnum}) |
|
if not f: |
|
return [] |
|
|
|
return f[0].getObject().getVersionList() |
|
|
|
|
def URLquote(self,str): |
def URLquote(self,str): |
"""quote url""" |
"""quote url""" |
return urllib.quote(str) |
return urllib.quote(str) |