/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

Reinstate the use of the Branch.get_config_file verb.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from bzrlib import (
23
23
    branch,
24
24
    bzrdir,
 
25
    config,
25
26
    debug,
26
27
    errors,
27
28
    graph,
1937
1938
            return
1938
1939
        self._activate_fallback_location(fallback_url)
1939
1940
 
 
1941
    def _get_config(self):
 
1942
        return RemoteBranchConfig(self)
 
1943
 
1940
1944
    def _get_real_transport(self):
1941
1945
        # if we try vfs access, return the real branch's vfs transport
1942
1946
        self._ensure_real()
2355
2359
        return self._real_branch.set_push_location(location)
2356
2360
 
2357
2361
 
 
2362
class RemoteBranchConfig(object):
 
2363
    """A Config that reads from a smart branch and writes via smart methods.
 
2364
 
 
2365
    It is a low-level object that considers config data to be name/value pairs
 
2366
    that may be associated with a section. Assigning meaning to the these
 
2367
    values is done at higher levels like bzrlib.config.TreeConfig.
 
2368
    """
 
2369
 
 
2370
    def __init__(self, branch):
 
2371
        self._branch = branch
 
2372
 
 
2373
    def get_option(self, name, section=None, default=None):
 
2374
        """Return the value associated with a named option.
 
2375
 
 
2376
        :param name: The name of the value
 
2377
        :param section: The section the option is in (if any)
 
2378
        :param default: The value to return if the value is not set
 
2379
        :return: The value or default value
 
2380
        """
 
2381
        configobj = self._get_configobj()
 
2382
        if section is None:
 
2383
            section_obj = configobj
 
2384
        else:
 
2385
            try:
 
2386
                section_obj = configobj[section]
 
2387
            except KeyError:
 
2388
                return default
 
2389
        return section_obj.get(name, default)
 
2390
 
 
2391
    def _get_configobj(self):
 
2392
        path = self._branch.bzrdir._path_for_remote_call(
 
2393
            self._branch._client)
 
2394
        response = self._branch._client.call_expecting_body(
 
2395
            'Branch.get_config_file', path)
 
2396
        if response[0][0] != 'ok':
 
2397
            raise UnexpectedSmartServerResponse(response)
 
2398
        bytes = response[1].read_body_bytes()
 
2399
        return config.ConfigObj([bytes], encoding='utf-8')
 
2400
 
 
2401
    def set_option(self, value, name, section=None):
 
2402
        """Set the value associated with a named option.
 
2403
 
 
2404
        :param value: The value to set
 
2405
        :param name: The name of the value to set
 
2406
        :param section: The section the option is in (if any)
 
2407
        """
 
2408
        return self._vfs_set_option(value, name, section)
 
2409
 
 
2410
    def _vfs_set_option(self, value, name, section=None):
 
2411
        self._branch._ensure_real()
 
2412
        return self._branch._real_branch._get_config().set_option(
 
2413
            value, name, section)
 
2414
 
 
2415
 
2358
2416
def _extract_tar(tar, to_dir):
2359
2417
    """Extract all the contents of a tarfile object.
2360
2418