summaryrefslogtreecommitdiff
path: root/yaksh/scripts/cli.py
diff options
context:
space:
mode:
authorPrabhu Ramachandran2017-03-17 17:51:42 +0530
committerGitHub2017-03-17 17:51:42 +0530
commitc0928d64d04c010ff34538f50a3c02a37b20b235 (patch)
tree34468f85ef76df6e92291039f0282ed6241b9146 /yaksh/scripts/cli.py
parent6ff0e4213ab1685200b71ad6bcc1fcdabd6ebf78 (diff)
parent39fcbfd9b8d4072482b1dee2532ef66c64ad630a (diff)
downloadonline_test-c0928d64d04c010ff34538f50a3c02a37b20b235.tar.gz
online_test-c0928d64d04c010ff34538f50a3c02a37b20b235.tar.bz2
online_test-c0928d64d04c010ff34538f50a3c02a37b20b235.zip
Merge pull request #245 from prathamesh920/migrations-in-script
Migrations in script
Diffstat (limited to 'yaksh/scripts/cli.py')
-rw-r--r--yaksh/scripts/cli.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/yaksh/scripts/cli.py b/yaksh/scripts/cli.py
index 4a58e48..a1a49ee 100644
--- a/yaksh/scripts/cli.py
+++ b/yaksh/scripts/cli.py
@@ -101,10 +101,6 @@ def create_demo(project_name='yaksh_demo', project_dir=CUR_DIR):
'fixture_dir': fixture_dir})
urls_template_path = path.join(TEMPLATE_DIR, 'demo_urls.py')
urls_target_path = path.join(project_path, 'demo_urls.py')
- command = ("python ../manage.py migrate --run-syncdb "
- "--noinput --settings={0}.demo_settings").format(
- project_name)
-
loaddata_command = ("python ../manage.py loaddata "
"--settings={0}.demo_settings {1}").format(
project_name, fixture_path)
@@ -115,14 +111,18 @@ def create_demo(project_name='yaksh_demo', project_dir=CUR_DIR):
)
# Create demo_urls file
_render_demo_files(urls_template_path, urls_target_path)
- # Run syncdb
- subprocess.call(
- "{0}; {1}".format(command, loaddata_command), shell=True
- )
+ # Create database and load initial data
+ command_path = path.join(top_dir, 'manage.py')
+ _check_migrations(project_name, command_path)
+ _migrate(project_name, command_path)
+ subprocess.call(loaddata_command, shell=True)
def run_demo(project_name, top_dir):
with _chdir(top_dir):
+ command_path = path.join(top_dir, 'manage.py')
+ _check_migrations(project_name, command_path)
+ _migrate(project_name, command_path)
command = ("python manage.py runserver "
"--settings={0}.demo_settings").format(project_name)
subprocess.call(command, shell=True)
@@ -136,6 +136,18 @@ def run_server(args=None):
print("Error: {0}\nExiting yaksh code server".format(e))
+def _check_migrations(project_name, command_path):
+ migrations = ("python {0} makemigrations --settings={1}.demo_settings"
+ ).format(command_path, project_name)
+ subprocess.call(migrations, shell=True)
+
+
+def _migrate(project_name, command_path):
+ migrate = ("python {0} migrate --settings={1}.demo_settings"
+ ).format(command_path, project_name)
+ subprocess.call(migrate, shell=True)
+
+
def _render_demo_files(template_path, output_path, context=None):
with open(template_path, 'r') as template_file:
content = template_file.read()