diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2011-10-20 18:33:11 -0300 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2011-10-20 18:33:11 -0300 |
commit | 7a339c065c5f7b549d2e838d849459163514f807 (patch) | |
tree | 6344a275e95c6260462ae7af788634cfea11f501 /askbot/deployment | |
parent | 1ff1bf97acd3e9ccb4ffe529095ba75b3399e4fd (diff) | |
download | askbot-7a339c065c5f7b549d2e838d849459163514f807.tar.gz askbot-7a339c065c5f7b549d2e838d849459163514f807.tar.bz2 askbot-7a339c065c5f7b549d2e838d849459163514f807.zip |
finished refactoring of the deployment script
Diffstat (limited to 'askbot/deployment')
-rw-r--r-- | askbot/deployment/__init__.py | 88 | ||||
-rw-r--r-- | askbot/deployment/messages.py | 8 | ||||
-rw-r--r-- | askbot/deployment/path_utils.py | 25 |
3 files changed, 71 insertions, 50 deletions
diff --git a/askbot/deployment/__init__.py b/askbot/deployment/__init__.py index 1ddf24ca..f4844083 100644 --- a/askbot/deployment/__init__.py +++ b/askbot/deployment/__init__.py @@ -6,6 +6,7 @@ import sys from optparse import OptionParser from askbot.utils import console from askbot.deployment import messages +from askbot.deployment.messages import print_message from askbot.deployment import path_utils def askbot_setup(): @@ -15,7 +16,7 @@ def askbot_setup(): or gives hints on how to add askbot to an existing Django project """ - parser = OptionParser(usage="%prog [options]") + parser = OptionParser(usage = "%prog [options]") parser.add_option( "-v", "--verbose", @@ -34,66 +35,65 @@ def askbot_setup(): parser.add_option( "-d", "--db-name", - dest="database_name", - default=None, - help="The database name" + dest = "database_name", + default = None, + help = "The database name" ) parser.add_option( "-u", "--db-user", - dest="database_user", - default=None, - help="The database user" + dest = "database_user", + default = None, + help = "The database user" ) parser.add_option( "-p", "--db-password", - dest="database_password", - default=None, - help="the database password" + dest = "database_password", + default = None, + help = "the database password" ) parser.add_option( "--domain", - dest="domain_name", - default=None, - help="the domain name of the instance" + dest = "domain_name", + default = None, + help = "the domain name of the instance" ) parser.add_option( "--append-settings", - dest="local_settings", - default='', - help="Extra settings file to append custom settings" + dest = "local_settings", + default = '', + help = "Extra settings file to append custom settings" ) parser.add_option( "--force", - dest="force", - action='store_true', - help="Force overwrite settings.py file" + dest = "force", + action = 'store_true', + help = "Force overwrite settings.py file" ) - (options, args) = parser.parse_args() - #ask - if options.verbosity >= 1: - print messages.DEPLOY_PREAMBLE - - directory = path_utils.clean_directory(options.dir_name) - if options.verbosity >= 1 and directory is None: - print messages.CANT_INSTALL_INTO_FILE % {'path':directory} - sys.exit(1) + try: + options = parser.parse_args()[0] + #ask + if options.verbosity >= 1: + print messages.DEPLOY_PREAMBLE - create_new = False #create new django project or not - while directory is None: - directory = get_install_directory(force = options.force) + directory = path_utils.clean_directory(options.dir_name) + while directory is None: + directory = path_utils.get_install_directory(force = options.force) - deploy_askbot(directory, create_new_project, options) + deploy_askbot(directory, options) + except KeyboardInterrupt: + print "\n\nAborted." + sys.exit(1) #separated all the directory creation process to make it more useful -def deploy_askbot(directory, create_new_project, options): +def deploy_askbot(directory, options): """function that creates django project files, all the neccessary directories for askbot, and the log file @@ -107,19 +107,21 @@ def deploy_askbot(directory, create_new_project, options): 'domain_name': options.domain_name, 'local_settings': options.local_settings, } - for key in context.keys(): - if context[key] == None: - input_message = 'Please enter a value for %s:' % (key.replace('_', ' ')) - new_value = raw_input(input_message) - context[key] = new_value - - path_utils.create_path(directory) + if not options.force: + for key in context.keys(): + if context[key] == None: + input_message = 'Please enter a value for %s:' \ + % (key.replace('_', ' ')) + new_value = raw_input(input_message) + context[key] = new_value create_new_project = False if os.path.exists(directory): - if path_utils - - create_new_project or options.force + create_new_project = bool(options.force) + else: + create_new_project = True + + path_utils.create_path(directory) path_utils.deploy_into( directory, diff --git a/askbot/deployment/messages.py b/askbot/deployment/messages.py index a108d927..44dde979 100644 --- a/askbot/deployment/messages.py +++ b/askbot/deployment/messages.py @@ -32,6 +32,10 @@ but %(existing_prefix)s is not writable""" CONFIRM_DIR_CREATION = """Adding new directories:\n%(existing_prefix)s <-/%(non_existing_tail)s Accept?""" +CANNOT_OVERWRITE_DJANGO_PROJECT = """Directory %(directory)s +already has a django project. If you want to overwrite +settings.py and urls.py files, use parameter --force""" + INVALID_INPUT = 'Please type one of: %(opt_string)s ' \ + '(or hit Ctrl-C to quit)' @@ -89,3 +93,7 @@ def format_msg_bad_dir_name(directory): return DIR_NAME_TAKEN_BY_ASKBOT else: return DIR_NAME_TAKEN_BY_PYTHON % {'dir': dir_name} + +def print_message(message, verbosity): + if verbosity >= 1: + print message diff --git a/askbot/deployment/path_utils.py b/askbot/deployment/path_utils.py index 806fa80c..d0b0a011 100644 --- a/askbot/deployment/path_utils.py +++ b/askbot/deployment/path_utils.py @@ -11,6 +11,7 @@ import re import glob import shutil import imp +from askbot.utils import console from askbot.deployment.template_loader import SettingsTemplate @@ -33,11 +34,19 @@ def split_at_break_point(directory): def clean_directory(directory): """Returns normalized absolute path to the directory regardless of whether it exists or not - or None - if the path is a file""" + or ``None`` - if the path is a file or if ``directory`` + parameter is ``None``""" + if directory is None: + return None + directory = os.path.normpath(directory) directory = os.path.abspath(directory) if os.path.isfile(directory): + if options.verbosity >= 1 and os.path.isfile(directory): + print messages.CANT_INSTALL_INTO_FILE % {'path':directory} + sys.exit(1) + return None return directory @@ -68,7 +77,7 @@ def can_create_path(directory): if not os.path.isdir(directory): return False else: - directory, junk = split_at_break_point(directory) + directory = split_at_break_point(directory)[0] return directory_is_writable(directory) @@ -137,14 +146,14 @@ def get_path_to_help_file(): """returns path to the main plain text help file""" return os.path.join(SOURCE_DIR, 'doc', 'INSTALL') -def deploy_into(directory, new_project = None, verbosity = 1, context = None): +def deploy_into(directory, new_project = False, verbosity = 1, context = None): """will copy necessary files into the directory """ assert(isinstance(new_project, bool)) if new_project: copy_files = ('__init__.py', 'manage.py', 'urls.py') blank_files = ('__init__.py', 'manage.py') - if verbosity >=1: + if verbosity >= 1: print 'Copying files: ' for file_name in copy_files: src = os.path.join(SOURCE_DIR, 'setup_templates', file_name) @@ -233,7 +242,7 @@ def get_install_directory(force = False): If ``force`` is ``True`` - will permit using a directory with an existing django project. """ - + from askbot.deployment import messages where_to_deploy_msg = messages.WHERE_TO_DEPLOY_QUIT directory = raw_input(where_to_deploy_msg + ' ') directory = clean_directory(directory) @@ -248,8 +257,9 @@ def get_install_directory(force = False): if os.path.exists(directory): if path_is_clean_for_django(directory): if has_existing_django_project(directory): - if force == False: - print messages.CANNOT_OVERWRITE_EXISTING_DJANGO_PROJECT + if not force: + print messages.CANNOT_OVERWRITE_DJANGO_PROJECT % \ + {'directory': directory} return None else: print messages.format_msg_dir_unclean_django(directory) @@ -268,3 +278,4 @@ def get_install_directory(force = False): print messages.format_msg_bad_dir_name(directory) return None + return directory |