Пример #1
0
    def parseArgs(self, *args):
        if self["node-directory"] and self["basedir"]:
            raise usage.UsageError("The --node-directory (or -d) and --basedir (or -C) " "options cannot both be used.")

        if self["node-directory"] or self["basedir"]:
            self.basedirs = [argv_to_abspath(self["node-directory"] or self["basedir"])]
        else:
            self.basedirs = []

        if self.allow_multiple and self["multiple"]:
            self.basedirs.extend(map(argv_to_abspath, args))
        else:
            if len(args) > 1:
                raise usage.UsageError(
                    "I wasn't expecting so many arguments."
                    + (
                        self.allow_multiple
                        and " Use the --multiple option to specify more than one node directory."
                        or ""
                    )
                )

            if len(args) == 0 and self.default_nodedir and not self.basedirs:
                self.basedirs.append(self.default_nodedir)
            elif len(args) > 0:
                self.basedirs.append(argv_to_abspath(args[0]))
Пример #2
0
    def parseArgs(self, basedir=None):
        # This finds the node-directory option correctly even if we are in a subcommand.
        root = self.parent
        while root.parent is not None:
            root = root.parent

        if root['node-directory'] and self['basedir']:
            raise usage.UsageError("The --node-directory (or -d) and --basedir (or -C) options cannot both be used.")
        if root['node-directory'] and basedir:
            raise usage.UsageError("The --node-directory (or -d) option and a basedir argument cannot both be used.")
        if self['basedir'] and basedir:
            raise usage.UsageError("The --basedir (or -C) option and a basedir argument cannot both be used.")

        if basedir:
            b = argv_to_abspath(basedir)
        elif self['basedir']:
            b = argv_to_abspath(self['basedir'])
        elif root['node-directory']:
            b = argv_to_abspath(root['node-directory'])
        elif self.default_nodedir:
            b = self.default_nodedir
        else:
            raise usage.UsageError("No default basedir available, you must provide one with --node-directory, --basedir, or a basedir argument")
        self['basedir'] = b
        self['node-directory'] = b
Пример #3
0
    def parseArgs(self, basedir=None):
        if self["node-directory"] and self["basedir"]:
            raise usage.UsageError("The --node-directory (or -d) and --basedir (or -C) " "options cannot both be used.")

        if basedir:
            b = argv_to_abspath(basedir)
        elif self["basedir"]:
            b = argv_to_abspath(self["basedir"])
        elif self["node-directory"]:
            b = argv_to_abspath(self["node-directory"])
        else:
            b = self.default_nodedir
        self["basedir"] = b
Пример #4
0
def invite(options):
    if options.parent['node-directory']:
        basedir = argv_to_abspath(options.parent['node-directory'])
    else:
        basedir = get_default_nodedir()
    config = configutil.get_config(join(basedir, 'tahoe.cfg'))
    out = options.stdout
    err = options.stderr

    try:
        introducer_furl = get_introducer_furl(basedir, config)
    except Exception as e:
        print("Can't find introducer FURL for node '{}': {}".format(basedir, str(e)), file=err)
        raise SystemExit(1)

    nick = options['nick']

    remote_config = {
        "shares-needed": options["shares-needed"] or config.get('client', 'shares.needed'),
        "shares-total": options["shares-total"] or config.get('client', 'shares.total'),
        "shares-happy": options["shares-happy"] or config.get('client', 'shares.happy'),
        "nickname": nick,
        "introducer": introducer_furl,
    }

    yield _send_config_via_wormhole(options, remote_config)
    print("Completed successfully", file=out)
Пример #5
0
    def postOptions(self):
        self["quiet"] = self.parent["quiet"]
        if self.parent['node-directory']:
            self['node-directory'] = argv_to_abspath(self.parent['node-directory'])
        else:
            self['node-directory'] = _default_nodedir

        # compute a node-url from the existing options, put in self['node-url']
        if self['node-url']:
            if (not isinstance(self['node-url'], basestring)
                or not NODEURL_RE.match(self['node-url'])):
                msg = ("--node-url is required to be a string and look like "
                       "\"http://HOSTNAMEORADDR:PORT\", not: %r" %
                       (self['node-url'],))
                raise usage.UsageError(msg)
        else:
            node_url_file = os.path.join(self['node-directory'], "node.url")
            self['node-url'] = open(node_url_file, "r").read().strip()
        if self['node-url'][-1] != "/":
            self['node-url'] += "/"

        aliases = get_aliases(self['node-directory'])
        if self['dir-cap']:
            aliases[DEFAULT_ALIAS] = self['dir-cap']
        self.aliases = aliases # maps alias name to dircap
Пример #6
0
    def parseArgs(self, basedir=None):
        if self.parent['node-directory'] and self['basedir']:
            raise usage.UsageError("The --node-directory (or -d) and --basedir (or -C) options cannot both be used.")
        if self.parent['node-directory'] and basedir:
            raise usage.UsageError("The --node-directory (or -d) option and a basedir argument cannot both be used.")
        if self['basedir'] and basedir:
            raise usage.UsageError("The --basedir (or -C) option and a basedir argument cannot both be used.")

        if basedir:
            b = argv_to_abspath(basedir)
        elif self['basedir']:
            b = argv_to_abspath(self['basedir'])
        elif self.parent['node-directory']:
            b = argv_to_abspath(self.parent['node-directory'])
        elif self.default_nodedir:
            b = self.default_nodedir
        else:
            raise usage.UsageError("No default basedir available, you must provide one with --node-directory, --basedir, or a basedir argument")
        self['basedir'] = b
Пример #7
0
    def parseArgs(self, arg1, arg2=None):
        # tahoe get FOO |less            # write to stdout
        # tahoe get tahoe:FOO |less      # same
        # tahoe get FOO bar              # write to local file
        # tahoe get tahoe:FOO bar        # same

        if arg2 == "-":
            arg2 = None

        self.from_file = argv_to_unicode(arg1)
        self.to_file   = None if arg2 is None else argv_to_abspath(arg2)
Пример #8
0
    def parseArgs(self, arg1=None, arg2=None):
        # see Examples below

        if arg1 == "-":
            arg1 = None

        self.from_file = None if arg1 is None else argv_to_abspath(arg1)
        self.to_file   = None if arg2 is None else argv_to_unicode(arg2)

        if self['format']:
            if self['format'].upper() not in ("SDMF", "MDMF", "CHK"):
                raise usage.UsageError("%s is an invalid format" % self['format'])
Пример #9
0
 def opt_exclude_from(self, filepath):
     """Ignore file matching glob patterns listed in file, one per
     line. The file is assumed to be in the argv encoding."""
     abs_filepath = argv_to_abspath(filepath)
     try:
         exclude_file = file(abs_filepath)
     except:
         raise BackupConfigurationError("Error opening exclude file %s." % quote_output(abs_filepath))
     try:
         for line in exclude_file:
             self.opt_exclude(line)
     finally:
         exclude_file.close()
Пример #10
0
    def parseArgs(self, invite_code, local_dir):
        BasedirOptions.parseArgs(self)

        try:
            if int(self['poll-interval']) <= 0:
                raise ValueError("should be positive")
        except ValueError:
            raise usage.UsageError(
                "--poll-interval must be a positive integer"
            )
        # Expand the path relative to the current directory of the CLI command, not the node.
        self.local_dir = None if local_dir is None else argv_to_abspath(local_dir, long_path=False)
        self.invite_code = to_str(argv_to_unicode(invite_code))
Пример #11
0
    def parseArgs(self, alias, nickname=None, local_dir=None):
        BasedirOptions.parseArgs(self)
        alias = argv_to_unicode(alias)
        if not alias.endswith(u':'):
            raise usage.UsageError("An alias must end with a ':' character.")
        self.alias = alias[:-1]
        self.nickname = None if nickname is None else argv_to_unicode(nickname)

        # Expand the path relative to the current directory of the CLI command, not the node.
        self.local_dir = None if local_dir is None else argv_to_abspath(local_dir, long_path=False)

        if self.nickname and not self.local_dir:
            raise usage.UsageError("If NICKNAME is specified then LOCAL_DIR must also be specified.")
        node_url_file = os.path.join(self['node-directory'], u"node.url")
        self['node-url'] = fileutil.read(node_url_file).strip()
Пример #12
0
 def parseArgs(self, filename):
     from allmydata.util.encodingutil import argv_to_abspath
     self['filename'] = argv_to_abspath(filename)
Пример #13
0
    def parseArgs(self, invite_code, local_dir):
        BasedirOptions.parseArgs(self)

        # Expand the path relative to the current directory of the CLI command, not the node.
        self.local_dir = None if local_dir is None else argv_to_abspath(local_dir, long_path=False)
        self.invite_code = to_str(argv_to_unicode(invite_code))
Пример #14
0
 def postOptions(self):
     if self.parent['node-directory']:
         self['node-directory'] = argv_to_abspath(self.parent['node-directory'])
     else:
         self['node-directory'] = get_default_nodedir()
Пример #15
0
 def parseArgs(self, localdir, topath):
     self.from_dir = argv_to_abspath(localdir)
     self.to_dir = argv_to_unicode(topath)