Commit 5d7bec61 authored by Bartek Górny's avatar Bartek Górny

changed the ingestion procedure - in some cases some properties are read from...

changed the ingestion procedure - in some cases some properties are read from the content, and sometimes we do not check for consistency

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11253 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6c7aa0d3
......@@ -18,8 +18,34 @@ def extractContent(data):
z.close()
return s
def getAttrFromContent(data):
return dict(rx_atr.findall(extractContent(data)))
rx_fileno=re.compile('File No.: *(?P<reference>(?P<group>[A-Za-z-]+)-(?P<project>\d+)-(?P<number>\d+)\.(?P<year>\d{2}))')
rx_classif=re.compile('([A-Z]{1}[a-z]+/[A-Z]{1}[a-z]+)')
def getAttrFromContent(self,data,ptype):
if ptype!='Memo':return {}
atrs={}
fileno=rx_fileno.search(data)
if fileno:
dic=fileno.groupdict()
atrs['source_project']='project_module/'+dic['project']
atrs['reference']=dic['reference']
classif=rx_classif.search(data)
log=[]
if classif:
classif=classif.groups()[0].split('/')
classif.reverse()
res=self.portal_catalog(portal_type='Category',title=classif[0])
for r in res:
c=r.getObject()
for x,t in enumerate(classif):
c=c.aq_parent
if c.getId()=='classification':
atrs['classification']='/'.join(r.getRelativeUrl().split('/')[1:])
break
if c.getTitle()!=classif[x+1]:
break
self.log(atrs)
return atrs
def getDoctypeFromContent(data):
atrs=getAttrFromContent(data)
......
......@@ -70,8 +70,8 @@
<key> <string>_body</string> </key>
<value> <string># determine content type if not given\n
# first try from content\n
if not doctype:\n
doctype=context.Document_getDoctypeFromContent(data)\n
#if not doctype:\n
# doctype=context.Document_getDoctypeFromContent(data)\n
# then from filename\n
if not doctype:\n
doctype=context.content_type_registry.findTypeName(fname,None,None)\n
......
......@@ -78,8 +78,8 @@ if data is None:\n
else:\n
if hasattr(context,\'data\'):\n
data=data\n
if data is not None:\n
context.setPropertyListFromContent(data)\n
#if data is not None:\n
# context.setPropertyListFromContent(data)\n
\n
if fname is None:\n
fname=context.getSourceReference()\n
......
......@@ -76,8 +76,11 @@ if pref is not None and len(pref)==0:\n
if pref==\'never\':return\n
\n
ob=kw[\'object\']\n
res=ob.checkConsistency()\n
res=[c for c in res if c[1]==\'DocumentCoordinatesConstraint inconsistency\']\n
if ob.getPortalType()==\'Memo\': # we don\'t check constistency for Memo XXX use type groups, or what?\n
res=\'\'\n
else:\n
res=ob.checkConsistency()\n
res=[c for c in res if c[1]==\'DocumentCoordinatesConstraint inconsistency\']\n
\n
# shall we send?\n
send=(pref==\'always\' or len(res)>0)\n
......
......@@ -38,7 +38,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
<value> <string>(not used)</string> </value>
</item>
</dictionary>
</pickle>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.PythonScripts.PythonScript</string>
<string>PythonScript</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Python_magic</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>return {}\n
\n
# write your own method (probably External Method, since it is most likely\n
# to use re) that would analyze text content of the doc\n
# and return a dictionary of properties\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_filepath</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>ob,content,ptype</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>ob</string>
<string>content</string>
<string>ptype</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Document_getPropertyListFromContent</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -69,9 +69,12 @@
<item>
<key> <string>_body</string> </key>
<value> <string>ob=context\n
if ob.hasFile() and not ob.hasOOFile(): #doublecheck\n
context.log(kw)\n
if (ob.hasFile() and not ob.hasOOFile()) or context.REQUEST.get(\'force\'): #doublecheck\n
context.log(\'we go ahead\')\n
try:\n
res=ob.convert(force=1)\n
ob.setPropertyListFromContent()\n
ob.setExternalProcessingStatusMessage(\'converted\')\n
except Exception,e:\n
ob.log(\'Exception\',e)\n
......
327
\ No newline at end of file
330
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment