]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/scripts/create_node.py
cli: improve formatting of all commands
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / scripts / create_node.py
index d98b421d5682807fa6ec277469bfabb348788a39..65cbb63ae740d1e8630dffde99ee820e59a08914 100644 (file)
@@ -1,32 +1,45 @@
 
 import os, sys
-from twisted.python import usage
-from allmydata.scripts.common import BasedirMixin, NoDefaultBasedirMixin
+from allmydata.scripts.common import BasedirOptions, NoDefaultBasedirOptions
+from allmydata.scripts.default_nodedir import _default_nodedir
 from allmydata.util.assertutil import precondition
-from allmydata.util.encodingutil import listdir_unicode, argv_to_unicode, quote_output
+from allmydata.util.encodingutil import listdir_unicode, argv_to_unicode, quote_output, quote_local_unicode_path
 import allmydata
 
-class CreateClientOptions(BasedirMixin, usage.Options):
+class _CreateBaseOptions(BasedirOptions):
     optParameters = [
-        ("basedir", "C", None, "which directory to create the node in"),
         # we provide 'create-node'-time options for the most common
         # configuration knobs. The rest can be controlled by editing
         # tahoe.cfg before node startup.
-        ("nickname", "n", None, "nickname for this node"),
-        ("introducer", "i", None, "introducer FURL to use"),
+        ("nickname", "n", None, "Specify the nickname for this node."),
+        ("introducer", "i", None, "Specify the introducer FURL to use."),
         ("webport", "p", "tcp:3456:interface=127.0.0.1",
-         "which TCP port to run the HTTP interface on. Use 'none' to disable."),
+         "Specify which TCP port to run the HTTP interface on. Use 'none' to disable."),
+        ("basedir", "C", None, "Specify which Tahoe base directory should be used. This has the same effect as the global --node-directory option. [default: %s]"
+         % quote_local_unicode_path(_default_nodedir)),
+
         ]
 
+    # This is overridden in order to ensure we get a "Wrong number of
+    # arguments." error when more than one argument is given.
+    def parseArgs(self, basedir=None):
+        BasedirOptions.parseArgs(self, basedir)
+
+class CreateClientOptions(_CreateBaseOptions):
+    synopsis = "[options] [NODEDIR]"
+    description = "Create a client-only Tahoe-LAFS node (no storage server)."
+
 class CreateNodeOptions(CreateClientOptions):
     optFlags = [
-        ("no-storage", None, "do not offer storage service to other nodes"),
+        ("no-storage", None, "Do not offer storage service to other nodes."),
         ]
+    synopsis = "[options] [NODEDIR]"
+    description = "Create a full Tahoe-LAFS node (client+server)."
+
+class CreateIntroducerOptions(NoDefaultBasedirOptions):
+    subcommand_name = "create-introducer"
+    description = "Create a Tahoe-LAFS introducer."
 
-class CreateIntroducerOptions(NoDefaultBasedirMixin, usage.Options):
-    optParameters = [
-        ["basedir", "C", None, "which directory to create the introducer in"],
-        ]
 
 client_tac = """
 # -*- python -*-
@@ -65,16 +78,19 @@ def write_node_config(c, config):
     c.write("# This file controls the configuration of the Tahoe node that\n")
     c.write("# lives in this directory. It is only read at node startup.\n")
     c.write("# For details about the keys that can be set here, please\n")
-    c.write("# read the 'docs/configuration.txt' file that came with your\n")
+    c.write("# read the 'docs/configuration.rst' file that came with your\n")
     c.write("# Tahoe installation.\n")
     c.write("\n\n")
 
     c.write("[node]\n")
-    c.write("nickname = %s\n" % config.get("nickname", "")) #TODO: utf8 in argv?
-    webport = config.get("webport", "none")
+    nickname = argv_to_unicode(config.get("nickname") or "")
+    c.write("nickname = %s\n" % (nickname.encode('utf-8'),))
+
+    # TODO: validate webport
+    webport = argv_to_unicode(config.get("webport") or "none")
     if webport.lower() == "none":
         webport = ""
-    c.write("web.port = %s\n" % webport)
+    c.write("web.port = %s\n" % (webport.encode('utf-8'),))
     c.write("web.static = public_html\n")
     c.write("#tub.port =\n")
     c.write("#tub.location = \n")
@@ -86,7 +102,8 @@ def write_node_config(c, config):
     c.write("\n")
 
 
-def create_node(basedir, config, out=sys.stdout, err=sys.stderr):
+def create_node(config, out=sys.stdout, err=sys.stderr):
+    basedir = config['basedir']
     # This should always be called with an absolute Unicode basedir.
     precondition(isinstance(basedir, unicode), basedir)
 
@@ -108,10 +125,13 @@ def create_node(basedir, config, out=sys.stdout, err=sys.stderr):
     write_node_config(c, config)
 
     c.write("[client]\n")
+    c.write("# Which services should this client connect to?\n")
     c.write("introducer.furl = %s\n" % config.get("introducer", ""))
     c.write("helper.furl =\n")
     c.write("#key_generator.furl =\n")
     c.write("#stats_gatherer.furl =\n")
+    c.write("\n")
+    c.write("# What encoding parameters should this client use for uploads?\n")
     c.write("#shares.needed = 3\n")
     c.write("#shares.happy = 7\n")
     c.write("#shares.total = 10\n")
@@ -119,16 +139,26 @@ def create_node(basedir, config, out=sys.stdout, err=sys.stderr):
 
     boolstr = {True:"true", False:"false"}
     c.write("[storage]\n")
+    c.write("# Shall this node provide storage service?\n")
     storage_enabled = not config.get("no-storage", None)
     c.write("enabled = %s\n" % boolstr[storage_enabled])
     c.write("#readonly =\n")
-    c.write("#reserved_space =\n")
+    c.write("reserved_space = 1G\n")
     c.write("#expire.enabled =\n")
     c.write("#expire.mode =\n")
     c.write("\n")
 
     c.write("[helper]\n")
+    c.write("# Shall this node run a helper service that clients can use?\n")
+    c.write("enabled = false\n")
+    c.write("\n")
+
+    c.write("[drop_upload]\n")
+    c.write("# Shall this node automatically upload files created or modified in a local directory?\n")
     c.write("enabled = false\n")
+    c.write("# To specify the target of uploads, a mutable directory writecap URI must be placed\n"
+            "# in 'private/drop_upload_dircap'.\n")
+    c.write("local.directory = ~/drop_upload\n")
     c.write("\n")
 
     c.close()
@@ -141,14 +171,15 @@ def create_node(basedir, config, out=sys.stdout, err=sys.stderr):
         print >>out, " The node cannot connect to a grid without it."
     if not config.get("nickname", ""):
         print >>out, " Please set [node]nickname= in tahoe.cfg"
+    return 0
 
-
-def create_client(basedir, config, out=sys.stdout, err=sys.stderr):
+def create_client(config, out=sys.stdout, err=sys.stderr):
     config['no-storage'] = True
-    return create_node(basedir, config, out=out, err=err)
+    return create_node(config, out=out, err=err)
 
 
-def create_introducer(basedir, config, out=sys.stdout, err=sys.stderr):
+def create_introducer(config, out=sys.stdout, err=sys.stderr):
+    basedir = config['basedir']
     # This should always be called with an absolute Unicode basedir.
     precondition(isinstance(basedir, unicode), basedir)
 
@@ -170,6 +201,7 @@ def create_introducer(basedir, config, out=sys.stdout, err=sys.stderr):
     c.close()
 
     print >>out, "Introducer created in %s" % quote_output(basedir)
+    return 0
 
 
 subCommands = [