diff options
author | Adolfo Fitoria <adolfo.fitoria@gmail.com> | 2011-09-14 16:52:13 -0300 |
---|---|---|
committer | Adolfo Fitoria <adolfo.fitoria@gmail.com> | 2011-09-14 16:52:13 -0300 |
commit | 84e573c204b24fe06d4edba03bf4b4696da3339a (patch) | |
tree | de7e559bdf4c591d372958d14a6f13f9dc416acc | |
parent | ef34ad4f4767f20a8bd77aa8ed95abc7b223fb0d (diff) | |
download | askbot-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
-rw-r--r-- | askbot/deployment/__init__.py | 199 | ||||
-rw-r--r-- | askbot/deployment/path_utils.py | 31 | ||||
-rw-r--r-- | askbot/deployment/template_loader.py | 13 | ||||
-rw-r--r-- | askbot/setup_templates/settings.py.mustache | 217 | ||||
-rw-r--r-- | askbot_requirements.txt | 1 |
5 files changed, 392 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) diff --git a/askbot/setup_templates/settings.py.mustache b/askbot/setup_templates/settings.py.mustache new file mode 100644 index 00000000..55fbb4a5 --- /dev/null +++ b/askbot/setup_templates/settings.py.mustache @@ -0,0 +1,217 @@ +## Django settings for ASKBOT enabled project. +import os.path +import logging +import sys +import askbot + +#this line is added so that we can import pre-packaged askbot dependencies +sys.path.append(os.path.join(os.path.dirname(askbot.__file__), 'deps')) + +DEBUG = False#set to True to enable debugging +TEMPLATE_DEBUG = False#keep false when debugging jinja2 templates +INTERNAL_IPS = ('127.0.0.1',) + +ADMINS = ( + ('Your Name', 'your_email@domain.com'), +) + +MANAGERS = ADMINS + +DATABASE_ENGINE = 'postgresql_psycopg2' # only postgres (>8.3) and mysql are supported so far others have not been tested yet +DATABASE_NAME = '{{database_name}}' # Or path to database file if using sqlite3. +DATABASE_USER = '{{database_user}}' # Not used with sqlite3. +DATABASE_PASSWORD = '{{database_password}}' # Not used with sqlite3. +DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. +DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. + +#outgoing mail server settings +SERVER_EMAIL = '' +DEFAULT_FROM_EMAIL = '' +EMAIL_HOST_USER = '' +EMAIL_HOST_PASSWORD = '' +EMAIL_SUBJECT_PREFIX = '' +EMAIL_HOST='' +EMAIL_PORT='' +EMAIL_USE_TLS=False +EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' + +#incoming mail settings +#after filling out these settings - please +#go to the site's live settings and enable the feature +#"Email settings" -> "allow asking by email" +# +# WARNING: command post_emailed_questions DELETES all +# emails from the mailbox each time +# do not use your personal mail box here!!! +# +IMAP_HOST = '' +IMAP_HOST_USER = '' +IMAP_HOST_PASSWORD = '' +IMAP_PORT = '' +IMAP_USE_TLS = False + +# Local time zone for this installation. Choices can be found here: +# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name +# although not all choices may be available on all operating systems. +# On Unix systems, a value of None will cause Django to use the same +# timezone as the operating system. +# If running in a Windows environment this must be set to the same as your +# system time zone. +TIME_ZONE = 'America/Chicago' + +SITE_ID = 1 + +# If you set this to False, Django will make some optimizations so as not +# to load the internationalization machinery. +USE_I18N = True +LANGUAGE_CODE = 'en' + +# Absolute path to the directory that holds media. +# Example: "/home/media/media.lawrence.com/" +ASKBOT_FILE_UPLOAD_DIR = os.path.join(os.path.dirname(__file__), 'askbot', 'upfiles') + +PROJECT_ROOT = os.path.dirname(__file__) + +# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a +# trailing slash. +# Examples: "http://foo.com/media/", "/media/". +ADMIN_MEDIA_PREFIX = '/admin/media/' + +# Make up some unique string, and don't share it with anybody. +SECRET_KEY = 'sdljdfjkldsflsdjkhsjkldgjlsdgfs s ' + +# List of callables that know how to import templates from various sources. +TEMPLATE_LOADERS = ( + 'django.template.loaders.filesystem.load_template_source', + 'django.template.loaders.app_directories.load_template_source', + #below is askbot stuff for this tuple + 'askbot.skins.loaders.load_template_source', + #'django.template.loaders.eggs.load_template_source', +) + + +MIDDLEWARE_CLASSES = ( + #'django.middleware.gzip.GZipMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + #'django.middleware.cache.UpdateCacheMiddleware', + 'django.middleware.common.CommonMiddleware', + #'django.middleware.cache.FetchFromCacheMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + #'django.middleware.sqlprint.SqlPrintingMiddleware', + + #below is askbot stuff for this tuple + 'askbot.middleware.anon_user.ConnectToSessionMessagesMiddleware', + 'askbot.middleware.pagesize.QuestionsPageSizeMiddleware', + 'askbot.middleware.cancel.CancelActionMiddleware', + 'django.middleware.transaction.TransactionMiddleware', + #'debug_toolbar.middleware.DebugToolbarMiddleware', + 'askbot.middleware.view_log.ViewLogMiddleware', + 'askbot.middleware.spaceless.SpacelessMiddleware', +) + + +ROOT_URLCONF = os.path.basename(os.path.dirname(__file__)) + '.urls' + + +#UPLOAD SETTINGS +FILE_UPLOAD_TEMP_DIR = os.path.join( + os.path.dirname(__file__), + 'tmp' + ).replace('\\','/') + +FILE_UPLOAD_HANDLERS = ( + 'django.core.files.uploadhandler.MemoryFileUploadHandler', + 'django.core.files.uploadhandler.TemporaryFileUploadHandler', +) +ASKBOT_ALLOWED_UPLOAD_FILE_TYPES = ('.jpg', '.jpeg', '.gif', '.bmp', '.png', '.tiff') +ASKBOT_MAX_UPLOAD_FILE_SIZE = 1024 * 1024 #result in bytes +DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage' + + +#TEMPLATE_DIRS = (,) #template have no effect in askbot, use the variable below +#ASKBOT_EXTRA_SKIN_DIR = #path to your private skin collection +#take a look here http://askbot.org/en/question/207/ + +TEMPLATE_CONTEXT_PROCESSORS = ( + 'django.core.context_processors.request', + 'askbot.context.application_settings', + #'django.core.context_processors.i18n', + 'askbot.user_messages.context_processors.user_messages',#must be before auth + 'django.core.context_processors.auth', #this is required for admin + 'django.core.context_processors.csrf', #necessary for csrf protection +) + + +INSTALLED_APPS = ( + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.sites', + + #all of these are needed for the askbot + 'django.contrib.admin', + 'django.contrib.humanize', + 'django.contrib.sitemaps', + #'debug_toolbar', + 'askbot', + 'askbot.deps.django_authopenid', + #'askbot.importers.stackexchange', #se loader + 'south', + 'askbot.deps.livesettings', + 'keyedcache', + 'robots', + 'django_countries', + 'djcelery', + 'djkombu', + 'followit', + #'avatar',#experimental use git clone git://github.com/ericflo/django-avatar.git$ + #requires setting of MEDIA_ROOT and MEDIA_URL +) + + +#setup memcached for production use! +#see http://docs.djangoproject.com/en/1.1/topics/cache/ for details +CACHE_BACKEND = 'locmem://' +#needed for django-keyedcache +CACHE_TIMEOUT = 6000 +CACHE_PREFIX = 'askbot' #make this unique +#If you use memcache you may want to uncomment the following line to enable memcached based sessions +#SESSION_ENGINE = 'django.contrib.sessions.backends.cache_db' + +AUTHENTICATION_BACKENDS = ( + 'django.contrib.auth.backends.ModelBackend', + 'askbot.deps.django_authopenid.backends.AuthBackend', +) + +#logging settings +LOG_FILENAME = 'askbot.log' +logging.basicConfig( + filename=os.path.join(os.path.dirname(__file__), 'log', LOG_FILENAME), + level=logging.CRITICAL, + format='%(pathname)s TIME: %(asctime)s MSG: %(filename)s:%(funcName)s:%(lineno)d %(message)s', +) + +########################### +# +# this will allow running your forum with url like http://site.com/forum +# +# ASKBOT_URL = 'forum/' +# +ASKBOT_URL = '' #no leading slash, default = '' empty string +_ = lambda v:v #fake translation function for the login url +LOGIN_URL = '/%s%s%s' % (ASKBOT_URL,_('account/'),_('signin/')) +#note - it is important that upload dir url is NOT translated!!! +#also, this url must not have the leading slash +ASKBOT_UPLOADED_FILES_URL = '%s%s' % (ASKBOT_URL, 'upfiles/') +ALLOW_UNICODE_SLUGS = False +ASKBOT_USE_STACKEXCHANGE_URLS = False #mimic url scheme of stackexchange + +#Celery Settings +BROKER_BACKEND = "djkombu.transport.DatabaseTransport" +CELERY_ALWAYS_EAGER = True + +import djcelery +djcelery.setup_loader() + +CSRF_COOKIE_NAME = 'askbot_scrf' +CSRF_COOKIE_DOMAIN = ''#enter domain name here - e.g. example.com diff --git a/askbot_requirements.txt b/askbot_requirements.txt index 70bc5874..b4b5a1f4 100644 --- a/askbot_requirements.txt +++ b/askbot_requirements.txt @@ -15,3 +15,4 @@ django-kombu==0.9.2 django-followit django-recaptcha-works python-openid +pystache==0.3.1 |