/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 tools/win32/bzr-win32-bdist-postinstall.py

  • Committer: Robert Collins
  • Date: 2008-01-06 20:04:22 UTC
  • mto: (3221.11.1 StackableBranch)
  • mto: This revision was merged to the branch mainline in revision 3226.
  • Revision ID: robertc@robertcollins.net-20080106200422-x8yz6cxotlzltvwp
The bzrdir format registry now accepts an ``alias`` keyword to
register_metadir, used to indicate that a format name is an alias for
some other format and thus should not be reported when describing the
format. (Robert Collins)
-------------- This line and the fmllowing will be ignored --------------

modified:
  NEWS
  bzrlib/bzrdir.py
  bzrlib/info.py
  bzrlib/tests/test_bzrdir.py
  bzrlib/tests/test_info.py

=== modified file 'NEWS'
--- a/NEWS      2008-01-02 22:30:46 +0000
+++ b/NEWS      2008-01-06 20:04:15 +0000
@@ -135,6 +135,11 @@
     * Patience Diff now supports arbitrary python objects, as long as they
       support ``hash()``. (John Arbash Meinel)
 
+    * The bzrdir format registry now accepts an ``alias`` keyword to
+      register_metadir, used to indicate that a format name is an alias for
+      some other format and thus should not be reported when describing the
+      format. (Robert Collins)
+
   API BREAKS:
 
   TESTING:

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py  2008-01-02 22:30:46 +0000
+++ b/bzrlib/bzrdir.py  2008-01-06 19:41:29 +0000
@@ -2447,12 +2447,22 @@
     e.g. BzrDirMeta1 with weave repository.  Also, it's more user-oriented.
     """
 
+    def __init__(self):
+        """Create a BzrDirFormatRegistry."""
+        self._aliases = set()
+        super(BzrDirFormatRegistry, self).__init__()
+
+    def aliases(self):
+        """Return a set of the format names which are aliases."""
+        return frozenset(self._aliases)
+
     def register_metadir(self, key,
              repository_format, help, native=True, deprecated=False,
              branch_format=None,
              tree_format=None,
              hidden=False,
-             experimental=False):
+             experimental=False,
+             alias=False):
         """Register a metadir subformat.
 
         These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
@@ -2491,10 +2501,10 @@
                 bd.repository_format = _load(repository_format)
             return bd
         self.register(key, helper, help, native, deprecated, hidden,
-            experimental)
+            experimental, alias)
 
     def register(self, key, factory, help, native=True, deprecated=False,
-                 hidden=False, experimental=False):
+                 hidden=False, experimental=False, alias=False):
         """Register a BzrDirFormat factory.
         
         The factory must be a callable that takes one parameter: the key.
@@ -2505,11 +2515,15 @@
         """
         registry.Registry.register(self, key, factory, help,
             BzrDirFormatInfo(native, deprecated, hidden, experimental))
+        if alias:
+            self._aliases.add(key)
 
     def register_lazy(self, key, module_name, member_name, help, native=True,
-                      deprecated=False, hidden=False, experimental=False):
+        deprecated=False, hidden=False, experimental=False, alias=False):
         registry.Registry.register_lazy(self, key, module_name, member_name,
             help, BzrDirFormatInfo(native, deprecated, hidden, experimental))
+        if alias:
+            self._aliases.add(key)
 
     def set_default(self, key):
         """Set the 'default' key to be a clone of the supplied key.
@@ -2518,6 +2532,7 @@
         """
         registry.Registry.register(self, 'default', self.get(key),
             self.get_help(key), info=self.get_info(key))
+        self._aliases.add('default')
 
     def set_default_repository(self, key):
         """Set the FormatRegistry default and Repository default.
@@ -2670,6 +2685,7 @@
     tree_format='bzrlib.workingtree.WorkingTreeFormat4',
     hidden=False,
     )
+# The following two formats should always just be aliases.
 format_registry.register_metadir('development',
     'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0',
     help='Current development format. Can convert data to and from pack-0.92 '
@@ -2681,6 +2697,7 @@
     branch_format='bzrlib.branch.BzrBranchFormat6',
     tree_format='bzrlib.workingtree.WorkingTreeFormat4',
     experimental=True,
+    alias=True,
     )
 format_registry.register_metadir('development-subtree',
     'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0Subtree',
@@ -2693,7 +2710,9 @@
     branch_format='bzrlib.branch.BzrBranchFormat6',
     tree_format='bzrlib.workingtree.WorkingTreeFormat4',
     experimental=True,
+    alias=True,
     )
+# And the development formats which the will have aliased one of follow:
 format_registry.register_metadir('development0',
     'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0',
     help='Trivial rename of pack-0.92 to provide a development format. '

=== modified file 'bzrlib/info.py'
--- a/bzrlib/info.py    2007-11-06 09:00:25 +0000
+++ b/bzrlib/info.py    2008-01-06 20:01:30 +0000
@@ -440,7 +440,9 @@
         tree.bzrdir.root_transport.base):
         branch = None
         repository = None
-    for key in bzrdir.format_registry.keys():
+    non_aliases = set(bzrdir.format_registry.keys())
+    non_aliases.difference_update(bzrdir.format_registry.aliases())
+    for key in non_aliases:
         format = bzrdir.format_registry.make_bzrdir(key)
         if isinstance(format, bzrdir.BzrDirMetaFormat1):
             if (tree and format.workingtree_format !=
@@ -457,11 +459,12 @@
         candidates.append(key)
     if len(candidates) == 0:
         return 'unnamed'
-    new_candidates = [c for c in candidates if c != 'default']
-    if len(new_candidates) > 0:
-        candidates = new_candidates
+    candidates.sort()
     new_candidates = [c for c in candidates if not
         bzrdir.format_registry.get_info(c).hidden]
     if len(new_candidates) > 0:
+        # If there are any non-hidden formats that match, only return those to
+        # avoid listing hidden formats except when only a hidden format will
+        # do.
         candidates = new_candidates
     return ' or '.join(candidates)

=== modified file 'bzrlib/tests/test_bzrdir.py'
--- a/bzrlib/tests/test_bzrdir.py       2007-12-21 20:32:22 +0000
+++ b/bzrlib/tests/test_bzrdir.py       2008-01-06 19:45:00 +0000
@@ -170,6 +170,16 @@
         finally:
             bzrdir.format_registry.set_default_repository(old_default)
 
+    def test_aliases(self):
+        a_registry = bzrdir.BzrDirFormatRegistry()
+        a_registry.register('weave', bzrdir.BzrDirFormat6,
+            'Pre-0.8 format.  Slower and does not support checkouts or shared'
+            ' repositories', deprecated=True)
+        a_registry.register('weavealias', bzrdir.BzrDirFormat6,
+            'Pre-0.8 format.  Slower and does not support checkouts or shared'
+            ' repositories', deprecated=True, alias=True)
+        self.assertEqual(frozenset(['weavealias']), a_registry.aliases())
+    
 
 class SampleBranch(bzrlib.branch.Branch):
     """A dummy branch for guess what, dummy use."""

=== modified file 'bzrlib/tests/test_info.py'
--- a/bzrlib/tests/test_info.py 2007-11-26 13:55:51 +0000
+++ b/bzrlib/tests/test_info.py 2008-01-06 20:02:10 +0000
@@ -126,16 +126,22 @@
 
     def test_describe_tree_format(self):
         for key in bzrdir.format_registry.keys():
-            if key == 'default':
+            if key in bzrdir.format_registry.aliases():
                 continue
             self.assertTreeDescription(key)
 
     def test_describe_checkout_format(self):
         for key in bzrdir.format_registry.keys():
-            if key in ('default', 'weave', 'experimental'):
-                continue
-            if key.startswith('experimental-'):
-                # these are typically hidden or aliases for other formats
+            if key in bzrdir.format_registry.aliases():
+                # Aliases will not describe correctly in the UI because the
+                # real format is found.
+                continue
+            # legacy: weave does not support checkouts
+            if key == 'weave':
+                continue
+            if bzrdir.format_registry.get_info(key).experimental:
+                # We don't require that experimental formats support checkouts
+                # or describe correctly in the UI.
                 continue
             expected = None
             if key in ('dirstate', 'dirstate-tags', 'dirstate-with-subtree',
@@ -149,7 +155,7 @@
 
     def test_describe_branch_format(self):
         for key in bzrdir.format_registry.keys():
-            if key == 'default':
+            if key in bzrdir.format_registry.aliases():
                 continue
             expected = None
             if key in ('dirstate', 'knit'):
@@ -158,7 +164,7 @@
 
     def test_describe_repo_format(self):
         for key in bzrdir.format_registry.keys():
-            if key == 'default':
+            if key in bzrdir.format_registry.aliases():
                 continue
             expected = None
             if key in ('dirstate', 'knit', 'dirstate-tags'):

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# (c) Canonical Ltd, 2006
 
2
# written by Alexander Belchenko for bzr project
 
3
#
 
4
# This script will be executed after installation of bzrlib package
 
5
# and before installer exits.
 
6
# All printed data will appear on the last screen of installation
 
7
# procedure.
 
8
# The main goal of this script is to create special batch file
 
9
# launcher for bzr. Typical content of this batch file is:
 
10
#  @python bzr %*
 
11
#
 
12
# This file works only on Windows 2000/XP. For win98 there is
 
13
# should be "%1 %2 %3 %4 %5 %6 %7 %8 %9" instead of "%*".
 
14
# Or even more complex thing.
 
15
#
 
16
# [bialix]: bzr de-facto does not support win98.
 
17
#           Although it seems to work on. Sometimes.
 
18
# 2006/07/30    added minimal support of win98.
 
19
# 2007/01/30    added *real* support of win98.
 
20
 
 
21
import os
 
22
import sys
 
23
import _winreg
 
24
 
 
25
from bzrlib import win32utils
 
26
 
 
27
 
 
28
def _quoted_path(path):
 
29
    if ' ' in path:
 
30
        return '"' + path + '"'
 
31
    else:
 
32
        return path
 
33
 
 
34
def _win_batch_args():
 
35
    if win32utils.winver == 'Windows NT':
 
36
        return '%*'
 
37
    else:
 
38
        return '%1 %2 %3 %4 %5 %6 %7 %8 %9'
 
39
 
 
40
 
 
41
if "-install" in sys.argv[1:]:
 
42
    # try to detect version number automatically
 
43
    try:
 
44
        import bzrlib
 
45
    except ImportError:
 
46
        ver = ''
 
47
    else:
 
48
        ver = bzrlib.__version__
 
49
 
 
50
    ##
 
51
    # XXX change message for something more appropriate
 
52
    print """Bazaar %s
 
53
 
 
54
Congratulation! Bzr successfully installed.
 
55
 
 
56
""" % ver
 
57
 
 
58
    batch_path = "bzr.bat"
 
59
    prefix = sys.exec_prefix
 
60
    try:
 
61
        ##
 
62
        # try to create
 
63
        scripts_dir = os.path.join(prefix, "Scripts")
 
64
        script_path = _quoted_path(os.path.join(scripts_dir, "bzr"))
 
65
        python_path = _quoted_path(os.path.join(prefix, "python.exe"))
 
66
        args = _win_batch_args()
 
67
        batch_str = "@%s %s %s" % (python_path, script_path, args)
 
68
        # support of win98
 
69
        # if there is no HOME for bzr then set it for Bazaar manually
 
70
        base = os.environ.get('BZR_HOME', None)
 
71
        if base is None:
 
72
            base = win32utils.get_appdata_location()
 
73
        if base is None:
 
74
            base = os.environ.get('HOME', None)
 
75
        if base is None:
 
76
            base = os.path.splitdrive(sys.prefix)[0] + '\\'
 
77
            batch_str = ("@SET BZR_HOME=" + _quoted_path(base) + "\n" +
 
78
                         batch_str)
 
79
 
 
80
        batch_path = os.path.join(scripts_dir, "bzr.bat")
 
81
        f = file(batch_path, "w")
 
82
        f.write(batch_str)
 
83
        f.close()
 
84
        file_created(batch_path)        # registering manually created files for
 
85
                                        # auto-deinstallation procedure
 
86
        ##
 
87
        # inform user where batch launcher is.
 
88
        print "Created:", batch_path
 
89
        print "Use this batch file to run bzr"
 
90
    except Exception, e:
 
91
        print "ERROR: Unable to create %s: %s" % (batch_path, e)
 
92
 
 
93
    ## this hunk borrowed from pywin32_postinstall.py
 
94
    # use bdist_wininst builtins to create a shortcut.
 
95
    # CSIDL_COMMON_PROGRAMS only available works on NT/2000/XP, and
 
96
    # will fail there if the user has no admin rights.
 
97
    if get_root_hkey()==_winreg.HKEY_LOCAL_MACHINE:
 
98
        try:
 
99
            fldr = get_special_folder_path("CSIDL_COMMON_PROGRAMS")
 
100
        except OSError:
 
101
            # No CSIDL_COMMON_PROGRAMS on this platform
 
102
            fldr = get_special_folder_path("CSIDL_PROGRAMS")
 
103
    else:
 
104
        # non-admin install - always goes in this user's start menu.
 
105
        fldr = get_special_folder_path("CSIDL_PROGRAMS")
 
106
 
 
107
    # make Bazaar entry
 
108
    fldr = os.path.join(fldr, 'Bazaar')
 
109
    if not os.path.isdir(fldr):
 
110
        os.mkdir(fldr)
 
111
        directory_created(fldr)
 
112
 
 
113
    # link to documentation
 
114
    docs = os.path.join(sys.exec_prefix, 'Doc', 'Bazaar', 'index.html')
 
115
    dst = os.path.join(fldr, 'Documentation.lnk')
 
116
    create_shortcut(docs, 'Bazaar Documentation', dst)
 
117
    file_created(dst)
 
118
    print 'Documentation for Bazaar: Start => Programs => Bazaar'
 
119
 
 
120
    # bzr in cmd shell
 
121
    if os.name == 'nt':
 
122
        cmd = os.environ.get('COMSPEC', 'cmd.exe')
 
123
        args = "/K bzr help"
 
124
    else:
 
125
        # minimal support of win98
 
126
        cmd = os.environ.get('COMSPEC', 'command.com')
 
127
        args = "bzr help"
 
128
    dst = os.path.join(fldr, 'Start bzr.lnk')
 
129
    create_shortcut(cmd,
 
130
                    'Start bzr in cmd shell',
 
131
                    dst,
 
132
                    args,
 
133
                    os.path.join(sys.exec_prefix, 'Scripts'))
 
134
    file_created(dst)
 
135
 
 
136
    # uninstall shortcut
 
137
    uninst = os.path.join(sys.exec_prefix, 'Removebzr.exe')
 
138
    dst = os.path.join(fldr, 'Uninstall Bazaar.lnk')
 
139
    create_shortcut(uninst,
 
140
                    'Uninstall Bazaar',
 
141
                    dst,
 
142
                    '-u bzr-wininst.log',
 
143
                    sys.exec_prefix,
 
144
                    )
 
145
    file_created(dst)