Exemplo n.º 1
0
 def test_optional_mapping_template_null_missing_not_allowed(self):
     config = _root({'foo': None})
     template = {'bar': confuse.Integer(), 'baz': confuse.String()}
     valid = config.get(
         {'foo': confuse.Optional(template, allow_missing=False)})
     self.assertIsNone(valid['foo'])
Exemplo n.º 2
0
 def test_optional_mapping_template_allow_missing_default_value(self):
     config = _root({})
     template = {'bar': confuse.Integer(), 'baz': confuse.String()}
     valid = config.get({'foo': confuse.Optional(template, {})})
     self.assertIsInstance(valid['foo'], dict)
Exemplo n.º 3
0
 def test_optional_mapping_template_missing_not_allowed(self):
     config = _root({})
     template = {'bar': confuse.Integer(), 'baz': confuse.String()}
     with self.assertRaises(confuse.NotFoundError):
         config.get(
             {'foo': confuse.Optional(template, allow_missing=False)})
Exemplo n.º 4
0
 def test_optional_mapping_template_invalid(self):
     config = _root({'foo': {'bar': 5, 'baz': 10}})
     template = {'bar': confuse.Integer(), 'baz': confuse.String()}
     with self.assertRaises(confuse.ConfigTypeError):
         config.get({'foo': confuse.Optional(template)})
Exemplo n.º 5
0
 def test_optional_mapping_template_allow_missing_no_explicit_default(self):
     config = _root({})
     template = {'bar': confuse.Integer(), 'baz': confuse.String()}
     valid = config.get({'foo': confuse.Optional(template)})
     self.assertIsNone(valid['foo'])
Exemplo n.º 6
0
 def test_optional_string_null_missing_not_allowed(self):
     config = _root({'foo': None})
     valid = config['foo'].get(
         confuse.Optional(confuse.String(), allow_missing=False))
     self.assertIsNone(valid)
Exemplo n.º 7
0
 def test_optional_mapping_template_valid(self):
     config = _root({'foo': {'bar': 5, 'baz': 'bak'}})
     template = {'bar': confuse.Integer(), 'baz': confuse.String()}
     valid = config.get({'foo': confuse.Optional(template)})
     self.assertEqual(valid['foo']['bar'], 5)
     self.assertEqual(valid['foo']['baz'], 'bak')
Exemplo n.º 8
0
 def test_optional_string_allow_missing_default_value(self):
     config = _root({})
     valid = config['foo'].get(confuse.Optional(confuse.String(), 'baz'))
     self.assertEqual(valid, 'baz')
Exemplo n.º 9
0
 def test_optional_string_missing_not_allowed(self):
     config = _root({})
     with self.assertRaises(confuse.NotFoundError):
         config['foo'].get(
             confuse.Optional(confuse.String(), allow_missing=False))
Exemplo n.º 10
0
 def test_optional_string_null_string_default_override(self):
     config = _root({'foo': None})
     valid = config['foo'].get(
         confuse.Optional(confuse.String('baz'), default='bar'))
     self.assertEqual(valid, 'bar')
Exemplo n.º 11
0
 def test_optional_string_allow_missing_no_explicit_default(self):
     config = _root({})
     valid = config['foo'].get(confuse.Optional(confuse.String()))
     self.assertIsNone(valid)
Exemplo n.º 12
0
 def test_optional_string_null_string_provides_default(self):
     config = _root({'foo': None})
     valid = config['foo'].get(confuse.Optional(confuse.String('baz')))
     self.assertEqual(valid, 'baz')
Exemplo n.º 13
0
 def test_optional_string_null(self):
     config = _root({'foo': None})
     valid = config['foo'].get(confuse.Optional(confuse.String()))
     self.assertIsNone(valid)
Exemplo n.º 14
0
 def test_optional_string_invalid_type(self):
     config = _root({'foo': 5})
     with self.assertRaises(confuse.ConfigTypeError):
         config['foo'].get(confuse.Optional(confuse.String()))
Exemplo n.º 15
0
 def test_optional_string_valid_type(self):
     config = _root({'foo': 'bar'})
     valid = config['foo'].get(confuse.Optional(confuse.String()))
     self.assertEqual(valid, 'bar')
Exemplo n.º 16
0
    def __init__(self):
        super().__init__()

        # Holds candidates corresponding to downloaded images between
        # fetching them and placing them in the filesystem.
        self.art_candidates = {}

        self.config.add({
            'auto': True,
            'minwidth': 0,
            'maxwidth': 0,
            'quality': 0,
            'max_filesize': 0,
            'enforce_ratio': False,
            'cautious': False,
            'cover_names': ['cover', 'front', 'art', 'album', 'folder'],
            'sources': ['filesystem',
                        'coverart', 'itunes', 'amazon', 'albumart'],
            'google_key': None,
            'google_engine': '001442825323518660753:hrh5ch1gjzm',
            'fanarttv_key': None,
            'lastfm_key': None,
            'store_source': False,
            'high_resolution': False,
            'deinterlace': False,
            'cover_format': None,
        })
        self.config['google_key'].redact = True
        self.config['fanarttv_key'].redact = True
        self.config['lastfm_key'].redact = True

        self.minwidth = self.config['minwidth'].get(int)
        self.maxwidth = self.config['maxwidth'].get(int)
        self.max_filesize = self.config['max_filesize'].get(int)
        self.quality = self.config['quality'].get(int)

        # allow both pixel and percentage-based margin specifications
        self.enforce_ratio = self.config['enforce_ratio'].get(
            confuse.OneOf([bool,
                           confuse.String(pattern=self.PAT_PX),
                           confuse.String(pattern=self.PAT_PERCENT)]))
        self.margin_px = None
        self.margin_percent = None
        self.deinterlace = self.config['deinterlace'].get(bool)
        if type(self.enforce_ratio) is str:
            if self.enforce_ratio[-1] == '%':
                self.margin_percent = float(self.enforce_ratio[:-1]) / 100
            elif self.enforce_ratio[-2:] == 'px':
                self.margin_px = int(self.enforce_ratio[:-2])
            else:
                # shouldn't happen
                raise confuse.ConfigValueError()
            self.enforce_ratio = True

        cover_names = self.config['cover_names'].as_str_seq()
        self.cover_names = list(map(util.bytestring_path, cover_names))
        self.cautious = self.config['cautious'].get(bool)
        self.store_source = self.config['store_source'].get(bool)

        self.src_removed = (config['import']['delete'].get(bool) or
                            config['import']['move'].get(bool))

        self.cover_format = self.config['cover_format'].get(
            confuse.Optional(str)
        )

        if self.config['auto']:
            # Enable two import hooks when fetching is enabled.
            self.import_stages = [self.fetch_art]
            self.register_listener('import_task_files', self.assign_art)

        available_sources = list(SOURCES_ALL)
        if not self.config['google_key'].get() and \
                'google' in available_sources:
            available_sources.remove('google')
        if not self.config['lastfm_key'].get() and \
                'lastfm' in available_sources:
            available_sources.remove('lastfm')
        available_sources = [(s, c)
                             for s in available_sources
                             for c in ART_SOURCES[s].VALID_MATCHING_CRITERIA]
        sources = plugins.sanitize_pairs(
            self.config['sources'].as_pairs(default_value='*'),
            available_sources)

        if 'remote_priority' in self.config:
            self._log.warning(
                'The `fetch_art.remote_priority` configuration option has '
                'been deprecated. Instead, place `filesystem` at the end of '
                'your `sources` list.')
            if self.config['remote_priority'].get(bool):
                fs = []
                others = []
                for s, c in sources:
                    if s == 'filesystem':
                        fs.append((s, c))
                    else:
                        others.append((s, c))
                sources = others + fs

        self.sources = [ART_SOURCES[s](self._log, self.config, match_by=[c])
                        for s, c in sources]