Commits

Marcin Kuzminski committed ddae7c5 Merge

merge with command fixes

Comments (0)

Files changed (2)

akhet/paster_templates/akhet/+package+/scripts/__init__.py

+
+def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
+    while True:
+        ok = raw_input(prompt)
+        if ok in ('y', 'ye', 'yes'):
+            return True
+        if ok in ('n', 'no', 'nop', 'nope'):
+            return False
+        retries = retries - 1
+        if retries < 0:
+            raise IOError
+        print complaint

akhet/paster_templates/akhet/+package+/scripts/create_db.py_tmpl

 Run this once after installing the application::
 
     python -m {{package}}.scripts.create_db development.ini
+    python -m {{package}}.scripts.create_db development.ini drop_all    
 """
 import logging.config
 import sys
 import transaction
 
 import sqlalchemy
+import sqlahelper
 import {{package}}.models as models
 
+from crm.scripts import ask_ok
+
 def main():
-    if len(sys.argv) != 2:
-        sys.exit("Usage: python -m {{package}}.scripts.create_db INI_FILE")
+    if len(sys.argv) < 2:
+        sys.exit("Usage: python -m {{package}}.scripts.create_db INI_FILE [drop_all]")
     ini_file = sys.argv[1]
+    dropfirst = False
+    if len(sys.argv) == 3:
+        dropfirst = sys.argv[2] == 'drop_all'    
     logging.config.fileConfig(ini_file)
     log = logging.getLogger(__name__)
     app = get_app(ini_file, "myapp")
     sqlahelper.add_engine(engine)
     
     tables = list()
-    
+    if dropfirst:
+        upgrade = ask_ok('You are about to perform db creation, and '
+                         'have choosen to drop all tables'
+                         'Continue ? [y/n]')
+        if not upgrade:
+            sys.exit('Nothing done')
+
+        models.BaseCrm.metadata.drop_all()
+            
     # Check for any existing tables, and add only tables that are not present
     # in current database skipping those already created
     for table in models.Base.metadata.sorted_tables: