def get_log_file_path(self, root_dir):
        """Returns valid log file path
        Relative path is interpreted as relative to the ${root_dir}
        Absolute path will be accepted as is.
        """
        if self.options.logging_settings:
            return None

        raw_path = self.options.log_file_path
        if os.path.isabs(raw_path):
            return raw_path

        prompt = 'Enter the ' + bold('path to the log file')
        default_value = self.parser.get_default('log_file_path')

        validator = OptionValidator(self.console,
                                    self.parser,
                                    option_name='log_file_path',
                                    default_value=default_value,
                                    prompt=prompt,
                                    validator=LogFilePathValidator,
                                    cli_error_messages=\
                                            {'invalid': 'value of --log-file-path is invalid'},
                                    interactive_error_messages=\
                                            {'invalid': 'Path is invalid'})
        value = validator.get_value()
        if os.path.isabs(value):
            return value
        return os.path.join(root_dir, value)
예제 #2
0
    def get_admin_name(self):  #pylint: disable=missing-function-docstring
        if self.options.admin_settings:
            # we won't use this if admin_settings is provided
            return ''

        validator = OptionValidator(self.console,
                                    self.parser,
                                    option_name='admin_name',
                                    required=True,
                                    prompt='Enter name of the site admin',
                                    cli_error_messages={'missing': '--admin-name is required'},
                                    interactive_error_messages=\
                                            {'missing': 'Admin name is required'})
        return validator.get_value()
예제 #3
0
    def get_domain_name(self):
        """Returns valdated domain name"""
        if not self.options.domain_name:
            return None

        validator = OptionValidator(self.console,
                                    self.parser,
                                    option_name='domain_name',
                                    default_value='',
                                    prompt='Enter the domain name',
                                    validator=DomainNameValidator,
                                    cli_error_messages=\
                                            {'invalid': 'value of --domain-name is invalid'},
                                    interactive_error_messages=\
                                            {'invalid': 'Domain name is invalid'})
        return validator.get_value()
    def get_email_port(self):
        """Returns the mail server port number"""
        if self.options.interactive and not self.options.email_port:
            return ''

        validator = OptionValidator(self.console,
                                    self.parser,
                                    option_name='email_port',
                                    default_value='',
                                    required=False,
                                    prompt='Enter the ' + bold('mail server port number'),
                                    validator=PortNumberValidator,
                                    cli_error_messages=\
                                            {'invalid': 'value of --email-port is invalid'},
                                    interactive_error_messages=\
                                            {'invalid': 'Port is invalid'})
        return validator.get_value()
    def get_server_email(self, default_value):
        """Returns server email"""
        if self.options.email_settings:
            return ''

        validator = OptionValidator(self.console,
                                    self.parser,
                                    required=False,
                                    default_value=default_value,
                                    option_name='server_email',
                                    prompt='Enter the ' + bold('server email'),
                                    validator=EmailValidator,
                                    cli_error_messages=\
                                            {'invalid': 'value of --server-email is invalid'},
                                    interactive_error_messages=\
                                            {'invalid': 'Invalid email address'})
        return validator.get_value()
    def get_default_from_email(self):
        """Returns DEFAULT_FROM_EMAIL email"""
        if self.options.email_settings:
            return ''

        validator = OptionValidator(self.console,
                                    self.parser,
                                    required=False,
                                    default_value=self.prev_params['admin_email'],
                                    option_name='default_from_email',
                                    prompt='Enter the ' + bold('default from email'),
                                    validator=EmailValidator,
                                    cli_error_messages=\
                                            {'invalid': 'value of --default-from-email is invalid'},
                                    interactive_error_messages=\
                                            {'invalid': 'Invalid email address'})
        return validator.get_value()
예제 #7
0
    def get_db_port(self, db_engine):
        """Returns port number, default value is empty string"""
        if self.options.database_settings:
            return ''
        if 'sqlite' in db_engine:
            return ''

        validator = OptionValidator(self.console,
                                    self.parser,
                                    option_name='database_port',
                                    default_value='',
                                    prompt='Enter the ' + bold('database port'),
                                    validator=PortNumberValidator,
                                    cli_error_messages=\
                                            {'invalid': 'value of --db-port is invalid'},
                                    interactive_error_messages=\
                                            {'invalid': 'Port is invalid'})
        return validator.get_value()
예제 #8
0
    def get_admin_email(self):
        """Returns valid email"""
        if self.options.admin_settings:
            # we won't use this if admin_settings is provided
            return ''

        validator = OptionValidator(self.console,
                                    self.parser,
                                    required=True,
                                    option_name='admin_email',
                                    prompt='Enter email of the site admin',
                                    validator=EmailValidator,
                                    cli_error_messages=\
                                            {'missing': '--admin-email is required',
                                             'invalid': 'value of --admin-email is invalid'},
                                    interactive_error_messages=\
                                            {'missing': 'Admin email is required',
                                             'invalid': 'Invalid email address'})
        return validator.get_value()
예제 #9
0
    def get_db_host(self, db_engine):
        """Returns host name for the db settings, default value is empty string"""
        if self.options.database_settings:
            return ''

        if 'sqlite' in db_engine:
            return ''

        validator = OptionValidator(self.console,
                                    self.parser,
                                    option_name='database_host',
                                    default_value='',
                                    prompt='Enter the ' + bold('database host name'),
                                    validator=DomainNameValidator,
                                    cli_error_messages=\
                                            {'invalid': 'value of --db-host is invalid'},
                                    interactive_error_messages=\
                                            {'invalid': 'Database host is invalid'})
        return validator.get_value()
    def get_email_host(self):
        """Returns host name of the email server"""
        if self.options.email_settings:
            return ''

        if self.options.interactive and not self.options.email_host:
            return ''

        validator = OptionValidator(self.console,
                                    self.parser,
                                    option_name='email_host',
                                    default_value='',
                                    required=False,
                                    prompt='Enter the ' + bold('mail server host name'),
                                    validator=DomainNameValidator,
                                    cli_error_messages=\
                                            {'invalid': 'value of --email-host is invalid'},
                                    interactive_error_messages=\
                                            {'invalid': 'Host name is invalid'})
        return validator.get_value()
예제 #11
0
    def get_timezone(self):
        """Returns valid timezone for the TIME_ZONE setting"""
        default_tz = self.parser.get_default('timezone')
        if self.options.interactive and self.options.timezone == default_tz:
            return self.options.timezone

        tz_prompt = 'Enter the ' + bold('time zone') + '\n' + \
                'Allowed timezone values are here:\n' + \
                'https://en.wikipedia.org/wiki/List_of_tz_database_time_zones'

        validator = OptionValidator(self.console,
                                    self.parser,
                                    option_name='timezone',
                                    default_value=default_tz,
                                    prompt=tz_prompt,
                                    required=True,
                                    validator=TimezoneValidator,
                                    cli_error_messages=\
                                            {'invalid': 'value of --timezone is invalid'},
                                    interactive_error_messages=\
                                            {'invalid': 'Timezone is invalid'})
        return validator.get_value()
예제 #12
0
    def get_language_code(self):
        """Returns valid language code"""
        default_lang_code = self.parser.get_default('language_code')
        is_default = self.options.language_code == default_lang_code
        if self.options.interactive and is_default:
            return self.options.language_code

        language_code_prompt = 'Enter the ' + bold('language code') + '\n' + \
                'Allowed language code values are here:\n' + \
                'https://github.com/django/django/blob/master/django/conf/global_settings.py'

        validator = OptionValidator(self.console,
                                    self.parser,
                                    option_name='language_code',
                                    default_value=default_lang_code,
                                    prompt=language_code_prompt,
                                    required=True,
                                    validator=LanguageCodeValidator,
                                    cli_error_messages=\
                                            {'invalid': 'value of --language-code is invalid'},
                                    interactive_error_messages=\
                                            {'invalid': 'Language code is invalid'})
        return validator.get_value()