Browse Source

do not declare pointless static methods

283
ThomasV 9 years ago
parent
commit
1c83c3e060
  1. 45
      electrum
  2. 50
      lib/daemon.py

45
electrum

@ -313,19 +313,54 @@ if __name__ == '__main__':
sys.exit(0) sys.exit(0)
if cmdname == 'gui': if cmdname == 'gui':
result = Daemon.gui_command(config, config_options, plugins) lockfile = Daemon.lockfile(config)
fd = Daemon.get_fd_or_server(lockfile)
if isinstance(fd, int):
daemon = Daemon.create_daemon(config, fd)
daemon.init_gui(config, plugins)
sys.exit(0)
server = fd
result = server.gui(config_options)
elif cmdname == 'daemon': elif cmdname == 'daemon':
result = Daemon.daemon_command(config, config_options) lockfile = Daemon.lockfile(config)
fd = Daemon.get_fd_or_server(lockfile)
if isinstance(fd, int):
subcommand = config.get('subcommand')
assert subcommand in ['start', 'stop', 'status']
if subcommand != 'start':
print_msg("Daemon not running")
os.close(fd)
Daemon.remove_lockfile(lockfile)
sys.exit(1)
pid = os.fork()
if pid:
print_stderr("starting daemon (PID %d)" % pid)
sys.exit(0)
daemon = Daemon.create_daemon(config, fd)
if config.get('websocket_server'):
from electrum import websockets
websockets.WebSocketServer(config, daemon.network).start()
if config.get('requests_dir'):
util.check_www_dir(config.get('requests_dir'))
daemon.join()
sys.exit(0)
else:
server = fd
result = server.daemon(config_options)
else: else:
# command line # command line
init_cmdline(config_options) init_cmdline(config_options)
run_offline, result = Daemon.cmdline_command(config, config_options) server = Daemon.get_server(Daemon.lockfile(config))
if run_offline: if server is not None:
result = server.run_cmdline(config_options)
else:
cmd = known_commands[cmdname] cmd = known_commands[cmdname]
if cmd.requires_network: if cmd.requires_network:
print_msg("Daemon not running; try 'electrum daemon start'") print_msg("Daemon not running; try 'electrum daemon start'")
sys.exit(1) sys.exit(1)
result = run_offline_command(config, config_options) else:
result = run_offline_command(config, config_options)
# print result # print result
if type(result) in [str, unicode]: if type(result) in [str, unicode]:

50
lib/daemon.py

@ -25,7 +25,7 @@ import jsonrpclib
from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer, SimpleJSONRPCRequestHandler from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer, SimpleJSONRPCRequestHandler
from network import Network from network import Network
from util import check_www_dir, json_decode, DaemonThread from util import json_decode, DaemonThread
from util import print_msg, print_error, print_stderr from util import print_msg, print_error, print_stderr
from wallet import WalletStorage, Wallet from wallet import WalletStorage, Wallet
from wizard import WizardBase from wizard import WizardBase
@ -234,51 +234,3 @@ class Daemon(DaemonThread):
daemon = Daemon(config, server) daemon = Daemon(config, server)
daemon.start() daemon.start()
return daemon return daemon
@staticmethod
def gui_command(config, config_options, plugins):
lockfile = Daemon.lockfile(config)
fd = Daemon.get_fd_or_server(lockfile)
if isinstance(fd, int):
daemon = Daemon.create_daemon(config, fd)
daemon.init_gui(config, plugins)
sys.exit(0)
server = fd
return server.gui(config_options)
@staticmethod
def cmdline_command(config, config_options):
server = Daemon.get_server(Daemon.lockfile(config))
if server is not None:
return False, server.run_cmdline(config_options)
return True, None
@staticmethod
def daemon_command(config, config_options):
lockfile = Daemon.lockfile(config)
fd = Daemon.get_fd_or_server(lockfile)
if isinstance(fd, int):
subcommand = config.get('subcommand')
assert subcommand in ['start', 'stop', 'status']
if subcommand != 'start':
print_msg("Daemon not running")
os.close(fd)
Daemon.remove_lockfile(lockfile)
sys.exit(1)
pid = os.fork()
if pid:
print_stderr("starting daemon (PID %d)" % pid)
sys.exit(0)
daemon = Daemon.create_daemon(config, fd)
if config.get('websocket_server'):
from electrum import websockets
websockets.WebSocketServer(config, daemon.network).start()
if config.get('requests_dir'):
check_www_dir(config.get('requests_dir'))
daemon.join()
sys.exit(0)
server = fd
if server is not None:
return server.daemon(config_options)

Loading…
Cancel
Save