392
392
return self._real_bzrdir.clone(url, revision_id=revision_id,
393
393
force_new_repo=force_new_repo, preserve_stacking=preserve_stacking)
395
def get_config(self):
397
return self._real_bzrdir.get_config()
395
def _get_config(self):
396
return RemoteBzrDirConfig(self)
400
399
class RemoteRepositoryFormat(repository.RepositoryFormat):
2385
2384
return self._real_branch.set_push_location(location)
2388
class RemoteBranchConfig(object):
2389
"""A Config that reads from a smart branch and writes via smart methods.
2387
class RemoteConfig(object):
2388
"""A Config that reads and writes from smart verbs.
2391
2390
It is a low-level object that considers config data to be name/value pairs
2392
2391
that may be associated with a section. Assigning meaning to the these
2393
2392
values is done at higher levels like bzrlib.config.TreeConfig.
2396
def __init__(self, branch):
2397
self._branch = branch
2399
2395
def get_option(self, name, section=None, default=None):
2400
2396
"""Return the value associated with a named option.
2404
2400
:param default: The value to return if the value is not set
2405
2401
:return: The value or default value
2407
configobj = self._get_configobj()
2409
section_obj = configobj
2412
section_obj = configobj[section]
2415
return section_obj.get(name, default)
2404
configobj = self._get_configobj()
2406
section_obj = configobj
2409
section_obj = configobj[section]
2412
return section_obj.get(name, default)
2413
except errors.UnknownSmartMethod:
2414
return self._vfs_get_option(name, section, default)
2417
def _get_configobj(self):
2418
path = self._branch._remote_path()
2419
response = self._branch._client.call_expecting_body(
2420
'Branch.get_config_file', path)
2416
def _response_to_configobj(self, response):
2421
2417
if response[0][0] != 'ok':
2422
2418
raise UnexpectedSmartServerResponse(response)
2423
2419
lines = response[1].read_body_bytes().splitlines()
2424
2420
return config.ConfigObj(lines, encoding='utf-8')
2423
class RemoteBranchConfig(RemoteConfig):
2424
"""A RemoteConfig for Branches."""
2426
def __init__(self, branch):
2427
self._branch = branch
2429
def _get_configobj(self):
2430
path = self._branch._remote_path()
2431
response = self._branch._client.call_expecting_body(
2432
'Branch.get_config_file', path)
2433
return self._response_to_configobj(response)
2426
2435
def set_option(self, value, name, section=None):
2427
2436
"""Set the value associated with a named option.
2444
2453
if response != ():
2445
2454
raise errors.UnexpectedSmartServerResponse(response)
2456
def _real_object(self):
2457
self._branch._ensure_real()
2458
return self._branch._real_branch
2447
2460
def _vfs_set_option(self, value, name, section=None):
2448
self._branch._ensure_real()
2449
return self._branch._real_branch._get_config().set_option(
2450
value, name, section)
2461
return self._real_object()._get_config().set_option(
2462
value, name, section)
2465
class RemoteBzrDirConfig(RemoteConfig):
2466
"""A RemoteConfig for BzrDirs."""
2468
def __init__(self, bzrdir):
2469
self._bzrdir = bzrdir
2471
def _get_configobj(self):
2472
path = self._bzrdir._path_for_remote_call(self._bzrdir._client)
2473
response = self._bzrdir._call_expecting_body(
2474
'BzrDir.get_config_file', path)
2475
return self._response_to_configobj(response)
2477
def _vfs_get_option(self, name, section, default):
2478
return self._real_object()._get_config().get_option(
2479
name, section, default)
2481
def set_option(self, value, name, section=None):
2482
"""Set the value associated with a named option.
2484
:param value: The value to set
2485
:param name: The name of the value to set
2486
:param section: The section the option is in (if any)
2488
return self._real_object()._get_config().set_option(
2489
value, name, section)
2491
def _real_object(self):
2492
self._bzrdir._ensure_real()
2493
return self._bzrdir._real_bzrdir
2453
2497
def _extract_tar(tar, to_dir):