[migration] improve fix cwuri progress bar
* Use the progress context manager,
* Adds a title
* Informs that operation have been partially committed.
--- a/misc/migration/3.10.9_Any.py Thu Mar 24 13:24:26 2011 +0100
+++ b/misc/migration/3.10.9_Any.py Thu Mar 24 13:25:57 2011 +0100
@@ -8,21 +8,21 @@
commit()
if confirm('fix existing cwuri?'):
- from logilab.common.shellutils import ProgressBar
+ from logilab.common.shellutils import progress
from cubicweb.server.session import hooks_control
rset = rql('Any X, XC WHERE X cwuri XC, X cwuri ~= "%/eid/%"')
- if sys.stdout.isatty():
- pb = ProgressBar(nbops=rset.rowcount, size=70)
- else:
- pb = None
- with hooks_control(session, session.HOOKS_DENY_ALL, 'integrity'):
- for i, e in enumerate(rset.entities()):
- e.set_attributes(cwuri=e.cwuri.replace('/eid', ''))
- if i % 100: # commit every 100 entities to limit memory consumption
- commit(ask_confirm=False)
- if pb is not None:
+ title = "%i entites to fix" % len(rset)
+ nbops = rset.rowcount
+ enabled = interactive_mode
+ with progress(title=title, nbops=nbops, size=30, enabled=enabled) as pb:
+ with hooks_control(session, session.HOOKS_DENY_ALL, 'integrity'):
+ for i, e in enumerate(rset.entities()):
+ e.set_attributes(cwuri=e.cwuri.replace('/eid', ''))
+ if i % 100: # commit every 100 entities to limit memory consumption
+ pb.text = "%i committed" % i
+ commit(ask_confirm=False)
pb.update()
- commit(ask_confirm=False)
+ commit(ask_confirm=False)
try:
from cubicweb import devtools