/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 breezy/upgrade.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-11 04:08:32 UTC
  • mto: (7143.16.20 even-more-cleanups)
  • mto: This revision was merged to the branch mainline in revision 7175.
  • Revision ID: jelmer@jelmer.uk-20181111040832-nsljjynzzwmznf3h
Run autopep8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
            try:
87
87
                rich_root = self.controldir.find_repository()._format.rich_root_data
88
88
            except errors.NoRepositoryPresent:
89
 
                rich_root = False # assume no rich roots
 
89
                rich_root = False  # assume no rich roots
90
90
            if rich_root:
91
91
                format_name = "default-rich-root"
92
92
            else:
98
98
            raise errors.UpToDateFormat(self.controldir._format)
99
99
        if not self.controldir.can_convert_format():
100
100
            raise errors.BzrError(gettext("cannot upgrade from bzrdir format %s") %
101
 
                           self.controldir._format)
 
101
                                  self.controldir._format)
102
102
        self.controldir.check_conversion_target(format)
103
 
        ui.ui_factory.note(gettext('starting upgrade of %s') % 
104
 
            urlutils.unescape_for_display(self.transport.base, 'utf-8'))
 
103
        ui.ui_factory.note(gettext('starting upgrade of %s') %
 
104
                           urlutils.unescape_for_display(self.transport.base, 'utf-8'))
105
105
 
106
106
        self.backup_oldpath, self.backup_newpath = self.controldir.backup_bzrdir()
107
107
        while self.controldir.needs_format_conversion(format):
123
123
 
124
124
def upgrade(url, format=None, clean_up=False, dry_run=False):
125
125
    """Upgrade locations to format.
126
 
 
 
126
 
127
127
    This routine wraps the smart_upgrade() routine with a nicer UI.
128
128
    In particular, it ensures all URLs can be opened before starting
129
129
    and reports a summary at the end if more than one upgrade was attempted.
139
139
    """
140
140
    control_dirs = [ControlDir.open_unsupported(url)]
141
141
    attempted, succeeded, exceptions = smart_upgrade(control_dirs,
142
 
        format, clean_up=clean_up, dry_run=dry_run)
 
142
                                                     format, clean_up=clean_up, dry_run=dry_run)
143
143
    if len(attempted) > 1:
144
144
        attempted_count = len(attempted)
145
145
        succeeded_count = len(succeeded)
146
146
        failed_count = attempted_count - succeeded_count
147
147
        ui.ui_factory.note(
148
 
            gettext('\nSUMMARY: {0} upgrades attempted, {1} succeeded,'\
 
148
            gettext('\nSUMMARY: {0} upgrades attempted, {1} succeeded,'
149
149
                    ' {2} failed').format(
150
 
                     attempted_count, succeeded_count, failed_count))
 
150
                attempted_count, succeeded_count, failed_count))
151
151
    return exceptions
152
152
 
153
153
 
154
154
def smart_upgrade(control_dirs, format, clean_up=False,
155
 
    dry_run=False):
 
155
                  dry_run=False):
156
156
    """Convert control directories to a new format intelligently.
157
157
 
158
158
    If the control directory is a shared repository, dependent branches
171
171
    all_exceptions = []
172
172
    for control_dir in control_dirs:
173
173
        attempted, succeeded, exceptions = _smart_upgrade_one(control_dir,
174
 
            format, clean_up=clean_up, dry_run=dry_run)
 
174
                                                              format, clean_up=clean_up, dry_run=dry_run)
175
175
        all_attempted.extend(attempted)
176
176
        all_succeeded.extend(succeeded)
177
177
        all_exceptions.extend(exceptions)
179
179
 
180
180
 
181
181
def _smart_upgrade_one(control_dir, format, clean_up=False,
182
 
    dry_run=False):
 
182
                       dry_run=False):
183
183
    """Convert a control directory to a new format intelligently.
184
184
 
185
185
    See smart_upgrade for parameter details.
207
207
        # Convert dependent branches
208
208
        branch_cdirs = [b.controldir for b in dependents]
209
209
        successes, problems = _convert_items(branch_cdirs, format, clean_up,
210
 
            dry_run, label="branch")
 
210
                                             dry_run, label="branch")
211
211
        attempted.extend(branch_cdirs)
212
212
        succeeded.extend(successes)
213
213
        exceptions.extend(problems)
220
220
# - raising AssertionError is rude and may not be necessary
221
221
# - no tests
222
222
# - the only caller uses only the label
 
223
 
 
224
 
223
225
def _get_object_and_label(control_dir):
224
226
    """Return the primary object and type label for a control directory.
225
227
 
258
260
 
259
261
def _convert_items(items, format, clean_up, dry_run, label=None):
260
262
    """Convert a sequence of control directories to the given format.
261
 
 
 
263
 
262
264
    :param items: the control directories to upgrade
263
265
    :param format: the format to convert to or None for the best default
264
266
    :param clean-up: if True, the backup.bzr directory is removed if the
276
278
            location = control_dir.root_transport.base
277
279
            bzr_object, bzr_label = _get_object_and_label(control_dir)
278
280
            type_label = label or bzr_label
279
 
            child_pb.update(gettext("Upgrading %s") % (type_label), i+1, len(items))
280
 
            ui.ui_factory.note(gettext('Upgrading {0} {1} ...').format(type_label, 
281
 
                urlutils.unescape_for_display(location, 'utf-8'),))
 
281
            child_pb.update(gettext("Upgrading %s") %
 
282
                            (type_label), i + 1, len(items))
 
283
            ui.ui_factory.note(gettext('Upgrading {0} {1} ...').format(type_label,
 
284
                                                                       urlutils.unescape_for_display(location, 'utf-8'),))
282
285
            try:
283
286
                if not dry_run:
284
287
                    cv = Convert(control_dir=control_dir, format=format)
299
302
                    if not dry_run:
300
303
                        cv.clean_up()
301
304
                except Exception as ex:
302
 
                    trace.warning(gettext('failed to clean-up {0}: {1}') % (location, ex))
 
305
                    trace.warning(
 
306
                        gettext('failed to clean-up {0}: {1}') % (location, ex))
303
307
                    exceptions.append(ex)
304
308
 
305
309
    # Return the result