예제 #1
0
        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()
예제 #2
0
 def setUp(self):
     self.acd_client = client.ACDClient(path)
     self.acd_client.BOReq._wait = lambda: None
     self.assertTrue(os.path.isfile(os.path.join(path, 'oauth_data')))
     self.assertTrue(os.path.isfile(os.path.join(path, 'endpoint_data')))
예제 #3
0
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))