<commit_before># -*- coding: utf-8 -*-
#
# metadata.py - part of the FDroid server tools
# Copyright (C) 2013, <NAME>, <EMAIL>
# Copyright (C) 2013-2014 <NAME> <<EMAIL>>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os
import re
import glob
import cgi
import logging

from collections import OrderedDict

srclibs = None


class MetaDataException(Exception):
    def __init__(self, value):
        self.value = value

    def __str__(self):
        return self.value

# In the order in which they are laid out on files
app_defaults = OrderedDict([
    ('Disabled', None),
    ('AntiFeatures', None),
    ('Provides', None),
    ('Categories', ['None']),
    ('License', 'Unknown'),
    ('Web Site', ''),
    ('Source Code', ''),
    ('Issue Tracker', ''),
    ('Donate', None),
    ('FlattrID', None),
    ('Bitcoin', None),
    ('Litecoin', None),
    ('Dogecoin', None),
    ('Name', None),
    ('Auto Name', ''),
    ('Summary', ''),
    ('Description', []),
    ('Requires Root', False),
    ('Repo Type', ''),
    ('Repo', ''),
    ('Maintainer Notes', []),
    ('Archive Policy', None),
    ('Auto Update Mode', 'None'),
    ('Update Check Mode', 'None'),
    ('Update Check Ignore', None),
    ('Vercode Operation', None),
    ('Update Check Name', None),
    ('Update Check Data', None),
    ('Current Version', ''),
    ('Current Version Code', '0'),
    ('No Source Since', ''),
    ])


# In the order in which they are laid out on files
# Sorted by their action and their place in the build timeline
flag_defaults = OrderedDict([
    ('disable', False),
    ('commit', None),
    ('subdir', None),
    ('submodules', False),
    ('init', ''),
    ('patch', []),
    ('gradle', False),
    ('maven', False),
    ('kivy', False),
    ('output', None),
    ('srclibs', []),
    ('oldsdkloc', False),
    ('encoding', None),
    ('forceversion', False),
    ('forcevercode', False),
    ('rm', []),
    ('extlibs', []),
    ('prebuild', ''),
    ('update', ['auto']),
    ('target', None),
    ('scanignore', []),
    ('scandelete', []),
    ('build', ''),
    ('buildjni', []),
    ('preassemble', []),
    ('antcommand', None),
    ('novcheck', False),
    ])


# Designates a metadata field type and checks that it matches
#
# 'name'     - The long name of the field type
# 'matching' - List of possible values or regex expression
# 'sep'      - Separator to use if value may be a list
# 'fields'   - Metadata fields (Field:Value) of this type
# 'attrs'    - Build attributes (attr=value) of this type
#
class FieldValidator():

    def __init__(self, name, matching, sep, fields, attrs):
        self.name = name
        self.matching = matching
        if type(matching) is str:
            self.compiled = re.compile(matching)
        self.sep = sep
        self.fields = fields
        self.attrs = attrs

    def _assert_regex(self, values, appid):
        for v in values:
            if not self.compiled.match(v):
                raise MetaDataException("'%s' is not a valid %s in %s. "
                                        % (v, self.name, appid) +
                                        "Regex pattern: %s" % (self.matching))

    def _assert_list(self, values, appid):
        for v in values:
            if v not in self.matching:
                raise MetaDataException("'%s' is not a valid %s in %s. "
                                        % (v, self.name, appid) +
                                        "Possible values: %s" % (", ".join(self.matching)))

    def check(self, value, appid):
        if type(value) is not str or not value:
            return
        if self.sep is not None:
            values = value.split(self.sep)
        else:
            values = [value]
        if type(self.matching) is list:
            self._assert_list(values, appid)
        else:
            self._assert_regex(values, appid)


# Generic value types
valuetypes = {
    FieldValidator("Integer",
                   r'^[1-9][0-9]*$', None,
                   ['FlattrID'],
                   ['vercode']),

    FieldValidator("HTTP link",
                   r'^http[s]?://', None,
                   ["Web Site", "Source Code", "Issue Tracker", "Donate"], []),

    FieldValidator("Bitcoin address",
                   r'^[a-zA-Z0-9]{27,34}$', None,
                   ["Bitcoin"],
                   []),

    FieldValidator("Litecoin address",
                   r'^L[a-zA-Z0-9]{33}$', None,
                   ["Litecoin"],<commit_msg>Make FlattrID a hexadecimal value<commit_after># -*- coding: utf-8 -*-
#
# metadata.py - part of the FDroid server tools
# Copyright (C) 2013, <NAME>, <EMAIL>
# Copyright (C) 2013-2014 <NAME> <<EMAIL>>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os
import re
import glob
import cgi
import logging

from collections import OrderedDict

srclibs = None


class MetaDataException(Exception):
    def __init__(self, value):
        self.value = value

    def __str__(self):
        return self.value

# In the order in which they are laid out on files
app_defaults = OrderedDict([
    ('Disabled', None),
    ('AntiFeatures', None),
    ('Provides', None),
    ('Categories', ['None']),
    ('License', 'Unknown'),
    ('Web Site', ''),
    ('Source Code', ''),
    ('Issue Tracker', ''),
    ('Donate', None),
    ('FlattrID', None),
    ('Bitcoin', None),
    ('Litecoin', None),
    ('Dogecoin', None),
    ('Name', None),
    ('Auto Name', ''),
    ('Summary', ''),
    ('Description', []),
    ('Requires Root', False),
    ('Repo Type', ''),
    ('Repo', ''),
    ('Maintainer Notes', []),
    ('Archive Policy', None),
    ('Auto Update Mode', 'None'),
    ('Update Check Mode', 'None'),
    ('Update Check Ignore', None),
    ('Vercode Operation', None),
    ('Update Check Name', None),
    ('Update Check Data', None),
    ('Current Version', ''),
    ('Current Version Code', '0'),
    ('No Source Since', ''),
    ])


# In the order in which they are laid out on files
# Sorted by their action and their place in the build timeline
flag_defaults = OrderedDict([
    ('disable', False),
    ('commit', None),
    ('subdir', None),
    ('submodules', False),
    ('init', ''),
    ('patch', []),
    ('gradle', False),
    ('maven', False),
    ('kivy', False),
    ('output', None),
    ('srclibs', []),
    ('oldsdkloc', False),
    ('encoding', None),
    ('forceversion', False),
    ('forcevercode', False),
    ('rm', []),
    ('extlibs', []),
    ('prebuild', ''),
    ('update', ['auto']),
    ('target', None),
    ('scanignore', []),
    ('scandelete', []),
    ('build', ''),
    ('buildjni', []),
    ('preassemble', []),
    ('antcommand', None),
    ('novcheck', False),
    ])


# Designates a metadata field type and checks that it matches
#
# 'name'     - The long name of the field type
# 'matching' - List of possible values or regex expression
# 'sep'      - Separator to use if value may be a list
# 'fields'   - Metadata fields (Field:Value) of this type
# 'attrs'    - Build attributes (attr=value) of this type
#
class FieldValidator():

    def __init__(self, name, matching, sep, fields, attrs):
        self.name = name
        self.matching = matching
        if type(matching) is str:
            self.compiled = re.compile(matching)
        self.sep = sep
        self.fields = fields
        self.attrs = attrs

    def _assert_regex(self, values, appid):
        for v in values:
            if not self.compiled.match(v):
                raise MetaDataException("'%s' is not a valid %s in %s. "
                                        % (v, self.name, appid) +
                                        "Regex pattern: %s" % (self.matching))

    def _assert_list(self, values, appid):
        for v in values:
            if v not in self.matching:
                raise MetaDataException("'%s' is not a valid %s in %s. "
                                        % (v, self.name, appid) +
                                        "Possible values: %s" % (", ".join(self.matching)))

    def check(self, value, appid):
        if type(value) is not str or not value:
            return
        if self.sep is not None:
            values = value.split(self.sep)
        else:
            values = [value]
        if type(self.matching) is list:
            self._assert_list(values, appid)
        else:
            self._assert_regex(values, appid)


# Generic value types
valuetypes = {
    FieldValidator("Integer",
                   r'^[1-9][0-9]*$', None,
                   [],
                   ['vercode']),

    FieldValidator("Hexadecimal",
                   r'^[0-9a-f]+$', None,
                   ['FlattrID'],
                   []),

    FieldValidator("HTTP link",
                   r'^http[s]?://', None,
                   ["Web Site", "Source Code", "Issue Tracker", "Donate"], []),

    FieldValidator("Bitcoin address",
                   r'^[a-zA-Z0-9]{27,34}$', None,
                   ["Bitcoin"],
                   []),

    FieldValidator("Litecoin address",
                   r'^L[a-zA-Z0-9]{33}$', None,
                   ["Litecoin"],
{'fraction_non_alphanumeric': 0.15417434306215455, 'fraction_numerical': 0.005817899738194512, 'mean_word_length': 2.23728813559322, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2325621', 'n_tokens_mistral': 3088, 'n_tokens_neox': 2967, 'n_words': 1000}