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()
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"
return rc
return 0
+
class InviteOptions(BasedirOptions):
nickname = None
synopsis = "MAGIC_ALIAS: NICKNAME"
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.")
% (options.local_dir.encode('utf-8'),), mode="ab")
return 0
+
class MagicFolderCommand(BaseOptions):
subCommands = [
["create", None, CreateOptions, "Create a Magic Folder."],
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)
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):