Esempio n. 1
0
def deploy_askbot(directory, options):
    """function that creates django project files,
    all the neccessary directories for askbot,
    and the log file
    """

    help_file = path_utils.get_path_to_help_file()
    context = {
        'database_name': options.database_name,
        'database_password': options.database_password,
        'database_user': options.database_user,
        'domain_name': options.domain_name,
        'local_settings': options.local_settings,
    }
    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.has_existing_django_project(directory):
            create_new_project = bool(options.force)
        else:
            create_new_project = True
    else:
        create_new_project = True

    path_utils.create_path(directory)

    if django.VERSION[0] == 1 and django.VERSION[1] < 3:
        #force people install the django-staticfiles app
        context['staticfiles_app'] = ''
    else:
        context['staticfiles_app'] = "'django.contrib.staticfiles',"

    path_utils.deploy_into(
        directory,
        new_project = create_new_project,
        verbosity = options.verbosity,
        context = context
    )

    if create_new_project:
        print_message(
            messages.HOW_TO_DEPLOY_NEW % {'help_file': help_file},
            options.verbosity
        )
    else:
        print_message(
            messages.HOW_TO_ADD_ASKBOT_TO_DJANGO % {'help_file': help_file},
            options.verbosity
        )
Esempio n. 2
0
def deploy_askbot(options):
    """function that creates django project files,
    all the neccessary directories for askbot,
    and the log file
    """
    create_new_project = False
    if os.path.exists(options['dir_name']):
        if path_utils.has_existing_django_project(options['dir_name']):
            create_new_project = bool(options['force'])
        else:
            create_new_project = True
    else:
        create_new_project = True

    path_utils.create_path(options['dir_name'])

    if django.VERSION[0] > 1:
        raise Exception(
            'Django framework with major version > 1 is not supported'
        )

    if django.VERSION[1] < 3:
        #force people install the django-staticfiles app
        options['staticfiles_app'] = ''
    else:
        options['staticfiles_app'] = "'django.contrib.staticfiles',"

    if django.VERSION[1] <=3:
        auth_context_processor = 'django.core.context_processors.auth'
    else:
        auth_context_processor = 'django.contrib.auth.context_processors.auth'
    options['auth_context_processor'] = auth_context_processor

    verbosity = options['verbosity']

    path_utils.deploy_into(
        options['dir_name'],
        new_project=create_new_project,
        verbosity=verbosity,
        context=options
    )

    help_file = path_utils.get_path_to_help_file()

    if create_new_project:
        print_message(
            messages.HOW_TO_DEPLOY_NEW % {'help_file': help_file},
            verbosity
        )
    else:
        print_message(
            messages.HOW_TO_ADD_ASKBOT_TO_DJANGO % {'help_file': help_file},
            verbosity
        )
Esempio n. 3
0
def deploy_askbot(directory, options):
    """function that creates django project files,
    all the neccessary directories for askbot,
    and the log file
    """

    help_file = path_utils.get_path_to_help_file()
    context = {
        'database_name': options.database_name,
        'database_password': options.database_password,
        'database_user': options.database_user,
        'domain_name': options.domain_name,
        'local_settings': options.local_settings,
    }
    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.has_existing_django_project(directory):
            create_new_project = bool(options.force)
        else:
            create_new_project = True
    else:
        create_new_project = True

    path_utils.create_path(directory)

    if django.VERSION[0] == 1 and django.VERSION[1] < 3:
        #force people install the django-staticfiles app
        context['staticfiles_app'] = ''
    else:
        context['staticfiles_app'] = "'django.contrib.staticfiles',"

    path_utils.deploy_into(directory,
                           new_project=create_new_project,
                           verbosity=options.verbosity,
                           context=context)

    if create_new_project:
        print_message(messages.HOW_TO_DEPLOY_NEW % {'help_file': help_file},
                      options.verbosity)
    else:
        print_message(
            messages.HOW_TO_ADD_ASKBOT_TO_DJANGO % {'help_file': help_file},
            options.verbosity)
Esempio n. 4
0
    def _create_new_django_app(self, app_name, options):
        options['askbot_site'] = options['dir_name']
        options['askbot_app']  = app_name
        app_dir =  os.path.join(options['dir_name'], app_name)

        create_me = [ app_dir ]
        copy_me   = list()
        render_me = list()

        if 'django' in self._todo.get('create_project',[]):
            src = lambda x:os.path.join(self.SOURCE_DIR, 'setup_templates', x)
            dst = lambda x:os.path.join(app_dir, x)
            copy_me.extend([
                ( src(file_name), dst(file_name) )
                for file_name in self.APP_FILES_TO_CREATE
                ])
            render_me.extend([
                ( src('settings.py.jinja2'), dst('settings.py') )
                ])

        if 'container-uwsgi' in self._todo.get('create_project',[]):
            src = lambda x:os.path.join(self.SOURCE_DIR, 'container', x)
            dst = lambda x:os.path.join(app_dir, x)
            copy_me.extend([
                ( src(file_name), dst(file_name) )
                for file_name in [ 'cron-askbot.sh', 'prestart.sh', 'prestart.py' ]
            ])
            render_me.extend([
                ( src(file_name), dst(file_name) )
                for file_name in [ 'crontab', 'uwsgi.ini' ]
            ])

        for d in create_me:
            path_utils.create_path(d)

        self._install_copy(copy_me, skip_silently=path_utils.BLANK_FILES,
                                    forced_overwrite=['urls.py'])

        self._install_render_with_jinja2(render_me, options)

        if len(options['local_settings']) > 0 \
        and os.path.exists(options['local_settings']):
            dst = os.path.join(app_dir, 'settings.py')
            print_message(f'Appending {options["local_settings"]} to {dst}', self.verbosity)
            with open(dst, 'a') as settings_file:
                with open(context['local_settings'], 'r') as local_settings:
                    settings_file.write('\n')
                    settings_file.write(local_settings.read())
            print_message('Done.', self.verbosity)
Esempio n. 5
0
    def _create_new_django_project(self, install_dir, options):
        log_dir  = os.path.join(install_dir, path_utils.LOG_DIR_NAME)
        log_file = os.path.join(log_dir, options['logfile_name'])

        create_me = [ install_dir, log_dir ]
        copy_me   = list()

        if 'django' in self._todo.get('create_project',[]):
            src = lambda x:os.path.join(self.SOURCE_DIR, 'setup_templates', x)
            dst = lambda x:os.path.join(install_dir, x)
            copy_me.extend([
               ( src(file_name), dst(file_name) )
               for file_name in self.PROJECT_FILES_TO_CREATE
            ])

        for d in create_me:
            path_utils.create_path(d)

        path_utils.touch(log_file)
        self._install_copy(copy_me, skip_silently=path_utils.BLANK_FILES)
Esempio n. 6
0
def deploy_askbot(options):
    """function that creates django project files,
    all the neccessary directories for askbot,
    and the log file
    """
    create_new_project = True
    if os.path.exists(options['dir_name']):
        if path_utils.has_existing_django_project(options['dir_name']):
            create_new_project = bool(options['force'])

    path_utils.create_path(options['dir_name'])

    options['staticfiles_app'] = "'django.contrib.staticfiles',"

    options['auth_context_processor'] = 'django.contrib.auth.context_processors.auth'

    verbosity = options['verbosity']

    path_utils.deploy_into(
        options['dir_name'],
        new_project=create_new_project,
        verbosity=verbosity,
        context=options
    )

    help_file = path_utils.get_path_to_help_file()

    if create_new_project:
        print_message(
            messages.HOW_TO_DEPLOY_NEW % {'help_file': help_file},
            verbosity
        )
    else:
        print_message(
            messages.HOW_TO_ADD_ASKBOT_TO_DJANGO % {'help_file': help_file},
            verbosity
        )
Esempio n. 7
0
def askbot_setup():
    """basic deployment procedure
    asks user several questions, then either creates
    new deployment (in the case of new installation)
    or gives hints on how to add askbot to an existing
    Django project
    """
    #ask 
    print messages.DEPLOY_PREAMBLE

    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:

        directory = raw_input(where_to_deploy_msg + ' ')

        where_to_deploy_msg = messages.WHERE_TO_DEPLOY_QUIT

        directory = os.path.normpath(directory)
        directory = os.path.abspath(directory)

        if os.path.isfile(directory):
            print messages.CANT_INSTALL_INTO_FILE % {'path':directory}
            directory = None
            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:
                    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:
                    directory = None
                    continue
        else:
            print messages.format_msg_dir_not_writable(directory)
            directory = None
            continue

    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}
    else:
        path_utils.deploy_into(directory, new_project = False)
        print messages.HOW_TO_ADD_ASKBOT_TO_DJANGO % {'help_file': help_file}