Exemplo n.º 1
0
    def ask_create_mysql(self, mandatory=False):
        #mysql user name max length = 16
        #mysql schema name max length = 64
        mysql_user = self.conf.get('mysql','user')
        mysql_pass = self.conf.get('mysql','pass')
        mysql_schema = self.conf.get('mysql','schema')
        mysql_apply = False

        if mandatory or inputs.get_input_yesno(t("Do you want to create a MySQL user?")):
            self.ask_mysql_cred()
            mysql_apply = True
            prefix = 'mysql_'
            #username
            max_length = 16
            default = inputs.gen_id(length=(max_length-len(prefix)),prefix=prefix) if mysql_user is None else mysql_user
            username = ""
            while len(username) == 0 or len(username) > max_length or \
                    (mysql.user_exists(username) and not inputs.get_input_yesno(t("The user '%s' exists. Continue?") % username)):
                username = inputs.get_input_string("What is the username?", default)
                if len(username) == 0 or len(username) > max_length:
                    print t("The username length must be less than %s") % max_length
            mysql_user = username
            #password
            max_length = 64
            default = inputs.gen_password(allowed_chars=inputs.PASS_CHARS_MYSQL) if mysql_pass is None else mysql_pass
            password = ""
            while len(password) == 0 or len(password) > max_length:
                password = inputs.get_input_string("What is the password?", default)
                if len(password) == 0 or len(password) > max_length:
                    print t("The password length must be less than %s") % max_length
            mysql_pass = password

        if inputs.get_input_yesno(t("Do you want to create a MySQL schema?")):
            self.ask_mysql_cred()
            mysql_apply = True
            prefix = 'schema_'
            max_length = 64
            default = inputs.gen_id(prefix=prefix) if mysql_schema is None else mysql_schema
            schema = ""
            while len(schema) == 0 or len(schema) > max_length or \
                    (mysql.schema_exists(schema) and not inputs.get_input_yesno(t("The schema '%s' exists. Continue?") % schema)):
                schema = inputs.get_input_string("What is the schema name?", default)
                if len(schema) == 0 or len(schema) > max_length:
                    print t("The schema name length must be less than %s") % max_length
            mysql_schema = schema

        self.conf.mod('mysql','user', mysql_user)
        self.conf.mod('mysql','pass', mysql_pass)
        self.conf.mod('mysql','schema', mysql_schema)
        self.conf.mod('mysql','mysql_apply', mysql_apply)
Exemplo n.º 2
0
    def fix_mysql(self):
        mysql_user = self.conf.get('mysql','user')
        mysql_pass = self.conf.get('mysql','pass')
        mysql_schema = self.conf.get('mysql','schema')
        mysql_apply = self.conf.get('mysql','mysql_apply')

        if mysql_apply:
            self.ask_mysql_cred()

            if mysql_user:
                if mysql.user_exists(mysql_user):
                    mysql.update_user_password(mysql_user,mysql_pass)
                else:
                    mysql.create_user(mysql_user,mysql_pass)

            if mysql_schema and not mysql.schema_exists(mysql_schema):
                mysql.create_schema(mysql_schema)

            if mysql_schema and mysql_user:
                mysql.grant_user(mysql_user, mysql_schema)