~ubuntu-branches/debian/sid/bzr-explorer/sid

« back to all changes in this revision

Viewing changes to lib/location.py

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2011-07-21 12:53:07 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20110721125307-x7dh0x9ywm2mdzuo
Tags: 1.2.0-1
* New upstream release.
* debian/control: Update Vcs-* fields. 
* bzr-explorer.lintian-overrides: Fix format so
  lintian correctly picks it up again. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
327
327
        """Return the kind and naming details."""
328
328
        # Get the pieces
329
329
        kind = self.kind()
330
 
        repo_str = ""
331
 
        br_str = ""
332
 
        co_str = ""
333
 
        br_base = None
 
330
        locations = {
 
331
                'this_location': None,
 
332
                'master_location': None,
 
333
                'repository': None,
 
334
                }
334
335
        shared_tree_repo_found = False
 
336
        def format_location(location):
 
337
            return self.url_for_display(strip_trailing_slash(location))
335
338
        if kind == CHECKOUT_KIND:
336
 
            co_base = self._root
337
 
            co_str = os.path.basename(self.url_for_display(co_base))
338
 
        if self.branch:
339
 
            br_base = strip_trailing_slash(self.branch.base)
340
 
            br_str = os.path.basename(self.url_for_display(br_base))
 
339
            locations['this_location'] = format_location(self._root)
 
340
            locations['master_location'] = format_location(self.branch.base)
 
341
        elif kind == BOUND_BRANCH_KIND:
 
342
            locations['this_location'] = format_location(self.branch.base)
 
343
            locations['master_location'] = format_location(self.branch.get_bound_location())
 
344
        elif kind == BRANCH_KIND:
 
345
            locations['this_location'] = format_location(self.branch.base)
341
346
        if self.repository:
342
 
            repo_base = strip_trailing_slash(
343
 
                self.repository.bzrdir.root_transport.external_url())
344
 
            if br_base is not None and repo_base == br_base:
345
 
                loc_str = self.location
346
 
                if loc_str.endswith(br_str):
347
 
                    loc_str = os.path.basename(loc_str[:-(len(br_str) + 1)])
348
 
                repo_str = '(%s)' % (loc_str,)
 
347
            repository_location = format_location(self.repository.bzrdir.root_transport.external_url())
 
348
            if repository_location != locations['this_location']:
 
349
                locations['repository'] = repository_location
 
350
                if os.path.basename(locations['repository']) == '.bzrbranches':
 
351
                    locations['repository'] = os.path.split(locations['repository'])[0]
 
352
                    shared_tree_repo_found = True
 
353
                elif locations['repository'].endswith('/.bzr/branches'):
 
354
                    locations['repository'] = locations['repository'][:-len('/.bzr/branches')]
 
355
                    shared_tree_repo_found = True
 
356
        for key in locations.keys():
 
357
            if locations[key] is not None:
 
358
                locations[key + '_base'] = os.path.basename(locations[key])
349
359
            else:
350
 
                repo_path = self.url_for_display(repo_base)
351
 
                repo_str = os.path.basename(repo_path)
352
 
                # If this is a nested shared repo inside a checkout
353
 
                # (as happens in the 'colocated-branches' model), use the
354
 
                # checkout name as the label.
355
 
                if repo_str == '.bzrbranches':
356
 
                    repo_str = repo_path.split("/")[-2]
357
 
                    shared_tree_repo_found = True
358
 
                elif repo_path.endswith("/.bzr/branches"):
359
 
                    repo_str = repo_path.split("/")[-3]
360
 
                    shared_tree_repo_found = True
361
 
                if kind != REPOSITORY_KIND:
362
 
                    repo_str = '[%s]' % (repo_str,)
363
 
        template = {
364
 
            'repo': repo_str,
365
 
            'br': br_str,
366
 
            'co': co_str,
367
 
            'relpath': self.relpath,
368
 
            'pathsep': os.path.sep,
369
 
        }
370
 
        return kind, template, shared_tree_repo_found
 
360
                locations[key + '_base'] = None
 
361
        return kind, locations, shared_tree_repo_found
371
362
 
372
363
    def display_name(self):
373
364
        """Return a name suitable for displaying in a tab or title bar.
381
372
          [repository]
382
373
          checkout -> branch [repository]
383
374
        """
384
 
        kind, template, shared_tree_repo_found = self._get_name_details()
385
 
        if kind in [BRANCH_KIND, BOUND_BRANCH_KIND]:
386
 
            if self.repository:
387
 
                format = "%(br)s %(repo)s"
 
375
        kind, locations, shared_tree_repo_found = self._get_name_details()
 
376
        if kind == BRANCH_KIND:
 
377
            if locations['repository'] is not None:
 
378
                format = "%(this_location_base)s [%(repository_base)s]"
388
379
            else:
389
 
                format = "%(br)s"
 
380
                format = "%(this_location_base)s"
390
381
        elif kind == CHECKOUT_KIND:
391
 
            if template['br'] == 'trunk':
392
 
                format = "%(co)s"
393
 
            else:
394
 
                format = "%(co)s -> %(br)s"
395
 
            if self.repository and not shared_tree_repo_found:
396
 
                format += " %(repo)s"
 
382
            format = "%(this_location_base)s -> %(master_location_base)s"
 
383
            if locations['repository'] is not None and not shared_tree_repo_found:
 
384
                format += " %(repository)s"
 
385
        elif kind == BOUND_BRANCH_KIND:
 
386
            format = "%(this_location_base)s -> %(master_location_base)s"
397
387
        elif kind == REPOSITORY_KIND:
398
 
            format = "%(repo)s"
 
388
            format = "[%(repository_base)s]"
399
389
        else:
400
390
            format = None
401
 
        return format % template
 
391
        return format % locations
402
392
 
403
393
    def display_local_name(self):
404
394
        """Return a name to display - context is implied. """
405
 
        kind, template, _ = self._get_name_details()
406
 
        if kind in [BRANCH_KIND, BOUND_BRANCH_KIND]:
407
 
            format = "%(br)s"
408
 
        elif kind == CHECKOUT_KIND:
409
 
            if template['br'] == 'trunk':
410
 
                format = "%(co)s"
411
 
            else:
412
 
                format = "%(co)s -> %(br)s"
 
395
        kind, locations, _ = self._get_name_details()
 
396
        if kind == BRANCH_KIND:
 
397
            format = "%(this_location_base)s"
 
398
        elif kind in [CHECKOUT_KIND, BOUND_BRANCH_KIND]:
 
399
            format = "%(this_location_base)s -> %(master_location_base)s"
413
400
        elif kind == REPOSITORY_KIND:
414
401
            # Just the icon would do but it looks too plain if that's
415
402
            # the only object open. If the space could be better used
418
405
            format = gettext("Repository")
419
406
        else:
420
407
            format = None
421
 
        return format % template
 
408
        return format % locations
 
409
 
 
410
    def display_tooltip(self):
 
411
        kind, locations, shared_tree_repo_found = self._get_name_details()
 
412
        format = kind + " "
 
413
        if kind == BRANCH_KIND:
 
414
            format += "%(this_location)s"
 
415
            if locations['repository'] is not None:
 
416
                format += "\n" + gettext("in repository") + " %(repository)s"
 
417
        elif kind == CHECKOUT_KIND:
 
418
            format += "%(this_location)s\n-> %(master_location)s"
 
419
            if locations['repository'] is not None and not shared_tree_repo_found:
 
420
                format += "\n" + gettext("in repository") + " %(repository)s"
 
421
        elif kind == BOUND_BRANCH_KIND:
 
422
            format += "%(this_location)s\n-> %(master_location)s"
 
423
        elif kind == REPOSITORY_KIND:
 
424
            format += "%(this_location)s"
 
425
 
 
426
        return format % locations
422
427
 
423
428
    def display_diagnostics(self):
424
429
        """Return diagnostic information as a string.