[CPS-users-fr] Stockage de documents Office

Pierre Maris pierre.maris at capgemini.com
Mer 24 Jan 11:21:37 CET 2007


Une pièce jointe HTML a été enlevée...
URL: http://lists.nuxeo.com/pipermail/cps-users-fr/attachments/20070124/3141df3c/attachment.html
-------------- section suivante --------------

import os
import sys
import mx.DateTime
from zLOG import DEBUG, INFO, LOG 
from string import maketrans

def getFolder(dest, title):
	id = testid(title)
	if not hasattr(dest, id):
		dest.invokeFactory('Section', id)
		ob = getattr(dest, id)
		doc = ob.getEditableContent()
		dico = {'Title':title}
		doc.edit(dico)
	return getattr(dest, id)

max_chars_for_id=40
def testid(compute_from):
	# Create, no id, get from title
	newid = compute_from.strip()[:max_chars_for_id]
	
	# Normalization
	newid = newid.replace('Æ', 'AE')
	newid = newid.replace('æ', 'ae')
	newid = newid.replace('¼', 'OE')
	newid = newid.replace('½', 'oe')
	newid = newid.replace('ß', 'ss')
	tr = maketrans(
		r"'\;/ &:ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ",
		r'_______AAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy')
	newid = newid.translate(tr)
	ok = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.'
	newid = ''.join([c for c in newid if c in ok])
	while newid.startswith('_') or newid.startswith('.'):
		newid = newid[1:]
	
	while newid.endswith('_'):
		newid = newid[:-1]
	
	if newid:
		newid = newid.lower()
	else:
		# Fallback if empty
		newid = str(int(DateTime())) + str(randrange(1000, 10000))
	return newid

def load(self, min=1, max=33000):
	dest = self
	type_name = 'AVI_Deliberations'
	f = open(os.path.join(CLIENT_HOME,'../import/export_delib.txt'), mode='r')
	source = f.read(-1)
	delibs = source.split('\n')
	i = 0
	t = get_transaction()
	t.begin()
	for delib  in delibs[min:max]:
		fields = delib.split('\t')
		ordre = fields[0]
		date = fields[1]
		jma = date.split('/')
		jour = jma[0]
		mois = jma[1]
		annee = jma[2]
		if int(annee)>20:
			annee = '19'+annee
		else:
			annee = '20'+annee
		dt = fields[2].split(':')
		if len(dt)>1:
			domaine = dt[0].strip()
			title = dt[1].strip()
		else:
			title = dt[0]
			domaine = "Autres"
		folderAnnee = getFolder(dest, annee)
		folderMois = getFolder(folderAnnee, mois)
		folderDomaine = getFolder(folderMois, domaine)
		dico = {}
		dico['Ordre'] = ordre
		dico['Date-Delib'] = "%s/%s/%s" % (jour, mois, annee)
		dico['Domaine'] = domaine
		dico['Title'] = title
		id = dico['Ordre']
		if not hasattr(folderDomaine, id):
			folderDomaine.invokeFactory(type_name, id)
		ob = getattr(folderDomaine, id)
		doc = ob.getEditableContent()
		LOG('Upload Delib', INFO, '%s : %s/%s/%s/%s : %s created' % (i, annee, mois, domaine, id, title))
		doc.edit(dico)
		i = i+1
		if i%100==0:
			t.commit()
			LOG('Upload Delib', INFO, '%s : commit' % i)
			t = get_transaction()
			t.begin
		
	t.commit()
	
	return "%s deliberations importees" % i


This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient,  you are not authorized to read, print, retain, copy, disseminate,  distribute, or use this message or any part thereof. If you receive this  message in error, please notify the sender immediately and delete all  copies of this message.


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.