Nuxeo mailing list archives
[CPS-users-fr] Stockage de documents Office
Cédric Marfil
cedric.marfil at capgemini.com
Mar 23 Jan 19:36:15 CET 2007
contenu de type multipart/alternative sauté-------------- section suivante --------------
import os
import sys
from OFS.Image import File
def isNumeric(pString):
toReturn = True
try:
a = int(pString)
except:
toReturn = False
return toReturn
def integrate(self):
logStringBuffer = []
logStringBuffer.append('STARTING FORMATIONS INTEGRATION')
logStringBuffer.append('-------------------------------')
logStringBuffer.append('')
#CMA Getting necessary Tools & Workspaces
portal = self.portal_url.getPortalObject()
wTool = portal.portal_workflow
formationsWs = portal.workspaces.offre_formation
fichesWs = formationsWs.fiches_formation
#CMA Building path to disk files
tipiHome = sys.modules['Products.Tipi'].__path__[0]
formationsDir = os.path.join(tipiHome, 'Formations')
fichesDir = os.path.join(formationsDir, 'Fiches')
filesNumber = 0
for ws, path in [(formationsWs, formationsDir), (fichesWs, fichesDir)]:
#CMA Removing old files ...
logStringBuffer.append('"%s" Management'%(ws.getId()))
logStringBuffer.append(' REMOVING OLD FILES')
logStringBuffer.append(' ..................')
logStringBuffer.append('')
filesIdToDelete = ws.objectIds(['CPS Proxy Document'])
logStringBuffer.append('Removing %s'%(str(filesIdToDelete)))
ws.manage_delObjects(filesIdToDelete)
#CMA Creating new files
logStringBuffer.append(' CREATING NEW FILES')
logStringBuffer.append(' ..................')
logStringBuffer.append('')
for objectName in os.listdir(path):
if not os.path.isfile(os.path.join(path,objectName)):
continue
#CMA Building file Id
fileId = ws.computeId(compute_from=objectName)
nameElts = objectName.split(' ')
if len(nameElts)>1:
if isNumeric(nameElts[1]):
fileId = str(int(nameElts[1])).zfill(3)
logStringBuffer.append('%s: "%s"'%(fileId, objectName))
#CMA Creating file document
wTool.invokeFactoryFor(ws, 'File', fileId)
logStringBuffer.append(' created...')
document = getattr(ws, fileId)
documentRepository = document.getContent()
datamodel = documentRepository.getDataModel()
datamodel.set('Title', objectName)
#CMA Getting file data
#CMA Be careful to open the file in binary mode ;-)
diskFile = open(os.path.join(path, objectName), 'rb')
ofsFile = File('file', '%s.doc'%(fileId), diskFile)
diskFile.close()
datamodel.set('file', ofsFile)
datamodel._commit()
logStringBuffer.append(' uploaded...')
#CMA Reindexing file
documentRepository.reindexObject()
logStringBuffer.append(' reindexed...')
#CMA Counting files number
filesNumber += 1
logStringBuffer.append('')
logStringBuffer.append(' --> %d files built'%(filesNumber))
return "\r\n".join(logStringBuffer)
Plus d'informations sur la liste de diffusion cps-users-fr
This list archive provided by Nuxeo, the
leaders of open source ECM.
Check out the Nuxeo 5 open source,
standards-based ECM project.