diff --git a/.hgtags b/.hgtags index 6021317707a16027e590edf5c8dbbe3e18dff20f_LmhndGFncw==..b11900a5038e530e8f70400e36f6264a28951b16_LmhndGFncw== 100644 --- a/.hgtags +++ b/.hgtags @@ -9,3 +9,5 @@ a8f44368bb939573ae91319d30d09139a65cc26b oldstable 2b28a03294722693bf48ceaa806fcc21d904f401 cubicweb-link-version-1.4.1 d59aa7ff464afcffb11c47fd95e23011320c849e cubicweb-link-debian-version-1.4.1-1 +7fcfc70977f5e1b6cdd0f072937a5b81e2821e5c cubicweb-link-version-1.5.0 +84c4ccce2c999024ec14114f9f2a2e8263e888a1 cubicweb-link-debian-version-1.5.0-1 diff --git a/README b/README new file mode 100644 index 0000000000000000000000000000000000000000..b11900a5038e530e8f70400e36f6264a28951b16_UkVBRE1F --- /dev/null +++ b/README @@ -0,0 +1,2 @@ +This cube provides the `Link` entity type to model links, eg an URL with a +description. diff --git a/__pkginfo__.py b/__pkginfo__.py index 6021317707a16027e590edf5c8dbbe3e18dff20f_X19wa2dpbmZvX18ucHk=..b11900a5038e530e8f70400e36f6264a28951b16_X19wa2dpbmZvX18ucHk= 100644 --- a/__pkginfo__.py +++ b/__pkginfo__.py @@ -4,7 +4,7 @@ modname = 'link' distname = "cubicweb-%s" % modname -numversion = (1, 4, 1) +numversion = (1, 5, 0) version = '.'.join(str(num) for num in numversion) license = 'LGPL' @@ -8,9 +8,6 @@ version = '.'.join(str(num) for num in numversion) license = 'LGPL' -copyright = '''Copyright (c) 2003-2010 LOGILAB S.A. (Paris, FRANCE). -http://www.logilab.fr/ -- mailto:contact@logilab.fr''' - author = "Logilab" author_email = "contact@logilab.fr" web = 'http://www.cubicweb.org/project/%s' % distname @@ -14,13 +11,7 @@ author = "Logilab" author_email = "contact@logilab.fr" web = 'http://www.cubicweb.org/project/%s' % distname - -short_desc = "link component for the CubicWeb framework" -long_desc = """This CubicWeb component provides links (a URL with a description). - -CubicWeb is a semantic web application framework, see http://www.cubicweb.org -""" - +description = "link component for the CubicWeb framework" classifiers = [ 'Environment :: Web Environment', 'Framework :: CubicWeb', @@ -28,11 +19,7 @@ 'Programming Language :: JavaScript', ] -# dependencies - -__depends_cubes__ = {} -__depends__ = {'cubicweb': '>= 3.6.1'} -__use__ = tuple(__depends_cubes__) +__depends__ = {'cubicweb': '>= 3.9.0'} # packaging @@ -36,6 +23,9 @@ # packaging -from os import listdir -from os.path import join +from os import listdir as _listdir +from os.path import join, isdir +from glob import glob + +THIS_CUBE_DIR = join('share', 'cubicweb', 'cubes', modname) @@ -41,18 +31,7 @@ -CUBES_DIR = join('share', 'cubicweb', 'cubes') -try: - data_files = [ - [join(CUBES_DIR, 'link'), - [fname for fname in listdir('.') - if fname.endswith('.py') and fname != 'setup.py']], - [join(CUBES_DIR, 'link', 'data'), - [join('data', fname) for fname in listdir('data')]], - [join(CUBES_DIR, 'link', 'i18n'), - [join('i18n', fname) for fname in listdir('i18n')]], - [join(CUBES_DIR, 'link', 'migration'), - [join('migration', fname) for fname in listdir('migration')]], - ] -except OSError: - # we are in an installed directory - pass +def listdir(dirpath): + return [join(dirpath, fname) for fname in _listdir(dirpath) + if fname[0] != '.' and not fname.endswith('.pyc') + and not fname.endswith('~') + and not isdir(join(dirpath, fname))] @@ -58,2 +37,11 @@ -cube_eid = 20332 +data_files = [ + # common files + [THIS_CUBE_DIR, [fname for fname in glob('*.py') if fname != 'setup.py']], + ] +# check for possible extended cube layout +for dirname in ('entities', 'views', 'sobjects', 'hooks', 'schema', 'data', 'i18n', 'migration', 'wdoc'): + if isdir(dirname): + data_files.append([join(THIS_CUBE_DIR, dirname), listdir(dirname)]) +# Note: here, you'll need to add subdirectories if you want +# them to be included in the debian package diff --git a/debian/changelog b/debian/changelog index 6021317707a16027e590edf5c8dbbe3e18dff20f_ZGViaWFuL2NoYW5nZWxvZw==..b11900a5038e530e8f70400e36f6264a28951b16_ZGViaWFuL2NoYW5nZWxvZw== 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +cubicweb-link (1.5.0-1) unstable; urgency=low + + * new upstream release + + -- Sylvain Thénault <sylvain.thenault@logilab.fr> Tue, 05 Oct 2010 11:10:10 +0200 + cubicweb-link (1.4.1-1) unstable; urgency=low * new upstream release diff --git a/debian/control b/debian/control index 6021317707a16027e590edf5c8dbbe3e18dff20f_ZGViaWFuL2NvbnRyb2w=..b11900a5038e530e8f70400e36f6264a28951b16_ZGViaWFuL2NvbnRyb2w= 100644 --- a/debian/control +++ b/debian/control @@ -11,7 +11,7 @@ Architecture: all Conflicts: erudi-link, erudi-link-server, erudi-link-client, erudi-link-comp Replaces: erudi-link, erudi-link-server, erudi-link-client, erudi-link-comp -Depends: cubicweb-common (>= 3.6.1) +Depends: cubicweb-common (>= 3.9.0) Description: link component for the CubicWeb framework This CubicWeb component provides links (a URL with a description). . diff --git a/debian/rules b/debian/rules index 6021317707a16027e590edf5c8dbbe3e18dff20f_ZGViaWFuL3J1bGVz..b11900a5038e530e8f70400e36f6264a28951b16_ZGViaWFuL3J1bGVz 100755 --- a/debian/rules +++ b/debian/rules @@ -7,7 +7,7 @@ build: build-stamp build-stamp: dh_testdir - python setup.py -q build + NO_SETUPTOOLS=1 python setup.py -q build touch build-stamp clean: @@ -24,7 +24,7 @@ dh_testroot dh_clean -k dh_installdirs -i - python setup.py -q install --no-compile --prefix=debian/cubicweb-link/usr/ + NO_SETUPTOOLS=1 python setup.py -q install --no-compile --prefix=debian/cubicweb-link/usr/ rm -rf debian/cubicweb-addressbook/usr/lib/python* diff --git a/entities.py b/entities.py index 6021317707a16027e590edf5c8dbbe3e18dff20f_ZW50aXRpZXMucHk=..b11900a5038e530e8f70400e36f6264a28951b16_ZW50aXRpZXMucHk= 100644 --- a/entities.py +++ b/entities.py @@ -1,9 +1,9 @@ """entity classes for Link entities :organization: Logilab -:copyright: 2003-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +:copyright: 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr """ __docformat__ = "restructuredtext en" from cubicweb.entities import AnyEntity, fetch_config @@ -5,13 +5,12 @@ :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr """ __docformat__ = "restructuredtext en" from cubicweb.entities import AnyEntity, fetch_config - -from cubicweb.interfaces import IEmbedable - +from cubicweb.web.views.embedding import IEmbedableAdapter +from cubicweb.selectors import is_instance class Link(AnyEntity): """customized class for Link entities""" __regid__ = 'Link' fetch_attrs, fetch_order = fetch_config(['title', 'url']) @@ -13,11 +12,10 @@ class Link(AnyEntity): """customized class for Link entities""" __regid__ = 'Link' fetch_attrs, fetch_order = fetch_config(['title', 'url']) - __implements__ = (IEmbedable,) def dc_title(self): return u'%s (%s)' % (self.title, self.url) @@ -19,14 +17,10 @@ def dc_title(self): return u'%s (%s)' % (self.title, self.url) - def embeded_url(self): - """embed action interface""" - return self.url - def actual_url(self): if not self.embed: return self.url return self._cw.build_url('embed', url=self.url, rql=self._cw.form.get('rql')) @@ -28,5 +22,11 @@ def actual_url(self): if not self.embed: return self.url return self._cw.build_url('embed', url=self.url, rql=self._cw.form.get('rql')) +class LinkIEmbedableAdapter(IEmbedableAdapter): + __select__ = is_instance('Link') + + def embeded_url(self): + """embed action interface""" + return self.entity.url diff --git a/hooks.py b/hooks.py index 6021317707a16027e590edf5c8dbbe3e18dff20f_aG9va3MucHk=..b11900a5038e530e8f70400e36f6264a28951b16_aG9va3MucHk= 100644 --- a/hooks.py +++ b/hooks.py @@ -1,5 +1,5 @@ -from cubicweb.selectors import implements +from cubicweb.selectors import is_instance from cubicweb.sobjects.notification import ContentAddedView class LinkAddedView(ContentAddedView): """get notified from new links""" @@ -2,6 +2,6 @@ from cubicweb.sobjects.notification import ContentAddedView class LinkAddedView(ContentAddedView): """get notified from new links""" - __select__ = implements('Link') + __select__ = is_instance('Link') content_attr = 'description' diff --git a/setup.py b/setup.py index 6021317707a16027e590edf5c8dbbe3e18dff20f_c2V0dXAucHk=..b11900a5038e530e8f70400e36f6264a28951b16_c2V0dXAucHk= 100644 --- a/setup.py +++ b/setup.py @@ -1,22 +1,10 @@ #!/usr/bin/env python -# pylint: disable-msg=W0404,W0622,W0704,W0613,W0152 -# Copyright (c) 2003-2004 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 -# version. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# 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 """ +# pylint: disable=W0404,W0622,W0704,W0613 +# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr + +__docformat__ = "restructuredtext en" import os import sys import shutil @@ -19,9 +7,6 @@ import os import sys import shutil -from distutils.core import setup -from distutils import command -from distutils.command import install_lib from os.path import isdir, exists, join, walk @@ -26,3 +11,16 @@ from os.path import isdir, exists, join, walk +try: + if os.environ.get('NO_SETUPTOOLS'): + raise ImportError() + from setuptools import setup + from setuptools.command import install_lib + USE_SETUPTOOLS = 1 +except ImportError: + from distutils.core import setup + from distutils.command import install_lib + USE_SETUPTOOLS = 0 + + +sys.modules.pop('__pkginfo__', None) # import required features @@ -28,4 +26,4 @@ # import required features -from __pkginfo__ import distname, version, license, short_desc, long_desc, \ +from __pkginfo__ import modname, version, license, description, \ web, author, author_email # import optional features @@ -30,17 +28,29 @@ web, author, author_email # import optional features -try: - from __pkginfo__ import distname -except ImportError: - distname = distname -try: - from __pkginfo__ import scripts -except ImportError: - scripts = [] -try: - from __pkginfo__ import data_files -except ImportError: - data_files = None - +import __pkginfo__ +distname = getattr(__pkginfo__, 'distname', modname) +scripts = getattr(__pkginfo__, 'scripts', []) +data_files = getattr(__pkginfo__, 'data_files', None) +include_dirs = getattr(__pkginfo__, 'include_dirs', []) +ext_modules = getattr(__pkginfo__, 'ext_modules', None) +dependency_links = getattr(__pkginfo__, 'dependency_links', []) + +STD_BLACKLIST = ('CVS', '.svn', '.hg', 'debian', 'dist', 'build') + +IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~') + +if exists('README'): + long_description = file('README').read() +else: + long_description = '' +if USE_SETUPTOOLS: + requires = {} + for entry in ("__depends__", "__recommends__"): + requires.update(getattr(__pkginfo__, entry, {})) + install_requires = [("%s %s" % (d, v and v or "")).strip() + for d, v in requires.iteritems()] +else: + install_requires = [] + def ensure_scripts(linux_scripts): @@ -45,6 +55,6 @@ def ensure_scripts(linux_scripts): - """creates the proper script names required for each platform + """Creates the proper script names required for each platform (taken from 4Suite) """ from distutils import util @@ -54,4 +64,18 @@ scripts_ = linux_scripts return scripts_ +def get_packages(directory, prefix): + """return a list of subpackages for the given directory""" + result = [] + for package in os.listdir(directory): + absfile = join(directory, package) + if isdir(absfile): + if exists(join(absfile, '__init__.py')) or \ + package in ('test', 'tests'): + if prefix: + result.append('%s.%s' % (prefix, package)) + else: + result.append(package) + result += get_packages(absfile, result[-1]) + return result @@ -57,4 +81,58 @@ +def export(from_dir, to_dir, + blacklist=STD_BLACKLIST, + ignore_ext=IGNORED_EXTENSIONS, + verbose=True): + """make a mirror of from_dir in to_dir, omitting directories and files + listed in the black list + """ + def make_mirror(arg, directory, fnames): + """walk handler""" + for norecurs in blacklist: + try: + fnames.remove(norecurs) + except ValueError: + pass + for filename in fnames: + # don't include binary files + if filename[-4:] in ignore_ext: + continue + if filename[-1] == '~': + continue + src = join(directory, filename) + dest = to_dir + src[len(from_dir):] + if verbose: + print >> sys.stderr, src, '->', dest + if os.path.isdir(src): + if not exists(dest): + os.mkdir(dest) + else: + if exists(dest): + os.remove(dest) + shutil.copy2(src, dest) + try: + os.mkdir(to_dir) + except OSError, ex: + # file exists ? + import errno + if ex.errno != errno.EEXIST: + raise + walk(from_dir, make_mirror, None) + + +class MyInstallLib(install_lib.install_lib): + """extend install_lib command to handle package __init__.py and + include_dirs variable if necessary + """ + def run(self): + """overridden from install_lib class""" + install_lib.install_lib.run(self) + # manually install included directories if any + if include_dirs: + base = modname + for directory in include_dirs: + dest = join(self.install_dir, base, directory) + export(directory, dest, verbose=False) def install(**kwargs): """setup entry point""" @@ -58,18 +136,29 @@ def install(**kwargs): """setup entry point""" - #kwargs['distname'] = modname - return setup(name=distname, - version=version, - license =license, - description=short_desc, - long_description=long_desc, - author=author, - author_email=author_email, - url=web, - scripts=ensure_scripts(scripts), - data_files=data_files, - **kwargs) - + if USE_SETUPTOOLS: + if '--force-manifest' in sys.argv: + sys.argv.remove('--force-manifest') + # install-layout option was introduced in 2.5.3-1~exp1 + elif sys.version_info < (2, 5, 4) and '--install-layout=deb' in sys.argv: + sys.argv.remove('--install-layout=deb') + if USE_SETUPTOOLS and install_requires: + kwargs['install_requires'] = install_requires + kwargs['dependency_links'] = dependency_links + return setup(name = distname, + version = version, + license = license, + description = description, + long_description = long_description, + author = author, + author_email = author_email, + url = web, + scripts = ensure_scripts(scripts), + data_files = data_files, + ext_modules = ext_modules, + cmdclass = {'install_lib': MyInstallLib}, + **kwargs + ) + if __name__ == '__main__' : install() diff --git a/test/unittest_link.py b/test/unittest_link.py index 6021317707a16027e590edf5c8dbbe3e18dff20f_dGVzdC91bml0dGVzdF9saW5rLnB5..b11900a5038e530e8f70400e36f6264a28951b16_dGVzdC91bml0dGVzdF9saW5rLnB5 100644 --- a/test/unittest_link.py +++ b/test/unittest_link.py @@ -14,7 +14,7 @@ def test_possible_actions(self): req = self.request() rset = self.execute('Any X WHERE X is Link') - self.assertEquals(self.pactionsdict(req, rset), + self.assertEqual(self.pactionsdict(req, rset), {'moreactions': [embedding.EmbedAction], 'mainactions': [actions.ModifyAction, views.LinkFollowAction], 'moreactions': [actions.ManagePermissionsAction, actions.AddRelatedActions, @@ -27,7 +27,7 @@ return [(rschema.type, x) for rschema, tschemas, x in iterable] e = self.vreg["etypes"].etype_class('Link')(self.request()) # we should only see embed when we are in the managers group - self.assertEquals(rbc(afs.relations_by_section(e, 'main', 'attributes', 'update')), + self.assertEqual(rbc(afs.relations_by_section(e, 'main', 'attributes', 'update')), [('title', 'subject'), ('url', 'subject'), ('embed', 'subject'), ('description', 'subject')]) @@ -35,7 +35,7 @@ self.login('toto') # create a new instance with the new connection e = self.vreg["etypes"].etype_class('Link')(self.request()) - self.assertEquals(rbc(afs.relations_by_section(e, 'main', 'attributes', 'update')), + self.assertEqual(rbc(afs.relations_by_section(e, 'main', 'attributes', 'update')), [('title', 'subject'), ('url', 'subject'), ('description', 'subject')]) diff --git a/data/external_resources b/uiprops.py similarity index 0% rename from data/external_resources rename to uiprops.py index 6021317707a16027e590edf5c8dbbe3e18dff20f_ZGF0YS9leHRlcm5hbF9yZXNvdXJjZXM=..b11900a5038e530e8f70400e36f6264a28951b16_dWlwcm9wcy5weQ== 100644 --- a/data/external_resources +++ b/uiprops.py @@ -1,1 +1,1 @@ -LINK_ICON = DATADIR/icon_link.gif +LINK_ICON = data('icon_link.gif') diff --git a/views.py b/views.py index 6021317707a16027e590edf5c8dbbe3e18dff20f_dmlld3MucHk=..b11900a5038e530e8f70400e36f6264a28951b16_dmlld3MucHk= 100644 --- a/views.py +++ b/views.py @@ -7,5 +7,5 @@ __docformat__ = "restructuredtext en" _ = unicode -from logilab.mtconverter import html_escape +from logilab.mtconverter import xml_escape @@ -11,5 +11,5 @@ -from cubicweb.selectors import implements +from cubicweb.selectors import is_instance from cubicweb.view import EntityView from cubicweb.web import uicfg, formwidgets from cubicweb.web.views import primary, baseviews @@ -23,7 +23,7 @@ class LinkPrimaryView(primary.PrimaryView): - __select__ = implements('Link') + __select__ = is_instance('Link') show_attr_label = False def render_entity_title(self, entity): @@ -27,8 +27,8 @@ show_attr_label = False def render_entity_title(self, entity): - title = u'<a href="%s">%s</a>' % (html_escape(entity.actual_url()), - html_escape(entity.title)) + title = u'<a href="%s">%s</a>' % (xml_escape(entity.actual_url()), + xml_escape(entity.title)) self.w(u'<h1><span class="etype">%s</span> %s</h1>' % (entity.dc_type().capitalize(), title)) @@ -37,9 +37,9 @@ class LinkOneLineView(baseviews.OneLineView): - __select__ = implements('Link') + __select__ = is_instance('Link') def cell_call(self, row, col): entity = self.cw_rset.complete_entity(row, col) descr = entity.printable_value('description', format='text/plain') descr = descr and descr.splitlines()[0] @@ -41,12 +41,12 @@ def cell_call(self, row, col): entity = self.cw_rset.complete_entity(row, col) descr = entity.printable_value('description', format='text/plain') descr = descr and descr.splitlines()[0] - values = {'title': html_escape(entity.title), - 'url': html_escape(entity.absolute_url()), - 'description': html_escape(descr), + values = {'title': xml_escape(entity.title), + 'url': xml_escape(entity.absolute_url()), + 'description': xml_escape(descr), } self.w(u'<a href="%(url)s" title="%(description)s">%(title)s</a>' % values) self.w(u' [<a href="%s">%s</a>]' @@ -49,10 +49,10 @@ } self.w(u'<a href="%(url)s" title="%(description)s">%(title)s</a>' % values) self.w(u' [<a href="%s">%s</a>]' - % (html_escape(entity.actual_url()), + % (xml_escape(entity.actual_url()), self._cw._('follow'))) class LinkView(EntityView): __regid__ = 'link' @@ -54,10 +54,10 @@ self._cw._('follow'))) class LinkView(EntityView): __regid__ = 'link' - __select__ = implements('Link') + __select__ = is_instance('Link') title = _('link') def cell_call(self, row, col): entity = self.cw_rset.complete_entity(row, col) @@ -60,12 +60,12 @@ title = _('link') def cell_call(self, row, col): entity = self.cw_rset.complete_entity(row, col) - values = {'title': html_escape(entity.title), - 'url': html_escape(entity.actual_url()), - 'description': html_escape(entity.printable_value('description')), + values = {'title': xml_escape(entity.title), + 'url': xml_escape(entity.actual_url()), + 'description': xml_escape(entity.printable_value('description')), } self.w(u'<a href="%(url)s" title="%(description)s">%(title)s</a>' % values) class XbelItemLinkView(xbel.XbelItemView): @@ -67,12 +67,12 @@ } self.w(u'<a href="%(url)s" title="%(description)s">%(title)s</a>' % values) class XbelItemLinkView(xbel.XbelItemView): - __select__ = implements('Link') + __select__ = is_instance('Link') def url(self, entity): return entity.url class LinkFollowAction(bookmark.FollowAction): @@ -73,7 +73,7 @@ def url(self, entity): return entity.url class LinkFollowAction(bookmark.FollowAction): - __select__ = implements('Link') + __select__ = is_instance('Link')