From: Zooko O'Whielacronx Date: Fri, 4 Jan 2008 00:35:35 +0000 (-0700) Subject: cmdline: give useful error messages about the --dir-uri and ~/.tahoe/private/root_dir.cap X-Git-Tag: allmydata-tahoe-0.7.0~38 X-Git-Url: https://git.rkrishnan.org/vdrive/%22news.html/$rel_link?a=commitdiff_plain;h=ab4303609daf16f8fc3c6e297a1face928f9e7fa;p=tahoe-lafs%2Ftahoe-lafs.git cmdline: give useful error messages about the --dir-uri and ~/.tahoe/private/root_dir.cap --- diff --git a/src/allmydata/scripts/cli.py b/src/allmydata/scripts/cli.py index 4824d268..beeff150 100644 --- a/src/allmydata/scripts/cli.py +++ b/src/allmydata/scripts/cli.py @@ -39,15 +39,35 @@ class VDriveOptions(BaseOptions, usage.Options): node_url_file = os.path.join(self['node-directory'], "node.url") self['node-url'] = open(node_url_file, "r").read().strip() - # also compute self['dir-uri'] - if self['dir-uri'] == "root": - uri_file = os.path.join(self['node-directory'], "root_dir.cap") - self['dir-uri'] = open(uri_file, "r").read().strip() + rootdircap = None + if self['dir-uri'] == 'root': + uri_file = os.path.join(self['node-directory'], 'private', "root_dir.cap") + try: + rootdircap = open(uri_file, "r").read().strip() + except EnvironmentError, le: + raise usage.UsageError("\n" + "If --dir-uri is absent or is 'root', then the node directory's 'private'\n" + "subdirectory is required to contain a file named 'root_dir.cap' which must\n" + "contain a dir cap, but when we tried to open that file we got:\n" + "'%s'." % (le,)) + else: + rootdircap = self['dir-uri'] from allmydata import uri - parsed = uri.NewDirectoryURI.init_from_human_encoding(self['dir-uri']) - if not uri.IDirnodeURI.providedBy(parsed): - raise usage.UsageError("--dir-uri must be a dir URI, or 'root'") - + try: + parsed = uri.NewDirectoryURI.init_from_human_encoding(rootdircap) + except: + try: + parsed = uri.ReadonlyNewDirectoryURI.init_from_human_encoding(rootdircap) + except: + if self['dir-uri'] == 'root': + raise usage.UsageError("\n" + "If --dir-uri is absent or is 'root', then the node directory's 'private'\n" + "subdirectory's 'root_dir.cap' is required to contain a dir cap, but we found\n" + "'%s'." % (rootdircap,)) + else: + raise usage.UsageError("--dir-uri must be a dir cap (or \"root\"), but we got '%s'." % (self['dir-uri'],)) + + self['dir-uri'] = parsed.to_string() class ListOptions(VDriveOptions): def parseArgs(self, vdrive_pathname=""): diff --git a/src/allmydata/uri.py b/src/allmydata/uri.py index 5cb74f21..66a1874b 100644 --- a/src/allmydata/uri.py +++ b/src/allmydata/uri.py @@ -327,7 +327,7 @@ class _NewDirectoryBaseURI(_BaseURI): @classmethod def init_from_human_encoding(cls, uri): mo = cls.BASE_HUMAN_RE.search(uri) - assert mo, uri + assert mo, (uri, cls) bits = uri[mo.end():] while bits and bits[-1] == '/': bits = bits[:-1]