Commit e6f9e8ba authored by sylvain.thenault@logilab.fr's avatar sylvain.thenault@logilab.fr
Browse files

make pylint happy, fix some bugs on the way

--HG--
branch : tls-sprint
parent 00eb43688a57
......@@ -126,7 +126,7 @@ class CubicWebRegistry(VRegistry):
for cls in classes:
for iface in cls.__implements__:
interfaces.update(iface.__mro__)
interfaces.update(expand_parent_classes(cls.__mro__))
interfaces.update(cls.__mro__)
for obj, ifaces in self._needs_iface.items():
ifaces = frozenset(isinstance(iface, basestring)
and iface in self.schema
......
......@@ -61,6 +61,7 @@ def unprotected_entities(app_schema, strict=False):
def ignore_relations(*relations):
global SYSTEM_RELATIONS
SYSTEM_RELATIONS += relations
class TestEnvironment(object):
......@@ -83,7 +84,6 @@ class TestEnvironment(object):
self.restore_database()
if verbose:
print "init done"
login = source['db-user']
config.repository = lambda x=None: self.repo
self.app = CubicWebPublisher(config, vreg=vreg)
self.verbose = verbose
......
......@@ -16,10 +16,11 @@ from os.path import join, exists, abspath, basename, normpath, split, isdir
from logilab.common import STD_BLACKLIST
from logilab.common.modutils import get_module_files
from logilab.common.textutils import get_csv
from logilab.common.clcommands import register_commands
from cubicweb import CW_SOFTWARE_ROOT as BASEDIR, BadCommandUsage
from cubicweb.__pkginfo__ import version as cubicwebversion
from cubicweb.toolsutils import Command, register_commands, confirm, copy_skeleton
from cubicweb.toolsutils import Command, confirm, copy_skeleton
from cubicweb.web.webconfig import WebConfiguration
from cubicweb.server.serverconfig import ServerConfiguration
......
......@@ -36,12 +36,9 @@ class LivetestResource(CubicWebRootResource):
"""Indicate which resource to use to process down the URL's path"""
if len(segments) and segments[0] == 'data':
# Anything in data/ is treated as static files
dirlist = [self.data_dir, join(dirname(cubicweb.web.__file__), 'data')]
for alternative in dirlist:
filepath = join(alternative, *segments[1:])
if exists(filepath):
self.info('publish static file: %s', '/'.join(segments))
return static.File(filepath), ()
datadir = self.config.locate_resource(segments[1])
if datadir:
return static.File(str(datadir), segments[1:])
# Otherwise we use this single resource
return self, ()
......
......@@ -256,7 +256,7 @@ try:
from cubicweb.server.msplanner import PartPlanInformation
except ImportError:
class PartPlanInformation(object):
def merge_input_maps(*args):
def merge_input_maps(self, *args):
pass
def _choose_var(self, sourcevars):
pass
......
......@@ -226,12 +226,13 @@ class Entity(AppRsetObject, dict):
__registry__ = 'etypes'
__select__ = yes()
widgets = {}
rtags = None
id = None
e_schema = None
eid = None
rest_attr = None
fetch_attrs = None
skip_copy_for = ()
@classmethod
def registered(cls, registry):
"""build class using descriptor at registration time"""
......
......@@ -442,7 +442,6 @@ def textdomain(domain=None):
def bindtextdomain(domain, localedir=None):
global _localedirs
if localedir is not None:
_localedirs[domain] = localedir
return _localedirs.get(domain, _default_localedir)
......
......@@ -10,10 +10,9 @@ from os.path import exists, join, split, basename, normpath, abspath
from logilab.common.clcommands import register_commands
from cubicweb import BadCommandUsage
from cubicweb import CW_SOFTWARE_ROOT
from cubicweb.toolsutils import (Command, register_commands, copy_skeleton,
create_dir, create_symlink)
from cubicweb import CW_SOFTWARE_ROOT, BadCommandUsage
from cubicweb.toolsutils import (Command, copy_skeleton, create_symlink,
create_dir)
from cubicweb.cwconfig import CubicWebConfiguration
from logilab import common as lgc
......
......@@ -17,8 +17,8 @@ try:
from cubicweb.goa import db, do_monkey_patch
import_appengine_failed = None
except ImportError, exc:
raise
class db:
# XXX necessary ?
class db:
class Model:
pass
class DummyProperty:
......
"""RQL client for cubicweb, connecting to application using pyro
:organization: Logilab
:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
"""
__docformat__ = "restructuredtext en"
......@@ -132,11 +132,11 @@ class RQLCli(CLIHelper):
def do_description(self):
"""display the description of the latest result"""
if self.cursor.description is None:
if self.rset.description is None:
print _('No query has been executed')
else:
print '\n'.join([', '.join(line_desc)
for line_desc in self.cursor.description])
for line_desc in self.rset.description])
help_do_description = ('description', "description", _(do_description.__doc__))
......@@ -200,7 +200,7 @@ class RQLCli(CLIHelper):
self._previous_lines = []
# search results
try:
self.cursor.execute(query)
self.rset = rset = self.cursor.execute(query)
except:
if self.autocommit:
self.cnx.rollback()
......@@ -208,18 +208,18 @@ class RQLCli(CLIHelper):
else:
if self.autocommit:
self.cnx.commit()
self.handle_result(self.cursor.fetchall(), self.cursor.description)
self.handle_result(rset)
def handle_result(self, result, description):
def handle_result(self, rset):
"""display query results if any"""
if not result:
if not rset:
print _('No result matching query')
else:
from logilab.common.ureports import Table
children = flatten(izip2(description, result), to_string)
layout = Table(cols=2*len(result[0]), children=children, cheaders=1)
children = flatten(izip2(rset.description, rset.rows), to_string)
layout = Table(cols=2*len(rset.rows[0]), children=children, cheaders=1)
self._format(self.writer, layout)
print _('%s results matching query') % len(result)
print _('%s results matching query') % rset.rowcount
def display_schema(self, schema):
"""display a schema object"""
......
......@@ -22,6 +22,7 @@ from yams.reader import (CONSTRAINTS, RelationFileReader, PyFileReader,
from rql import parse, nodes, RQLSyntaxError, TypeResolverException
from cubicweb import ETYPE_NAME_MAP, ValidationError, Unauthorized
from cubicweb import set_log_methods
# XXX <3.2 bw compat
from yams import schema
......@@ -981,8 +982,6 @@ format_constraint = FormatConstraint()
CONSTRAINTS['FormatConstraint'] = FormatConstraint
PyFileReader.context['format_constraint'] = format_constraint
from logging import getLogger
from cubicweb import set_log_methods
set_log_methods(CubicWebSchemaLoader, getLogger('cubicweb.schemaloader'))
set_log_methods(BootstrapSchemaLoader, getLogger('cubicweb.bootstrapschemaloader'))
set_log_methods(RQLExpression, getLogger('cubicweb.schema'))
......
......@@ -218,10 +218,13 @@ class EntitySelector(EClassSelector):
# very basic selectors ########################################################
@objectify_selector
def yes(cls, *args, **kwargs):
"""accept everything"""
return 1
class yes(Selector):
"""return arbitrary score"""
def __init__(self, score=1):
self.score = score
def __call__(self, *args, **kwargs):
return self.score
@objectify_selector
@lltrace
......@@ -908,7 +911,7 @@ class score_entity(EntitySelector):
return a score >= 0
"""
def __init__(self, scorefunc, once_is_enough=False):
super(EntitySelector, self).__init__(once_is_enough)
super(score_entity, self).__init__(once_is_enough)
self.score_entity = scorefunc
......
......@@ -394,11 +394,13 @@ class Repository(object):
return euser
def _build_user(self, session, eid):
"""return a EUser entity for user with the given eid"""
cls = self.vreg.etype_class('EUser')
rql = cls.fetch_rql(session.user, ['X eid %(x)s'])
rset = session.execute(rql, {'x': eid}, 'x')
assert len(rset) == 1, rset
euser = rset.get_entity(0, 0)
# pylint: disable-msg=W0104
# prefetch / cache euser's groups and properties. This is especially
# useful for internal sessions to avoid security insertions
euser.groups
......
......@@ -315,7 +315,7 @@ class RQLRewriter(object):
return cmp_
def visit_mathexpression(self, mexpr):
cmp_ = nodes.MathExpression(cmp.operator)
cmp_ = nodes.MathExpression(mexpr.operator)
for c in cmp.children:
cmp_.append(c.accept(self))
return cmp_
......
......@@ -100,6 +100,7 @@ class UpdateSchemaOp(SingleLastOperation):
class DropTableOp(PreCommitOperation):
"""actually remove a database from the application's schema"""
table = None # make pylint happy
def precommit_event(self):
dropped = self.session.query_data('droppedtables',
default=set(), setdefault=True)
......@@ -113,6 +114,7 @@ class DropColumnOp(PreCommitOperation):
"""actually remove the attribut's column from entity table in the system
database
"""
table = column = None # make pylint happy
def precommit_event(self):
session, table, column = self.session, self.table, self.column
# drop index if any
......@@ -236,6 +238,7 @@ def after_del_relation_type(session, rdefeid, rtype, rteid):
class AddEETypeOp(EarlySchemaOperation):
"""actually add the entity type to the application's schema"""
eid = None # make pylint happy
def commit_event(self):
eschema = self.schema.add_entity_type(self.kobj)
eschema.eid = self.eid
......@@ -296,6 +299,7 @@ def after_add_eetype(session, entity):
class AddERTypeOp(EarlySchemaOperation):
"""actually add the relation type to the application's schema"""
eid = None # make pylint happy
def commit_event(self):
rschema = self.schema.add_relation_type(self.kobj)
rschema.set_default_groups()
......@@ -355,6 +359,7 @@ class AddEFRDefPreCommitOp(PreCommitOperation):
constraints are handled by specific hooks
"""
entity = None # make pylint happy
def precommit_event(self):
session = self.session
entity = self.entity
......@@ -439,6 +444,7 @@ class AddENFRDefPreCommitOp(PreCommitOperation):
constraints are handled by specific hooks
"""
entity = None # make pylint happy
def precommit_event(self):
session = self.session
entity = self.entity
......@@ -530,6 +536,7 @@ def before_update_ertype(session, entity):
class UpdateEntityTypeName(SchemaOperation):
"""this operation updates physical storage accordingly"""
oldname = newname = None # make pylint happy
def precommit_event(self):
# we need sql to operate physical changes on the system database
......@@ -547,6 +554,7 @@ class UpdateEntityTypeName(SchemaOperation):
class UpdateRdefOp(SchemaOperation):
"""actually update some properties of a relation definition"""
rschema = values = None # make pylint happy
def precommit_event(self):
if 'indexed' in self.values:
......@@ -581,6 +589,8 @@ def after_update_erdef(session, entity):
class UpdateRtypeOp(SchemaOperation):
"""actually update some properties of a relation definition"""
rschema = values = entity = None # make pylint happy
def precommit_event(self):
session = self.session
rschema = self.rschema
......@@ -655,6 +665,8 @@ from cubicweb.schema import CONSTRAINTS
class ConstraintOp(SchemaOperation):
"""actually update constraint of a relation definition"""
entity = None # make pylint happy
def prepare_constraints(self, rtype, subjtype, objtype):
constraints = rtype.rproperty(subjtype, objtype, 'constraints')
self.constraints = list(constraints)
......@@ -708,6 +720,7 @@ def after_update_econstraint(session, entity):
class DelConstraintOp(ConstraintOp):
"""actually remove a constraint of a relation definition"""
rtype = subjtype = objtype = None # make pylint happy
def precommit_event(self):
self.prepare_constraints(self.rtype, self.subjtype, self.objtype)
......
......@@ -24,7 +24,7 @@ from cubicweb import BadConnectionId, UnknownEid, ConnectionError
from cubicweb.cwconfig import register_persistent_options
from cubicweb.server.sources import AbstractSource, ConnectionWrapper
class ReplaceByInOperator:
class ReplaceByInOperator(Exception):
def __init__(self, eids):
self.eids = eids
......
......@@ -117,7 +117,7 @@ class RepoThread(Thread):
func()
finally:
self.running_threads.remove(self)
Thread.__init__(self, target=target)
Thread.__init__(self, target=auto_remove_func)
self.running_threads = running_threads
self._name = target.__name__
......
......@@ -14,7 +14,8 @@ class SetUseEmailRelationOp(PreCommitOperation):
already setting the relation
"""
rtype = 'use_email'
fromeid = toeid = None # make pylint happy
def condition(self):
"""check entity has use_email set for the email address"""
return not self.session.unsafe_execute(
......
......@@ -22,6 +22,7 @@ class AddUpdateEUserHook(Hook):
class AutoDeleteBookmark(PreCommitOperation):
beid = None # make pylint happy
def precommit_event(self):
session = self.session
if not self.beid in session.query_data('pendingeids', ()):
......
......@@ -114,7 +114,7 @@ def copy_skeleton(skeldir, targetdir, context,
tfpath = tfpath[:-5]
if not askconfirm or not exists(tfpath) or \
confirm('%s exists, overwrite?' % tfpath):
fname = fill_templated_file(fpath, tfpath, context)
fill_templated_file(fpath, tfpath, context)
print '[generate] %s <-- %s' % (tfpath, fpath)
elif exists(tfpath):
show_diffs(tfpath, fpath, askconfirm)
......
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