Browse Source

PEP8/Pylint on lefactory.py

Roland Haroutiounian 9 years ago
parent
commit
a904ac0a09
1 changed files with 38 additions and 37 deletions
  1. 38
    37
      leobject/lefactory.py

+ 38
- 37
leobject/lefactory.py View File

@@ -6,23 +6,25 @@ import EditorialModel
6 6
 from EditorialModel.model import Model
7 7
 from EditorialModel.fieldtypes.generic import GenericFieldType
8 8
 
9
+
9 10
 ## @brief This class is designed to generated the leobject API given an EditorialModel.model
10 11
 # @note Contains only static methods
11 12
 #
12 13
 # The name is not good but i've no other ideas for the moment
13 14
 class LeFactory(object):
14
-    
15
+
15 16
     output_file = 'dyn.py'
16 17
     modname = None
17 18
 
18
-    def __init__(LeFactory):raise NotImplementedError("Not designed (yet?) to be implemented")
19
+    def __init__(self):
20
+        raise NotImplementedError("Not designed (yet?) to be implemented")
19 21
 
20 22
     ## @brief Return a LeObject child class given its name
21 23
     # @return a python class or False
22 24
     @staticmethod
23 25
     def leobj_from_name(name):
24 26
         if LeFactory.modname is None:
25
-            modname = 'leobject.'+LeFactory.output_file.split('.')[1]
27
+            modname = 'leobject.' + LeFactory.output_file.split('.')[1]
26 28
         else:
27 29
             modname = LeFactory.modname
28 30
         mod = importlib.import_module(modname)
@@ -31,7 +33,7 @@ class LeFactory(object):
31 33
         except AttributeError:
32 34
             return False
33 35
         return res
34
-    
36
+
35 37
     @classmethod
36 38
     def leobject(cls):
37 39
         return cls.leobj_from_name('LeObject')
@@ -42,15 +44,15 @@ class LeFactory(object):
42 44
     @staticmethod
43 45
     def name2classname(name):
44 46
         if not isinstance(name, str):
45
-            raise AttributeError("Argument name should be a str and not a %s"%type(name))
47
+            raise AttributeError("Argument name should be a str and not a %s" % type(name))
46 48
         return name.title()
47 49
 
48 50
     ## @brief Return a call to a FieldType constructor given an EmField
49 51
     # @param emfield EmField : An EmField
50 52
     # @return a string representing the python code to instanciate a EmFieldType
51 53
     @staticmethod
52
-    def fieldtype_construct_from_field(emfield):    
53
-        return '%s.EmFieldType(**%s)'%(
54
+    def fieldtype_construct_from_field(emfield):
55
+        return '%s.EmFieldType(**%s)' % (
54 56
             GenericFieldType.module_name(emfield.fieldtype),
55 57
             repr(emfield._fieldtype_args),
56 58
         )
@@ -74,18 +76,18 @@ class LeFactory(object):
74 76
             cls_fieldgroup[fieldgroup.name] = list()
75 77
             for field in fieldgroup.fields():
76 78
                 cls_fieldgroup[fieldgroup.name].append(field.name)
77
-        
79
+
78 80
         return """
79 81
 #Initialisation of {name} class attributes
80 82
 {name}._fieldtypes = {ftypes}
81 83
 {name}._linked_types = {ltypes}
82 84
 {name}._fieldgroups = {fgroups}
83 85
 """.format(
84
-    name = LeFactory.name2classname(emclass.name),
85
-    ftypes = "{"+(','.join([ '\n\t%s:%s'%(repr(f),v) for f,v in cls_fields.items()]))+"\n}",
86
-    ltypes = "{"+(','.join(cls_linked_types))+'}',
87
-    fgroups = repr(cls_fieldgroup)
88
-)
86
+            name=LeFactory.name2classname(emclass.name),
87
+            ftypes="{" + (','.join(['\n\t%s:%s' % (repr(f), v) for f, v in cls_fields.items()])) + "\n}",
88
+            ltypes="{" + (','.join(cls_linked_types)) + '}',
89
+            fgroups=repr(cls_fieldgroup)
90
+        )
89 91
 
90 92
     ## @brief Given a Model and an EmType instances generate python code for corresponding LeType
91 93
     # @param model Model : A Model instance
@@ -99,9 +101,9 @@ class LeFactory(object):
99 101
             type_fields.append(field.name)
100 102
 
101 103
         for nat, sup_l in emtype.superiors().items():
102
-            type_superiors.append('%s:[%s]'%(
104
+            type_superiors.append('%s:[%s]' % (
103 105
                 repr(nat),
104
-                ','.join([ LeFactory.name2classname(sup.name) for sup in sup_l])
106
+                ','.join([LeFactory.name2classname(sup.name) for sup in sup_l])
105 107
             ))
106 108
 
107 109
         return """
@@ -110,11 +112,11 @@ class LeFactory(object):
110 112
 {name}._superiors = {dsups}
111 113
 {name}._leclass = {leclass}
112 114
 """.format(
113
-    name = LeFactory.name2classname(emtype.name),
114
-    fields = repr(type_fields),
115
-    dsups = '{'+(','.join(type_superiors))+'}',
116
-    leclass = LeFactory.name2classname(emtype.em_class.name)
117
-)
115
+            name=LeFactory.name2classname(emtype.name),
116
+            fields=repr(type_fields),
117
+            dsups='{' + (','.join(type_superiors)) + '}',
118
+            leclass=LeFactory.name2classname(emtype.em_class.name)
119
+        )
118 120
 
119 121
     ## @brief Generate python code containing the LeObject API
120 122
     # @param backend_cls Backend : A model backend class
@@ -141,10 +143,10 @@ import EditorialModel.fieldtypes
141 143
         result += """
142 144
 import %s
143 145
 import %s
144
-"""%(backend_cls.__module__, datasource_cls.__module__)
146
+""" % (backend_cls.__module__, datasource_cls.__module__)
145 147
 
146 148
         #Generating the code for LeObject class
147
-        backend_constructor = '%s.%s(**%s)'%(backend_cls.__module__, backend_cls.__name__, repr(backend_args))
149
+        backend_constructor = '%s.%s(**%s)' % (backend_cls.__module__, backend_cls.__name__, repr(backend_args))
148 150
         leobj_me_uid = dict()
149 151
         for comp in model.components('EmType') + model.components('EmClass'):
150 152
             leobj_me_uid[comp.uid] = LeFactory.name2classname(comp.name)
@@ -157,35 +159,35 @@ class LeObject(_LeObject):
157 159
     _datasource = %s(**%s)
158 160
     _me_uid = %s
159 161
 
160
-"""%(backend_constructor, datasource_cls.__module__+'.'+datasource_cls.__name__, repr(datasource_args), repr(leobj_me_uid))
161
-        
162
+""" % (backend_constructor, datasource_cls.__module__ + '.' + datasource_cls.__name__, repr(datasource_args), repr(leobj_me_uid))
163
+
162 164
         emclass_l = model.components(EditorialModel.classes.EmClass)
163 165
         emtype_l = model.components(EditorialModel.types.EmType)
164 166
 
165 167
         #LeClass child classes definition
166 168
         for emclass in emclass_l:
167
-           result += """
169
+            result += """
168 170
 ## @brief EmClass {name} LeClass child class
169 171
 # @see leobject::leclass::LeClass
170 172
 class {name}(LeObject,LeClass):
171 173
     _class_id = {uid}
172 174
 """.format(
173
-    name = LeFactory.name2classname(emclass.name),
174
-    uid = emclass.uid
175
-)
175
+                name=LeFactory.name2classname(emclass.name),
176
+                uid=emclass.uid
177
+            )
176 178
         #LeType child classes definition
177 179
         for emtype in emtype_l:
178
-           result += """
180
+            result += """
179 181
 ## @brief EmType {name} LeType child class
180 182
 # @see leobject::letype::LeType
181 183
 class {name}(LeType, {leclass}):
182 184
     _type_id = {uid}
183 185
 """.format(
184
-    name = LeFactory.name2classname(emtype.name),
185
-    leclass = LeFactory.name2classname(emtype.em_class.name),
186
-    uid = emtype.uid
187
-)
188
-            
186
+                name=LeFactory.name2classname(emtype.name),
187
+                leclass=LeFactory.name2classname(emtype.em_class.name),
188
+                uid=emtype.uid
189
+            )
190
+
189 191
         #Set attributes of created LeClass and LeType child classes
190 192
         for emclass in emclass_l:
191 193
             result += LeFactory.emclass_pycode(model, emclass)
@@ -193,10 +195,9 @@ class {name}(LeType, {leclass}):
193 195
             result += LeFactory.emtype_pycode(model, emtype)
194 196
 
195 197
         #Populating LeObject._me_uid dict for a rapid fetch of LeType and LeClass given an EM uid
196
-        me_uid = { comp.uid:LeFactory.name2classname(comp.name) for comp in emclass_l + emtype_l }
198
+        me_uid = {comp.uid: LeFactory.name2classname(comp.name) for comp in emclass_l + emtype_l}
197 199
         result += """
198 200
 ## @brief Dict for getting LeClass and LeType child classes given an EM uid
199 201
 LeObject._me_uid = %s
200
-"""%"{"+(','.join([ '%s:%s'%(k,v) for k,v in me_uid.items()]))+"}"       
202
+""" % "{" + (','.join(['%s:%s' % (k, v) for k, v in me_uid.items()])) + "}"
201 203
         return result
202
-

Loading…
Cancel
Save