subscribe to this blog

CubicWeb Blog

News about the framework and its uses.

Summer CubicWeb/Narval Sprint - Final report

2010/08/18 by Sylvain Thenault

For that last sprint day, each team made some nice achievements:

  • Steph & Alain worked on the mv/cp actions implementation to makes them working properly and supporting globs. Last but not least, with a full set of tests.
  • Alex & Charles got back what we call apycot 'full' tests, eg running test with coverage enabled, checking that code coverage is greater than a given threshold, but also running pylint and checking that its global evaluation is at least 7 (configurable, of course).
  • Katia & Aurélien provided a sharp implementation of recipe checking, so that we know we don't launch a recipe badly constructed, as well as informing the user nicely from what errors his recipe suffer.
  • Julien managed to set up a recipe managing from Debian package construction to Debian repository publication, going through lintian on the way
  • Pierre-Yves helped other teams to solve the narval related bugs they encountered, and finished by writing a thread-safe implementation of apycot's writer so we can run several checker simultaneously.
  • Celso continued working on a proof of concept blue-theme cube, wondering how to make CubicWeb looks nicer and be easily customisable in future versions.
  • Sylvain helped there and there and integrated patches...

So we finally didn't get up to the demo. But we now have everything to set it up, so I've a good hope that we will have a beta version of our brand new production chain up and running before the end of August!

Thanks to everyone for all this good work, and for this time spent all together!


CubicWeb gets press coverage at SemanticWeb.com

2010/08/15 by Nicolas Chauvat

Following the presentation of CubicWeb at OSCON 2010 in July, the editor of SemanticWeb.com wrote an article describing the CubicWeb framwork. Read the article and ask your questions on the mailing list!


Summer CubicWeb/Narval Sprint - Day 4

2010/08/13 by Pierre-Yves David

In this fourth day of the our Summer Sprint important progress have been made.

  • Stéphanie and Alain cleaned up the Apycot's bot sources from deprecated code and rewrite part of the test suite to follow the new way to launch apycot. They cleaned up the handling of VCS sources for tested project taking advantages of the new mercurial cache for vcsfile implemented by Katia and Aurélien last Tuesday. This feature keep a local clone of the remote repository and allow much faster checkout during test runs.
  • Julien made significant progress in the writing of the Debian recipe. A recipes can now successfully build Debian packages of a project and validate them with lintian and lgp. He later paired with Pierre-Yves and they improved the annotation of Apycot's Narval variable to enhance Input validation in Apycot's Narval recipes. For example, the action building a Debian package will explicitly refuse to run on a project not yet checked-out.
  • Aurelien first paired with Pierre-Yves to improve some views and the consistency of the database schema, then he worked on a dashboard displaying various indicators useful to the version publishing process.
  • Pierre-Yves spent some time improving the ability of Narval to recover on errors and to display meaningful logs about them.
  • Alexandre and Charles finished the re-implementation of the full python recipe.They used options at the Narval level to run test suite with the coverage enabled and re-enabled the coverage checker to process the result, discovering some problems in Narval's engine on the way...
  • Celso finished Spanish translation of Cubicweb's core and started to work on a new css theme
  • Sylvain helped several groups along the day and reviewed patches from them.

Summer CubicWeb/Narval Sprint - Day 3

2010/08/13

CubicWeb/Narval Sprint is going on !

The third day of our sprint focused on the following points:

  • Pierre-Yves worked to prevent duplicate test executions (eg running several time the same test with the same version configuration),
  • Celso has terminated the spanish translation of CubicWeb. He's now working on various cubes translation,
  • Stéphanie and Alain spent some time on the narval bot view. They also modified ProjectEnvironement's attributes in order to use similar information available on the vcsfile repository, hence simplifying the configuration (more to do on this!),
  • Julien worked on the debian package recipe,
  • Katia and Aurélien worked on recipe security (using CWPermission),
  • Alexandre and Charles produced a first template of a full test recipe using pyunit and pycoverage,
  • Finally, our captain, Sylvain, is at the helm !

We'll hopefuly be able to present a functionnal demo at the end of the week.

Narval/Cubicweb left off !


Summer CubicWeb/Narval Sprint - Day 2

2010/08/11 by Katia Saurfelt

During the second day of our Summer CubicWeb/Narval Sprint, several tasks started on the first day were completed and new tasks started:

  • Charles, Alexandre and Julien finished writing the "copy" and "move" Narval actions, and then started transforming existing apycot checkers into Narval actions.
  • Pierre-Yves managed to improve Narval reports with more explicit and relevant content.
  • Stéphanie and Alain finished the bot status view as well as the recipe graph view.
  • Katia and Aurélien finished writing the new mercurial cache solution for vcsfile and started improving the security of Narval recipes (i.e. who can start which recipe).
  • Celso kept on his life-long work of translating CubicWeb to Spanish.
  • Sylvain wrote some Narval views, improved Narval execution logs handling and kept on reviewing patches and helping various people...

Summer CubicWeb/Narval Sprint - Day 1

2010/08/10 by Sylvain Thenault

We started this first day by several presentations by Sylvain about Logilab's current development process workflow, and compared it to what it should be after the sprint. Sylvain also introduced Narval.

We then set up a dev environment on everyone's computer: a working forge with a local Narval agent that can be used for tests during the week.

Regarding more concrete tasks:

  • Charles and Alexandre started writing some basic Narval actions such as move, to move a file from a place to another, and had to grasp narval's concepts on the way.
  • Pierre-Yves dug into the code to understand how exceptions are propagated in the Narval engine, his goal was to get better reports.
  • Stéphanie and Alain worked on a nice bot status view.
  • Katia, Aurélien studied the new mercurial cache solution for vcsfile
  • Julien started some piece of documentation.
  • Celso, our Mexican friend, discovered some new features of recent cubicweb releases and setup his environment to later work on Spanish translation, CSS, etc.
  • Sylvain came with a basically working narval implementation on top of cubicweb, and spent the day helping various people...

Summer CubicWeb/Narval Sprint

2010/08/10 by Sylvain Thenault

Although this week is normally the regular annual holidays here at Logilab, some of us will sprint in Paris exceptionally.

Focus

We're starting this week with an exciting goal: integrating all our release process into our continuous integration suite (through the apycot cube). Including Debian repository management, pypi registration, etc...

The hot stuff to achieve this is the third resurrection of Narval, the project Logilab was originaly based on, but this time it is built on top of CubicWeb framework. Narval will be used to rewrite some parts of apycot, in order to make it more flexible and powerful.

It is not just a refactoring or a simple upgrade! We hope to automate common tasks, simplify maintenance, and thus enhance release quality, but also gain a lot of functionality in near future.

Sprint roadmap

  • merge Apycotbot process manager into a new Narval incarnation, and rewrite it as Narval actions and recipes
  • improve vcsfile cube with a new cache system for mercurial
  • define Logilab's release process as new Narval recipes, triggered by actions such as adding release tag into the source repository

More detailed stuff will come with the sprint reports that we'll try to issue each day.

Information

This sprint is taking place in Logilab's offices in Paris from Monday the 9th to the 13th of August 2010.


HOWTO change the value of a variable in all-in-one.conf with a migration script

2010/08/03

Here is a sample migration script (see also the cubicweb documentation on that topic) which changes the variable 'sender-addr'. There is an additional twist in that the variable is only updated if the instance is configured with a known value for that variable.

wrong_addr = 'cubicweb@loiglab.fr' # known wrong address
fixed_addr = 'cubicweb@logilab.fr'
configured_addr = config.get('sender-addr')
# check that the address has not been hand fixed by a sysadmin
if configured_addr == wrong_addr:
    config['sender-addr'] = fixed-addr
    config.save()

This is very useful in cases such as:

  • automatically changing the value of a variable which used a default value set by cubicweb-ctl create
  • changing the configuration of an instance with limited intervention from the local sysadmin (because asking him to hand edit the config file is error prone): he just has to deploy the new release and run cubicweb-ctl upgrade
  • fixing issues caused by settings in the all-in-one.conf file (e.g. changing the value of max-post-length)

OSCON 2010 - Data freedom and the semantic web

2010/07/29 by Sandrine Ribeau

I presented CubicWeb at OSCON 2010. I could only stay for a day and I did not get a chance to see a lot of talks, but judging from the conference schedule it seems only a few of them were related to making data available on the web. I will focus on these talks, for they are very relevant to us who are building the semantic web.

http://assets.en.oreilly.com/1/event/45/oscon2010_125x125.jpg

I highly encourage you to watch this video of Stormy Peters, "Is Your Data Free?". It addresses the issue of the privacy of data that you think belongs to you but actually doesn't. This is exactly what is behind the CubicWeb design: build your own web of data in a permission based environment in order to preserve your privacy.

http://wiki.freebase.com/skins/freebaseUpdate/freebaselogo.png

Open source, Open data presented by the Freebase folk, makes a very interesting parallel between open source and open data raising the problematic of versioning open data and providing quality data. There are methodologies and tools for open source software to ensure well designed and reliable code. There is absolutely nothing so far that could handle properly data versioning and data quality assurance. That is the biggest concern freebase has and through this talk they asked for help from the open source community so that more people would get involved in finding solutions to serve open data.

An attendee raised an interesting question about the format that everybody would agree to use to represent the data. I was surprised by the answer. It seems that so far they do not believe that this is a concern, not to say they don't care, but almost. For freebase, the main concern and most challenging part of the data representation is to have a unique identifier. I am not quite sure I agree on that part. Yes, this is important, even mandatory, but there is also the need to define or use a known format to represent this data, (RDF for example) so that we can source this data. To be semantic data, it needs to be both identifiable and readable. And I do not see the point of publishing data on the web if it is not ready to use.

Just for fun, look at Rewrite or Refactor: When to Declare Technical Bankruptcy, it might sounds familiar to you...

CubicWeb presentation went well, an interested audience which was very happy to see that we could aggregate multiple types of sources in a CubicWeb application. Of course, it would be even better if we would support an RDF source such as dbpedia: don't worry that's going to happen. Also what raised an interest is the semantic views already integrated in the framework such as SIOC, OWL, FOAF, DOAP that you can find in blog entries (sioc), schema (owl), user (foaf), project (doap).

 

RDF Resource Description Framework Icon OWL Button - microformats JSON - RSS dublincore DOAP SIOC - FOAF

 

By providing a platform for using data from multiple sources and publishing semantic data, CubicWeb is already a piece of the web of open data!


Building my photos web site with CubicWeb part IV: let's make it more user friendly

2010/07/13 by Sylvain Thenault

Step 0: updating code to CubicWeb 3.9 / cubicweb-file 1.9

CubicWeb 3.9 brings several improvements that we'll want to use, and the 1.9 version of the file cube has a major change: the Image type has been dropped in favor of an IImage adapter that makes code globally much cleaner (although this is not directly visible here). So the first thing to do is to upgrade our cube to the 3.9 API. As CubicWeb releases are mostly backward compatible, this is not mandatory but it's easier to follow changes as they come than having a huge upgrade to do at some point. Also, this remove deprecation warnings which are a bit tedious...

Since we only have very few lines of code, this step is pretty simple. Actually the main thing we have to do is to upgrade our schema, to remove occurrences of the Image type or replace them by the File type. Here is the (striped) diff:

 class comments(RelationDefinition):
     subject = 'Comment'
-    object = ('File', 'Image')
+    object = 'File'
     cardinality = '1*'
     composite = 'object'

 class tags(RelationDefinition):
     subject = 'Tag'
-    object = ('File', 'Image')
+    object = 'File'

 class displayed_on(RelationDefinition):
     subject = 'Person'
-    object = 'Image'
+    object = 'File'

 class situated_in(RelationDefinition):
-    subject = 'Image'
+    subject = 'File'
     object = 'Zone'

 class filed_under(RelationDefinition):
-    subject = ('File', 'Image')
+    subject = 'File'
     object = 'Folder'

 class visibility(RelationDefinition):
-    subject = ('Folder', 'File', 'Image', 'Comment')
+    subject = ('Folder', 'File', 'Comment')
     object = 'String'
     constraints = [StaticVocabularyConstraint(('public', 'authenticated',
                                                'restricted', 'parent'))]

 class may_be_readen_by(RelationDefinition):
-    subject = ('Folder', 'File', 'Image', 'Comment',)
+    subject = ('Folder', 'File', 'Comment',)
     object = 'CWUser'


-from cubes.file.schema import File, Image
+from cubes.file.schema import File

 File.__permissions__ = VISIBILITY_PERMISSIONS
-Image.__permissions__ = VISIBILITY_PERMISSIONS

Now, let's set the dependency in the __pkginfo__ file. As 3.8 simplifies this file, we can merge __depends_cubes__ (as introduced in the first blog of this series) with __depends__ to get the following result:

__depends__ = {'cubicweb': '>= 3.9.0',
               'cubicweb-file': '>= 1.9.0',
               'cubicweb-folder': None,
               'cubicweb-person': None,
               'cubicweb-zone': None,
               'cubicweb-comment': None,
               'cubicweb-tag': None,
               }

If your cube is packaged for debian, it's a good idea to update the debian/control file at the same time, so you won't forget it.

That's it for the API update, CubicWeb and cubicweb-file will handle other stuff for us. Easy, no?

We can now start some more fun stuff...

Step 1: let's improve site's usability for our visitors

The first thing I've noticed is that people to whom I send links to photos with some login/password authentication get lost, because they don't grasp they have to login by clicking on the 'authenticate' link. That's probably because they only get a 404 when trying to access an unauthorized folder, and the site doesn't make clear that 1. you're not authenticated, 2. you could get more content by authenticating yourself.

So, to improve this situation, I decided that I should:

  • make a login box appears for anonymous, so they see at a first glance a place to put the login / password information I provided
  • customize the 404 page, proposing to login to anonymous.

Here is the code, samples from my cube's views.py file:

from cubicweb.selectors import is_instance
from cubicweb.web import box
from cubicweb.web.views import basetemplates, error

class FourOhFour(error.FourOhFour):
    __select__ = error.FourOhFour.__select__ & anonymous_user()

    def call(self):
        self.w(u"<h1>%s</h1>" % self._cw._('this resource does not exist'))
        self.w(u"<p>%s</p>" % self._cw._('have you tried to login?'))

class LoginBox(box.BoxTemplate, basetemplates.LogFormView):
    """display a box containing links to all startup views"""
    __regid__ = 'sytweb.loginbox'
    __select__ = box.BoxTemplate.__select__ & anonymous_user()

    title = _('Authenticate yourself')
    order = 70

    def call(self, **kwargs):
        self.w(u'<div class="sideBoxTitle"><span>%s</span></div>' % self.title)
        self.w(u'<div class="sideBox"><div class="sideBoxBody">')
        self.login_form('loginBox')
        self.w(u'</div></div>')

The first class provides a new specific implementation of the default page you get on a 404 error, to display an explicit message for anonymous users.

Note

Thanks to the selection mechanism, it will be selected for anonymous users, since the additional anonymous_user() selector gives it a higher score than the default, and not for authenticated since this selector will return 0 otherwise (hence the object won't be selectable).

The second class defines a simple box, that will be displayed by default with boxes in the left column, thanks to default box.BoxTemplate'selector. The HTML is written to match default CubicWeb boxes style. To get the actual login form, we inherit from the LogFormView view which provides a login_form method (handling some stuff under the cover for us, hence the multiple inheritance), that we simply have to call to get the form's HTML.

login box / 404 screenshot

The login box and the custom 404 page for an anonymous visitor (translated in french)

Step 2: providing a custom index page

Another thing we can easily do to improve the site is... A nicer index page (e.g. the first page you get when accessing the web site)! The default one is quite intimidating (that should change in a near future). I will provide a much simpler index page that simply list available folders (e.g. photo albums in that site).

from cubicweb.web.views import startup

class IndexView(startup.IndexView):
    def call(self, **kwargs):
        self.w(u'<div>\n')
        if self._cw.cnx.anonymous_connection:
            self.w(u'<h4>%s</h4>\n' % self._cw._('Public Albums'))
        else:
            self.w(u'<h4>%s</h4>\n' % self._cw._('Albums for %s') % self._cw.user.login)
        self._cw.vreg['views'].select('tree', self._cw).render(w=self.w)
        self.w(u'</div>\n')

def registration_callback(vreg):
    vreg.register_all(globals().values(), __name__, (IndexView,))
    vreg.register_and_replace(IndexView, startup.IndexView)

As you can see, we override the default index view found in cubicweb.web.views.startup, getting back nothing but its identifier and selector since we override the top level view's call method.

Note

In that case, we want our index view to replace the existing one. We implement the registration_callback function, in which we code a registeration of everything in the module but our IndexView, then we register it instead of the former index view.

Also, we added a title that tries to make it more evident that the visitor is authenticated, or not. Hopefully people will get it now!

default index page screenshot

The default index page

new index page screenshot

Our simpler, less intimidating, index page (still translated in french)

Step 3: more navigation improvements

There are still a few problems I want to solve...

  • Images in a folder are displayed in a somewhat random order. I would like to have them ordered by file's name (which will usually, inside a given folder, also result ordering photo by their date and time)
  • When clicking a photo from an album view, you've to get back to the gallery view to go to the next photo. This is pretty annoying...
  • Also, when viewing an image, there is no clue about the folder to which this image belongs to.

I will first try to explain the ordering problem. By default, when accessing related entities by using the ORM's API, you should get them ordered according to the target's class fetch_order. If we take a look at the file cube's schema, we can see:

class File(AnyEntity):
    """customized class for File entities"""
    __regid__ = 'File'
    fetch_attrs, fetch_order = fetch_config(['data_name', 'title'])

By default, fetch_config will return a fetch_order method that will order on the first attribute in the list. We could expect to get files ordered by their name. But we don't. What's up doc ?

The problem is that files are related to folder using the filed_under relation. And that relation is ambiguous, eg it can lead to File entities, but also to Folder entities. In such a case, since both entity types don't share the attribute on which we want to sort, we'll get linked entities sorted on a common attribute (usually modification_date).

To fix this, we have to help the ORM. We'll do this in the method from the ITree folder's adapter, used in the folder's primary view to display the folder's content. Here's the code that I've put in our cube's entities.py file, since it's more logical stuff than view stuff:

from cubes.folder import entities as folder

class FolderITreeAdapter(folder.FolderITreeAdapter):

    def different_type_children(self, entities=True):
        rql = self.entity.cw_related_rql(self.tree_relation,
                                         self.parent_role, ('File',))
        rset = self._cw.execute(rql, {'x': self.entity.eid})
        if entities:
            return list(rset.entities())
        return rset

def registration_callback(vreg):
    vreg.register_and_replace(FolderITreeAdapter, folder.FolderITreeAdapter)

As you can see, we simply inherit from the adapter defined in the folder cube, then we override the different_type_children method to give a clue to the ORM's cw_related_rql method, that will generate the rql to get entities related to the folder by the filed_under relation (the value of the tree_relation attribute). The clue is that we only want to consider the File target entity type. By doing this, we remove the ambiguity and get back a RQL query that correctly orders files by their data_name attribute.

Note

  • Adapters have been introduced in CubicWeb 3.9 / cubicweb-folder 1.8.
  • As seen earlier, we want to replace the folder's ITree adapter by our implementation, hence the custom registration_callback method.

Ouf. That one was tricky...

Now the easier parts. Let's start by adding some links on the file's primary view to see the previous / next image in the same folder. CubicWeb provides a component that do exactly that. To make it appear, it has to be adaptable to the IPrevNext interface. Here is the related code sample, extracted from our cube's views.py file:

from cubicweb.selectors import is_instance
from cubicweb.web.views import navigation


class FileIPrevNextAdapter(navigation.IPrevNextAdapter):
    __select__ = is_instance('File')

    def previous_entity(self):
        rset = self._cw.execute('File F ORDERBY FDN DESC LIMIT 1 WHERE '
                                'X filed_under FOLDER, F filed_under FOLDER, '
                                'F data_name FDN, X data_name > FDN, X eid %(x)s',
                                {'x': self.entity.eid})
        if rset:
            return rset.get_entity(0, 0)

    def next_entity(self):
        rset = self._cw.execute('File F ORDERBY FDN ASC LIMIT 1 WHERE '
                                'X filed_under FOLDER, F filed_under FOLDER, '
                                'F data_name FDN, X data_name < FDN, X eid %(x)s',
                                {'x': self.entity.eid})
        if rset:
            return rset.get_entity(0, 0)

The IPrevNext interface implemented by the adapter simply consist of the previous_entity / next_entity methods, that should respectively return the previous / next entity or None. We make an RQL query to get files in the same folder, ordered similarly (eg by their data_name attribute). We set ascendant/descendant ordering and a strict comparison with current file's name (the "X" variable representing the current file).

Note

  • Former implements selector should be replaced by is_instance or adaptable selector with CubicWeb >= 3.9. In our case, is_instance is used to tell our adapter to get File entities.

Notice that this query supposes we wont have two files of the same name in the same folder. Fixing this is out of the scope of this blog. And as I would like to have at some point a smarter, context sensitive previous/next entity, I'll probably never fix this query (though if I had to, I would probably choose to add a constraint in the schema so that we can't add two files of the same name in a folder).

One more thing: by default, the component will be displayed below the content zone (the one with the white background). You can change this in the site's properties through the ui, but you can also change the default value in the code by modifying the context attribute of the component:

navigation.NextPrevNavigationComponent.context = 'navcontentbottom'

Note

context may be one of 'navtop', 'navbottom', 'navcontenttop' or 'navcontentbottom'; the first two being outside the main content zone, the two others inside it.

screenshot of the previous/next entity component

The previous/next entity component, at the bottom of the main content zone.

Now, the only remaining stuff in my todo list is to see the file's folder. I'll use the standard breadcrumb component to do so. Similarly as what we've seen before, this component is controlled by the IBreadCrumbs interface, so we'll have to provide a custom adapter for File entity, telling the a file's parent entity is its folder:

from cubicweb.web.views import ibreadcrumbs

class FileIBreadCrumbsAdapter(ibreadcrumbs.IBreadCrumbsAdapter):
    __select__ = is_instance('File')

    def parent_entity(self):
        if self.entity.filed_under:
            return self.entity.filed_under[0]

In this case, we simply use the attribute notation provided by the ORM to get the folder in which the current file (e.g. self.entity) is located.

Note

The IBreadCrumbs interface is a breadcrumbs method, but the default IBreadCrumbsAdapter provides a default implementation for it that will look at the value returned by its parent_entity method. It also provides a default implementation for this method for entities adapting to the ITree interface, but as our File doesn't, we've to provide a custom adapter.

screenshot of the breadcrumb component

The breadcrumb component when on a file entity, now displaying parent folder.

Step 4: preparing the release and migrating the instance

Now that greatly enhanced our cube, it's time to release it and to upgrade production site. I'll probably detail that process later, but I currently simply transfer the new code to the server running the web site.

However, there's some commands to get things done properly... First, as I've added some translatable string, I have to run:

$ cubicweb-ctl i18ncube sytweb

To update the cube's gettext catalogs (the '.po' files under the cube's i18n directory). Once the above command is executed, I'll then update translations.

To see if everything is ok on my test instance, I do:

$ cubicweb-ctl i18ninstance sytweb
$ cubicweb-ctl start -D sytweb

The first command compile i18n catalogs (e.g. generates '.mo' files) for my test instance. The second command starts it in debug mode, so I can open my browser and navigate through the web site to see if everything is ok...

Note

In the 'cubicweb-ctl i18ncube' command, sytweb refers to the cube, while in the two other, it refers to the instance (if you can't see the difference, reread CubicWeb's concept chapter !).

Once I've checked it's ok, I simply have to bump the version number in the __pkginfo__ module to trigger a migration once I'll have updated the code on the production site. I can check the migration is also going fine, by first restoring a dump from the production site, then upgrading my test instance.

To generate a dump from the production site:

$ cubicweb-ctl db-dump sytweb
pg_dump -Fc --username=syt --no-owner --file /home/syt/etc/cubicweb.d/sytweb/backup/tmpYIN0YI/system sytweb
-> backup file /home/syt/etc/cubicweb.d/sytweb/backup/sytweb-2010-07-13_10-22-40.tar.gz

I can now get back the dump file ('sytweb-2010-07-13_10-22-40.tar.gz') to my test machine (using scp for instance) to restore it and start migration:

$ cubicweb-ctl db-restore sytweb sytweb-2010-07-13_10-22-40.tar.gz
$ cubicweb-ctl upgrade sytweb

You'll have to answer some questions, as we've seen in an earlier post.

Now that everything is tested, I can transfer the new code to the production server, apt-get upgrade cubicweb 3.9 and its dependencies, and eventually upgrade the production instance.

Conclusion

This is a somewhat long post that starts showing you the way CubicWeb provides a highly configurable user interface, as well as powerful and reusable components. And there are a lot of others like those!

So see you next time for part V, where we'll probably want to do more ui stuff!