Example #1
0
def get_install_directory(force = False):
    """returns a directory where a new django app/project
    can be installed.
    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
    directory = raw_input(where_to_deploy_msg + ' ')

    if directory.strip() == '':
        return None

    directory = clean_directory(directory)

    if directory is None:
        return None

    if can_create_path(directory) == False:
        print messages.format_msg_dir_not_writable(directory)
        return None

    if os.path.exists(directory):
        if path_is_clean_for_django(directory):
            if has_existing_django_project(directory):
                if not force:
                    print messages.CANNOT_OVERWRITE_DJANGO_PROJECT % \
                        {'directory': directory}
                    return None
        else:
            print messages.format_msg_dir_unclean_django(directory)
            return None
    elif force == False:
        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 == 'no':
            return None

    if dir_taken_by_python_module(directory):
        print messages.format_msg_bad_dir_name(directory)
        return None
    if dir_name_unacceptable_for_django_project(directory):
        print """\nDirectory %s is not acceptable for a Django project.
Please use lower case characters, numbers and underscore.
The first character cannot be a number.\n""" % os.path.basename(directory)
        return None

    return directory
Example #2
0
def get_install_directory(force = False):
    """returns a directory where a new django app/project 
    can be installed.
    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
    directory = raw_input(where_to_deploy_msg + ' ')

    if directory.strip() == '':
        return None

    directory = clean_directory(directory)

    if directory is None:
        return None

    if can_create_path(directory) == False:
        print messages.format_msg_dir_not_writable(directory)
        return None

    if os.path.exists(directory):
        if path_is_clean_for_django(directory):
            if has_existing_django_project(directory):
                if not force:
                    print messages.CANNOT_OVERWRITE_DJANGO_PROJECT % \
                        {'directory': directory}
                    return None
        else:
            print messages.format_msg_dir_unclean_django(directory)
            return None
    elif force == False:
        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 == 'no':
            return None

    if dir_taken_by_python_module(directory):
        print messages.format_msg_bad_dir_name(directory)
        return None
    if dir_name_unacceptable_for_django_project(directory):
        print """\nDirectory %s is not acceptable for a Django project.
Please use lower case characters, numbers and underscore.
The first character cannot be a number.\n""" % os.path.basename(directory)
        return None

    return directory
Example #3
0
def get_install_directory(force = False):
    """returns a directory where a new django app/project 
    can be installed.
    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)

    if directory is None:
        return None

    if can_create_path(directory) == False:
        print messages.format_msg_dir_not_writable(directory)
        return None

    if os.path.exists(directory):
        if path_is_clean_for_django(directory):
            if has_existing_django_project(directory):
                if not force:
                    print messages.CANNOT_OVERWRITE_DJANGO_PROJECT % \
                        {'directory': directory}
                    return None
        else:
            print messages.format_msg_dir_unclean_django(directory)
            return None
    elif force == False:
        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 == 'no':
            return None

    if not dir_name_acceptable(directory):
        print messages.format_msg_bad_dir_name(directory)
        return None

    return directory
Example #4
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}