[Cubicweb] easier transition from one cw version to the next

Nicolas Chauvat nicolas.chauvat at logilab.fr
Mon Jun 18 22:53:53 CEST 2012


Hi List,

Discussing on friday with the author of http://coccinelle.lip6.fr/ got
me thinking that we could apply the same idea to migrating away from
deprecated functions when upgrading cubes to the latest cw version.

A semantic patch http://coccinelle.lip6.fr/sp.php could be written for
each deprecation warning and applied to the code base.

That would require to work on porting Coccinelle to Python and I do
not have the time to do it. So I tried to get something to work using
grep. Here it is:

# -*- coding: utf-8 -*-

"""Run with:
python cw-help-migrate.py path/to/cubicweb path/to/your/cube(s)
"""

import sys
import subprocess
from pprint import pprint

cmd = "grep -i '@deprecated' `find %s -name '*.py'` -A1 -B0" %
sys.argv[1]
stdout = subprocess.Popen(cmd, shell=True,
stdout=subprocess.PIPE).stdout
deprecated = {}
dep_seen = ''
for line in stdout:
    if dep_seen:
        if line[idx:idx+4] == 'def ' and line[idx+4:idx+6] != '__':
            deprecated.setdefault(line[idx+4:line.find('(', idx)],
	    dep_seen)
        dep_seen = ''
    else:
        idx = line.find('@deprecated')
        if idx > 0:
            dep_seen = line[idx:]
        else:
            dep_seen = ''
#pprint(sorted(deprecated))

cmd = "grep -n '%%s(' `find %s -name '*.py'`" % sys.argv[2]
for funcname, msg in sorted(deprecated.items()):
    data = subprocess.Popen(cmd % funcname, shell=True,
    stdout=subprocess.PIPE).stdout.readlines()
    if data:
        print '**',funcname,msg,'\n',''.join(data)

# ---------------------

I am sorry to say it does not work for it raises tons of false
positives that will be difficult to remove without getting info from
the AST or type inference or the preceding lines of code.

Well, at least I can say I tried and shared the idea in the hope
someone else would pick it up :)

-- 
Nicolas Chauvat

logilab.fr - services en informatique scientifique et gestion de connaissances  



More information about the Cubicweb mailing list