Commit 0b0b2126 authored by Jérome Perrin's avatar Jérome Perrin

dms: fix pylint messages and enable coding style test

parent bd601780
......@@ -115,7 +115,7 @@ class PDFDocument(Image):
return outputStream.getvalue()
# Conversion API
def _convert(self, format, **kw):
def _convert(self, format, **kw): # pylint: disable=redefined-builtin
"""
Implementation of conversion for PDF files
"""
......@@ -164,7 +164,7 @@ class PDFDocument(Image):
raise NotImplementedError
security.declarePrivate('_convertToText')
def _convertToText(self):
def _convertToText(self, format='txt'): # pylint: disable=redefined-builtin
"""
Convert the PDF text content to text with pdftotext
"""
......@@ -346,9 +346,9 @@ class PDFDocument(Image):
self._content_information = result
return result.copy()
def _setFile(self, data, precondition=None):
def _setFile(self, *args, **kw):
try:
del self._content_information
except (AttributeError, KeyError):
pass
Image._setFile(self, data, precondition=precondition)
Image._setFile(self, *args, **kw)
......@@ -6,6 +6,12 @@
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>PDFDocument</string> </value>
......@@ -43,11 +49,7 @@
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple>
<string>W:117, 21: Redefining built-in \'format\' (redefined-builtin)</string>
<string>W:166, 2: Arguments number differs from overridden \'_convertToText\' method (arguments-differ)</string>
<string>W:348, 2: Arguments number differs from overridden \'_setFile\' method (arguments-differ)</string>
</tuple>
<tuple/>
</value>
</item>
<item>
......@@ -57,13 +59,28 @@
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
......@@ -76,7 +93,7 @@
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
......@@ -85,7 +102,7 @@
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
......
......@@ -71,7 +71,7 @@ def mkProxy(self):
sp = xmlrpclib.ServerProxy('http://%s:%d' % (adr,nr), allow_none=True)
return sp
def generateFile(self, name, data, format):
def generateFile(self, name, data, format): # pylint: disable=redefined-builtin
sp = mkProxy(self)
kw = sp.run_generate(name, data, None, format)
res = base64.decodestring(kw['data'])
......@@ -92,7 +92,7 @@ def getLastWorkflowDate(self, state_name='simulation_state', state=('released','
or JP says "there is an API for it" and we trash this one'''
if not hasattr(self, 'workflow_history'):
return None
for name,wflow in self.workflow_history.items():
for wflow in self.workflow_history.values():
if wflow is None or len(wflow) == 0: continue # empty history
if wflow[0].get(state_name) is None: continue # not the right one
for i in range(len(wflow)):
......@@ -110,7 +110,7 @@ def findAddress(txt):
"""
find email address in a string
"""
validchars='0-9A-Za-z.\-_'
validchars = r'0-9A-Za-z.\-_'
r=re.compile('[%s]+@[%s]+' % (validchars,validchars))
m=r.search(txt)
return m and m.group()
......@@ -121,7 +121,7 @@ def extractParams(txt):
We assume that parameters are given as lines of the format:
name:value
"""
r=re.compile('^([\w_]+):([\w_/]+)$')
r = re.compile(r'^([\w_]+):([\w_/]+)$')
res=[]
for line in txt.split():
found=r.findall(line.strip())
......
......@@ -6,10 +6,22 @@
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>DocumentManagement</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>extension.erp5.DocumentManagement</string> </value>
......@@ -24,6 +36,18 @@
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
......@@ -31,13 +55,28 @@
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
......@@ -50,7 +89,7 @@
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
......@@ -59,13 +98,15 @@
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -78,7 +119,9 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -26,7 +26,7 @@
##############################################################################
def getPersonRoleList(self, person, object):
def getPersonRoleList(self, person, object): # pylint: disable=redefined-builtin
"""
Get list of local roles for user.
"""
......
......@@ -6,10 +6,22 @@
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>DocumentSecurity</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>extension.erp5.DocumentSecurity</string> </value>
......@@ -24,6 +36,18 @@
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
......@@ -31,13 +55,28 @@
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
......@@ -50,7 +89,7 @@
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
......@@ -59,13 +98,15 @@
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -78,7 +119,9 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -27,7 +27,7 @@ for frequency_reference, creation_date in date_dict.items():
max_in_activities = 1000
offset = 0
loop = documents_to_update / max_in_activities
for i in range(loop):
for _ in range(loop):
limit = '%s,%s' % (offset, max_in_activities)
sql_kw['limit'] = limit
updateDocumentList(**sql_kw)
......
......@@ -6,5 +6,4 @@ if I don't have permissions to access the object)
object_list = context.Base_getRelatedObjectValueList(base_category, portal_type_list)
title_list = [o.getTitle() for o in object_list]
return filter(lambda t:t!='', title_list)
return [t for t in title_list if t != '']
......@@ -10,8 +10,8 @@ nr_of_types = len(type_list)
basecatdict = {}
for type in type_list:
type_base_cat_list = context.portal_types[type].getInstanceBaseCategoryList()
for type_info in type_list:
type_base_cat_list = context.portal_types[type_info].getInstanceBaseCategoryList()
for base_cat in type_base_cat_list:
basecatdict[base_cat] = basecatdict.setdefault(base_cat, 0)+1
......
# this script has an `format` argument
# pylint: disable=redefined-builtin
"""
Generic method to handle conversion failures ans still return something to use
to explain what when wrong, etc.
......
......@@ -12,8 +12,7 @@ version of each of them.
# Document_getSimilarityCloud = Document_get + upperCase(cloud) + ValueList
# BG - not much use, they're too different
from Products.ERP5Type.Utils import convertToUpperCase, convertToMixedCase
from Products.ERP5Type.Log import log
from Products.ERP5Type.Utils import convertToUpperCase
def getRelatedLatest(category):
funcname = 'get%sValueList' % convertToUpperCase(category)
......@@ -44,5 +43,4 @@ if relation_id == 'all':
dic[obj] = None
return dic.keys()
log('Relation %s is not provided for in this script' % relation)
return [] # failover - undefined relation
......@@ -26,7 +26,6 @@ if default_sub_field_property_dict is None:
}
sub_field_dict = {}
maximum_list_size = 5
default_sub_field_property_dict['field_type'] = 'ListField'
default_sub_field_property_dict['size'] = 1
......
......@@ -3,6 +3,8 @@
in such way that it is possible to select multiple
group categories for the same document
"""
if default_sub_field_property_dict is None:
default_sub_field_property_dict = {}
# Initialise result
sub_field_list = []
......@@ -16,7 +18,7 @@ default_sub_field_property_dict.update({
})
z = 0
for i in range(1):
for _ in range(1):
new_dict = default_sub_field_property_dict.copy()
new_dict['title'] = '&nbsp;'
new_dict['key'] = str(z)
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>item_list, value_list, default_sub_field_property_dict={}, is_right_display=0</string> </value>
<value> <string>item_list, value_list, default_sub_field_property_dict=None, is_right_display=0</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -3,6 +3,8 @@
in such way that it is possible to select multiple
function categories for the same document
"""
if default_sub_field_property_dict is None:
default_sub_field_property_dict = {}
# Initialise result
sub_field_list = []
......@@ -16,7 +18,7 @@ default_sub_field_property_dict.update({
})
z = 0
for i in range(1):
for _ in range(1):
new_dict = default_sub_field_property_dict.copy()
new_dict['title'] = '&nbsp;'
new_dict['key'] = str(z)
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>item_list, value_list, default_sub_field_property_dict={}, is_right_display=0</string> </value>
<value> <string>item_list, value_list, default_sub_field_property_dict=None, is_right_display=0</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -3,6 +3,8 @@
in such way that it is possible to select multiple
site categories for the same document
"""
if default_sub_field_property_dict is None:
default_sub_field_property_dict = {}
# Initialise result
sub_field_list = []
......@@ -16,7 +18,7 @@ default_sub_field_property_dict.update({
})
z = 0
for i in range(1):
for _ in range(1):
new_dict = default_sub_field_property_dict.copy()
new_dict['title'] = '&nbsp;'
new_dict['key'] = str(z)
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>item_list, value_list, default_sub_field_property_dict={}, is_right_display=0</string> </value>
<value> <string>item_list, value_list, default_sub_field_property_dict=None, is_right_display=0</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -19,8 +19,6 @@ if context.getExternalProcessingState() not in ('converted', 'empty'):
message = 'Socket Error: %s' % (repr(e) or 'undefined.')
except Exception, e:
message = 'Problem: %s' % (repr(e) or 'undefined.')
except:
message = 'Problem: unknown'
# reach here, then exception was raised, message must be logged in workflow
# do not simply raise but rather change external processing state
# so user will see something is wrong
......
......@@ -11,8 +11,6 @@ except ConversionError, e:
message = 'Conversion Error: %s' % (str(e) or 'undefined.')
except Exception, e:
message = 'Problem: %s' % (repr(e) or 'undefined.')
except:
message = 'Problem: unknown'
# reach here, then exception was raised, message must be logged in workflow
# do not simply raise but rather change external processing state
......
# this script has an `file` argument
# pylint: disable=redefined-builtin
"""
This script is called when a file is uploaded to an object via ERP5 standard interface.
It does the following:
......@@ -9,9 +11,9 @@ Otherwise it just uploads the file, bumps up revision number and calls metadata
"""
from Products.ERP5Type.Log import log, WARNING
from Products.ERP5Type.Message import translateString
translate = context.Base_translateString
request = context.REQUEST
current_type = context.getPortalType()
file_name = file.filename
......
......@@ -3,4 +3,4 @@
only the group the user is directly assigned to (not the whole group hierarchy path).
"""
return context.ERP5Type_getSecurityCategoryFromAssignmentTree(base_category_list, user_name, object, portal_type, strict=True)
return context.ERP5Type_getSecurityCategoryFromAssignmentTree(base_category_list, user_name, obj, portal_type, strict=True)
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>base_category_list, user_name, object, portal_type</string> </value>
<value> <string>base_category_list, user_name, obj, portal_type</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>base_category_list, user_name, object, portal_type, strict=False, root=False</string> </value>
<value> <string>base_category_list, user_name, obj, portal_type, strict=False, root=False</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -5,7 +5,7 @@ of the document (e.g. in Memo type).
from Products.ERP5Type.Log import log
category_list = []
for ob in object.getDestinationValueList():
for ob in obj.getDestinationValueList():
category_dict = {}
for base_category in base_category_list:
if base_category == 'group':
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>base_category_list, user_name, object, portal_type</string> </value>
<value> <string>base_category_list, user_name, obj, portal_type</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -6,7 +6,7 @@ is addressed to (destination). Can be multiple destination persons.
category_list = []
# We look for valid assignments of destination users
for person_object in object.getDestinationValueList(portal_type='Person'):
for person_object in obj.getDestinationValueList(portal_type='Person'):
for assignment in person_object.contentValues(filter={'portal_type': 'Assignment'}):
if assignment.getValidationState() == 'open':
category_dict = {}
......@@ -18,7 +18,7 @@ for person_object in object.getDestinationValueList(portal_type='Person'):
if category_value not in (None, ''):
category_dict[base_category] = category_value
else:
raise RuntimeError, "Error: '%s' property is required in order to update person security group" % (base_category)
raise RuntimeError("Error: '%s' property is required in order to update person security group" % (base_category))
category_list.append(category_dict)
return category_list
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>base_category_list, user_name, object, portal_type</string> </value>
<value> <string>base_category_list, user_name, obj, portal_type</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -8,10 +8,8 @@ Person, just take from the object.
category_list = []
person_object = object
# We look for valid assignments of this user
for assignment in person_object.contentValues(filter={'portal_type': 'Assignment'}):
for assignment in obj.contentValues(filter={'portal_type': 'Assignment'}):
if assignment.getValidationState() == 'open':
category_dict = {}
for base_category in base_category_list:
......@@ -22,7 +20,7 @@ for assignment in person_object.contentValues(filter={'portal_type': 'Assignment
if category_value not in (None, ''):
category_dict[base_category] = category_value
else:
raise RuntimeError, "Error: '%s' property is required in order to update person security group" % (base_category)
raise RuntimeError("Error: '%s' property is required in order to update person security group" % (base_category))
category_list.append(category_dict)
return category_list
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>base_category_list, user_name, object, portal_type</string> </value>
<value> <string>base_category_list, user_name, obj, portal_type</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>base_category_list, user_name, object, portal_type</string> </value>
<value> <string>base_category_list, user_name, obj, portal_type</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -6,4 +6,4 @@ in the certain organisation - for this, all we need is the first part
of the group category.
"""
return context.ERP5Type_getSecurityCategoryFromAssignmentTree(base_category_list, user_name, object, portal_type, strict=True, root=True)
return context.ERP5Type_getSecurityCategoryFromAssignmentTree(base_category_list, user_name, obj, portal_type, strict=True, root=True)
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>base_category_list, user_name, object, portal_type</string> </value>
<value> <string>base_category_list, user_name, obj, portal_type</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -4,5 +4,11 @@ if brain.getValidationState() == 'embedded':
reference = brain.getId()
else:
reference = brain.getReference()
format = context.getPortalObject().portal_preferences.getPreferredImageFormat()
return unicode("javascript:SelectFile('%s?format=%s')" % (reference.replace("'", "\\'"), format), 'utf-8')
return unicode(
"javascript:SelectFile('%s?format=%s')" % (
reference.replace("'", "\\'"),
context.getPortalObject().portal_preferences.getPreferredImageFormat()
),
'utf-8',
)
# this script has an `format` argument
# pylint: disable=redefined-builtin
if format in ('svg',):
image_pixels = context.getHeight()* context.getWidth()
max_pixels = 128*128 # default thumbnail size
......
# this script has an `format` argument
# pylint: disable=redefined-builtin
"""
Convert Image (context) to a desired format and return as a binary `filename` file.
Requires format and desired filename (adds extension if missing).
......
# this script has an `format` argument
# pylint: disable=redefined-builtin
"""
Convert OOoDocument (context) to a desired format and return as a binary `filename` file.
Requires format and desired filename (adds extension if missing).
......
# this script has an `format` argument
# pylint: disable=redefined-builtin
from Products.ERP5.Document.Document import VALID_IMAGE_FORMAT_LIST
if format in VALID_IMAGE_FORMAT_LIST:
......
content_information = context.getContentInformation()
number_of_pages = int(content_information.get('Pages', 1))
max = number_of_pages - 1
max_ = number_of_pages - 1
selection_index = int(selection_index)
if selection_index > max:
return max
elif -max > selection_index:
if selection_index > max_:
return max_
elif -max_ > selection_index:
return 0
elif selection_index < 0:
return max + selection_index + 1
return max_ + selection_index + 1
else:
return selection_index
message = state_change.kwargs['reply_body']
subject = state_change.kwargs['reply_subject']
recipient = state_change.kwargs['reply_to']
object = state_change['object']
event = state_change['object']
state_change['object'].MailHost.send(message, mto=recipient,
mfrom=object.portal_preferences.getPreferredEventSenderEmail(),
event.MailHost.send(
message,
mto=recipient,
mfrom=event.portal_preferences.getPreferredEventSenderEmail(),
subject=subject)
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change, validation_state=[\'published\', \'published_alive\', \'released\', \'released_alive\', \'shared\', \'shared_alive\'], now=None</string> </value>
<value> <string>state_change, validation_state=(\'published\', \'published_alive\', \'released\', \'released_alive\', \'shared\', \'shared_alive\'), now=None</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
......
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