mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-11 07:23:04 +00:00
Convert subcommands to tuples instead of lists, as that's what mypy demands for heterogeneous sequences.
This commit is contained in:
parent
41c341a3cc
commit
acbb6b3e93
@ -1,5 +1,10 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
try:
|
||||||
|
from allmydata.scripts.types_ import SubCommands
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
from twisted.python import usage
|
from twisted.python import usage
|
||||||
from allmydata.scripts.common import BaseOptions
|
from allmydata.scripts.common import BaseOptions
|
||||||
|
|
||||||
@ -79,8 +84,8 @@ def do_admin(options):
|
|||||||
|
|
||||||
|
|
||||||
subCommands = [
|
subCommands = [
|
||||||
["admin", None, AdminCommand, "admin subcommands: use 'tahoe admin' for a list"],
|
("admin", None, AdminCommand, "admin subcommands: use 'tahoe admin' for a list"),
|
||||||
]
|
] # type: SubCommands
|
||||||
|
|
||||||
dispatch = {
|
dispatch = {
|
||||||
"admin": do_admin,
|
"admin": do_admin,
|
||||||
|
@ -4,6 +4,7 @@ import os.path, re, fnmatch
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from typing import List, Sequence, Any
|
from typing import List, Sequence, Any
|
||||||
|
from allmydata.scripts.types_ import SubCommands
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -461,25 +462,25 @@ class DeepCheckOptions(FileStoreOptions):
|
|||||||
Optionally repair any problems found."""
|
Optionally repair any problems found."""
|
||||||
|
|
||||||
subCommands = [
|
subCommands = [
|
||||||
["mkdir", None, MakeDirectoryOptions, "Create a new directory."],
|
("mkdir", None, MakeDirectoryOptions, "Create a new directory."),
|
||||||
["add-alias", None, AddAliasOptions, "Add a new alias cap."],
|
("add-alias", None, AddAliasOptions, "Add a new alias cap."),
|
||||||
["create-alias", None, CreateAliasOptions, "Create a new alias cap."],
|
("create-alias", None, CreateAliasOptions, "Create a new alias cap."),
|
||||||
["list-aliases", None, ListAliasesOptions, "List all alias caps."],
|
("list-aliases", None, ListAliasesOptions, "List all alias caps."),
|
||||||
["ls", None, ListOptions, "List a directory."],
|
("ls", None, ListOptions, "List a directory."),
|
||||||
["get", None, GetOptions, "Retrieve a file from the grid."],
|
("get", None, GetOptions, "Retrieve a file from the grid."),
|
||||||
["put", None, PutOptions, "Upload a file into the grid."],
|
("put", None, PutOptions, "Upload a file into the grid."),
|
||||||
["cp", None, CpOptions, "Copy one or more files or directories."],
|
("cp", None, CpOptions, "Copy one or more files or directories."),
|
||||||
["unlink", None, UnlinkOptions, "Unlink a file or directory on the grid."],
|
("unlink", None, UnlinkOptions, "Unlink a file or directory on the grid."),
|
||||||
["mv", None, MvOptions, "Move a file within the grid."],
|
("mv", None, MvOptions, "Move a file within the grid."),
|
||||||
["ln", None, LnOptions, "Make an additional link to an existing file or directory."],
|
("ln", None, LnOptions, "Make an additional link to an existing file or directory."),
|
||||||
["backup", None, BackupOptions, "Make target dir look like local dir."],
|
("backup", None, BackupOptions, "Make target dir look like local dir."),
|
||||||
["webopen", None, WebopenOptions, "Open a web browser to a grid file or directory."],
|
("webopen", None, WebopenOptions, "Open a web browser to a grid file or directory."),
|
||||||
["manifest", None, ManifestOptions, "List all files/directories in a subtree."],
|
("manifest", None, ManifestOptions, "List all files/directories in a subtree."),
|
||||||
["stats", None, StatsOptions, "Print statistics about all files/directories in a subtree."],
|
("stats", None, StatsOptions, "Print statistics about all files/directories in a subtree."),
|
||||||
["check", None, CheckOptions, "Check a single file or directory."],
|
("check", None, CheckOptions, "Check a single file or directory."),
|
||||||
["deep-check", None, DeepCheckOptions, "Check all files/directories reachable from a starting point."],
|
("deep-check", None, DeepCheckOptions, "Check all files/directories reachable from a starting point."),
|
||||||
["status", None, TahoeStatusCommand, "Various status information."],
|
("status", None, TahoeStatusCommand, "Various status information."),
|
||||||
]
|
] # type: SubCommands
|
||||||
|
|
||||||
def mkdir(options):
|
def mkdir(options):
|
||||||
from allmydata.scripts import tahoe_mkdir
|
from allmydata.scripts import tahoe_mkdir
|
||||||
|
@ -3,6 +3,11 @@ from __future__ import print_function
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
try:
|
||||||
|
from allmydata.scripts.types_ import SubCommands
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
from twisted.internet import reactor, defer
|
from twisted.internet import reactor, defer
|
||||||
from twisted.python.usage import UsageError
|
from twisted.python.usage import UsageError
|
||||||
from allmydata.scripts.common import BasedirOptions, NoDefaultBasedirOptions
|
from allmydata.scripts.common import BasedirOptions, NoDefaultBasedirOptions
|
||||||
@ -478,10 +483,10 @@ def create_introducer(config):
|
|||||||
|
|
||||||
|
|
||||||
subCommands = [
|
subCommands = [
|
||||||
["create-node", None, CreateNodeOptions, "Create a node that acts as a client, server or both."],
|
("create-node", None, CreateNodeOptions, "Create a node that acts as a client, server or both."),
|
||||||
["create-client", None, CreateClientOptions, "Create a client node (with storage initially disabled)."],
|
("create-client", None, CreateClientOptions, "Create a client node (with storage initially disabled)."),
|
||||||
["create-introducer", None, CreateIntroducerOptions, "Create an introducer node."],
|
("create-introducer", None, CreateIntroducerOptions, "Create an introducer node."),
|
||||||
]
|
] # type: SubCommands
|
||||||
|
|
||||||
dispatch = {
|
dispatch = {
|
||||||
"create-node": create_node,
|
"create-node": create_node,
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
try:
|
||||||
|
from allmydata.scripts.types_ import SubCommands
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
# do not import any allmydata modules at this level. Do that from inside
|
# do not import any allmydata modules at this level. Do that from inside
|
||||||
# individual functions instead.
|
# individual functions instead.
|
||||||
import struct, time, os, sys
|
import struct, time, os, sys
|
||||||
@ -1051,8 +1056,8 @@ def do_debug(options):
|
|||||||
|
|
||||||
|
|
||||||
subCommands = [
|
subCommands = [
|
||||||
["debug", None, DebugCommand, "debug subcommands: use 'tahoe debug' for a list."],
|
("debug", None, DebugCommand, "debug subcommands: use 'tahoe debug' for a list."),
|
||||||
]
|
] # type: SubCommands
|
||||||
|
|
||||||
dispatch = {
|
dispatch = {
|
||||||
"debug": do_debug,
|
"debug": do_debug,
|
||||||
|
@ -4,6 +4,11 @@ import os, sys
|
|||||||
from six.moves import StringIO
|
from six.moves import StringIO
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
try:
|
||||||
|
from allmydata.scripts.types_ import SubCommands
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
from twisted.python import usage
|
from twisted.python import usage
|
||||||
from twisted.internet import defer, task, threads
|
from twisted.internet import defer, task, threads
|
||||||
|
|
||||||
@ -45,12 +50,12 @@ _control_node_dispatch = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
process_control_commands = [
|
process_control_commands = [
|
||||||
["run", None, tahoe_run.RunOptions, "run a node without daemonizing"],
|
("run", None, tahoe_run.RunOptions, "run a node without daemonizing"),
|
||||||
["daemonize", None, tahoe_daemonize.DaemonizeOptions, "(deprecated) run a node in the background"],
|
("daemonize", None, tahoe_daemonize.DaemonizeOptions, "(deprecated) run a node in the background"),
|
||||||
["start", None, tahoe_start.StartOptions, "(deprecated) start a node in the background and confirm it started"],
|
("start", None, tahoe_start.StartOptions, "(deprecated) start a node in the background and confirm it started"),
|
||||||
["stop", None, tahoe_stop.StopOptions, "(deprecated) stop a node"],
|
("stop", None, tahoe_stop.StopOptions, "(deprecated) stop a node"),
|
||||||
["restart", None, tahoe_restart.RestartOptions, "(deprecated) restart a node"],
|
("restart", None, tahoe_restart.RestartOptions, "(deprecated) restart a node"),
|
||||||
]
|
] # type: SubCommands
|
||||||
|
|
||||||
|
|
||||||
class Options(usage.Options):
|
class Options(usage.Options):
|
||||||
|
@ -2,6 +2,11 @@ from __future__ import print_function
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
try:
|
||||||
|
from allmydata.scripts.types_ import SubCommands
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
# Python 2 compatibility
|
# Python 2 compatibility
|
||||||
from future.utils import PY2
|
from future.utils import PY2
|
||||||
if PY2:
|
if PY2:
|
||||||
@ -93,8 +98,8 @@ def create_stats_gatherer(config):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
subCommands = [
|
subCommands = [
|
||||||
["create-stats-gatherer", None, CreateStatsGathererOptions, "Create a stats-gatherer service."],
|
("create-stats-gatherer", None, CreateStatsGathererOptions, "Create a stats-gatherer service."),
|
||||||
]
|
] # type: SubCommands
|
||||||
|
|
||||||
dispatch = {
|
dispatch = {
|
||||||
"create-stats-gatherer": create_stats_gatherer,
|
"create-stats-gatherer": create_stats_gatherer,
|
||||||
|
@ -3,6 +3,11 @@ from __future__ import print_function
|
|||||||
import json
|
import json
|
||||||
from os.path import join
|
from os.path import join
|
||||||
|
|
||||||
|
try:
|
||||||
|
from allmydata.scripts.types_ import SubCommands
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
from twisted.python import usage
|
from twisted.python import usage
|
||||||
from twisted.internet import defer, reactor
|
from twisted.internet import defer, reactor
|
||||||
|
|
||||||
@ -104,7 +109,7 @@ def invite(options):
|
|||||||
subCommands = [
|
subCommands = [
|
||||||
("invite", None, InviteOptions,
|
("invite", None, InviteOptions,
|
||||||
"Invite a new node to this grid"),
|
"Invite a new node to this grid"),
|
||||||
]
|
] # type: SubCommands
|
||||||
|
|
||||||
dispatch = {
|
dispatch = {
|
||||||
"invite": invite,
|
"invite": invite,
|
||||||
|
10
src/allmydata/scripts/types_.py
Normal file
10
src/allmydata/scripts/types_.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from typing import List, Tuple, Type
|
||||||
|
from allmydata.scripts.common import BaseOptions
|
||||||
|
|
||||||
|
|
||||||
|
# Historically, subcommands were implemented as lists, but due to a
|
||||||
|
# [designed contraint in mypy](https://stackoverflow.com/a/52559625/70170),
|
||||||
|
# a Tuple is required.
|
||||||
|
SubCommand = Tuple[str, None, Type[BaseOptions], str]
|
||||||
|
|
||||||
|
SubCommands = List[SubCommand]
|
Loading…
Reference in New Issue
Block a user