Exemple #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
        )
Exemple #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
        )
Exemple #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)
Exemple #4
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
        )
Exemple #5
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}