From 516284689fa9daa9b4487e4c5683997111df6049 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 15 Jun 2015 18:23:29 +0530 Subject: Modify installer script and cleanup; - Add __init__.py - Add templates dir to MANIFEST - Add persistent store for project details - Modify initial_data.json - Fix imports Conflicts: testapp/templates/demo_settings.py --- testapp/scripts/__init__.py | 0 testapp/scripts/project_detail.py | 2 + testapp/scripts/vimarsh.py | 127 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 testapp/scripts/__init__.py create mode 100644 testapp/scripts/project_detail.py create mode 100644 testapp/scripts/vimarsh.py (limited to 'testapp/scripts') diff --git a/testapp/scripts/__init__.py b/testapp/scripts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/testapp/scripts/project_detail.py b/testapp/scripts/project_detail.py new file mode 100644 index 0000000..583e9f4 --- /dev/null +++ b/testapp/scripts/project_detail.py @@ -0,0 +1,2 @@ +NAME = None +PATH = None diff --git a/testapp/scripts/vimarsh.py b/testapp/scripts/vimarsh.py new file mode 100644 index 0000000..863193a --- /dev/null +++ b/testapp/scripts/vimarsh.py @@ -0,0 +1,127 @@ +import subprocess +import contextlib +import os +from os import path +import argparse +from django.conf import settings +from django.core import management +from django.template import Template, Context, loader + +from project_detail import NAME, PATH + +CUR_DIR = os.getcwd() +SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) +PARENT_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir)) +TEMPLATE_DIR = path.join(PARENT_DIR, 'templates') + +def main(): + #Parse command-line to obtain the arguments and/or options + help_msg = ("Enter the subcommand to be executed.\n" + "Available subcommands:\n" + " - create_demo [destination-path]\n" + " - run_demo") + + parser = argparse.ArgumentParser(prog="vimarsh", + usage="vimarsh.py subcommand [args]", + formatter_class=argparse.RawTextHelpFormatter) + parser.add_argument("subcommand", type=str, nargs='+', help=help_msg) + args = parser.parse_args() + + if args.subcommand[0] == "create_demo": + if len(args.subcommand) > 3 or len(args.subcommand) <= 1: + parser.print_help() + elif len(args.subcommand) == 3: + project_name = args.subcommand[1] + project_dir = args.subcommand[2] + create_demo(args.subcommand[1], args.subcommand[2]) + else: + project_name = args.subcommand[1] + create_demo(args.subcommand[1]) + + elif args.subcommand[0] == "run_demo": + if len(args.subcommand) != 1: + parser.print_help() + else: + try: + run_demo(NAME, PATH) + except Exception, e: + if not NAME or not PATH: + print "Error: Unable to find Project Name and Path variables\n" + else: + print "Error: ", e, "\n" + parser.print_help() + + else: + parser.print_help() + + +def create_demo(project_name='vimarsh_demo', project_dir=None): + try: + management.call_command('startproject', project_name, project_dir) + print "Demo Django project '{0}' created at '{1}'" + except Exception, e: + print "Error: ", e, "\nExiting Vimarsh Installer" + + if project_dir is None: + top_dir = path.join(os.getcwd(), project_name) + else: + top_dir = project_dir + + project_path = path.join(top_dir, project_name) + # Store project details + _set_project_details(project_name, top_dir) + + with _chdir(project_path): + root_urlconf = "{0}.{1}".format(project_name, 'demo_urls') + settings_template_path = path.join(TEMPLATE_DIR, 'demo_settings.py') + settings_target_path = path.join(project_path, 'demo_settings.py') + settings_context = Context({'project_name': project_name, # 'custom_apps': custom_apps, + 'root_urlconf': root_urlconf}) + urls_template_path = path.join(TEMPLATE_DIR, 'demo_urls.py') + urls_target_path = path.join(project_path, 'demo_urls.py') + command = ("python ../manage.py syncdb " + "--noinput --settings={0}.demo_settings").format(project_name) + + # Create demo_settings file + _render_demo_files(settings_template_path, settings_target_path, settings_context) + # Create demo_urls file + _render_demo_files(urls_template_path, urls_target_path) + # Run syncdb + subprocess.call(command, shell=True) + +def run_demo(project_name, top_dir): + with _chdir(top_dir): + project_path = path.join(top_dir, 'manage.py') + command = ("python manage.py runserver " + "--settings={0}.demo_settings").format(project_name) + subprocess.call(command, shell=True) + +def _set_project_details(project_name, top_dir): + file_path = path.join(SCRIPT_DIR, 'project_detail.py') + detail = "NAME ='{0}'\nPATH ='{1}'".format(project_name, top_dir) + with open(file_path, 'w') as data_store: + data_store.write(detail) + +def _render_demo_files(template_path, output_path, context=None): + with open(template_path, 'r') as template_file: + content = template_file.read() + if context: + content = content.decode('utf-8') + template = Template(content) + content = template.render(context) + content = content.encode('utf-8') + + with open(output_path, 'w') as new_file: + new_file.write(content) + +@contextlib.contextmanager +def _chdir(path): + starting_directory = os.getcwd() + try: + os.chdir(path) + yield + finally: + os.chdir(starting_directory) + +if __name__ == '__main__': + main() -- cgit From 6399ddce69a71f87a2e164a2b6e77a2f105f4741 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 22 Jun 2015 17:09:30 +0530 Subject: - Install script: Add subcommands - Install script: Add code server launcher - Add requirements.txt - Edit README to fix changes/errors - Remove jquery v1.11.3 and add v1.4.2 - Edit initial_data.json --- testapp/scripts/vimarsh.py | 92 +++++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 37 deletions(-) (limited to 'testapp/scripts') diff --git a/testapp/scripts/vimarsh.py b/testapp/scripts/vimarsh.py index 863193a..07966d8 100644 --- a/testapp/scripts/vimarsh.py +++ b/testapp/scripts/vimarsh.py @@ -1,8 +1,11 @@ +from __future__ import print_function + import subprocess import contextlib import os from os import path import argparse +from importlib import import_module from django.conf import settings from django.core import management from django.template import Template, Context, loader @@ -16,51 +19,59 @@ TEMPLATE_DIR = path.join(PARENT_DIR, 'templates') def main(): #Parse command-line to obtain the arguments and/or options - help_msg = ("Enter the subcommand to be executed.\n" - "Available subcommands:\n" - " - create_demo [destination-path]\n" - " - run_demo") - - parser = argparse.ArgumentParser(prog="vimarsh", - usage="vimarsh.py subcommand [args]", - formatter_class=argparse.RawTextHelpFormatter) - parser.add_argument("subcommand", type=str, nargs='+', help=help_msg) + # create top-level parser object + parser = argparse.ArgumentParser(prog="vimarsh") + subparser = parser.add_subparsers(dest="subcommand") + + # create parser for the "create_demo" subcommand + create_demo_parser = subparser.add_parser("create_demo", + help="Create a new demo Django project") + create_demo_parser.add_argument("project_name", type=str, + help="name of demo Django project") + create_demo_parser.add_argument("-p", "--path", type=str, + help="path of demo Django project") + + # create parser for the "run_demo" subcommand + run_demo_parser = subparser.add_parser("run_demo", + help="Initialise django server and run the demo project") + + # create parser for the "run_code_server" subcommand + code_server_parser = subparser.add_parser("run_code_server", + help="Initialise Vimarsh code server") + code_server_parser.add_argument("-P", "--ports", type=int, nargs='+', + help="code server ports") + args = parser.parse_args() - if args.subcommand[0] == "create_demo": - if len(args.subcommand) > 3 or len(args.subcommand) <= 1: - parser.print_help() - elif len(args.subcommand) == 3: - project_name = args.subcommand[1] - project_dir = args.subcommand[2] - create_demo(args.subcommand[1], args.subcommand[2]) + if args.subcommand == "create_demo": + if args.path: + create_demo(args.project_name, args.path) else: - project_name = args.subcommand[1] - create_demo(args.subcommand[1]) - - elif args.subcommand[0] == "run_demo": - if len(args.subcommand) != 1: - parser.print_help() + create_demo(args.project_name) + + elif args.subcommand == "run_demo": + try: + run_demo(NAME, PATH) + except Exception as e: + if not NAME or not PATH: + print("Error: Unable to find Project Name or Path variables\n") + else: + print("Error: {0}\n".format(e)) + subparser.print_help() + + elif args.subcommand == "run_code_server": + if args.ports: + run_server(args.ports) else: - try: - run_demo(NAME, PATH) - except Exception, e: - if not NAME or not PATH: - print "Error: Unable to find Project Name and Path variables\n" - else: - print "Error: ", e, "\n" - parser.print_help() - - else: - parser.print_help() - + run_server() -def create_demo(project_name='vimarsh_demo', project_dir=None): +def create_demo(project_name='vimarsh_demo', project_dir=CUR_DIR): try: management.call_command('startproject', project_name, project_dir) - print "Demo Django project '{0}' created at '{1}'" + print("Demo Django project '{0}' created at '{1}'".format(project_name, + project_dir)) except Exception, e: - print "Error: ", e, "\nExiting Vimarsh Installer" + print("Error: {0}\nExiting Vimarsh Installer".format(e)) if project_dir is None: top_dir = path.join(os.getcwd(), project_name) @@ -96,6 +107,13 @@ def run_demo(project_name, top_dir): "--settings={0}.demo_settings").format(project_name) subprocess.call(command, shell=True) +def run_server(): + try: + from testapp.exam import code_server + code_server.main() + except Exception as e: + print("Error: {0}\nExiting Vimarsh code server".format(e)) + def _set_project_details(project_name, top_dir): file_path = path.join(SCRIPT_DIR, 'project_detail.py') detail = "NAME ='{0}'\nPATH ='{1}'".format(project_name, top_dir) -- cgit From 483bc9008d4f510ee8db4ee06e07a6c6bde063ab Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Wed, 24 Jun 2015 18:32:06 +0530 Subject: - Move initial_fixtures to testapp/fixtures - Add fixtures path to demo_settings - Modify installer to include fixtures while creating proj --- testapp/scripts/vimarsh.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'testapp/scripts') diff --git a/testapp/scripts/vimarsh.py b/testapp/scripts/vimarsh.py index 07966d8..8b3e8b7 100644 --- a/testapp/scripts/vimarsh.py +++ b/testapp/scripts/vimarsh.py @@ -79,6 +79,7 @@ def create_demo(project_name='vimarsh_demo', project_dir=CUR_DIR): top_dir = project_dir project_path = path.join(top_dir, project_name) + fixture_dir = path.join(PARENT_DIR, 'fixtures') # Store project details _set_project_details(project_name, top_dir) @@ -86,8 +87,9 @@ def create_demo(project_name='vimarsh_demo', project_dir=CUR_DIR): root_urlconf = "{0}.{1}".format(project_name, 'demo_urls') settings_template_path = path.join(TEMPLATE_DIR, 'demo_settings.py') settings_target_path = path.join(project_path, 'demo_settings.py') - settings_context = Context({'project_name': project_name, # 'custom_apps': custom_apps, - 'root_urlconf': root_urlconf}) + settings_context = Context({'project_name': project_name, + 'root_urlconf': root_urlconf, + '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 syncdb " -- cgit From c261ae92e5d4578b4e36c32def862bec4c6692aa Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Fri, 28 Aug 2015 14:25:51 +0530 Subject: Change install script name --- testapp/scripts/vimarsh.py | 147 --------------------------------------------- testapp/scripts/yaksh.py | 147 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 147 deletions(-) delete mode 100644 testapp/scripts/vimarsh.py create mode 100644 testapp/scripts/yaksh.py (limited to 'testapp/scripts') diff --git a/testapp/scripts/vimarsh.py b/testapp/scripts/vimarsh.py deleted file mode 100644 index 8b3e8b7..0000000 --- a/testapp/scripts/vimarsh.py +++ /dev/null @@ -1,147 +0,0 @@ -from __future__ import print_function - -import subprocess -import contextlib -import os -from os import path -import argparse -from importlib import import_module -from django.conf import settings -from django.core import management -from django.template import Template, Context, loader - -from project_detail import NAME, PATH - -CUR_DIR = os.getcwd() -SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) -PARENT_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir)) -TEMPLATE_DIR = path.join(PARENT_DIR, 'templates') - -def main(): - #Parse command-line to obtain the arguments and/or options - # create top-level parser object - parser = argparse.ArgumentParser(prog="vimarsh") - subparser = parser.add_subparsers(dest="subcommand") - - # create parser for the "create_demo" subcommand - create_demo_parser = subparser.add_parser("create_demo", - help="Create a new demo Django project") - create_demo_parser.add_argument("project_name", type=str, - help="name of demo Django project") - create_demo_parser.add_argument("-p", "--path", type=str, - help="path of demo Django project") - - # create parser for the "run_demo" subcommand - run_demo_parser = subparser.add_parser("run_demo", - help="Initialise django server and run the demo project") - - # create parser for the "run_code_server" subcommand - code_server_parser = subparser.add_parser("run_code_server", - help="Initialise Vimarsh code server") - code_server_parser.add_argument("-P", "--ports", type=int, nargs='+', - help="code server ports") - - args = parser.parse_args() - - if args.subcommand == "create_demo": - if args.path: - create_demo(args.project_name, args.path) - else: - create_demo(args.project_name) - - elif args.subcommand == "run_demo": - try: - run_demo(NAME, PATH) - except Exception as e: - if not NAME or not PATH: - print("Error: Unable to find Project Name or Path variables\n") - else: - print("Error: {0}\n".format(e)) - subparser.print_help() - - elif args.subcommand == "run_code_server": - if args.ports: - run_server(args.ports) - else: - run_server() - -def create_demo(project_name='vimarsh_demo', project_dir=CUR_DIR): - try: - management.call_command('startproject', project_name, project_dir) - print("Demo Django project '{0}' created at '{1}'".format(project_name, - project_dir)) - except Exception, e: - print("Error: {0}\nExiting Vimarsh Installer".format(e)) - - if project_dir is None: - top_dir = path.join(os.getcwd(), project_name) - else: - top_dir = project_dir - - project_path = path.join(top_dir, project_name) - fixture_dir = path.join(PARENT_DIR, 'fixtures') - # Store project details - _set_project_details(project_name, top_dir) - - with _chdir(project_path): - root_urlconf = "{0}.{1}".format(project_name, 'demo_urls') - settings_template_path = path.join(TEMPLATE_DIR, 'demo_settings.py') - settings_target_path = path.join(project_path, 'demo_settings.py') - settings_context = Context({'project_name': project_name, - 'root_urlconf': root_urlconf, - '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 syncdb " - "--noinput --settings={0}.demo_settings").format(project_name) - - # Create demo_settings file - _render_demo_files(settings_template_path, settings_target_path, settings_context) - # Create demo_urls file - _render_demo_files(urls_template_path, urls_target_path) - # Run syncdb - subprocess.call(command, shell=True) - -def run_demo(project_name, top_dir): - with _chdir(top_dir): - project_path = path.join(top_dir, 'manage.py') - command = ("python manage.py runserver " - "--settings={0}.demo_settings").format(project_name) - subprocess.call(command, shell=True) - -def run_server(): - try: - from testapp.exam import code_server - code_server.main() - except Exception as e: - print("Error: {0}\nExiting Vimarsh code server".format(e)) - -def _set_project_details(project_name, top_dir): - file_path = path.join(SCRIPT_DIR, 'project_detail.py') - detail = "NAME ='{0}'\nPATH ='{1}'".format(project_name, top_dir) - with open(file_path, 'w') as data_store: - data_store.write(detail) - -def _render_demo_files(template_path, output_path, context=None): - with open(template_path, 'r') as template_file: - content = template_file.read() - if context: - content = content.decode('utf-8') - template = Template(content) - content = template.render(context) - content = content.encode('utf-8') - - with open(output_path, 'w') as new_file: - new_file.write(content) - -@contextlib.contextmanager -def _chdir(path): - starting_directory = os.getcwd() - try: - os.chdir(path) - yield - finally: - os.chdir(starting_directory) - -if __name__ == '__main__': - main() diff --git a/testapp/scripts/yaksh.py b/testapp/scripts/yaksh.py new file mode 100644 index 0000000..8b3e8b7 --- /dev/null +++ b/testapp/scripts/yaksh.py @@ -0,0 +1,147 @@ +from __future__ import print_function + +import subprocess +import contextlib +import os +from os import path +import argparse +from importlib import import_module +from django.conf import settings +from django.core import management +from django.template import Template, Context, loader + +from project_detail import NAME, PATH + +CUR_DIR = os.getcwd() +SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) +PARENT_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir)) +TEMPLATE_DIR = path.join(PARENT_DIR, 'templates') + +def main(): + #Parse command-line to obtain the arguments and/or options + # create top-level parser object + parser = argparse.ArgumentParser(prog="vimarsh") + subparser = parser.add_subparsers(dest="subcommand") + + # create parser for the "create_demo" subcommand + create_demo_parser = subparser.add_parser("create_demo", + help="Create a new demo Django project") + create_demo_parser.add_argument("project_name", type=str, + help="name of demo Django project") + create_demo_parser.add_argument("-p", "--path", type=str, + help="path of demo Django project") + + # create parser for the "run_demo" subcommand + run_demo_parser = subparser.add_parser("run_demo", + help="Initialise django server and run the demo project") + + # create parser for the "run_code_server" subcommand + code_server_parser = subparser.add_parser("run_code_server", + help="Initialise Vimarsh code server") + code_server_parser.add_argument("-P", "--ports", type=int, nargs='+', + help="code server ports") + + args = parser.parse_args() + + if args.subcommand == "create_demo": + if args.path: + create_demo(args.project_name, args.path) + else: + create_demo(args.project_name) + + elif args.subcommand == "run_demo": + try: + run_demo(NAME, PATH) + except Exception as e: + if not NAME or not PATH: + print("Error: Unable to find Project Name or Path variables\n") + else: + print("Error: {0}\n".format(e)) + subparser.print_help() + + elif args.subcommand == "run_code_server": + if args.ports: + run_server(args.ports) + else: + run_server() + +def create_demo(project_name='vimarsh_demo', project_dir=CUR_DIR): + try: + management.call_command('startproject', project_name, project_dir) + print("Demo Django project '{0}' created at '{1}'".format(project_name, + project_dir)) + except Exception, e: + print("Error: {0}\nExiting Vimarsh Installer".format(e)) + + if project_dir is None: + top_dir = path.join(os.getcwd(), project_name) + else: + top_dir = project_dir + + project_path = path.join(top_dir, project_name) + fixture_dir = path.join(PARENT_DIR, 'fixtures') + # Store project details + _set_project_details(project_name, top_dir) + + with _chdir(project_path): + root_urlconf = "{0}.{1}".format(project_name, 'demo_urls') + settings_template_path = path.join(TEMPLATE_DIR, 'demo_settings.py') + settings_target_path = path.join(project_path, 'demo_settings.py') + settings_context = Context({'project_name': project_name, + 'root_urlconf': root_urlconf, + '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 syncdb " + "--noinput --settings={0}.demo_settings").format(project_name) + + # Create demo_settings file + _render_demo_files(settings_template_path, settings_target_path, settings_context) + # Create demo_urls file + _render_demo_files(urls_template_path, urls_target_path) + # Run syncdb + subprocess.call(command, shell=True) + +def run_demo(project_name, top_dir): + with _chdir(top_dir): + project_path = path.join(top_dir, 'manage.py') + command = ("python manage.py runserver " + "--settings={0}.demo_settings").format(project_name) + subprocess.call(command, shell=True) + +def run_server(): + try: + from testapp.exam import code_server + code_server.main() + except Exception as e: + print("Error: {0}\nExiting Vimarsh code server".format(e)) + +def _set_project_details(project_name, top_dir): + file_path = path.join(SCRIPT_DIR, 'project_detail.py') + detail = "NAME ='{0}'\nPATH ='{1}'".format(project_name, top_dir) + with open(file_path, 'w') as data_store: + data_store.write(detail) + +def _render_demo_files(template_path, output_path, context=None): + with open(template_path, 'r') as template_file: + content = template_file.read() + if context: + content = content.decode('utf-8') + template = Template(content) + content = template.render(context) + content = content.encode('utf-8') + + with open(output_path, 'w') as new_file: + new_file.write(content) + +@contextlib.contextmanager +def _chdir(path): + starting_directory = os.getcwd() + try: + os.chdir(path) + yield + finally: + os.chdir(starting_directory) + +if __name__ == '__main__': + main() -- cgit