def test_sources(self): """ Getting/Add/Remove Sources should work """ srcs = settings.get_sources() cnt = len(srcs) self.assertGreater(cnt, 0, msg='Failed to get any sources!') settings.add_source(srcs[0], prevent_duplicate=True) self.assertEqual(len(settings.get_sources()), cnt, msg='Incorrectly added duplicate source!') ups = UpvotedSaved() ups.set_alias('new-source') settings.add_source(ups) self.assertGreater(len(settings.get_sources()), cnt, msg='Failed to add new source!') settings.remove_source(ups) self.assertEqual(cnt, len(settings.get_sources()), msg='Failed to remove source!')
def _adapt(obj): # !cover """ Convert old versions of the Settings files up to the newest version. """ version = 1 converted = False if 'meta-version' in obj: version = obj['meta-version'] elif _default_cat in obj and 'meta-version' in obj[_default_cat]: version = obj[_default_cat]['meta-version'] if version == 1: # Version 1->2 saw addition of Sources & Filters. obj['meta-version'] = 2 obj['sources'] = {} from sources import UpvotedSaved us = UpvotedSaved( ) # This Source doesn't need any extra info, and it simulates original behavior. us.set_alias('default-downloader') obj['sources'].append(us.to_obj()) version = 2 print("Adapted from Settings version 1 -> 2!") converted = True if version == 2: # Version 2->3 saw addition of display config, for Threading. obj['meta-version'] = 3 obj['threading'] = { "max_handler_threads": 5, "display_clear_screen": True, "display_refresh_rate": 5 } version = 3 print("Adapted from Settings version 2 -> 3!") converted = True if version == 3: # Version 3->4 saw the Manifest shift to SQLite, the Settings overhaul, and the WebUI. obj[_default_cat] = {} rm = [] for k, v in obj.items(): if isinstance(v, dict): continue if k not in [ 'build_manifest', 'last_started', 'deduplicate_files', 'client_id', 'client_secret', 'password', 'username' ]: obj[_default_cat][k] = v rm.append(k) obj[_default_cat]['meta-version'] = 4 obj['output']['deduplicate_files'] = obj['deduplicate_files'] for r in rm: del obj[r] obj['interface'] = {} # obj['interface']['start_server'] = False # Default to old behavior. print("Adapted from Settings version 3 -> 4!") converted = True version = 4 if version == 4: # Moved to SqlAlchemy and Multiprocessing. obj['processing'] = { 'deduplicate_files': obj['output']['deduplicate_files'] } obj['output']['file_name_pattern'] = \ ('%s/%s' % (obj['output']['subdir_pattern'], obj['output']['file_name_pattern'])).replace('//', '/') obj['threading']['console_clear_screen'] = obj['threading'][ 'display_clear_screen'] obj['threading']['concurrent_downloads'] = obj['threading'][ 'max_handler_threads'] del obj['output']['subdir_pattern'] del obj['output']['deduplicate_files'] del obj['threading']['display_clear_screen'] del obj['threading']['max_handler_threads'] print("Adapted from Settings version 4 -> 5!") obj[_default_cat]['meta-version'] = 5 converted = True # version = 5 return obj, converted
def _adapt(obj): """ Convert old versions of the Settings files up to the newest version. """ version = 1 converted = False if 'meta-version' in obj: version = obj['meta-version'] elif _default_cat in obj and 'meta-version' in obj[_default_cat]: version = obj[_default_cat]['meta-version'] max_version = get('meta-version') if version > max_version: raise ValueError( 'The loaded settings are on version %s, but this RMD build only supports up to %s!' 'Please update RMD, or fix/delete your settings file.' % (version, max_version)) if version == 1: # Version 1->2 saw addition of Sources & Filters. obj['meta-version'] = 2 obj['sources'] = [] from sources import UpvotedSaved us = UpvotedSaved( ) # This Source doesn't need any extra info, and it simulates original behavior. us.set_alias('default-downloader') obj['sources'].append(us.to_obj()) version = 2 print("Adapted from Settings version 1 -> 2!") converted = True if version == 2: # Version 2->3 saw addition of display config, for Threading, as well as oAuth. del obj['auth']['client_id'] del obj['auth']['client_secret'] del obj['auth']['password'] del obj['auth']['username'] obj['meta-version'] = 3 obj['threading'] = { "max_handler_threads": 5, "display_clear_screen": True, "display_refresh_rate": 5 } obj['deduplicate_files'] = True version = 3 print("Adapted from Settings version 2 -> 3!") converted = True if version == 3: # Version 3->4 saw the Manifest shift to SQLite, the Settings overhaul, and the WebUI. obj[_default_cat] = {} rm = [] for k, v in obj.items(): if isinstance(v, dict): continue if k not in [ 'build_manifest', 'last_started', 'deduplicate_files', 'client_id', 'client_secret', 'password', 'username' ]: obj[_default_cat][k] = v rm.append(k) obj[_default_cat]['meta-version'] = 4 obj['output']['deduplicate_files'] = obj['deduplicate_files'] for r in rm: del obj[r] obj['interface'] = {} # obj['interface']['start_server'] = False # Default to old behavior. print("Adapted from Settings version 3 -> 4!") converted = True version = 4 if version == 4: # Moved to SqlAlchemy and Multiprocessing. obj['processing'] = { 'deduplicate_files': obj['output']['deduplicate_files'] } obj['output']['file_name_pattern'] = \ ('%s/%s' % (obj['output']['subdir_pattern'], obj['output']['file_name_pattern'])).replace('//', '/') obj['output']['base_dir'] = os.path.abspath(obj['output']['base_dir']) obj['threading']['console_clear_screen'] = obj['threading'][ 'display_clear_screen'] obj['threading']['concurrent_downloads'] = obj['threading'][ 'max_handler_threads'] obj['imgur'] = {'client_id': '', 'client_secret': ''} del obj['output']['subdir_pattern'] del obj['output']['deduplicate_files'] del obj['threading']['display_clear_screen'] del obj['threading']['max_handler_threads'] print("Adapted from Settings version 4 -> 5!") obj[_default_cat]['meta-version'] = 5 converted = True version = 5 if version == 5: # RMD 3.1.0 # Added setting for custom manifest file location. obj['output']['manifest'] = "./manifest.sqlite" obj['processing']['retry_failed'] = True print("Adapted from Settings version 5 -> 6!") converted = True obj[_default_cat]['meta-version'] = 6 # version = 6 # Adjust meta-version Setting object when you make changes. return obj, converted