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

pylint style fixes

--HG--
branch : stable
parent ddf4f19eb07a
......@@ -17,8 +17,10 @@ from os import remove, listdir, system, pathsep
try:
from os import kill, getpgid
except ImportError:
def kill(*args): pass
def getpgid(): pass
def kill(*args):
"""win32 kill implementation"""
def getpgid():
"""win32 getpgid implementation"""
from os.path import exists, join, isfile, isdir, dirname, abspath
......@@ -166,7 +168,7 @@ class InstanceCommandFork(InstanceCommand):
# base commands ###############################################################
def version_strictly_lower(a,b):
def version_strictly_lower(a, b):
from logilab.common.changelog import Version
if a:
a = Version(a)
......@@ -228,11 +230,11 @@ class ConfigurationProblem(object):
if hasattr(info,'__depends_cubes__'):
use = info.__depends_cubes__
if not isinstance(use, dict):
use = dict((key,None) for key in use)
use = dict((key, None) for key in use)
self.warnings.append('cube %s should define __depends_cubes__ as a dict not a list')
else:
self.warnings.append('cube %s should define __depends_cubes__' % cube)
use = dict((key,None) for key in info.__use__)
use = dict((key, None) for key in info.__use__)
for name, constraint in use.items():
self.constraints.setdefault(name,set())
if constraint:
......
......@@ -200,7 +200,7 @@ class DBAPIRequest(RequestSessionBase):
except KeyError:
# this occurs usually during test execution
self._ = self.__ = unicode
self.pgettext = lambda x,y: y
self.pgettext = lambda x, y: y
self.debug('request default language: %s', self.lang)
def decorate_rset(self, rset):
......
......@@ -152,7 +152,7 @@ def tell(msg):
def confirm(question):
"""A confirm function that asks for yes/no/abort and exits on abort."""
answer = shellutils.ASK.ask(question, ('Y','n','abort'), 'Y')
answer = shellutils.ASK.ask(question, ('Y', 'n', 'abort'), 'Y')
if answer == 'abort':
sys.exit(1)
return answer == 'Y'
......@@ -275,11 +275,12 @@ def alldigits(txt):
def check_doubles(buckets):
"""Extract the keys that have more than one item in their bucket."""
return [(key, len(value)) for key,value in buckets.items() if len(value) > 1]
return [(k, len(v)) for k, v in buckets.items() if len(v) > 1]
def check_doubles_not_none(buckets):
"""Extract the keys that have more than one item in their bucket."""
return [(key, len(value)) for key,value in buckets.items() if key is not None and len(value) > 1]
return [(k, len(v)) for k, v in buckets.items()
if k is not None and len(v) > 1]
# object stores #################################################################
......@@ -430,12 +431,14 @@ class RQLObjectStore(ObjectStore):
return entity
def _put(self, type, item):
query = ('INSERT %s X: ' % type) + ', '.join(['X %s %%(%s)s' % (key,key) for key in item])
query = ('INSERT %s X: ' % type) + ', '.join('X %s %%(%s)s' % (k, k)
for k in item])
return self.rql(query, item)[0][0]
def relate(self, eid_from, rtype, eid_to):
# if reverse relation is found, eids are exchanged
eid_from, rtype, eid_to = super(RQLObjectStore, self).relate(eid_from, rtype, eid_to)
eid_from, rtype, eid_to = super(RQLObjectStore, self).relate(
eid_from, rtype, eid_to)
self.rql('SET X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % rtype,
{'x': int(eid_from), 'y': int(eid_to)}, ('x', 'y'))
......@@ -513,7 +516,7 @@ class CWImportController(object):
% (len(self.store.eids), len(self.store.types),
len(self.store.relations), nberrors))
if self.errors:
if self.askerror==2 or (self.askerror and confirm('Display errors ?')):
if self.askerror == 2 or (self.askerror and confirm('Display errors ?')):
from pprint import pformat
for errkey, error in self.errors.items():
self.tell("\n%s (%s): %d\n" % (error[0], errkey, len(error[1])))
......
......@@ -64,7 +64,7 @@ class ReportTransformer(XHTML2FOTransformer):
u'bottom': self.page_bmargin*cm,
u'left' : self.page_lmargin*cm,
u'right' : self.page_rmargin*cm })
pm.add_peripheral_region(u"end",self.hf_height)
pm.add_peripheral_region(u"end", self.hf_height)
dims = {}
dims[u"bottom"] = self.hf_height + 0.25
pm.set_main_region_margins(dims)
......@@ -82,41 +82,39 @@ class ReportTransformer(XHTML2FOTransformer):
props = { u"force-page-count": u"no-force",
u"initial-page-number": u"1",
u"format": u"1", }
self._output_properties(ps,props)
self._output_properties(ps, props)
sc = self.create_staticcontent(ps, u"end")
sc_bl = self.create_block(sc)
attrs = { u"hyphenate": u"false", }
attrs[u"font-size"] = u"%.1fpt" %(self.font_size*0.7)
attrs[u"font-size"] = u"%.1fpt" % (self.font_size * 0.7)
attrs[u"language"] = self.lang
attrs[u"text-align"] = u"center"
self._output_properties(sc_bl,attrs)
self._output_properties(sc_bl, attrs)
sc_bl.text = u"Page" + u" " # ### Should be localised!
pn = self.create_pagenumber(sc_bl)
pn.tail = u"/"
lpn = self.create_pagenumbercitation( sc_bl,
u"last-block-of-report-%d" % params[u"context_pos"]
)
self.create_pagenumbercitation(
sc_bl, u"last-block-of-report-%d" % params[u"context_pos"])
fl = self.create_flow(ps,u"body")
fl = self.create_flow(ps, u"body")
bl = self.create_block(fl)
# Sets on the highest block element the properties of the XHTML body
# element. These properties (at the least the inheritable ones) will
# be inherited by all the future FO elements.
bodies = list(self.in_tree.getiterator(QName(XHTML_NS,u"body")))
bodies = list(self.in_tree.getiterator(QName(XHTML_NS, u"body")))
if len(bodies) > 0:
attrs = self._extract_properties([bodies[0]])
else:
attrs = default_styles[u"body"].copy()
attrs[u"font-size"] = u"%.1fpt" %self.font_size
attrs[u"font-size"] = u"%.1fpt" % self.font_size
attrs[u"language"] = self.lang
self._output_properties(bl,attrs)
# Processes the report content
self._copy_text(in_elt,bl)
self._process_nodes(in_elt.getchildren(),bl)
self._copy_text(in_elt, bl)
self._process_nodes(in_elt.getchildren(), bl)
# Inserts an empty block at the end of the report in order to be able
# to compute the last page number of this report.
......@@ -130,7 +128,7 @@ class ReportTransformer(XHTML2FOTransformer):
"""
Visit function called when starting the process of the input tree.
"""
content = [ d for d in self.in_tree.getiterator(QName(XHTML_NS,u"div"))
content = [ d for d in self.in_tree.getiterator(QName(XHTML_NS, u"div"))
if d.get(u"id") == self.section ]
# Asks the process of the report elements with a specific visit
# function
......
......@@ -29,8 +29,8 @@ class NotificationHook(hook.Hook):
category = 'notification'
def select_view(self, vid, rset, row=0, col=0):
return self._cw.vreg['views'].select_or_none(vid, self._cw,
rset=rset, row=0, col=0)
return self._cw.vreg['views'].select_or_none(vid, self._cw, rset=rset,
row=row, col=col)
class StatusChangeHook(NotificationHook):
......
......@@ -26,8 +26,9 @@ class PreUpdateEntityHook(BFSSHook):
events = ('before_update_entity', )
def __call__(self):
for attr in ETYPE_ATTR_STORAGE.get(self.entity.__regid__, ()):
ETYPE_ATTR_STORAGE[self.entity.__regid__][attr].entity_updated(self.entity, attr)
etype = self.entity.__regid__
for attr in ETYPE_ATTR_STORAGE.get(etype, ()):
ETYPE_ATTR_STORAGE[etype][attr].entity_updated(self.entity, attr)
class PreDeleteEntityHook(BFSSHook):
""""""
......@@ -35,5 +36,6 @@ class PreDeleteEntityHook(BFSSHook):
events = ('before_delete_entity', )
def __call__(self):
for attr in ETYPE_ATTR_STORAGE.get(self.entity.__regid__, ()):
ETYPE_ATTR_STORAGE[self.entity.__regid__][attr].entity_deleted(self.entity, attr)
etype = self.entity.__regid__
for attr in ETYPE_ATTR_STORAGE.get(etype, ()):
ETYPE_ATTR_STORAGE[etype][attr].entity_deleted(self.entity, attr)
......@@ -85,6 +85,7 @@ def add_inline_relation_column(session, etype, rtype):
session.transaction_data.setdefault('createdattrs', []).append(
'%s.%s' % (etype, rtype))
def check_valid_changes(session, entity, ro_attrs=('name', 'final')):
errors = {}
# don't use getattr(entity, attr), we would get the modified value if any
......@@ -1137,20 +1138,22 @@ class UpdateFTIndexOp(hook.SingleLastOperation):
def postcommit_event(self):
session = self.session
source = session.repo.system_source
to_reindex = session.transaction_data.get('fti_update_etypes',())
self.info('%i etypes need full text indexed reindexation', len(to_reindex))
to_reindex = session.transaction_data.get('fti_update_etypes', ())
self.info('%i etypes need full text indexed reindexation',
len(to_reindex))
schema = self.session.repo.vreg.schema
for etype in to_reindex:
rset = session.execute('Any X WHERE X is %s' % etype)
self.info('Reindexing full text index for %i entity of type %s', len(rset), etype)
self.info('Reindexing full text index for %i entity of type %s',
len(rset), etype)
still_fti = list(schema[etype].indexable_attributes())
for entity in rset.entities():
try:
source.fti_unindex_entity(session, entity.eid)
for container in entity.fti_containers():
if still_fti or container is not entity:
session.repo.index_entity(session, container)
except Exception, ex:
source.fti_unindex_entity(session, entity.eid)
for container in entity.fti_containers():
if still_fti or container is not entity:
session.repo.index_entity(session, container)
except Exception:
self.critical('Error while updating Full Text Index for'
' entity %s', entity.eid, exc_info=True)
if len(to_reindex):
......
......@@ -193,7 +193,7 @@ class MigrationHelper(object):
if `retry` is true the r[etry] answer may return 2
"""
possibleanswers = ['y','n']
possibleanswers = ['y', 'n']
if abort:
possibleanswers.append('abort')
if shell:
......
......@@ -109,7 +109,10 @@ def remove_solutions(origsolutions, solutions, defined):
return newsolutions
class Unsupported(Exception): pass
class Unsupported(Exception):
"""raised when an rql expression can't be inserted in some rql query
because it create an unresolvable query (eg no solutions found)
"""
class RQLRewriter(object):
......@@ -440,9 +443,9 @@ class RQLRewriter(object):
while argname in self.kwargs:
argname = select.allocate_varname()
# insert "U eid %(u)s"
var = select.get_variable(self.u_varname)
select.add_constant_restriction(select.get_variable(self.u_varname),
'eid', unicode(argname), 'Substitute')
select.add_constant_restriction(
select.get_variable(self.u_varname),
'eid', unicode(argname), 'Substitute')
self.kwargs[argname] = self.session.user.eid
return self.u_varname
key = (self.current_expr, self.varmap, vname)
......
......@@ -155,7 +155,7 @@ class ServerMigrationHelper(MigrationHelper):
else:
bkup = tarfile.open(backupfile, 'w|gz')
for filename in os.listdir(tmpdir):
bkup.add(osp.join(tmpdir,filename), filename)
bkup.add(osp.join(tmpdir, filename), filename)
bkup.close()
# call hooks
repo.hm.call_hooks('server_backup', repo=repo, timestamp=timestamp)
......@@ -731,7 +731,7 @@ class ServerMigrationHelper(MigrationHelper):
if (rschema.rdef(subjschema, objschema).infered
or (instschema.has_relation(rschema) and
(subjschema, objschema) in instschema[rschema].rdefs)):
continue
continue
self.cmd_add_relation_definition(
subjschema.type, rschema.type, objschema.type)
if auto:
......
......@@ -271,7 +271,7 @@ class PartPlanInformation(object):
for source in self._sourcesterms:
print '-', source
for term, sols in self._sourcesterms[source].items():
print ' -', term, id(term), ':' ,sols
print ' -', term, id(term), ':', sols
def copy_solutions(self, solindices):
return [self._solutions[solidx].copy() for solidx in solindices]
......@@ -683,11 +683,11 @@ class PartPlanInformation(object):
# go to the next iteration directly!
continue
if not sourceterms:
try:
del self._sourcesterms[source]
except KeyError:
# XXX already cleaned
pass
try:
del self._sourcesterms[source]
except KeyError:
# XXX already cleaned
pass
# set of terms which should be additionaly selected when
# possible
needsel = set()
......
......@@ -87,7 +87,7 @@ class ConnectionsPool(object):
# implementation details of flying insert requires the system source
# first
yield self.source_cnxs['system'][0]
for uri, (source, cursor) in self.source_cnxs.items():
for uri, (source, cnx) in self.source_cnxs.items():
if uri == 'system':
continue
yield source
......
......@@ -130,7 +130,8 @@ def _annotate_select(annotator, rqlst):
class CantSelectPrincipal(Exception): pass
class CantSelectPrincipal(Exception):
"""raised when no 'principal' variable can be found"""
def _select_principal(sqlscope, relations, _sort=lambda x:x):
"""given a list of rqlst relations, select one which will be used to
......
......@@ -225,7 +225,7 @@ class Session(RequestSessionBase):
self.pgettext = pgettext
except KeyError:
self._ = self.__ = unicode
self.pgettext = lambda x,y: y
self.pgettext = lambda x, y: y
self.lang = language
def change_property(self, prop, value):
......
......@@ -62,7 +62,7 @@ class BytesFileSystemStorage(Storage):
else:
fpath = self.new_fs_path(entity, attr)
# bytes storage used to store file's path
entity[attr]= Binary(fpath)
entity[attr] = Binary(fpath)
file(fpath, 'w').write(value.getvalue())
AddFileOp(entity._cw, filepath=fpath)
# else entity[attr] is expected to be an already existant file path
......
#!/usr/bin/env python
"""
"""Generic Setup script, takes package info from __pkginfo__.py file
:organization: Logilab
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
......@@ -8,9 +8,6 @@
"""
# pylint: disable-msg=W0142,W0403,W0404,W0613,W0622,W0622,W0704,R0904,C0103,E0611
#
# Copyright (c) 2003-2010 LOGILAB S.A. (Paris, FRANCE).
# http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
......@@ -23,7 +20,6 @@
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" Generic Setup script, takes package info from __pkginfo__.py file """
import os
import sys
......
......@@ -82,7 +82,7 @@ def show_diffs(appl_file, ref_file, askconfirm=True):
if askconfirm:
print
print diffs
action = ASK.ask('Replace ?', ('N','y','q'), 'N')
action = ASK.ask('Replace ?', ('N', 'y', 'q'), 'N')
else:
action = 'y'
if action == 'y':
......
......@@ -280,7 +280,7 @@ class SimpleTableModel(object):
if value is None:
return u''
elif isinstance(value, int):
return u'%09d'%value
return u'%09d' % value
else:
return unicode(value)
......
......@@ -402,7 +402,7 @@ class JSonController(Controller):
@xhtmlize
def js_reledit_form(self):
args = dict((x,self._cw.form[x])
args = dict((x, self._cw.form[x])
for x in frozenset(('rtype', 'role', 'reload', 'landing_zone')))
entity = self._cw.entity_from_eid(int(self._cw.form['eid']))
# note: default is reserved in js land
......
......@@ -122,7 +122,7 @@ class RegistryView(StartupView):
self.w(u'<p>%s</p>\n' % ' - '.join('<a href="/_registry#%s">%s</a>'
% (key, key) for key in keys))
for key in keys:
self.w(u'<h2><a name="%s">%s</a></h2>' % (key,key))
self.w(u'<h2><a name="%s">%s</a></h2>' % (key, key))
items = self._cw.vreg[key].items()
if items:
self.w(u'<table><tbody>')
......
Supports Markdown
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