Commit a96ea15c authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Polish migrate-list-070.py

parent d340b23c
......@@ -23,8 +23,13 @@
R. Le Gac -- Feb 2017
"""
import re
import sys
from gluon.storage import Storage
from gluon.tools import PluginManager
def fix_dbname(s):
......@@ -52,15 +57,22 @@ if __name__ == "__main__":
event.Core.define_tables(db, T)
event.Report.define_tables(db, T)
rex_id_events = re.compile("\.id_events *={1,2} *(\d+)")
sources = PluginManager("event").event.sources.keys()
sources.sort()
for row in db(db.lists.id > 0).select():
rep = raw_input("Migrate '%s' [y/N]: " % row.name)
if rep.lower() != "y":
continue
# copy and fix
list2 = Storage(name=row.name,
title=row.title,
definition=row.definition,
id_events=1,
group_field=row.group_field,
sorters=row.sorters,
columns=row.columns,
......@@ -72,7 +84,25 @@ if __name__ == "__main__":
list2.group_field = fix_dbname(list2.group_field)
list2.sorters = [fix_dbname(el) for el in list2.sorters]
# find the event identifier
m = rex_id_events.search(row.conditions)
if m:
list2.id_events = int(m.group(1))
# setup the source
print "\tSelect the source: "
for i in xrange(len(sources)):
print "\t%5i %s" % (i, sources[i])
rep = raw_input("\tEnter a value [i/N]: ")
if not rep.isdigit():
continue
list2.source = sources[int(rep)]
# create
db.lists2[0] = list2
db.commit()
print "\tNew %s list created" % row.name
sys.exit(0)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment