Exemple #1
0
 def test_missing_required_value(self):
     config = _root({})
     with self.assertRaises(confuse.NotFoundError):
         config['foo'].get(confuse.Path())
Exemple #2
0
 def test_default_value(self):
     import pathlib
     config = _root({})
     valid = config['foo'].get(confuse.Path('foo/bar'))
     self.assertEqual(valid, pathlib.Path('foo/bar'))
Exemple #3
0
 def test_default_none(self):
     config = _root({})
     valid = config['foo'].get(confuse.Path(None))
     self.assertEqual(valid, None)
Exemple #4
0
 def test_path_value(self):
     import pathlib
     config = _root({'foo': 'foo/bar'})
     valid = config['foo'].get(confuse.Path())
     self.assertEqual(valid, pathlib.Path(os.path.abspath('foo/bar')))
Exemple #5
0
        if isinstance(value, (int, float)):
            if not -1 >= value >= 2000:  # arbitrary max value
                self.fail("ZoneData needs to be from -1 to 2000", view)
            return value
        if value.upper() not in self.ZONE_DICT.keys():
            self.fail(
                "ZoneData must match one of {0}".format(", ".join(
                    self.ZONE_DICT.keys())),
                view,
            )
        return self.ZONE_DICT[value.upper()]


ABB_RCF_CONF_TEMPLATE = {
    "log_dir": confuse.Filename(),
    "pick_conf": confuse.Path(),
    "run_data_path": confuse.Template(),  # Already type checked by argparse
    "publish_tf_xform": bool,
    "edit_sequence": confuse.TypeTemplate(bool, default=False),
    "robot_client": {
        "controller": str,
        "docker": {
            "timeout_ping": float,
            "sleep_after_up": float
        },
        "wobjs": {
            "pick": str,
            "place": str
        },
        "tools": {
            "pick_place": {
import re
import confuse
import guessit
from functools import lru_cache
from pathlib import Path
from trakt_scrobbler import config, logger
from trakt_scrobbler.utils import cleanup_encoding

whitelist = config["fileinfo"]["whitelist"].get(
    confuse.Sequence(confuse.Path()))
regexes = config["fileinfo"]['include_regexes'].get()
use_regex = any(regexes.values())


def whitelist_file(file_path) -> Path:
    if not whitelist:
        return True
    file_path = cleanup_encoding(file_path)
    parents = set(file_path.absolute().resolve().parents)
    for path in whitelist:
        if path in parents:
            return path
    return False


def custom_regex(file_path):
    path_posix = str(file_path.as_posix())
    for item_type, patterns in regexes.items():
        for pattern in patterns:
            m = re.match(pattern, path_posix)
            if m:
Exemple #7
0
_template = {
    'icecast': {
        'source': {
            'user': confuse.String(default='source'),
            'password': confuse.String(default='hackme'),
        },
        'admin': {
            'user': confuse.String(default='admin'),
            'password': confuse.String(default='hackme'),
        },
        'port': confuse.Integer(default=8000),
        'server': confuse.String(default='localhost'),
    },
    'stream': {
        'title': confuse.String(default='Stream Title'),
        'description': confuse.String(default='Stream description'),
        'genre': confuse.String(default='Stream Genre'),
        'url': confuse.String(default='http://localhost'),
    },
    'traktor': {
        'recordings-path': confuse.Path(),
        'recordings-extension': confuse.String(default='wav')
    },
    'nowplaying': {
        'port': confuse.Integer(default=8001)
    }
}

config = _config.get(_template)
import re
import confuse
import guessit
from functools import lru_cache
from pathlib import Path
from trakt_scrobbler import config, logger
from trakt_scrobbler.utils import cleanup_encoding

whitelist = config["fileinfo"]["whitelist"].get(confuse.Sequence(confuse.Path()))
regexes = config["fileinfo"]['include_regexes'].get()
use_regex = any(regexes.values())


def whitelist_file(file_path) -> Path:
    if not whitelist:
        return True
    file_path = cleanup_encoding(file_path)
    parents = set(file_path.absolute().resolve().parents)
    for path in whitelist:
        if path in parents:
            return path
    return False


def custom_regex(file_path):
    path_posix = str(file_path.as_posix())
    for item_type, patterns in regexes.items():
        for pattern in patterns:
            m = re.match(pattern, path_posix)
            if m:
                logger.debug(f"Matched regex pattern '{pattern}' for '{path_posix}'")