Ejemplo n.º 1
0
    def __call__(self): # this is the main part of the original askbot_setup()
      try:
        options = self.parser.parse_args()
        self._set_verbosity(options)
        self._set_create_project(options)
        print_message(messages.DEPLOY_PREAMBLE, self.verbosity)

        # the destination directory
        directory = path_utils.clean_directory(options.dir_name)
        while directory is None:
            directory = path_utils.get_install_directory(force=options.get('force')) # i.e. ask the user
        options.dir_name = directory

        if options.database_engine not in DATABASE_ENGINE_CHOICES:
            options.database_engine = console.choice_dialog(
                'Please select database engine:\n1 - for postgresql, '
                '2 - for sqlite, 3 - for mysql, 4 - oracle',
                choices=DATABASE_ENGINE_CHOICES
            )

        options_dict = vars(options)
        if options.force is False:
            options_dict = collect_missing_options(options_dict)

        database_engine_codes = {
            '1': 'postgresql_psycopg2',
            '2': 'sqlite3',
            '3': 'mysql',
            '4': 'oracle'
        }
        database_engine = database_engine_codes[options.database_engine]
        options_dict['database_engine'] = database_engine

        self.deploy_askbot(options_dict)

        if database_engine == 'postgresql_psycopg2':
            try:
                import psycopg2
            except ImportError:
                print('\nNEXT STEPS: install python binding for postgresql')
                print('pip install psycopg2\n')
        elif database_engine == 'mysql':
            try:
                import _mysql
            except ImportError:
                print('\nNEXT STEP: install python binding for mysql')
                print('pip install mysql-python\n')

      except KeyboardInterrupt:
        print("\n\nAborted.")
        sys.exit(1)
        pass
Ejemplo n.º 2
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
    """
    parser = OptionParser(usage = "%prog [options]")

    parser.add_option(
                "-v", "--verbose",
                dest = "verbosity",
                type = "int",
                default = 1,
                help = "verbosity level available values 0, 1, 2."
            )

    parser.add_option(
                "-n", "--dir-name",
                dest = "dir_name",
                default = None,
                help = "Directory where you want to install."
            )

    parser.add_option(
                '-e', '--db-engine',
                dest='database_engine',
                action='store',
                type='choice',
                choices=DATABASE_ENGINE_CHOICES,
                default=None,
                help='Database engine, type 1 for postgresql, 2 for sqlite, 3 for mysql'
            )

    parser.add_option(
                "-d", "--db-name",
                dest = "database_name",
                default = None,
                help = "The database name"
            )

    parser.add_option(
                "-u", "--db-user",
                dest = "database_user",
                default = None,
                help = "The database user"
            )

    parser.add_option(
                "-p", "--db-password",
                dest = "database_password",
                default = None,
                help = "the database password"
            )

    parser.add_option(
                "--domain",
                dest = "domain_name",
                default = None,
                help = "the domain name of the instance"
            )

    parser.add_option(
                "--append-settings",
                dest = "local_settings",
                default = '',
                help = "Extra settings file to append custom settings"
            )

    parser.add_option(
                "--force",
                dest="force",
                action='store_true',
                default=False,
                help = "Force overwrite settings.py file"
            )

    try:
        options = parser.parse_args()[0]

        #ask users to give missing parameters
        #todo: make this more explicit here
        if options.verbosity >= 1:
            print messages.DEPLOY_PREAMBLE

        directory = path_utils.clean_directory(options.dir_name)
        while directory is None:
            directory = path_utils.get_install_directory(force=options.force)
        options.dir_name = directory

        if options.database_engine not in DATABASE_ENGINE_CHOICES:
            options.database_engine = console.choice_dialog(
                'Please select database engine:\n1 - for postgresql, '
                '2 - for sqlite, 3 - for mysql, 4 - oracle',
                choices=DATABASE_ENGINE_CHOICES
            )

        options_dict = vars(options)
        if options.force is False:
            options_dict = collect_missing_options(options_dict)

        database_engine_codes = {
            '1': 'postgresql_psycopg2',
            '2': 'sqlite3',
            '3': 'mysql',
            '4': 'oracle'
        }
        database_engine = database_engine_codes[options.database_engine]
        options_dict['database_engine'] = database_engine

        deploy_askbot(options_dict)

        if database_engine == 'postgresql_psycopg2':
            try:
                import psycopg2
            except ImportError:
                print '\nNEXT STEPS: install python binding for postgresql'
                print 'pip install psycopg2\n'
        elif database_engine == 'mysql':
            try:
                import _mysql
            except ImportError:
                print '\nNEXT STEP: install python binding for mysql'
                print 'pip install mysql-python\n'

    except KeyboardInterrupt:
        print "\n\nAborted."
        sys.exit(1)
Ejemplo n.º 3
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
    """
    parser = OptionParser(usage="%prog [options]")

    parser.add_option("-v",
                      "--verbose",
                      dest="verbosity",
                      type="int",
                      default=1,
                      help="verbosity level available values 0, 1, 2.")

    parser.add_option("-n",
                      "--dir-name",
                      dest="dir_name",
                      default=None,
                      help="Directory where you want to install.")

    parser.add_option("-d",
                      "--db-name",
                      dest="database_name",
                      default=None,
                      help="The database name")

    parser.add_option("-u",
                      "--db-user",
                      dest="database_user",
                      default=None,
                      help="The database user")

    parser.add_option("-p",
                      "--db-password",
                      dest="database_password",
                      default=None,
                      help="the database password")

    parser.add_option("--domain",
                      dest="domain_name",
                      default=None,
                      help="the domain name of the instance")

    parser.add_option("--append-settings",
                      dest="local_settings",
                      default='',
                      help="Extra settings file to append custom settings")

    parser.add_option("--force",
                      dest="force",
                      action='store_true',
                      help="Force overwrite settings.py file")

    try:
        options = parser.parse_args()[0]
        #ask
        if options.verbosity >= 1:
            print messages.DEPLOY_PREAMBLE

        directory = path_utils.clean_directory(options.dir_name)
        while directory is None:
            directory = path_utils.get_install_directory(force=options.force)

        deploy_askbot(directory, options)
    except KeyboardInterrupt:
        print "\n\nAborted."
        sys.exit(1)