]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
WIP 2438.magic-folder-stable.3.wip
authorDaira Hopwood <daira@jacaranda.org>
Thu, 8 Oct 2015 13:34:30 +0000 (14:34 +0100)
committerDaira Hopwood <daira@jacaranda.org>
Thu, 8 Oct 2015 13:34:30 +0000 (14:34 +0100)
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
src/allmydata/scripts/magic_folder_cli.py
src/allmydata/test/test_cli_magic_folder.py

index 14ba2ca610558de549d0852b9bf375bdd3fb2b09..6bdb0f5e477960974060f6d443b898e3b5f4b8ea 100644 (file)
@@ -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."],
index 1ba831ac3ba83901e64ce864bf973d86e7a5c46e..c7e7699c76b02dce78ac15d026347b7507b5b0a8 100644 (file)
@@ -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):