Commit d9cbe026 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

pylint suggested refactorings

--HG--
branch : stable
parent 8f63691ccb7f
......@@ -101,7 +101,7 @@ def generate_schema_pot(w, cubedir=None):
# set_schema triggers objects registrations
vreg.set_schema(schema)
w(DEFAULT_POT_HEAD)
_generate_schema_pot(w, vreg, schema, libconfig=libconfig, cube=cube)
_generate_schema_pot(w, vreg, schema, libconfig=libconfig)
def _generate_schema_pot(w, vreg, schema, libconfig=None):
......@@ -213,7 +213,7 @@ def _generate_schema_pot(w, vreg, schema, libconfig=None):
add_msg(w, objid)
def _iter_vreg_objids(vreg, done, prefix=None):
def _iter_vreg_objids(vreg, done):
for reg, objdict in vreg.items():
for objects in objdict.values():
for obj in objects:
......
......@@ -419,7 +419,7 @@ class SourceDbCWRelationAdd(SourceDbCWAttributeAdd):
rdef = self.init_rdef(composite=entity.composite)
schema = session.vreg.schema
rtype = rdef.name
rschema = session.vreg.schema.rschema(rtype)
rschema = schema.rschema(rtype)
# this have to be done before permissions setting
if rschema.inlined:
# need to add a column if the relation is inlined and if this is the
......@@ -441,15 +441,15 @@ class SourceDbCWRelationAdd(SourceDbCWAttributeAdd):
if not (rschema.subjects() or
rtype in session.transaction_data.get('createdtables', ())):
try:
rschema = session.vreg.schema.rschema(rtype)
rschema = schema.rschema(rtype)
tablesql = rschema2sql(rschema)
except KeyError:
# fake we add it to the schema now to get a correctly
# initialized schema but remove it before doing anything
# more dangerous...
rschema = session.vreg.schema.add_relation_type(rdef)
rschema = schema.add_relation_type(rdef)
tablesql = rschema2sql(rschema)
session.vreg.schema.del_relation_type(rtype)
schema.del_relation_type(rtype)
# create the necessary table
for sql in tablesql.split(';'):
if sql.strip():
......
......@@ -1027,7 +1027,7 @@ class MSPlanner(SSPlanner):
plan.preprocess(rqlst)
ppis = [PartPlanInformation(plan, select, self.rqlhelper)
for select in rqlst.children]
steps = self._union_plan(plan, rqlst, ppis)
steps = self._union_plan(plan, ppis)
if server.DEBUG & server.DBG_MS:
from pprint import pprint
for step in plan.steps:
......@@ -1045,7 +1045,7 @@ class MSPlanner(SSPlanner):
for sppi in sppis:
if sppi.needsplit or sppi.part_sources != ppi.part_sources:
temptable = 'T%s' % make_uid(id(subquery))
sstep = self._union_plan(plan, subquery.query, sppis, temptable)[0]
sstep = self._union_plan(plan, sppis, temptable)[0]
break
else:
sstep = None
......@@ -1056,7 +1056,7 @@ class MSPlanner(SSPlanner):
ppi.plan.add_step(sstep)
return inputmap
def _union_plan(self, plan, union, ppis, temptable=None):
def _union_plan(self, plan, ppis, temptable=None):
tosplit, cango, allsources = [], {}, set()
for planinfo in ppis:
if planinfo.needsplit:
......
......@@ -26,7 +26,7 @@ from cubicweb.server.ssplanner import add_types_restriction
READ_ONLY_RTYPES = set(('eid', 'has_text', 'is', 'is_instance_of', 'identity'))
def empty_rset(session, rql, args, rqlst=None):
def empty_rset(rql, args, rqlst=None):
"""build an empty result set object"""
return ResultSet([], rql, args, rqlst=rqlst)
......@@ -612,7 +612,7 @@ class QuerierHelper(object):
except UnknownEid:
# we want queries such as "Any X WHERE X eid 9999"
# return an empty result instead of raising UnknownEid
return empty_rset(session, rql, args)
return empty_rset(rql, args)
cachekey.append(etype)
# ensure eid is correctly typed in args
args[key] = typed_eid(args[key])
......@@ -630,7 +630,7 @@ class QuerierHelper(object):
except UnknownEid:
# we want queries such as "Any X WHERE X eid 9999"
# return an empty result instead of raising UnknownEid
return empty_rset(session, rql, args, rqlst)
return empty_rset(rql, args, rqlst)
self._rql_cache[cachekey] = rqlst
orig_rqlst = rqlst
if not rqlst.TYPE == 'select':
......
......@@ -294,7 +294,7 @@ def rschema_relations_values(rschema):
relations = ['X %s %%(%s)s' % (attr, attr) for attr in sorted(values)]
return relations, values
def _rdef_values(rschema, objtype, props):
def _rdef_values(objtype, props):
amap = {'order': 'ordernum'}
values = {}
for prop, default in schemamod.RelationDefinitionSchema.rproperty_defs(objtype).iteritems():
......@@ -310,13 +310,13 @@ def _rdef_values(rschema, objtype, props):
values[amap.get(prop, prop)] = value
return values
def nfrdef_relations_values(rschema, objtype, props):
values = _rdef_values(rschema, objtype, props)
def nfrdef_relations_values(objtype, props):
values = _rdef_values(objtype, props)
relations = ['X %s %%(%s)s' % (attr, attr) for attr in sorted(values)]
return relations, values
def frdef_relations_values(rschema, objtype, props):
values = _rdef_values(rschema, objtype, props)
def frdef_relations_values(objtype, props):
values = _rdef_values(objtype, props)
default = values['default']
del values['default']
if default is not None:
......@@ -429,7 +429,7 @@ _LOCATE_RDEF_RQL0 = 'X relation_type ER,X from_entity SE,X to_entity OE'
_LOCATE_RDEF_RQL1 = 'SE name %(se)s,ER name %(rt)s,OE name %(oe)s'
def frdef2rql(rschema, subjtype, objtype, props):
relations, values = frdef_relations_values(rschema, objtype, props)
relations, values = frdef_relations_values(objtype, props)
relations.append(_LOCATE_RDEF_RQL0)
values.update({'se': str(subjtype), 'rt': str(rschema), 'oe': str(objtype)})
yield 'INSERT CWAttribute X: %s WHERE %s' % (','.join(relations), _LOCATE_RDEF_RQL1), values
......@@ -437,7 +437,7 @@ def frdef2rql(rschema, subjtype, objtype, props):
yield rql + ', EDEF is CWAttribute', values
def nfrdef2rql(rschema, subjtype, objtype, props):
relations, values = nfrdef_relations_values(rschema, objtype, props)
relations, values = nfrdef_relations_values(objtype, props)
relations.append(_LOCATE_RDEF_RQL0)
values.update({'se': str(subjtype), 'rt': str(rschema), 'oe': str(objtype)})
yield 'INSERT CWRelation X: %s WHERE %s' % (','.join(relations), _LOCATE_RDEF_RQL1), values
......@@ -504,14 +504,14 @@ def updaterdef2rql(rschema, subjtype=None, objtype=None, props=None):
return __rdef2rql(genmap, rschema, subjtype, objtype, props)
def updatefrdef2rql(rschema, subjtype, objtype, props):
relations, values = frdef_relations_values(rschema, objtype, props)
relations, values = frdef_relations_values(objtype, props)
values.update({'se': subjtype, 'rt': str(rschema), 'oe': objtype})
yield 'SET %s WHERE %s, %s, X is CWAttribute' % (','.join(relations),
_LOCATE_RDEF_RQL0,
_LOCATE_RDEF_RQL1), values
def updatenfrdef2rql(rschema, subjtype, objtype, props):
relations, values = nfrdef_relations_values(rschema, objtype, props)
relations, values = nfrdef_relations_values(objtype, props)
values.update({'se': subjtype, 'rt': str(rschema), 'oe': objtype})
yield 'SET %s WHERE %s, %s, X is CWRelation' % (','.join(relations),
_LOCATE_RDEF_RQL0,
......
......@@ -38,7 +38,7 @@ def pil_captcha(text, fontfile, fontsize):
draw = ImageDraw.Draw(img)
# draw 100 random colored boxes on the background
x, y = img.size
for num in range(100):
for num in xrange(100):
draw.rectangle((randint(0, x), randint(0, y),
randint(0, x), randint(0, y)),
fill=randint(0, 0xffffff))
......
......@@ -136,11 +136,11 @@ class _CalendarView(EntityView):
end = last_day(next_month(day, shift))
return begin, end
def _build_ampm_cells(self, daynum, events):
def _build_ampm_cells(self, events):
"""create a view without any hourly details.
:param daynum: day of the built cell
:param events: dictionnary with all events classified by hours"""
:param events: dictionnary with all events classified by hours
"""
# split events according am/pm
am_events = [event for e_time, e_list in events.iteritems()
if 0 <= e_time.hour < 12
......@@ -317,7 +317,7 @@ class AMPMYearCalendarView(YearCalendarView):
day = first_day + timedelta(daynum)
events = schedule.get(day)
if events:
current_row.append((AMPM_DAY % (daynum+1),) + self._build_ampm_cells(daynum, events))
current_row.append((AMPM_DAY % (daynum+1),) + self._build_ampm_cells(events))
else:
current_row.append((AMPM_DAY % (daynum+1),
AMPM_EMPTY % ("amCell", "am"),
......@@ -386,7 +386,7 @@ class AMPMSemesterCalendarView(SemesterCalendarView):
def format_day_events(self, day, events):
if events:
self.w(u'\n'.join(self._build_ampm_cells(day, events)))
self.w(u'\n'.join(self._build_ampm_cells(events)))
else:
self.w(u'%s %s'% (AMPM_EMPTY % ("amCell", "am"),
AMPM_EMPTY % ("pmCell", "pm")))
......@@ -408,7 +408,7 @@ class AMPMMonthCalendarView(MonthCalendarView):
day = first_day + timedelta(daynum)
events = schedule.get(day)
if events:
current_row.append((AMPM_DAY % (daynum+1),) + self._build_ampm_cells(daynum, events))
current_row.append((AMPM_DAY % (daynum+1),) + self._build_ampm_cells(events))
else:
current_row.append((AMPM_DAY % (daynum+1),
AMPM_EMPTY % ("amCell", "am"),
......
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