~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Robert J. Tanner
  • Date: 2009-04-20 08:37:32 UTC
  • mfrom: (4299 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4300.
  • Revision ID: tanner@real-time.com-20090420083732-bzx919oo7wpmqc2u
[merge] 1.14rc2 back into bzr.dev (Bob Tanner)

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):
1962
1961
        except (errors.NotStacked, errors.UnstackableBranchFormat,
1963
1962
            errors.UnstackableRepositoryFormat), e:
1964
1963
            return
1965
 
        self._activate_fallback_location(fallback_url)
 
1964
        self._activate_fallback_location(fallback_url, None)
1966
1965
 
1967
1966
    def _get_config(self):
1968
1967
        return RemoteBranchConfig(self)
2301
2300
        self._ensure_real()
2302
2301
        return self._real_branch._get_parent_location()
2303
2302
 
2304
 
    def set_parent(self, url):
2305
 
        self._ensure_real()
2306
 
        return self._real_branch.set_parent(url)
2307
 
 
2308
2303
    def _set_parent_location(self, url):
2309
 
        # Used by tests, to poke bad urls into branch configurations
2310
 
        if url is None:
2311
 
            self.set_parent(url)
2312
 
        else:
2313
 
            self._ensure_real()
2314
 
            return self._real_branch._set_parent_location(url)
 
2304
        medium = self._client._medium
 
2305
        if medium._is_remote_before((1, 15)):
 
2306
            return self._vfs_set_parent_location(url)
 
2307
        try:
 
2308
            call_url = url or ''
 
2309
            if type(call_url) is not str:
 
2310
                raise AssertionError('url must be a str or None (%s)' % url)
 
2311
            response = self._call('Branch.set_parent_location',
 
2312
                self._remote_path(), self._lock_token, self._repo_lock_token,
 
2313
                call_url)
 
2314
        except errors.UnknownSmartMethod:
 
2315
            medium._remember_remote_is_before((1, 15))
 
2316
            return self._vfs_set_parent_location(url)
 
2317
        if response != ():
 
2318
            raise errors.UnexpectedSmartServerResponse(response)
 
2319
 
 
2320
    def _vfs_set_parent_location(self, url):
 
2321
        self._ensure_real()
 
2322
        return self._real_branch._set_parent_location(url)
2315
2323
 
2316
2324
    @needs_write_lock
2317
2325
    def pull(self, source, overwrite=False, stop_revision=None,
2385
2393
        return self._real_branch.set_push_location(location)
2386
2394
 
2387
2395
 
2388
 
class RemoteBranchConfig(object):
2389
 
    """A Config that reads from a smart branch and writes via smart methods.
 
2396
class RemoteConfig(object):
 
2397
    """A Config that reads and writes from smart verbs.
2390
2398
 
2391
2399
    It is a low-level object that considers config data to be name/value pairs
2392
2400
    that may be associated with a section. Assigning meaning to the these
2393
2401
    values is done at higher levels like bzrlib.config.TreeConfig.
2394
2402
    """
2395
2403
 
2396
 
    def __init__(self, branch):
2397
 
        self._branch = branch
2398
 
 
2399
2404
    def get_option(self, name, section=None, default=None):
2400
2405
        """Return the value associated with a named option.
2401
2406
 
2404
2409
        :param default: The value to return if the value is not set
2405
2410
        :return: The value or default value
2406
2411
        """
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)
 
2412
        try:
 
2413
            configobj = self._get_configobj()
 
2414
            if section is None:
 
2415
                section_obj = configobj
 
2416
            else:
 
2417
                try:
 
2418
                    section_obj = configobj[section]
 
2419
                except KeyError:
 
2420
                    return default
 
2421
            return section_obj.get(name, default)
 
2422
        except errors.UnknownSmartMethod:
 
2423
            return self._vfs_get_option(name, section, default)
 
2424
 
 
2425
    def _response_to_configobj(self, response):
 
2426
        if len(response[0]) and response[0][0] != 'ok':
 
2427
            raise errors.UnexpectedSmartServerResponse(response)
 
2428
        lines = response[1].read_body_bytes().splitlines()
 
2429
        return config.ConfigObj(lines, encoding='utf-8')
 
2430
 
 
2431
 
 
2432
class RemoteBranchConfig(RemoteConfig):
 
2433
    """A RemoteConfig for Branches."""
 
2434
 
 
2435
    def __init__(self, branch):
 
2436
        self._branch = branch
2416
2437
 
2417
2438
    def _get_configobj(self):
2418
2439
        path = self._branch._remote_path()
2419
2440
        response = self._branch._client.call_expecting_body(
2420
2441
            'Branch.get_config_file', path)
2421
 
        if response[0][0] != 'ok':
2422
 
            raise UnexpectedSmartServerResponse(response)
2423
 
        lines = response[1].read_body_bytes().splitlines()
2424
 
        return config.ConfigObj(lines, encoding='utf-8')
 
2442
        return self._response_to_configobj(response)
2425
2443
 
2426
2444
    def set_option(self, value, name, section=None):
2427
2445
        """Set the value associated with a named option.
2444
2462
        if response != ():
2445
2463
            raise errors.UnexpectedSmartServerResponse(response)
2446
2464
 
 
2465
    def _real_object(self):
 
2466
        self._branch._ensure_real()
 
2467
        return self._branch._real_branch
 
2468
 
2447
2469
    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)
 
2470
        return self._real_object()._get_config().set_option(
 
2471
            value, name, section)
 
2472
 
 
2473
 
 
2474
class RemoteBzrDirConfig(RemoteConfig):
 
2475
    """A RemoteConfig for BzrDirs."""
 
2476
 
 
2477
    def __init__(self, bzrdir):
 
2478
        self._bzrdir = bzrdir
 
2479
 
 
2480
    def _get_configobj(self):
 
2481
        medium = self._bzrdir._client._medium
 
2482
        verb = 'BzrDir.get_config_file'
 
2483
        if medium._is_remote_before((1, 15)):
 
2484
            raise errors.UnknownSmartMethod(verb)
 
2485
        path = self._bzrdir._path_for_remote_call(self._bzrdir._client)
 
2486
        response = self._bzrdir._call_expecting_body(
 
2487
            verb, path)
 
2488
        return self._response_to_configobj(response)
 
2489
 
 
2490
    def _vfs_get_option(self, name, section, default):
 
2491
        return self._real_object()._get_config().get_option(
 
2492
            name, section, default)
 
2493
 
 
2494
    def set_option(self, value, name, section=None):
 
2495
        """Set the value associated with a named option.
 
2496
 
 
2497
        :param value: The value to set
 
2498
        :param name: The name of the value to set
 
2499
        :param section: The section the option is in (if any)
 
2500
        """
 
2501
        return self._real_object()._get_config().set_option(
 
2502
            value, name, section)
 
2503
 
 
2504
    def _real_object(self):
 
2505
        self._bzrdir._ensure_real()
 
2506
        return self._bzrdir._real_bzrdir
 
2507
 
2451
2508
 
2452
2509
 
2453
2510
def _extract_tar(tar, to_dir):