예제 #1
0
def check_dexterity_type_name(configurator, question, answer):
    if keyword.iskeyword(answer):
        raise ValidationError(u'{key} is a reserved Python keyword'.format(
            key=answer))  # NOQA: E501
    if not re.match('[_a-zA-Z ]*$', answer):
        raise ValidationError(u'{key} is not a valid identifier'.format(
            key=answer))  # NOQA: E501
    return answer
예제 #2
0
def check_klass_name(configurator, question, answer):
    if keyword.iskeyword(answer):
        raise ValidationError(u'{key} is a reserved Python keyword'.format(
            key=answer))  # NOQA: E501
    if not re.match('[a-zA-Z_][a-zA-Z0-9_]*$', answer):
        raise ValidationError(u'{key} is not a valid class identifier'.format(
            key=answer))  # NOQA: E501
    return answer
예제 #3
0
def check_method_name(configurator, question, answer):
    if keyword.iskeyword(answer):
        raise ValidationError(
            u"{key} is a reserved Python keyword".format(key=answer)
        )  # NOQA: E501
    if not re.match("[a-z_][a-z0-9_]*$", answer):
        raise ValidationError(
            u"{key} is not a valid method identifier".format(key=answer)
        )  # NOQA: E501
    return answer
예제 #4
0
def check_mkdir(configurator, question, answer):
    try:
        from stat import ST_MODE, S_ISDIR
        if not os.path.lexists(answer):
            os.makedirs(answer)
        elif not S_ISDIR(os.stat(answer)[ST_MODE]):
            raise ValidationError("Invalid path (%s): path must point to a directory not a file." % answer)
        return os.path.realpath(answer)
    except OSError as e:
        raise ValidationError(e)
예제 #5
0
def check_dexterity_type_name(configurator, question, answer):
    """Test if type name is valid."""
    if keyword.iskeyword(answer):
        raise ValidationError(u'"{key}" is a reserved Python keyword!'.format(
            key=answer))  # NOQA: E501
    if not re.match('[_a-zA-Z ]*$', answer):
        raise ValidationError(
            u'"{key}" is not a valid identifier!\n'
            u'Allowed characters: _ a-z A-Z and whitespace.\n'.format(
                key=answer),  # NOQA: E501
        )
    return answer
예제 #6
0
def check_init_script(configurator, question, answer):
    try:
        if not os.path.lexists(answer):
            os.makedirs(answer)
        elif not S_ISDIR(os.stat(answer)[ST_MODE]):
            raise ValidationError(
                "Invalid path (%s): path must point to a directory not a file."
                % answer)

        with file(os.path.join(answer, 'plume'), 'w'):
            answer = os.path.realpath(answer)
            configurator.target_directory = answer
            return answer
    except OSError, e:
        raise ValidationError(e)
예제 #7
0
def check_port(configurator, question, answer):
    try:
        if 1 < int(answer) <= 65535:
            return answer
        raise ValueError("Port number needs to be between 1 and 65535.")
    except ValueError as e:
        raise ValidationError(e)
예제 #8
0
def _open_manifest(configurator, mode="r"):
    manifest_path = os.path.join(configurator.target_directory, "__openerp__.py")
    if not os.path.exists(manifest_path):
        manifest_path = os.path.join(configurator.target_directory, "__manifest__.py")
        if not os.path.exists(manifest_path):
            raise ValidationError("{} not found".format(manifest_path))
    return open(manifest_path, mode)
예제 #9
0
def configure_ssl(configurator, question, answer):
    answer = answer.lower()
    if answer not in ('0', '1', 'y', 'n'):
        raise ValidationError("Value must be either y/n.")
    answer = int(answer in ('1', 'y'))
    if answer:
        configurator.questions.extend([
            Question(
                    'plume.certificate',
                    'Please specify the path to the public key',
                    default='/etc/ssl/private/server.pem',
                    required=True,
                    post_ask_question='canari.commands.install_plume:validate_path'
            ),
            Question(
                    'plume.private_key',
                    'Please specify the path to the private key',
                    default='/etc/ssl/private/server.pem',
                    required=True,
                    post_ask_question='canari.commands.install_plume:validate_path'
            ),
        ])
    else:
        configurator.variables['plume.certificate'] = ''
        configurator.variables['plume.private_key'] = ''
    return answer
예제 #10
0
def post_theme_name(configurator, question, answer):
    regex = r'^\w+[a-zA-Z0-9 \.\-_]*\w$'
    if not re.match(regex, answer):
        msg = u"Error: '{0}' is not a valid themename.\n".format(answer)
        msg += u"Please use a valid name (like 'Tango' or 'my-tango.com')!\n"
        msg += u'At beginning or end only letters|diggits are allowed.\n'
        msg += u"Inside the name also '.-_' are allowed.\n"
        msg += u'No umlauts!'
        raise ValidationError(msg)
    return answer
예제 #11
0
def check_view_template_answer(configurator, question):
    if not configurator.variables[
            'view_template'] and not configurator.variables[
                'view_python_class']:  # NOQA: E501
        raise ValidationError(
            u'View must at least have a template or a python class'
        )  # NOQA: E501
    elif not configurator.variables['view_template']:
        raise SkipQuestion(
            u'No view template, so we skip view template name question.'
        )  # NOQA: E501
예제 #12
0
def check_root_folder(configurator, question):
    """Check if we are in a package.
    Should be called in first question pre hook.
    """
    root_folder = _get_package_root_folder(configurator)
    if not root_folder:
        raise ValidationError(
            '\n\nNo setup.py found in path!\n'
            'Please run this subtemplate inside an existing package,\n'
            'in the package dir, where the actual code is!\n'
            "In the package collective.dx it's in collective.dx/collective/dx"
            '\n')
예제 #13
0
def to_boolean(configurator, question, answer):
    """
    If you want to convert an answer to Python boolean, you can
    use this function as :ref:`post-question-hook`:

    .. code-block:: ini

        [questions]
        idiot.question = Are you young?
        idiot.post_ask_question = mrbob.hooks:to_boolean

    Following variables can be converted to a boolean:
    **y, n, yes, no, true, false, 1, 0**
    """
    if isinstance(answer, bool):
        return answer
    value = answer.lower()
    if value in ['y', 'yes', 'true', '1']:
        return True
    elif value in ['n', 'no', 'false', '0']:
        return False
    else:
        raise ValidationError('Value must be a boolean (y/n)')
예제 #14
0
def post_dexterity_type_name(configurator, question, answer):
    if keyword.iskeyword(answer):
        raise ValidationError('%s is a reserved keyword' % answer)
    if not re.match('[_A-Za-z][_a-zA-Z0-9_]*$', answer):
        raise ValidationError('%s is not a valid identifier' % answer)
    return answer
예제 #15
0
def valid_url(configurator, question, answer):
    """Check home page uri"""
    regex = re.compile("(https?|ftp)://(-\.)?([^\s/?\.#-]+\.?)+(/[^\s]*)?$")
    if not regex.match(answer):
        raise ValidationError("Not a valid URI")
    return answer
예제 #16
0
def valid_pkg_license(configurator, question, answer):
    """Check license answer."""
    licenses = ['BSD', 'GPL']
    if answer.upper().strip() not in licenses:
        raise ValidationError("'{0}' is not in {1}".format(answer, licenses))
    return answer.upper()
예제 #17
0
def check_name(configurator, question, answer):
    if not re.match("^[a-z]+-+[a-z0-9]+(-+[a-z0-9]+)*$", answer):
        raise ValidationError(
            u"{key} is not a valid custom-element identifier. Please try something like this 'my-element'"
            .format(key=answer))  # NOQA: E501
    return answer
예제 #18
0
def validate_path(configurator, question, answer):
    if not os.path.lexists(answer):
        raise ValidationError("Could not find file %r" % answer)
    return os.path.realpath(answer)
예제 #19
0
def check_uid(configurator, question, answer):
    try:
        import pwd
        return pwd.getpwnam(answer).pw_uid
    except KeyError as e:
        raise ValidationError(e)
예제 #20
0
def check_gid(configurator, question, answer):
    try:
        import grp
        return grp.getgrnam(answer).gr_gid
    except KeyError as e:
        raise ValidationError(e)
예제 #21
0
def _open_file(configurator, file, mode="r"):
    file_path = os.path.join(configurator.target_directory, file)
    if not os.path.exists(file_path):
        raise ValidationError("{} not found".format(file_path))
    return open(file_path, mode)
예제 #22
0
    try:
        if not os.path.lexists(answer):
            os.makedirs(answer)
        elif not S_ISDIR(os.stat(answer)[ST_MODE]):
            raise ValidationError(
                "Invalid path (%s): path must point to a directory not a file."
                % answer)

        with file(os.path.join(answer, 'plume'), 'w'):
            answer = os.path.realpath(answer)
            configurator.target_directory = answer
            return answer
    except OSError, e:
        raise ValidationError(e)
    except IOError, e:
        raise ValidationError(e)


def configure_ssl(configurator, question, answer):
    answer = answer.lower()
    if answer not in ('0', '1', 'y', 'n'):
        raise ValidationError("Value must be either y/n.")
    answer = int(answer in ('1', 'y'))
    if answer:
        configurator.questions.extend([
            Question(
                'plume.certificate',
                'Please specify the path to the public key',
                default='/etc/ssl/private/server.pem',
                required=True,
                post_ask_question='canari.commands.install_plume:validate_path'