summaryrefslogtreecommitdiffstats
path: root/askbot/deployment
diff options
context:
space:
mode:
authorAdolfo Fitoria <adolfo.fitoria@gmail.com>2011-09-14 16:52:13 -0300
committerAdolfo Fitoria <adolfo.fitoria@gmail.com>2011-09-14 16:52:13 -0300
commit84e573c204b24fe06d4edba03bf4b4696da3339a (patch)
treede7e559bdf4c591d372958d14a6f13f9dc416acc /askbot/deployment
parentef34ad4f4767f20a8bd77aa8ed95abc7b223fb0d (diff)
downloadaskbot-84e573c204b24fe06d4edba03bf4b4696da3339a.tar.gz
askbot-84e573c204b24fe06d4edba03bf4b4696da3339a.tar.bz2
askbot-84e573c204b24fe06d4edba03bf4b4696da3339a.zip
Added parameters to the askbot_setup command and checked verbosity
TODO: finish templating of settings.py to make it work
Diffstat (limited to 'askbot/deployment')
-rw-r--r--askbot/deployment/__init__.py199
-rw-r--r--askbot/deployment/path_utils.py31
-rw-r--r--askbot/deployment/template_loader.py13
3 files changed, 174 insertions, 69 deletions
diff --git a/askbot/deployment/__init__.py b/askbot/deployment/__init__.py
index 3f04e39d..bfddeccc 100644
--- a/askbot/deployment/__init__.py
+++ b/askbot/deployment/__init__.py
@@ -2,6 +2,7 @@
module for deploying askbot
"""
import os.path
+from optparse import OptionParser
from askbot.utils import console
from askbot.deployment import messages
from askbot.deployment import path_utils
@@ -13,52 +14,102 @@ def askbot_setup():
or gives hints on how to add askbot to an existing
Django project
"""
- #ask
- print messages.DEPLOY_PREAMBLE
+ parser = OptionParser(usage="%prog [options]")
+
+ parser.add_option("-v", "--verbose",
+ dest="verbosity",
+ type="int",
+ default=1,
+ help="verbosity level available values 0, 1, 2."
+ )
- directory = None #directory where to put stuff
- create_new = False #create new django project or not
- where_to_deploy_msg = messages.WHERE_TO_DEPLOY
- while directory is None:
+ parser.add_option("-n",
+ dest="name",
+ default=None,
+ help="Destination name"
+ )
- directory = raw_input(where_to_deploy_msg + ' ')
+ parser.add_option("-d", "--db-name",
+ dest="database_name",
+ default=None,
+ help="The database name"
+ )
- where_to_deploy_msg = messages.WHERE_TO_DEPLOY_QUIT
+ parser.add_option("-u", "--db-user",
+ dest="database_user",
+ default=None,
+ help="The database user"
+ )
- directory = os.path.normpath(directory)
- directory = os.path.abspath(directory)
+ parser.add_option("-p", "--db-password",
+ dest="database_password",
+ default=None,
+ help="the database password"
+ )
- if os.path.isfile(directory):
- print messages.CANT_INSTALL_INTO_FILE % {'path':directory}
- directory = None
- continue
+ (options, args) = parser.parse_args()
+ #ask
+ if options.verbosity >= 1:
+ print messages.DEPLOY_PREAMBLE
- if path_utils.can_create_path(directory):
- if os.path.exists(directory):
- if path_utils.path_is_clean_for_django(directory):
- if path_utils.has_existing_django_project(directory):
- message = messages.SHOULD_ADD_APP_HERE % \
- {
- 'path': directory
- }
- should_add_app = console.choice_dialog(
- message,
- choices = ['yes','no'],
- invalid_phrase = messages.INVALID_INPUT
- )
- if should_add_app == 'yes':
- assert(create_new == False)
+ directory = options.name #directory where to put stuff
+ create_new = False #create new django project or not
+ where_to_deploy_msg = messages.WHERE_TO_DEPLOY
+
+ if directory == None:
+ while directory is None:
+ where_to_deploy_msg = messages.WHERE_TO_DEPLOY_QUIT
+ directory = raw_input(where_to_deploy_msg + ' ')
+ directory = check_directory(directory, options)
+ if not directory:
+ continue
+
+ if path_utils.can_create_path(directory):
+ if os.path.exists(directory):
+ if path_utils.path_is_clean_for_django(directory):
+ if path_utils.has_existing_django_project(directory):
+ message = messages.SHOULD_ADD_APP_HERE % \
+ {
+ 'path': directory
+ }
+ should_add_app = console.choice_dialog(
+ message,
+ choices = ['yes','no'],
+ invalid_phrase = messages.INVALID_INPUT
+ )
+ if should_add_app == 'yes':
+ assert(create_new == False)
+ if path_utils.dir_name_acceptable(directory):
+ break
+ else:
+ print messages.format_msg_bad_dir_name(directory)
+ directory = None
+ continue
+ else:
+ directory = None
+ continue
+ else:
+ assert(directory != None)
if path_utils.dir_name_acceptable(directory):
+ create_new = True
break
else:
print messages.format_msg_bad_dir_name(directory)
directory = None
continue
- else:
- directory = None
- continue
else:
- assert(directory != None)
+ print messages.format_msg_dir_unclean_django(directory)
+ directory = None
+ continue
+ else:
+ #creates dir
+ message = messages.format_msg_create(directory)
+ should_create_new = console.choice_dialog(
+ message,
+ choices = ['yes','no'],
+ invalid_phrase = messages.INVALID_INPUT
+ )
+ if should_create_new == 'yes':
if path_utils.dir_name_acceptable(directory):
create_new = True
break
@@ -66,38 +117,70 @@ def askbot_setup():
print messages.format_msg_bad_dir_name(directory)
directory = None
continue
- else:
- print messages.format_msg_dir_unclean_django(directory)
- directory = None
- continue
- else:
- message = messages.format_msg_create(directory)
- should_create_new = console.choice_dialog(
- message,
- choices = ['yes','no'],
- invalid_phrase = messages.INVALID_INPUT
- )
- if should_create_new == 'yes':
- if path_utils.dir_name_acceptable(directory):
- create_new = True
- break
else:
- print messages.format_msg_bad_dir_name(directory)
directory = None
continue
+ else:
+ print messages.format_msg_dir_not_writable(directory)
+ directory = None
+ continue
+
+ deploy_askbot(directory, create_new, options)
+ else:
+ directory = check_directory(directory, options)
+ create_new = True
+ if directory==None:
+ raise Exception("the directory you choosed is invalid")
+ #TODO middle steps!
+ if path_utils.can_create_path(directory):
+ if os.path.exists(directory):
+ if path_utils.path_is_clean_for_django(directory):
+ if path_utils.has_existing_django_project(directory):
+ if options.verbosity >= 1:
+ print "Integrating askbot to your current app"
+ create_new=False
+ else:
+ assert(directory != None)
+ if path_utils.dir_name_acceptable(directory):
+ pass
+ else:
+ raise Exception(messages.format_msg_bad_dir_name(directory))
else:
- directory = None
- continue
+ raise Exception(messages.format_msg_dir_unclean_django(directory))
+ else:
+ if path_utils.dir_name_acceptable(directory):
+ pass
+ else:
+ raise Exception(messages.format_msg_bad_dir_name(directory))
else:
- print messages.format_msg_dir_not_writable(directory)
- directory = None
- continue
+ raise Exception(messages.format_msg_dir_not_writable(directory))
+
+ deploy_askbot(directory, create_new, options)
+#separated all the directory creation process to make it more useful
+
+def deploy_askbot(directory, create_new, options):
+ '''function that copies the templates'''
help_file = path_utils.get_path_to_help_file()
if create_new:
path_utils.create_path(directory)
- path_utils.deploy_into(directory, new_project = True)
- print messages.HOW_TO_DEPLOY_NEW % {'help_file': help_file}
+ path_utils.deploy_into(directory, new_project = True,
+ verbosity = options.verbosity)
+ if options.verbosity >= 1:
+ print messages.HOW_TO_DEPLOY_NEW % {'help_file': help_file}
else:
- path_utils.deploy_into(directory, new_project = False)
- print messages.HOW_TO_ADD_ASKBOT_TO_DJANGO % {'help_file': help_file}
+ path_utils.deploy_into(directory, new_project = False,
+ verbosity = options.verbosity)
+ if options.verbosity >= 1:
+ print messages.HOW_TO_ADD_ASKBOT_TO_DJANGO % {'help_file': help_file}
+
+def check_directory(directory, options):
+ directory = os.path.normpath(directory)
+ directory = os.path.abspath(directory)
+
+ if os.path.isfile(directory):
+ directory = None
+ if options.verbosity >= 1:
+ print messages.CANT_INSTALL_INTO_FILE % {'path':directory}
+
+ return directory
diff --git a/askbot/deployment/path_utils.py b/askbot/deployment/path_utils.py
index 6ad9fc99..7499e2c9 100644
--- a/askbot/deployment/path_utils.py
+++ b/askbot/deployment/path_utils.py
@@ -123,24 +123,27 @@ 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):
+def deploy_into(directory, new_project = None, verbosity=1):
"""will copy necessary files into the directory
"""
assert(new_project is not None)
if new_project:
copy_files = ('__init__.py', 'settings.py', 'manage.py', 'urls.py')
blank_files = ('__init__.py', 'manage.py')
- print 'Copying files: '
+ if verbosity >=1:
+ print 'Copying files: '
for file_name in copy_files:
src = os.path.join(SOURCE_DIR, 'setup_templates', file_name)
if os.path.exists(os.path.join(directory, file_name)):
if file_name in blank_files:
continue
else:
- print '* %s' % file_name,
- print "- you already have one, please add contents of %s" % src
+ if verbosity >=1:
+ print '* %s' % file_name,
+ print "- you already have one, please add contents of %s" % src
else:
- print '* %s ' % file_name
+ if verbosity >=1:
+ print '* %s ' % file_name
shutil.copy(src, directory)
#copy log directory
src = os.path.join(SOURCE_DIR, 'setup_templates', 'log')
@@ -148,7 +151,8 @@ def deploy_into(directory, new_project = None):
create_path(log_dir)
touch(os.path.join(log_dir, 'askbot.log'))
- print ''
+ if verbosity >=1:
+ print ''
app_dir = os.path.join(directory, 'askbot')
copy_dirs = ('doc', 'cron', 'upfiles')
@@ -158,17 +162,22 @@ def deploy_into(directory, new_project = None):
dst = os.path.join(app_dir, dir_name)
if os.path.abspath(src) != os.path.abspath(dst):
if dirs_copied == 0:
- print 'copying directories: ',
- print '* ' + dir_name
+ if verbosity >=1:
+ print 'copying directories: ',
+ if verbosity >=1:
+ print '* ' + dir_name
if os.path.exists(dst):
if os.path.isdir(dst):
- print 'Directory %s not empty - skipped' % dst
+ if verbosity >=1:
+ print 'Directory %s not empty - skipped' % dst
else:
- print 'File %s already exists - skipped' % dst
+ if verbosity >=1:
+ print 'File %s already exists - skipped' % dst
continue
shutil.copytree(src, dst)
dirs_copied += 1
- print ''
+ if verbosity >=1:
+ print ''
def dir_name_acceptable(directory):
"""True if directory is not taken by another python module"""
diff --git a/askbot/deployment/template_loader.py b/askbot/deployment/template_loader.py
new file mode 100644
index 00000000..b7820ed0
--- /dev/null
+++ b/askbot/deployment/template_loader.py
@@ -0,0 +1,13 @@
+import os
+import pystache
+from path_utils import SOURCE_DIR
+
+
+class SettingsTemplate(pystache.View):
+ '''Class for settings'''
+
+ template_path = os.path.join(SOURCE_DIR, 'setup_templates')
+ template_name = "settings.py"
+
+ def __init__(self, context, **kwargs):
+ super(SettingsTemplate, self).__init__(context=context, **kwargs)