Commit d979959a authored by Adrien Di Mascio's avatar Adrien Di Mascio
Browse files

Showtime !

Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
This diff is collapsed.
include README
include pylintrc
include bin/cubicweb-*
include man/cubicweb-ctl.1
recursive-include doc *.txt *.zargo *.png *.html makefile
recursive-include misc *
recursive-include web/data *
recursive-include web/wdoc *.rst *.png *.xml ChangeLog*
include web/views/*.pt
recursive-include etwist *.xml *.html
recursive-include i18n *.pot *.po
recursive-include schemas *.py *.rel *.sql.*
recursive-include common/test/data *
recursive-include entities/test/data *
recursive-include sobjects/test/data *
recursive-include server/test/data *
recursive-include server/test sources*
recursive-include web/test/data *.js *.css *.png *.gif *.jpg *.ico external_resources
recursive-include devtools/test/data *
prune misc/cwfs
CubicWeb semantic web framework
From the source distribution, extract the tarball and run ::
python install
For deb and rpm packages, use the tools recommended by your distribution.
Look in the doc/ subdirectory.
"""CubicWeb is a generic framework to quickly build applications which describes
relations between entitites.
:organization: Logilab
:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: --
:license: General Public License version 2 -
__docformat__ = "restructuredtext en"
from cubicweb.__pkginfo__ import version as __version__
import __builtin__
# '_' is available in builtins to mark internationalized string but should
# not be used to do the actual translation
if not hasattr(__builtin__, '_'):
__builtin__._ = unicode
CW_SOFTWARE_ROOT = __path__[0]
import sys, os, logging
from StringIO import StringIO
from urllib import quote as urlquote, unquote as urlunquote
from logilab.common.decorators import cached
logging.addLevelName(LLDEBUG, 'LLDEBUG')
class CubicWebLogger(logging.Logger):
def lldebug(self, msg, *args, **kwargs):
Log 'msg % args' with severity 'DEBUG'.
To pass exception information, use the keyword argument exc_info with
a true value, e.g.
logger.debug("Houston, we have a %s", "thorny problem", exc_info=1)
if self.manager.disable >= LLDEBUG:
if LLDEBUG >= self.getEffectiveLevel():
self._log(LLDEBUG, msg, args, **kwargs)
def set_log_methods(cls, logger):
"""bind standart logger's methods as static methods on the class
cls._logger = logger
for attr in ('lldebug', 'debug', 'info', 'warning', 'error', 'critical', 'exception'):
setattr(cls, attr, getattr(logger, attr))
if os.environ.get('APYCOT_ROOT'):
set_log_methods(sys.modules[__name__], logging.getLogger('cubicweb'))
# make all exceptions accessible from the package
from cubicweb._exceptions import *
# convert eid to the right type, raise ValueError if it's not a valid eid
typed_eid = int
#def log_thread(f, w, a):
# print f.f_code.co_filename, f.f_code.co_name
#import threading
class Binary(StringIO):
"""customize StringIO to make sure we don't use unicode"""
def __init__(self, buf= ''):
assert isinstance(buf, (str, buffer)), \
"Binary objects must use raw strings, not %s" % buf.__class__
StringIO.__init__(self, buf)
def write(self, data):
assert isinstance(data, (str, buffer)), \
"Binary objects must use raw strings, not %s" % data.__class__
StringIO.write(self, data)
class RequestSessionMixIn(object):
"""mixin class containing stuff shared by server session and web request
def __init__(self, vreg):
self.vreg = vreg
encoding = vreg.property_value('ui.encoding')
except: # no vreg or property not registered
encoding = 'utf-8'
self.encoding = encoding
# cache result of execution for (rql expr / eids),
# should be emptied on commit/rollback of the server session / web
# connection
self.local_perm_cache = {}
def property_value(self, key):
if self.user:
return self.user.property_value(key)
return self.vreg.property_value(key)
def etype_rset(self, etype, size=1):
"""return a fake result set for a particular entity type"""
from cubicweb.rset import ResultSet
rset = ResultSet([('A',)]*size, '%s X' % etype,
def get_entity(row, col=0, etype=etype, vreg=self.vreg, rset=rset):
return self.vreg.etype_class(etype)(self, rset, row, col)
rset.get_entity = get_entity
return self.decorate_rset(rset)
def eid_rset(self, eid, etype=None):
"""return a result set for the given eid without doing actual query
(we have the eid, we can suppose it exists and user has access to the
from cubicweb.rset import ResultSet
eid = typed_eid(eid)
if etype is None:
etype = self.describe(eid)[0]
rset = ResultSet([(eid,)], 'Any X WHERE X eid %(x)s', {'x': eid},
return self.decorate_rset(rset)
def entity_from_eid(self, eid, etype=None):
rset = self.eid_rset(eid, etype)
if rset:
return rset.get_entity(0, 0)
return None
# url generation methods ##################################################
def build_url(self, method, base_url=None, **kwargs):
"""return an absolute URL using params dictionary key/values as URL
parameters. Values are automatically URL quoted, and the
publishing method to use may be specified or will be guessed.
if base_url is None:
base_url = self.base_url()
if '_restpath' in kwargs:
assert method == 'view', method
path = kwargs.pop('_restpath')
path = method
if not kwargs:
return u'%s%s' % (base_url, path)
return u'%s%s?%s' % (base_url, path, self.build_url_params(**kwargs))
def build_url_params(self, **kwargs):
"""return encoded params to incorporate them in an URL"""
args = []
for param, values in kwargs.items():
if not isinstance(values, (list, tuple)):
values = (values,)
for value in values:
args.append(u'%s=%s' % (param, self.url_quote(value)))
return '&'.join(args)
def url_quote(self, value, safe=''):
"""urllib.quote is not unicode safe, use this method to do the
necessary encoding / decoding. Also it's designed to quote each
part of a url path and so the '/' character will be encoded as well.
if isinstance(value, unicode):
quoted = urlquote(value.encode(self.encoding), safe=safe)
return unicode(quoted, self.encoding)
return urlquote(str(value), safe=safe)
def url_unquote(self, quoted):
"""returns a unicode unquoted string
decoding is based on `self.encoding` which is the encoding
used in `url_quote`
if isinstance(quoted, unicode):
quoted = quoted.encode(self.encoding)
return unicode(urlunquote(quoted), self.encoding)
except UnicodeDecodeError: # might occurs on manually typed URLs
return unicode(urlunquote(quoted), 'iso-8859-1')
# session's user related methods #####################################
def user_data(self):
"""returns a dictionnary with this user's information"""
userinfo = {}
if self.is_internal_session:
userinfo['login'] = "cubicweb"
userinfo['name'] = "cubicweb"
userinfo['email'] = ""
return userinfo
user = self.actual_session().user
rql = "Any F,S,A where U eid %(x)s, U firstname F, U surname S, U primary_email E, E address A"
firstname, lastname, email = self.execute(rql, {'x': user.eid}, 'x')[0]
if firstname is None and lastname is None:
userinfo['name'] = ''
userinfo['name'] = ("%s %s" % (firstname, lastname))
userinfo['email'] = email
except IndexError:
userinfo['name'] = None
userinfo['email'] = None
userinfo['login'] = user.login
return userinfo
def is_internal_session(self):
"""overrided on the server-side"""
return False
# abstract methods to override according to the web front-end #############
def base_url(self):
"""return the root url of the application"""
raise NotImplementedError
def decorate_rset(self, rset):
"""add vreg/req (at least) attributes to the given result set """
raise NotImplementedError
def describe(self, eid):
"""return a tuple (type, sourceuri, extid) for the entity with id <eid>"""
raise NotImplementedError
# XXX 2.45 is allowing nicer entity type names, use this map for bw compat
ETYPE_NAME_MAP = {'Eetype': 'EEType',
'Ertype': 'ERType',
'Efrdef': 'EFRDef',
'Enfrdef': 'ENFRDef',
'Econstraint': 'EConstraint',
'Econstrainttype': 'EConstraintType',
'Epermission': 'EPermission',
'Egroup': 'EGroup',
'Euser': 'EUser',
'Eproperty': 'EProperty',
'Emailaddress': 'EmailAddress',
'Rqlexpression': 'RQLExpression',
'Trinfo': 'TrInfo',
# XXX cubic web cube migration map
CW_MIGRATION_MAP = {'erudi': 'cubicweb',
'eaddressbook': 'addressbook',
'ebasket': 'basket',
'eblog': 'blog',
'ebook': 'book',
'ecomment': 'comment',
'ecompany': 'company',
'econference': 'conference',
'eemail': 'email',
'eevent': 'event',
'eexpense': 'expense',
'efile': 'file',
'einvoice': 'invoice',
'elink': 'link',
'emailinglist': 'mailinglist',
'eperson': 'person',
'eshopcart': 'shopcart',
'eskillmat': 'skillmat',
'etask': 'task',
'eworkcase': 'workcase',
'eworkorder': 'workorder',
'ezone': 'zone',
'i18ncontent': 'i18ncontent',
'svnfile': 'vcsfile',
'eclassschemes': 'keyword',
'eclassfolders': 'folder',
'eclasstags': 'tag',
'jpl': 'jpl',
'jplintra': 'jplintra',
'jplextra': 'jplextra',
'jplorg': 'jplorg',
'jplrecia': 'jplrecia',
'crm': 'crm',
'agueol': 'agueol',
'docaster': 'docaster',
'asteretud': 'asteretud',
# XXX temp
'keywords': 'keyword',
'folders': 'folder',
'tags': 'tag',
# pylint: disable-msg=W0622,C0103
"""cubicweb global packaging information for the cubicweb knowledge management
distname = "cubicweb"
modname = "cubicweb"
numversion = (3, 0, 0)
version = '.'.join(str(num) for num in numversion)
license = 'LCL'
copyright = '''Copyright (c) 2003-2008 LOGILAB S.A. (Paris, FRANCE). --'''
author = "Logilab"
author_email = ""
short_desc = "a repository of entities / relations for knowledge management"
long_desc = """CubicWeb is a entities / relations based knowledge management system
developped at Logilab.
This package contains:
* a repository server
* a RQL command line client to the repository
* an adaptative modpython interface to the server
* a bunch of other management tools
web = ''
ftp = ''
pyversions = ['2.4']
from os import listdir, environ
from os.path import join, isdir
import glob
scripts = [s for s in glob.glob(join('bin', 'cubicweb-*'))
if not s.endswith('.bat')]
include_dirs = [join('common', 'test', 'data'),
join('server', 'test', 'data'),
join('web', 'test', 'data'),
join('devtools', 'test', 'data'),]
entities_dir = 'entities'
schema_dir = 'schemas'
sobjects_dir = 'sobjects'
server_migration_dir = join('misc', 'migration')
data_dir = join('web', 'data')
wdoc_dir = join('web', 'wdoc')
wdocimages_dir = join(wdoc_dir, 'images')
views_dir = join('web', 'views')
i18n_dir = 'i18n'
if environ.get('APYCOT_ROOT'):
# --home install
pydir = 'python'
pydir = join('python2.4', 'site-packages')
data_files = [
# common data
#[join('share', 'cubicweb', 'entities'),
# [join(entities_dir, filename) for filename in listdir(entities_dir)]],
# server data
[join('share', 'cubicweb', 'schemas'),
[join(schema_dir, filename) for filename in listdir(schema_dir)]],
#[join('share', 'cubicweb', 'sobjects'),
# [join(sobjects_dir, filename) for filename in listdir(sobjects_dir)]],
[join('share', 'cubicweb', 'migration'),
[join(server_migration_dir, filename)
for filename in listdir(server_migration_dir)]],
# web data
[join('share', 'cubicweb', 'cubes', 'shared', 'data'),
[join(data_dir, fname) for fname in listdir(data_dir) if not isdir(join(data_dir, fname))]],
[join('share', 'cubicweb', 'cubes', 'shared', 'data', 'timeline'),
[join(data_dir, 'timeline', fname) for fname in listdir(join(data_dir, 'timeline'))]],
[join('share', 'cubicweb', 'cubes', 'shared', 'wdoc'),
[join(wdoc_dir, fname) for fname in listdir(wdoc_dir) if not isdir(join(wdoc_dir, fname))]],
[join('share', 'cubicweb', 'cubes', 'shared', 'wdoc', 'images'),
[join(wdocimages_dir, fname) for fname in listdir(wdocimages_dir)]],
# XXX: .pt install should be handled properly in a near future version
[join('lib', pydir, 'cubicweb', 'web', 'views'),
[join(views_dir, fname) for fname in listdir(views_dir) if fname.endswith('.pt')]],
[join('share', 'cubicweb', 'cubes', 'shared', 'i18n'),
[join(i18n_dir, fname) for fname in listdir(i18n_dir)]],
except OSError:
# we are in an installed directory, don't care about this
"""Exceptions shared by different cubicweb packages.
:organization: Logilab
:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: --
__docformat__ = "restructuredtext en"
from yams import ValidationError
# abstract exceptions #########################################################
class CubicWebException(Exception):
"""base class for cubicweb server exception"""
msg = ""
def __str__(self):
if self.msg:
if self.args:
return self.msg % tuple(self.args)
return self.msg
return ' '.join(str(arg) for arg in self.args)
class ConfigurationError(CubicWebException):
"""a misconfiguration error"""