return True
return False
+class UnknownAliasError(Exception):
+ pass
+
def get_alias(aliases, path, default):
# transform "work:path/filename" into (aliases["work"], "path/filename").
# If default=None, then an empty alias is indicated by returning
if default == None:
return DefaultAliasMarker, path
return aliases[default], path
- if colon == 1 and platform_uses_lettercolon_drivename():
+ if colon == 1 and default == None and platform_uses_lettercolon_drivename():
# treat C:\why\must\windows\be\so\weird as a local path, not a tahoe
# file in the "C:" alias
return DefaultAliasMarker, path
if default == None:
return DefaultAliasMarker, path
return aliases[default], path
+ if alias not in aliases:
+ raise UnknownAliasError("Unknown alias '%s', please create it with 'tahoe add-alias' or 'tahoe create-alias'." % alias)
return aliases[alias], path[colon+1:]
def escape_path(path):
"c": "CA"}
def ga1(path):
return get_alias(aliases, path, "tahoe")
+ uses_lettercolon = common.platform_uses_lettercolon_drivename()
self.failUnlessEqual(ga1("bare"), ("TA", "bare"))
self.failUnlessEqual(ga1("baredir/file"), ("TA", "baredir/file"))
self.failUnlessEqual(ga1("baredir/file:7"), ("TA", "baredir/file:7"))
self.failUnlessEqual(ga1("work:"), ("WA", ""))
self.failUnlessEqual(ga1("work:file"), ("WA", "file"))
self.failUnlessEqual(ga1("work:dir/file"), ("WA", "dir/file"))
+ # default != None means we really expect a tahoe path, regardless of
+ # whether we're on windows or not. This is what 'tahoe get' uses.
self.failUnlessEqual(ga1("c:"), ("CA", ""))
self.failUnlessEqual(ga1("c:file"), ("CA", "file"))
self.failUnlessEqual(ga1("c:dir/file"), ("CA", "dir/file"))
self.failUnlessEqual(ga1("URI:stuff:./file"), ("URI:stuff", "file"))
self.failUnlessEqual(ga1("URI:stuff:./dir/file"),
("URI:stuff", "dir/file"))
+ self.failUnlessRaises(common.UnknownAliasError, ga1, "missing:")
+ self.failUnlessRaises(common.UnknownAliasError, ga1, "missing:dir")
+ self.failUnlessRaises(common.UnknownAliasError, ga1, "missing:dir/file")
+
def ga2(path):
return get_alias(aliases, path, None)
self.failUnlessEqual(ga2("bare"), (DefaultAliasMarker, "bare"))
self.failUnlessEqual(ga2("tahoe:"), ("TA", ""))
self.failUnlessEqual(ga2("tahoe:file"), ("TA", "file"))
self.failUnlessEqual(ga2("tahoe:dir/file"), ("TA", "dir/file"))
- self.failUnlessEqual(ga1("c:"), ("CA", ""))
- self.failUnlessEqual(ga1("c:file"), ("CA", "file"))
- self.failUnlessEqual(ga1("c:dir/file"), ("CA", "dir/file"))
+ # on windows, we really want c:foo to indicate a local file.
+ # default==None is what 'tahoe cp' uses.
+ if uses_lettercolon:
+ self.failUnlessEqual(ga2("c:"), (DefaultAliasMarker, "c:"))
+ self.failUnlessEqual(ga2("c:file"), (DefaultAliasMarker, "c:file"))
+ self.failUnlessEqual(ga2("c:dir/file"),
+ (DefaultAliasMarker, "c:dir/file"))
+ else:
+ self.failUnlessEqual(ga2("c:"), ("CA", ""))
+ self.failUnlessEqual(ga2("c:file"), ("CA", "file"))
+ self.failUnlessEqual(ga2("c:dir/file"), ("CA", "dir/file"))
self.failUnlessEqual(ga2("work:"), ("WA", ""))
self.failUnlessEqual(ga2("work:file"), ("WA", "file"))
self.failUnlessEqual(ga2("work:dir/file"), ("WA", "dir/file"))
self.failUnlessEqual(ga2("URI:stuff"), ("URI:stuff", ""))
self.failUnlessEqual(ga2("URI:stuff:./file"), ("URI:stuff", "file"))
self.failUnlessEqual(ga2("URI:stuff:./dir/file"), ("URI:stuff", "dir/file"))
+ self.failUnlessRaises(common.UnknownAliasError, ga2, "missing:")
+ self.failUnlessRaises(common.UnknownAliasError, ga2, "missing:dir")
+ self.failUnlessRaises(common.UnknownAliasError, ga2, "missing:dir/file")
def ga3(path):
old = common.pretend_platform_uses_lettercolon
self.failUnlessEqual(ga3("URI:stuff"), ("URI:stuff", ""))
self.failUnlessEqual(ga3("URI:stuff:./file"), ("URI:stuff", "file"))
self.failUnlessEqual(ga3("URI:stuff:./dir/file"), ("URI:stuff", "dir/file"))
+ self.failUnlessRaises(common.UnknownAliasError, ga3, "missing:")
+ self.failUnlessRaises(common.UnknownAliasError, ga3, "missing:dir")
+ self.failUnlessRaises(common.UnknownAliasError, ga3, "missing:dir/file")
class Help(unittest.TestCase):