[entities] flake8 draft
authorDavid Douard <david.douard@logilab.fr>
Thu, 22 Dec 2016 11:59:42 +0100
changeset 1867 a3860aa1e1e0
parent 1866 48313facded8
child 1868 64d8949910f2
[entities] flake8
entities.py
--- a/entities.py	Tue Nov 22 10:44:19 2016 +0100
+++ b/entities.py	Thu Dec 22 11:59:42 2016 +0100
@@ -6,18 +6,14 @@
 :license: General Public License version 2 - http://www.gnu.org/licenses
 """
 
-__docformat__ = "restructuredtext en"
-
 from itertools import chain
 
 from logilab.common.decorators import cached
 from logilab.common.textutils import text_to_dict
 from logilab.common.tasksqueue import LOW
-from logilab.mtconverter import xml_escape
 
 from cubicweb import ValidationError
 from cubicweb.uilib import domid
-from cubicweb.entity import _marker
 from cubicweb.entities import AnyEntity, fetch_config
 from cubicweb.entities.adapters import IFTIndexableAdapter
 from cubicweb.predicates import has_related_entities, is_instance
@@ -30,13 +26,14 @@
 
 from cubes.narval.entities import Plan
 
+
 def _anchor_name(data):
     """escapes XML/HTML forbidden characters in attributes and PCDATA"""
-    return (data.replace('&', '').replace('<', '').replace('>','')
+    return (data.replace('&', '').replace('<', '').replace('>', '')
             .replace('"', '').replace("'", '').replace(' ', '_'))
 
 
-class ExecutionRSSMixin(object): # XXX move to an ui adapter
+class ExecutionRSSMixin(object):  # XXX move to an ui adapter
 
     RSS_LIMIT = 20
 
@@ -101,7 +98,7 @@
     def refined_relation(self, attr):
         return self.owner_and_value(attr, False)[1]
 
-    # apycot bot helpers #######################################################
+    # apycot bot helpers ######################################################
 
     @property
     def my_apycot_configuration(self):
@@ -118,12 +115,13 @@
         return self._regroup_dict('my_apycot_process_environment')
 
 
-# Project environment ##########################################################
+# Project environment #########################################################
 
 class ProjectEnvironment(RefinementMixIn, ExecutionRSSMixin, AnyEntity):
     __regid__ = 'ProjectEnvironment'
 
-    fetch_attrs, cw_fetch_order = fetch_config(['name', 'check_config', 'check_environment'])
+    fetch_attrs, cw_fetch_order = fetch_config(
+        ['name', 'check_config', 'check_environment'])
 
     # rss related methods #####################################################
 
@@ -182,7 +180,8 @@
     def reverse_dependencies(self):
         result = []
         if self.project:
-            for dp in chain(self.project.reverse_uses, self.project.reverse_recommends):
+            for dp in chain(self.project.reverse_uses,
+                            self.project.reverse_recommends):
                 for dpe in getattr(dp, 'has_apycot_environment', ()):
                     result.append(dpe)
         return result
@@ -197,15 +196,16 @@
     def iter_configurations(self, startmode):
         for parent, tc in self.all_configurations().itervalues():
             if (tc.cw_adapt_to('IWorkflowable').state == 'activated'
-                and tc.computed_start_mode == startmode):
+                    and tc.computed_start_mode == startmode):
                 yield tc
 
     def configuration_by_name(self, name, checkstatus=True):
         for parent in reversed(self.config_parents()):
             for tc in parent.reverse_use_environment:
                 if tc.name == name:
-                    if not checkstatus or \
-                           tc.cw_adapt_to('IWorkflowable').state == 'activated':
+                    if (not checkstatus or
+                            tc.cw_adapt_to(
+                                'IWorkflowable').state == 'activated'):
                         return tc
                     return
 
@@ -224,21 +224,25 @@
 
         def serialize(self):
             entity = self.entity
-            data = super(ProjectEnvironmentSerializableAdapter, self).serialize()
-            data['apycot_process_environment'] = entity.apycot_process_environment()
+            data = super(ProjectEnvironmentSerializableAdapter,
+                         self).serialize()
+            pe = entity.apycot_process_environment()
+            data['apycot_process_environment'] = pe
             if entity.repository:
-                data['repository'] = entity.repository.cw_adapt_to('ISerializable').serialize()
+                data['repository'] = entity.repository.cw_adapt_to(
+                    'ISerializable').serialize()
             data['apycot_configuration'] = entity.apycot_configuration()
             return data
 
 
-# Test configuration ###########################################################
+# Test configuration ##########################################################
 
 class TestConfig(RefinementMixIn, ExecutionRSSMixin, AnyEntity):
     __regid__ = 'TestConfig'
 
-    fetch_attrs, cw_fetch_order = fetch_config(['name', 'label', 'check_config',
-                                             'check_environment'])
+    fetch_attrs, cw_fetch_order = fetch_config(
+        ['name', 'label', 'check_config',
+         'check_environment'])
 
     def dc_title(self):
         return self.label or self.name
@@ -263,7 +267,7 @@
                 '      TR tr_count 0,'
                 '      TR creation_date SD,'
                 '      TC eid %i'
-               % (self.RSS_LIMIT, self.eid))
+                % (self.RSS_LIMIT, self.eid))
 
     # cube specific logic #####################################################
 
@@ -312,14 +316,15 @@
     def start(self, pe, branch=None, start_rev_deps=None, priority=LOW,
               archive=False, check_duplicate=True):
         if self.recipe is None:
-            raise ValidationError(self.eid, {None: 'configuration has no recipe'})
+            raise ValidationError(self.eid,
+                                  {None: 'configuration has no recipe'})
         # don't overwrite branch hardcoded on the environment
         pecfg = pe.apycot_configuration()
         if pecfg.get('branch'):
             # make sure our configuration is consistent
             assert branch is None or branch == pecfg['branch']
             branch = pecfg['branch']
-        elif branch is None: # XXX shouldn't occurs?
+        elif branch is None:  # XXX shouldn't occurs?
             branch = self.apycot_configuration().get('branch')
         if branch is None:
             branch = pe.repository.default_branch()
@@ -330,7 +335,7 @@
             {'branch': branch, 'pe': pe.eid, 'tc': self.eid})
         if duplicate_rset:
             assert len(duplicate_rset) == 1
-            texec = duplicate_rset.get_entity(0,0)
+            texec = duplicate_rset.get_entity(0, 0)
             # if priority > duplicate.priority:
             #     duplicate.set_attributes(priority=priority)
             # if archive:
@@ -345,7 +350,8 @@
             texec = self._cw.create_entity(
                 'TestExecution', priority=priority, keep_archive=archive,
                 branch=branch, using_environment=pe, using_config=self)
-        if start_rev_deps or (start_rev_deps is None and self.start_reverse_dependencies):
+        if start_rev_deps or (start_rev_deps is None and
+                              self.start_reverse_dependencies):
             for dpe in pe.reverse_dependencies():
                 tc = dpe.configuration_by_name(self.name)
                 if tc is not None:
@@ -365,7 +371,8 @@
 
         def serialize(self):
             data = super(TestConfigSerializableAdapter, self).serialize()
-            data['apycot_process_environment'] = self.entity.apycot_process_environment()
+            pe = self.entity.apycot_process_environment()
+            data['apycot_process_environment'] = pe
             return data
 
 
@@ -406,31 +413,35 @@
             'branch': self.branch,
             }
         if vid == 'rss':
-            return self._cw._('Subscribe to all executions of %(conf)s for branch %(branch)s') % data
+            return self._cw._('Subscribe to all executions of %(conf)s '
+                              'for branch %(branch)s') % data
         elif vid == 'changes_rss':
-            return self._cw._('Subscribe to all changes of %(conf)s for branch %(branch)s') % data
+            return self._cw._('Subscribe to all changes of %(conf)s '
+                              'for branch %(branch)s') % data
         else:
             assert False, 'unknow vid %s' % vid
 
     def rss_rql(self, vid='rss'):
         if self.branch is None:
-            return 'TestExecution TE ORDERBY is_null(SD) DESC, SD DESC LIMIT %i '\
-                   'WHERE TE using_config TC,'\
-                   '      TR? wf_info_for TE,'\
-                   '      TR tr_count 0,'\
-                   '      TR creation_date SD,'\
-                   '      TC eid %i,'\
-                   '      TE branch NULL'\
-                   % (self.RSS_LIMIT, self.configuration.eid)
+            return ('TestExecution TE'
+                    '  ORDERBY is_null(SD) DESC, SD DESC LIMIT %i '
+                    'WHERE TE using_config TC,'
+                    '      TR? wf_info_for TE,'
+                    '      TR tr_count 0,'
+                    '      TR creation_date SD,'
+                    '      TC eid %i,'
+                    '      TE branch NULL'
+                    % (self.RSS_LIMIT, self.configuration.eid))
         else:
-            return 'TestExecution TE ORDERBY is_null(SD) DESC, SD DESC LIMIT %i '\
-                   'WHERE TE using_config TC,'\
-                   '      TR? wf_info_for TE,'\
-                   '      TR tr_count 0,'\
-                   '      TR creation_date SD,'\
-                   '      TC eid %i,'\
-                   '      TE branch "%s"'\
-                   % (self.RSS_LIMIT, self.configuration.eid, self.branch)
+            return ('TestExecution TE'
+                    '  ORDERBY is_null(SD) DESC, SD DESC LIMIT %i '
+                    'WHERE TE using_config TC,'
+                    '      TR? wf_info_for TE,'
+                    '      TR tr_count 0,'
+                    '      TR creation_date SD,'
+                    '      TC eid %i,'
+                    '      TE branch "%s"'
+                    % (self.RSS_LIMIT, self.configuration.eid, self.branch))
 
     # cube specific logic #####################################################
 
@@ -509,9 +520,11 @@
             entity = self.entity
             data = super(TestExecutionSerializableAdapter, self).serialize()
             if entity.environment:
-                data['environment'] = entity.environment.cw_adapt_to('ISerializable').serialize()
+                data['environment'] = entity.environment.cw_adapt_to(
+                    'ISerializable').serialize()
             if entity.configuration:
-                data['configuration'] = entity.configuration.cw_adapt_to('ISerializable').serialize()
+                data['configuration'] = entity.configuration.cw_adapt_to(
+                    'ISerializable').serialize()
             return data
 
 
@@ -556,9 +569,10 @@
     def to_environment(self):
         return self.on_environment[0]
 
+
 class NoIndexLogFileIndexableAdapter(IFTIndexableAdapter):
-    __select__ = is_instance('File') & has_related_entities('log_file', 'object')
+    __select__ = (is_instance('File')
+                  & has_related_entities('log_file', 'object'))
 
     def get_words(self):
         return {}
-