use the following command to create a new directory and set it as your
"tahoe:" alias:
- tahoe set-alias tahoe `tahoe mkdir`
+ tahoe add-alias tahoe `tahoe mkdir`
After that you can use "tahoe ls tahoe:" and "tahoe cp local.txt tahoe:",
and both will refer to the directory that you've just created.
=== Command Syntax Summary ===
+tahoe add-alias alias cap
+tahoe list-aliases
tahoe mkdir
tahoe mkdir [alias:]path
tahoe ls [alias:][path]
This creates a new empty unlinked directory, and prints its write-cap to
stdout. The new directory is not attached to anything else.
+tahoe add-alias work DIRCAP
+
+ This create an alias "work:" and configures it to use the given directory
+ cap. Once this is done, "tahoe ls work:" will list the contents of this
+ directory. Use "tahoe add-alias tahoe DIRCAP" to set the contents of the
+ default "tahoe:" alias.
+
+tahoe list-aliases
+
+ This displays a table of all configured aliases.
+
tahoe mkdir subdir
tahoe mkdir /subdir
import os.path, re, sys
from twisted.python import usage
-from allmydata.scripts.common import BaseOptions
+from allmydata.scripts.common import BaseOptions, get_aliases
NODEURL_RE=re.compile("http://([^:]*)(:([1-9][0-9]*))?")
node_url_file = os.path.join(self['node-directory'], "node.url")
self['node-url'] = open(node_url_file, "r").read().strip()
- aliases = self.get_aliases(self['node-directory'])
+ aliases = get_aliases(self['node-directory'])
if self['dir-cap']:
aliases["tahoe"] = self['dir-cap']
self.aliases = aliases # maps alias name to dircap
- def get_aliases(self, nodedir):
- from allmydata import uri
- aliases = {}
- aliasfile = os.path.join(nodedir, "private", "aliases")
- rootfile = os.path.join(nodedir, "private", "root_dir.cap")
- try:
- f = open(rootfile, "r")
- rootcap = f.read().strip()
- if rootcap:
- aliases["tahoe"] = uri.from_string_dirnode(rootcap).to_string()
- except EnvironmentError:
- pass
- try:
- f = open(aliasfile, "r")
- for line in f.readlines():
- line = line.strip()
- if line.startswith("#"):
- continue
- name, cap = line.split(":", 1)
- # normalize it: remove http: prefix, urldecode
- cap = cap.strip()
- aliases[name] = uri.from_string_dirnode(cap).to_string()
- except EnvironmentError:
- pass
- return aliases
-
class MakeDirectoryOptions(VDriveOptions):
def parseArgs(self, where=""):
self.where = where
self.alias = alias
self.cap = cap
+class ListAliasOptions(VDriveOptions):
+ pass
+
class ListOptions(VDriveOptions):
optFlags = [
("long", "l", "Use long format: show file sizes, and timestamps"),
subCommands = [
["mkdir", None, MakeDirectoryOptions, "Create a new directory"],
["add-alias", None, AddAliasOptions, "Add a new alias cap"],
+ ["list-aliases", None, ListAliasOptions, "List all alias caps"],
["ls", None, ListOptions, "List a directory"],
["get", None, GetOptions, "Retrieve a file from the virtual drive."],
["put", None, PutOptions, "Upload a file into the virtual drive."],
stdout, stderr)
return rc
+def list_aliases(config, stdout, stderr):
+ from allmydata.scripts import tahoe_add_alias
+ rc = tahoe_add_alias.list_aliases(config['node-directory'],
+ stdout, stderr)
+ return rc
+
def list(config, stdout, stderr):
from allmydata.scripts import tahoe_ls
rc = tahoe_ls.list(config['node-url'],
dispatch = {
"mkdir": mkdir,
"add-alias": add_alias,
+ "list-aliases": list_aliases,
"ls": list,
"get": get,
"put": put,
DEFAULT_ALIAS = "tahoe"
+
+def get_aliases(nodedir):
+ from allmydata import uri
+ aliases = {}
+ aliasfile = os.path.join(nodedir, "private", "aliases")
+ rootfile = os.path.join(nodedir, "private", "root_dir.cap")
+ try:
+ f = open(rootfile, "r")
+ rootcap = f.read().strip()
+ if rootcap:
+ aliases["tahoe"] = uri.from_string_dirnode(rootcap).to_string()
+ except EnvironmentError:
+ pass
+ try:
+ f = open(aliasfile, "r")
+ for line in f.readlines():
+ line = line.strip()
+ if line.startswith("#"):
+ continue
+ name, cap = line.split(":", 1)
+ # normalize it: remove http: prefix, urldecode
+ cap = cap.strip()
+ aliases[name] = uri.from_string_dirnode(cap).to_string()
+ except EnvironmentError:
+ pass
+ return aliases
+
def get_alias(aliases, path, default):
# transform "work:path/filename" into (aliases["work"], "path/filename")
# We special-case URI:
import os.path
from allmydata import uri
+from allmydata.scripts.common import get_aliases
def add_alias(nodedir, alias, cap, stdout, stderr):
aliasfile = os.path.join(nodedir, "private", "aliases")
print >>stdout, "Alias '%s' added" % (alias,)
return 0
+def list_aliases(nodedir, stdout, stderr):
+ aliases = get_aliases(nodedir)
+ alias_names = sorted(aliases.keys())
+ max_width = max([len(name) for name in alias_names] + [0])
+ fmt = "%" + str(max_width) + "s: %s"
+ for name in alias_names:
+ print >>stdout, fmt % (name, aliases[name])
+
d.addCallback(run, "ls")
d.addCallback(_check_ls, ["personal", "s2-ro", "s2-rw"])
+ d.addCallback(run, "list-aliases")
+ def _check_aliases_1((out,err)):
+ self.failUnlessEqual(err, "")
+ self.failUnlessEqual(out, "tahoe: %s\n" % private_uri)
+ d.addCallback(_check_aliases_1)
+
# now that that's out of the way, remove root_dir.cap and work with
# new files
d.addCallback(lambda res: os.unlink(root_file))
+ d.addCallback(run, "list-aliases")
+ def _check_aliases_2((out,err)):
+ self.failUnlessEqual(err, "")
+ self.failUnlessEqual(out, "")
+ d.addCallback(_check_aliases_2)
d.addCallback(run, "mkdir")
def _got_dir( (out,err) ):
return out.strip()
d.addCallback(_got_dir)
d.addCallback(lambda newcap: run(None, "add-alias", "tahoe", newcap))
+
+ d.addCallback(run, "list-aliases")
+ def _check_aliases_3((out,err)):
+ self.failUnlessEqual(err, "")
+ self.failUnless("tahoe: " in out)
+ d.addCallback(_check_aliases_3)
+
def _check_empty_dir((out,err)):
self.failUnlessEqual(out, "")
self.failUnlessEqual(err, "")