def sync_node_list(full=False) -> 'Union[int, None]': global cache cp_ = cache.KeyValueStorage.get(CacheConsts.CHECKPOINT_KEY) if not full else None if full: cache.drop_all() cache = db.NodeCache(CACHE_PATH) try: for changeset in acd_client.get_changes(checkpoint=cp_, include_purged=bool(cp_)): if changeset.reset and not full: cache.drop_all() cache = db.NodeCache(CACHE_PATH) full = True else: cache.remove_purged(changeset.purged_nodes) if len(changeset.nodes) > 0: cache.insert_nodes(changeset.nodes, partial=not full) cache.KeyValueStorage.update({CacheConsts.LAST_SYNC_KEY: time.time()}) if len(changeset.nodes) > 0 or len(changeset.purged_nodes) > 0: cache.KeyValueStorage.update({CacheConsts.CHECKPOINT_KEY: changeset.checkpoint}) except RequestError as e: print(e) if e.CODE == RequestError.CODE.INCOMPLETE_RESULT: logger.warning('Sync incomplete.') else: logger.critical('Sync failed.') return ERROR_RETVAL
def testList(self, print_): db.NodeCache(cache_path) folder = gen_folder([]) files = [gen_file([folder]) for _ in range(50)] self.cache.insert_nodes(files + [folder]) sys.argv.extend(['ls', '-t', '/']) self.assertEqual(run_main(), None) self.assertEqual(len(print_.mock_calls), 100)
def old_sync() -> 'Union[int, None]': global cache cache.drop_all() cache = db.NodeCache(CACHE_PATH) try: folders = acd_client.get_folder_list() folders.extend(acd_client.get_trashed_folders()) files = acd_client.get_file_list() files.extend(acd_client.get_trashed_files()) except RequestError as e: logger.critical('Sync failed.') print(e) return ERROR_RETVAL cache.insert_nodes(files + folders, partial=False) cache.KeyValueStorage['sync_date'] = time.time()
def __init__(self, storage_url, login, password, options): # Unused argument #pylint: disable=W0613 super().__init__() if not storage_url.startswith("acd://"): raise QuietError('Invalid storage URL', exitcode=2) with Backend._static_lock: if Backend._acd_client is None: # acd_cli path settings copied from acd_cli _app_name = 'acd_cli' cp = os.environ.get('ACD_CLI_CACHE_PATH') sp = os.environ.get('ACD_CLI_SETTINGS_PATH') CACHE_PATH = cp if cp else appdirs.user_cache_dir( _app_name) SETTINGS_PATH = sp if sp else appdirs.user_config_dir( _app_name) _SETTINGS_FILENAME = _app_name + '.ini' def_conf = ConfigParser() def_conf['download'] = dict(keep_corrupt=False, keep_incomplete=True) def_conf['upload'] = dict(timeout_wait=10) Backend._acd_conf = get_conf(SETTINGS_PATH, _SETTINGS_FILENAME, def_conf) Backend._acd_client = client.ACDClient( CACHE_PATH, SETTINGS_PATH) Backend._acd_cache = db.NodeCache(CACHE_PATH, SETTINGS_PATH) Backend.acd_client_owner = Backend._acd_cache.KeyValueStorage.get( CacheConsts.OWNER_ID) self.parent_node_id = Backend._acd_cache.get_root_node().id self.path = storage_url[6:].strip("/") self._create_rootdir()
def main(): opt_parser, subparsers = get_parser() opt_parser.set_defaults(acd_client=lambda: acd_client, cache=lambda: cache) # plugins plugin_log = [str(plugins.Plugin)] for plugin in plugins.Plugin: if plugin.check_version(acdcli.__version__): log = [] plugin.attach(subparsers, log) plugin_log.extend(log) else: plugin_log.append('Script version is not compatible with "%s".' % plugin) args = opt_parser.parse_args() set_log_level(args) if set_encoding(force_utf=args.utf): logger.info('Stdout/stderr encoding changed to UTF-8. ANSI escape codes may not work.') else: import colorama colorama.init() check_py_version() for msg in plugin_log: logger.info(msg) global acd_client global cache if args.func not in offline_actions: try: acd_client = client.ACDClient(CACHE_PATH) except: raise sys.exit(INIT_FAILED_RETVAL) if args.func not in nocache_actions: try: cache = db.NodeCache(CACHE_PATH, args.check) except: raise sys.exit(INIT_FAILED_RETVAL) if args.func not in [sync_action, old_sync_action, dump_sql_action]: if not check_cache(): sys.exit(INIT_FAILED_RETVAL) format.init(args.color) if args.no_wait: from acdcli.api.backoff_req import BackOffRequest BackOffRequest._wait = lambda x: None autoresolve_attrs = ['child', 'parent', 'node'] resolve_remote_path_args(args, autoresolve_attrs, incl_trash=args.action not in no_autores_trash_actions) # call appropriate sub-parser action if args.func: logger.debug(args) sys.exit(args.func(args))
def setUp(self): reload(acd_cli) sys.argv = [acd_cli._app_name, '-nw'] self.cache = db.NodeCache(cache_path)
def setUp(self): self.cache = db.NodeCache(self.path)
def setUp(self): db.remove_db_file(self.path) self.cache = db.NodeCache(self.path)