add some status messages when starting up and break commands into common and debug

This commit is contained in:
Jimmy Kiselak 2015-10-22 02:23:12 -04:00
parent 7df6e99e28
commit 385c221ef8
4 changed files with 99 additions and 18 deletions

View file

@ -17,6 +17,7 @@ import os
log = logging.getLogger(__name__)
alert = logging.getLogger("lbryalert." + __name__)
class ReservedPoints(object):
@ -63,10 +64,12 @@ class LBRYcrdWallet(object):
def start(self):
def make_connection():
alert.info("Connecting to lbrycrdd...")
if self.lbrycrdd_path is not None:
self._start_daemon()
self._get_info()
log.info("Connected!")
alert.info("Connected to lbrycrdd.")
def start_manage():
self.stopped = False

View file

@ -9,21 +9,57 @@ log = logging.getLogger(__name__)
class ConsoleControl(basic.LineReceiver):
from os import linesep as delimiter
def __init__(self, command_handlers):
def __init__(self):
self.connected = False
self.buffer = []
def start(self, command_handlers):
self.command_handlers = {h.command: h for h in command_handlers}
self.current_handler = None
self.send_initial_prompt()
return defer.succeed(True)
def connectionMade(self):
self.connected = True
if self.buffer:
self.send(self.buffer)
self.buffer = []
def send_initial_prompt(self):
self.sendLine("")
self.sendLine("Welcome to lbrynet-console!")
self.sendLine("")
self.sendLine("Enter a command. Try 'get wonderfullife' or 'help' to see more options.")
self.show_prompt()
def send(self, s):
self.transport.write(s)
def write(self, s):
if self.connected is False:
self.buffer.append(s)
else:
self.send(s)
def flush(self):
if self.connected is True and self.buffer:
self.send(self.buffer)
self.buffer = []
def show_prompt(self):
self.send("> ")
def show_help_overview(self):
def show_quick_help(self):
self.sendLine("Available commands:")
self.sendLine("")
for command, handler in sorted(self.command_handlers.items(), key=lambda x: x[0]):
if handler.is_main_command is True:
self.sendLine(command + " - " + handler.short_help)
self.sendLine("help-debug - Show the full list of available commands")
self.sendLine("")
self.sendLine("For more information about any command type 'help <command>'")
def show_full_help(self):
self.sendLine("Available commands:")
self.sendLine("")
for command, handler in sorted(self.command_handlers.items(), key=lambda x: x[0]):
@ -50,13 +86,24 @@ class ConsoleControl(basic.LineReceiver):
command, args = words[0], words[1:]
if command == "help":
if len(args) == 0:
self.show_help_overview()
self.show_quick_help()
self.show_prompt()
return
if args[0] in self.command_handlers:
self.sendLine(self.command_handlers[args[0]].full_help)
self.show_prompt()
return
if args[0] == "help-debug":
self.sendLine("Show the full list of available commands!")
self.show_prompt()
return
self.sendLine("Can't help you with '%s'. Sorry!" % args[0])
self.show_prompt()
return
elif command == "help-debug":
self.show_full_help()
self.show_prompt()
return
if command in self.command_handlers:
command_handler = self.command_handlers[command]
else:

View file

@ -48,6 +48,7 @@ class InvalidValueError(Exception):
class CommandHandlerFactory(object):
implements(ICommandHandlerFactory)
is_main_command = False
short_help = "This should be overridden"
full_help = "This should really be overridden"
command = "this-must-be-overridden"
@ -237,6 +238,7 @@ class ApplicationStatus(CommandHandler):
class ApplicationStatusFactory(CommandHandlerFactory):
control_handler_class = ApplicationStatus
is_main_command = True
command = "application-status"
short_help = "Show application status"
full_help = "Show total bytes uploaded to other peers, total bytes downloaded from peers," \
@ -275,7 +277,8 @@ class GetWalletBalances(CommandHandler):
class GetWalletBalancesFactory(CommandHandlerFactory):
control_handler_class = GetWalletBalances
command = "wallet-balance"
is_main_command = True
command = "balance"
short_help = "Show LBRYcrd balance"
full_help = "Show the LBRYcrd balance of the wallet to which this application is connected"
@ -305,6 +308,7 @@ class GetNewWalletAddress(CommandHandler):
class GetNewWalletAddressFactory(CommandHandlerFactory):
control_handler_class = GetNewWalletAddress
is_main_command = False
command = "get-new-address"
short_help = "Get a new LBRYcrd address"
full_help = "Get a new LBRYcrd address from the wallet to which this application is connected"
@ -339,6 +343,7 @@ class ShutDown(CommandHandler):
class ShutDownFactory(CommandHandlerFactory):
control_handler_class = ShutDown
is_main_command = True
command = "exit"
short_help = "Shut down"
full_help = "Shut down"
@ -374,6 +379,7 @@ class LBRYFileStatus(CommandHandler):
class LBRYFileStatusFactory(CommandHandlerFactory):
control_handler_class = LBRYFileStatus
is_main_command = True
command = "lbryfile-status"
short_help = "Print status information for LBRY files"
full_help = "Print the status information for all streams that are being saved to disk." \
@ -668,6 +674,7 @@ class AddStreamFromSD(AddStream):
class AddStreamFromSDFactory(CommandHandlerFactory):
control_handler_class = AddStreamFromSD
is_main_command = False
command = "get-sd"
short_help = "Download a stream from a plaintext stream descriptor file"
full_help = "Download a stream from a plaintext stream descriptor file.\n" \
@ -705,6 +712,7 @@ class AddStreamFromHash(AddStream):
class AddStreamFromHashFactory(CommandHandlerFactory):
control_handler_class = AddStreamFromHash
is_main_command = False
command = "get-hash"
short_help = "Download a stream from a hash"
full_help = "Download a stream from the hash of the stream descriptor. The stream " \
@ -789,6 +797,7 @@ class AddStreamFromLBRYcrdName(AddStreamFromHash):
class AddStreamFromLBRYcrdNameFactory(CommandHandlerFactory):
control_handler_class = AddStreamFromLBRYcrdName
is_main_command = True
command = "get"
short_help = "Download a stream from a name"
full_help = "Download a stream associated with a name on the LBRYcrd blockchain. The name will be" \
@ -841,6 +850,7 @@ class DeleteLBRYFileChooser(LBRYFileChooser):
class DeleteLBRYFileChooserFactory(CommandHandlerFactory):
control_handler_class = DeleteLBRYFileChooser
is_main_command = False
command = "delete-lbryfile"
short_help = "Delete an LBRY file"
full_help = "Delete an LBRY file which has been downloaded or created by this application"
@ -937,6 +947,7 @@ class ToggleLBRYFileRunningChooser(LBRYFileChooser):
class ToggleLBRYFileRunningChooserFactory(CommandHandlerFactory):
control_handler_class = ToggleLBRYFileRunningChooser
is_main_command = False
command = "toggle-running"
short_help = "Toggle whether an LBRY file is running"
full_help = "Toggle whether an LBRY file, which is being saved by this application," \
@ -1000,6 +1011,7 @@ class CreateLBRYFile(CommandHandler):
class CreateLBRYFileFactory(CommandHandlerFactory):
control_handler_class = CreateLBRYFile
is_main_command = True
command = "create-lbryfile"
short_help = "LBRYize a file"
full_help = "Split a file up into encrypted chunks compatible with LBRYnet"
@ -1016,6 +1028,7 @@ class PublishStreamDescriptorChooser(LBRYFileChooser):
class PublishStreamDescriptorChooserFactory(CommandHandlerFactory):
control_handler_class = PublishStreamDescriptorChooser
is_main_command = True
command = "publish-lbryfile"
short_help = "Put a stream descriptor onto LBRYnet"
full_help = "Make a stream descriptor available on LBRYnet at its sha384 hashsum"
@ -1065,6 +1078,7 @@ class ShowPublishedSDHashesChooser(LBRYFileChooser):
class ShowPublishedSDHashesChooserFactory(CommandHandlerFactory):
control_handler_class = ShowPublishedSDHashesChooser
is_main_command = False
command = "show-lbryfile-sd-hashes"
short_help = "Show the published stream descriptor files associated with an LBRY file"
full_help = "Show the published stream descriptor files associated with an LBRY file"
@ -1108,6 +1122,7 @@ class CreatePlainStreamDescriptorChooser(LBRYFileChooser):
class CreatePlainStreamDescriptorChooserFactory(CommandHandlerFactory):
control_handler_class = CreatePlainStreamDescriptorChooser
is_main_command = False
command = "create-stream-descriptor"
short_help = "Create a plaintext stream descriptor file for an LBRY file"
full_help = "Create a plaintext stream descriptor file for an LBRY file"
@ -1175,6 +1190,7 @@ class ShowLBRYFileStreamHashChooser(LBRYFileChooser):
class ShowLBRYFileStreamHashChooserFactory(CommandHandlerFactory):
control_handler_class = ShowLBRYFileStreamHashChooser
is_main_command = False
command = "lbryfile-streamhash"
short_help = "Show an LBRY file's stream hash"
full_help = "Show the stream hash of an LBRY file, which is how the LBRY file is referenced internally" \
@ -1238,6 +1254,7 @@ class ModifyLBRYFileOptionsChooser(LBRYFileChooser):
class ModifyLBRYFileOptionsChooserFactory(CommandHandlerFactory):
control_handler_class = ModifyLBRYFileOptionsChooser
is_main_command = False
command = "modify-lbryfile-options"
short_help = "Modify an LBRY file's options"
full_help = "Modify an LBRY file's options"
@ -1443,7 +1460,8 @@ class ClaimName(CommandHandler):
class ClaimNameFactory(CommandHandlerFactory):
control_handler_class = ClaimName
command = "claim-name"
is_main_command = True
command = "claim"
short_help = "Associate an LBRY file with a name on LBRYnet"
full_help = "Associate an LBRY file (or any hash) with a name on LBRYnet"
@ -1507,6 +1525,7 @@ class ModifyApplicationDefaults(RecursiveCommandHandler):
class ModifyApplicationDefaultsFactory(CommandHandlerFactory):
control_handler_class = ModifyApplicationDefaults
is_main_command = True
command = "modify-application-defaults"
short_help = "Modify application settings"
full_help = "Modify application settings"
@ -1545,6 +1564,7 @@ class ShowServerStatus(CommandHandler):
class ShowServerStatusFactory(CommandHandlerFactory):
control_handler_class = ShowServerStatus
is_main_command = False
command = "server-status"
short_help = "Show the server's status"
full_help = "Show the port on which the server is running, whether the server is running, and the" \
@ -1771,6 +1791,7 @@ class ModifyServerSettings(RecursiveCommandHandler):
class ModifyServerSettingsFactory(CommandHandlerFactory):
control_handler_class = ModifyServerSettings
is_main_command = True
command = "modify-server-settings"
short_help = "Modify server settings"
full_help = "Modify server settings"
@ -1856,6 +1877,7 @@ class PeerStatsAndSettingsChooser(PeerChooser):
class PeerStatsAndSettingsChooserFactory(CommandHandlerFactory):
control_handler_class = PeerStatsAndSettingsChooser
is_main_command = False
command = "peer-stats"
short_help = "Show some peer statistics"
full_help = "Show some peer statistics"

View file

@ -37,11 +37,12 @@ from lbrynet.core.LBRYcrdWallet import LBRYcrdWallet
log = logging.getLogger(__name__)
alert = logging.getLogger("lbryalert." + __name__)
class LBRYConsole():
"""A class which can upload and download file streams to and from the network"""
def __init__(self, peer_port, dht_node_port, known_dht_nodes, control_class, wallet_type,
def __init__(self, peer_port, dht_node_port, known_dht_nodes, wallet_type,
lbrycrd_conf, lbrycrd_dir, use_upnp, data_dir, created_data_dir,
lbrycrdd_path, start_lbrycrdd):
"""
@ -66,7 +67,6 @@ class LBRYConsole():
self.start_lbrycrdd = start_lbrycrdd
self.use_upnp = use_upnp
self.lbry_server_port = None
self.control_class = control_class
self.session = None
self.lbry_file_metadata_manager = None
self.lbry_file_manager = None
@ -91,7 +91,8 @@ class LBRYConsole():
def start(self):
"""Initialize the session and restore everything to its saved state"""
d = threads.deferToThread(self._setup_data_directory)
d = self._setup_controller()
d.addCallback(lambda _: threads.deferToThread(self._setup_data_directory))
d.addCallback(lambda _: self._check_db_migration())
d.addCallback(lambda _: self._get_settings())
d.addCallback(lambda _: self._get_session())
@ -144,6 +145,7 @@ class LBRYConsole():
return dl
def _setup_data_directory(self):
alert.info("Loading databases...")
if self.created_data_dir:
db_revision = open(os.path.join(self.db_dir, "db_revision"), mode='w')
db_revision.write(str(self.current_db_revision))
@ -270,6 +272,8 @@ class LBRYConsole():
def create_session(results):
alert.info("Databases loaded.")
self.session = LBRYSession(results['default_data_payment_rate'], db_dir=self.db_dir, lbryid=self.lbryid,
blob_dir=self.blobfile_dir, dht_node_port=self.dht_node_port,
known_dht_nodes=self.known_dht_nodes, peer_port=self.peer_port,
@ -422,10 +426,21 @@ class LBRYConsole():
else:
return defer.succeed(True)
def _start_controller(self):
self.control_class(self.command_handlers)
def _setup_controller(self):
self.controller = ConsoleControl()
stdio.StandardIO(self.controller)
logger = logging.getLogger()
formatter = logging.Formatter("%(message)s")
alert_handler = logging.StreamHandler(self.controller)
alert_handler.setFormatter(formatter)
alert_handler.addFilter(logging.Filter("lbryalert"))
alert_handler.setLevel(logging.DEBUG)
logger.addHandler(alert_handler)
return defer.succeed(True)
def _start_controller(self):
return self.controller.start(self.command_handlers)
def _shut_down(self):
self.plugin_manager = None
ds = []
@ -439,11 +454,6 @@ class LBRYConsole():
return dl
class StdIOControl():
def __init__(self, control_handlers):
stdio.StandardIO(ConsoleControl(control_handlers))
def launch_lbry_console():
from twisted.internet import reactor
@ -533,9 +543,8 @@ def launch_lbry_console():
file_handler.addFilter(logging.Filter("lbrynet"))
logger.addHandler(file_handler)
console = LBRYConsole(peer_port, dht_node_port, bootstrap_nodes, StdIOControl,
wallet_type=args.wallet_type, lbrycrd_conf=args.lbrycrd_wallet_conf,
lbrycrd_dir=args.lbrycrd_wallet_dir,
console = LBRYConsole(peer_port, dht_node_port, bootstrap_nodes, wallet_type=args.wallet_type,
lbrycrd_conf=args.lbrycrd_wallet_conf, lbrycrd_dir=args.lbrycrd_wallet_dir,
use_upnp=not args.disable_upnp, data_dir=data_dir,
created_data_dir=created_data_dir, lbrycrdd_path=args.lbrycrdd_path,
start_lbrycrdd=not args.disable_launch_lbrycrdd)