~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Robert Collins
  • Date: 2009-04-14 02:35:07 UTC
  • mto: This revision was merged to the branch mainline in revision 4291.
  • Revision ID: robertc@robertcollins.net-20090414023507-935t0u7ab2rt7kfk
Add support for a RemoteBzrDirConfig to support optimising push operations which need to look for default stacking locations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
392
392
        return self._real_bzrdir.clone(url, revision_id=revision_id,
393
393
            force_new_repo=force_new_repo, preserve_stacking=preserve_stacking)
394
394
 
395
 
    def get_config(self):
396
 
        self._ensure_real()
397
 
        return self._real_bzrdir.get_config()
 
395
    def _get_config(self):
 
396
        return RemoteBzrDirConfig(self)
398
397
 
399
398
 
400
399
class RemoteRepositoryFormat(repository.RepositoryFormat):
2385
2384
        return self._real_branch.set_push_location(location)
2386
2385
 
2387
2386
 
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.
2390
2389
 
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.
2394
2393
    """
2395
2394
 
2396
 
    def __init__(self, branch):
2397
 
        self._branch = branch
2398
 
 
2399
2395
    def get_option(self, name, section=None, default=None):
2400
2396
        """Return the value associated with a named option.
2401
2397
 
2404
2400
        :param default: The value to return if the value is not set
2405
2401
        :return: The value or default value
2406
2402
        """
2407
 
        configobj = self._get_configobj()
2408
 
        if section is None:
2409
 
            section_obj = configobj
2410
 
        else:
2411
 
            try:
2412
 
                section_obj = configobj[section]
2413
 
            except KeyError:
2414
 
                return default
2415
 
        return section_obj.get(name, default)
 
2403
        try:
 
2404
            configobj = self._get_configobj()
 
2405
            if section is None:
 
2406
                section_obj = configobj
 
2407
            else:
 
2408
                try:
 
2409
                    section_obj = configobj[section]
 
2410
                except KeyError:
 
2411
                    return default
 
2412
            return section_obj.get(name, default)
 
2413
        except errors.UnknownSmartMethod:
 
2414
            return self._vfs_get_option(name, section, default)
2416
2415
 
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')
2425
2421
 
 
2422
 
 
2423
class RemoteBranchConfig(RemoteConfig):
 
2424
    """A RemoteConfig for Branches."""
 
2425
 
 
2426
    def __init__(self, branch):
 
2427
        self._branch = branch
 
2428
 
 
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)
 
2434
 
2426
2435
    def set_option(self, value, name, section=None):
2427
2436
        """Set the value associated with a named option.
2428
2437
 
2444
2453
        if response != ():
2445
2454
            raise errors.UnexpectedSmartServerResponse(response)
2446
2455
 
 
2456
    def _real_object(self):
 
2457
        self._branch._ensure_real()
 
2458
        return self._branch._real_branch
 
2459
 
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)
 
2463
 
 
2464
 
 
2465
class RemoteBzrDirConfig(RemoteConfig):
 
2466
    """A RemoteConfig for BzrDirs."""
 
2467
 
 
2468
    def __init__(self, bzrdir):
 
2469
        self._bzrdir = bzrdir
 
2470
 
 
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)
 
2476
 
 
2477
    def _vfs_get_option(self, name, section, default):
 
2478
        return self._real_object()._get_config().get_option(
 
2479
            name, section, default)
 
2480
 
 
2481
    def set_option(self, value, name, section=None):
 
2482
        """Set the value associated with a named option.
 
2483
 
 
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)
 
2487
        """
 
2488
        return self._real_object()._get_config().set_option(
 
2489
            value, name, section)
 
2490
 
 
2491
    def _real_object(self):
 
2492
        self._bzrdir._ensure_real()
 
2493
        return self._bzrdir._real_bzrdir
 
2494
 
2451
2495
 
2452
2496
 
2453
2497
def _extract_tar(tar, to_dir):