~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to baz2bzr

  • Committer: Aaron Bentley
  • Date: 2005-06-08 17:33:51 UTC
  • Revision ID: abentley@panoramicfeedback.com-20050608173351-d3369f290544b136
Improved errors for invalid or missing versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
174
174
    add_file("trainfile", "void train(void){}", "trainfile by aaron")
175
175
    commit(tree, "altered trainfile")
176
176
 
 
177
class NoSuchVersion(Exception):
 
178
    def __init__(self, version):
 
179
        Exception.__init__(self, "The version %s does not exist." % version)
 
180
        self.version = version
 
181
 
177
182
def version_ancestry(version):
178
183
    """
179
184
    >>> q = test_environ()
184
189
    'test@example.com/test--test--0--base-0'
185
190
    >>> str(ancestors[1])
186
191
    'test@example.com/test--test--0--patch-1'
 
192
    >>> version = pybaz.Version("test@example.com/test--test--0.5")
 
193
    >>> ancestors = version_ancestry(version)
 
194
    Traceback (most recent call last):
 
195
    NoSuchVersion: The version test@example.com/test--test--0.5 does not exist.
187
196
    >>> teardown_environ(q)
188
197
    """
189
 
    revision = version.iter_revisions(reverse=True).next()
 
198
    try:
 
199
        revision = version.iter_revisions(reverse=True).next()
 
200
    except:
 
201
        if not version.exists():
 
202
            raise NoSuchVersion(version)
 
203
        else:
 
204
            raise
190
205
    ancestors = list(revision.iter_ancestors(metoo=True))
191
206
    ancestors.reverse()
192
207
    return ancestors
214
229
    elif version is None:
215
230
        raise UserError("No version specified, and directory does not exist.")
216
231
 
217
 
    ancestors = version_ancestry(version)
 
232
    try:
 
233
        ancestors = version_ancestry(version)
 
234
    except NoSuchVersion, e:
 
235
        raise UserError(e)
218
236
 
219
237
    if last_patch:
220
238
        for i in range(len(ancestors)):
237
255
    >>> q = test_environ()
238
256
    >>> result_path = os.path.join(q, "result")
239
257
    >>> commit_test_revisions()
240
 
    >>> version = pybaz.Version("test@example.com/test--test--0")
 
258
    >>> version = pybaz.Version("test@example.com/test--test--0.1")
241
259
    >>> import_version('/', version, fancy=False, dry_run=True)
242
260
    Traceback (most recent call last):
243
261
    UserError: / exists, but is not a bzr branch.
244
262
    >>> import_version(result_path, version, fancy=False, dry_run=True)
 
263
    Traceback (most recent call last):
 
264
    UserError: The version test@example.com/test--test--0.1 does not exist.
 
265
    >>> version = pybaz.Version("test@example.com/test--test--0")
 
266
    >>> import_version(result_path, version, fancy=False, dry_run=True)
245
267
    not fancy
246
268
    ....
247
269
    Dry run, not modifying output_dir
550
572
        else:
551
573
            return 0
552
574
    if len(args) == 2:
553
 
        output_dir = os.path.realpath(args[1]) 
554
 
        version = pybaz.Version(args[0])
 
575
        output_dir = os.path.realpath(args[1])
 
576
        try:
 
577
            version = pybaz.Version(args[0])
 
578
        except pybaz.errors.NamespaceError:
 
579
            print "%s is not a valid Arch branch." % args[0]
 
580
            return 1
 
581
            
555
582
    elif len(args) == 1:
556
583
        output_dir = os.path.realpath(args[0])
557
584
        version = None