2008-05-20 02:28:50 +00:00
|
|
|
|
|
|
|
import os.path
|
|
|
|
from allmydata import uri
|
2008-05-20 21:36:04 +00:00
|
|
|
from allmydata.scripts.common import get_aliases
|
2008-05-20 02:28:50 +00:00
|
|
|
|
2008-08-01 18:46:24 +00:00
|
|
|
def add_alias(options):
|
|
|
|
nodedir = options['node-directory']
|
|
|
|
alias = options.alias
|
|
|
|
cap = options.cap
|
|
|
|
stdout = options.stdout
|
|
|
|
stderr = options.stderr
|
2008-05-20 02:28:50 +00:00
|
|
|
aliasfile = os.path.join(nodedir, "private", "aliases")
|
|
|
|
cap = uri.from_string_dirnode(cap).to_string()
|
|
|
|
assert ":" not in alias
|
|
|
|
assert " " not in alias
|
|
|
|
# probably check for others..
|
|
|
|
f = open(aliasfile, "a")
|
|
|
|
f.write("%s: %s\n" % (alias, cap))
|
|
|
|
f.close()
|
|
|
|
print >>stdout, "Alias '%s' added" % (alias,)
|
|
|
|
return 0
|
|
|
|
|
2008-08-01 18:46:24 +00:00
|
|
|
def list_aliases(options):
|
|
|
|
nodedir = options['node-directory']
|
|
|
|
stdout = options.stdout
|
|
|
|
stderr = options.stderr
|
2008-05-20 21:36:04 +00:00
|
|
|
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])
|
|
|
|
|