From: Daira Hopwood Date: Thu, 8 Oct 2015 13:34:30 +0000 (+0100) Subject: WIP X-Git-Url: https://git.rkrishnan.org/?a=commitdiff_plain;h=13f1da58cc74a64d60f7ae4f7c86463d4cfde91c;p=tahoe-lafs%2Ftahoe-lafs.git WIP Signed-off-by: Daira Hopwood --- diff --git a/src/allmydata/scripts/magic_folder_cli.py b/src/allmydata/scripts/magic_folder_cli.py index 14ba2ca6..6bdb0f5e 100644 --- a/src/allmydata/scripts/magic_folder_cli.py +++ b/src/allmydata/scripts/magic_folder_cli.py @@ -11,18 +11,19 @@ from allmydata import uri INVITE_SEPARATOR = "+" + class CreateOptions(BasedirOptions): nickname = None - localdir = None + local_dir = None synopsis = "MAGIC_ALIAS: [NICKNAME LOCALDIR]" - def parseArgs(self, alias, nickname=None, localdir=None): + def parseArgs(self, alias, nickname=None, local_dir=None): BasedirOptions.parseArgs(self) if not alias.endswith(':'): raise usage.UsageError("An alias must end with a ':' character.") self.alias = alias[:-1] self.nickname = nickname - self.localdir = localdir - if self.nickname and not self.localdir: + self.local_dir = argv_to_abspath(local_dir) + if self.nickname and not self.local_dir: raise usage.UsageError("If NICKNAME is specified then LOCALDIR must also be specified.") node_url_file = os.path.join(self['node-directory'], "node.url") self['node-url'] = fileutil.read(node_url_file).strip() @@ -64,7 +65,7 @@ def create(options): if len(fields) != 2: raise usage.UsageError("Invalid invite code.") join_options.magic_readonly_cap, join_options.dmd_write_cap = fields - join_options.local_dir = options.localdir + join_options.local_dir = options.local_dir rc = join(join_options) if rc != 0: print >>options.stderr, "magic-folder: failed to join after create\n" @@ -72,6 +73,7 @@ def create(options): return rc return 0 + class InviteOptions(BasedirOptions): nickname = None synopsis = "MAGIC_ALIAS: NICKNAME" @@ -117,13 +119,14 @@ def invite(options): print >>options.stdout, "%s%s%s" % (magic_readonly_cap, INVITE_SEPARATOR, dmd_write_cap) return 0 + class JoinOptions(BasedirOptions): synopsis = "INVITE_CODE LOCAL_DIR" dmd_write_cap = "" magic_readonly_cap = "" def parseArgs(self, invite_code, local_dir): BasedirOptions.parseArgs(self) - self.local_dir = local_dir + self.local_dir = argv_to_abspath(local_dir) fields = invite_code.split(INVITE_SEPARATOR) if len(fields) != 2: raise usage.UsageError("Invalid invite code.") @@ -140,6 +143,7 @@ def join(options): % (options.local_dir.encode('utf-8'),), mode="ab") return 0 + class MagicFolderCommand(BaseOptions): subCommands = [ ["create", None, CreateOptions, "Create a Magic Folder."], diff --git a/src/allmydata/test/test_cli_magic_folder.py b/src/allmydata/test/test_cli_magic_folder.py index 1ba831ac..c7e7699c 100644 --- a/src/allmydata/test/test_cli_magic_folder.py +++ b/src/allmydata/test/test_cli_magic_folder.py @@ -72,13 +72,21 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin): def check_config(self, client_num, local_dir): client_config = fileutil.read(os.path.join(self.get_clientdir(i=client_num), "tahoe.cfg")) - # XXX utf-8? local_dir = local_dir.encode('utf-8') ret = re.search("\[magic_folder\]\nenabled = True\nlocal.directory = %s" % (local_dir,), client_config) self.failIf(ret is None) def create_invite_join_magic_folder(self, nickname, local_dir): - d = self.do_cli("magic-folder", "create", u"magic:", nickname, local_dir) + abs_local_dir = abspath_expanduser_unicode(local_dir) + try: + nickname_arg = nickname.encode(get_io_encoding()) + local_dir_arg = local_dir.encode(get_io_encoding()) + except UnicodeEncodeError: + raise unittest.SkipTest("A non-ASCII command argument could not be encoded on this platform.") + + self.skip_if_cannot_represent_filename(local_dir) + + d = self.do_cli("magic-folder", "create", "magic:", nickname_arg, local_dir_arg) def _done((rc,stdout,stderr)): self.failUnless(rc == 0) return (rc,stdout,stderr) @@ -90,7 +98,7 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin): self.upload_dirnode = client.create_node_from_uri(self.upload_dircap) d.addCallback(get_alice_caps) d.addCallback(lambda x: self.check_joined_config(0, self.upload_dircap)) - d.addCallback(lambda x: self.check_config(0, local_dir)) + d.addCallback(lambda x: self.check_config(0, abs_local_dir)) return d def cleanup(self, res):