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 @@ ...@@ -23,8 +23,13 @@
R. Le Gac -- Feb 2017 R. Le Gac -- Feb 2017
""" """
import re
import sys import sys
from gluon.storage import Storage from gluon.storage import Storage
from gluon.tools import PluginManager
def fix_dbname(s): def fix_dbname(s):
...@@ -52,15 +57,22 @@ if __name__ == "__main__": ...@@ -52,15 +57,22 @@ if __name__ == "__main__":
event.Core.define_tables(db, T) event.Core.define_tables(db, T)
event.Report.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(): for row in db(db.lists.id > 0).select():
rep = raw_input("Migrate '%s' [y/N]: " % row.name) rep = raw_input("Migrate '%s' [y/N]: " % row.name)
if rep.lower() != "y": if rep.lower() != "y":
continue continue
# copy and fix
list2 = Storage(name=row.name, list2 = Storage(name=row.name,
title=row.title, title=row.title,
definition=row.definition, definition=row.definition,
id_events=1,
group_field=row.group_field, group_field=row.group_field,
sorters=row.sorters, sorters=row.sorters,
columns=row.columns, columns=row.columns,
...@@ -72,7 +84,25 @@ if __name__ == "__main__": ...@@ -72,7 +84,25 @@ if __name__ == "__main__":
list2.group_field = fix_dbname(list2.group_field) list2.group_field = fix_dbname(list2.group_field)
list2.sorters = [fix_dbname(el) for el in list2.sorters] 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.lists2[0] = list2
db.commit() db.commit()
print "\tNew %s list created" % row.name
sys.exit(0) 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