2016-04-21 04:02:52 +02:00
|
|
|
import logging
|
|
|
|
import os
|
2016-05-01 11:17:59 +02:00
|
|
|
import sys
|
2016-04-21 04:02:52 +02:00
|
|
|
|
|
|
|
from appdirs import user_data_dir
|
2016-10-07 20:01:59 +02:00
|
|
|
from twisted.internet import defer
|
2016-09-27 20:18:35 +02:00
|
|
|
from lbrynet.lbrynet_daemon.Daemon import Daemon
|
2016-10-07 20:01:59 +02:00
|
|
|
from lbrynet.lbrynet_daemon.Resources import LBRYindex, HostedEncryptedFile, EncryptedFileUpload
|
|
|
|
from lbrynet.conf import API_ADDRESS, DEFAULT_UI_BRANCH, LOG_FILE_NAME
|
2016-04-21 04:02:52 +02:00
|
|
|
|
|
|
|
|
2016-09-27 20:18:35 +02:00
|
|
|
# TODO: omg, this code is essentially duplicated in Daemon
|
2016-05-01 11:17:59 +02:00
|
|
|
if sys.platform != "darwin":
|
|
|
|
data_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
|
|
|
else:
|
|
|
|
data_dir = user_data_dir("LBRY")
|
2016-04-21 04:02:52 +02:00
|
|
|
if not os.path.isdir(data_dir):
|
|
|
|
os.mkdir(data_dir)
|
|
|
|
|
2016-06-07 10:30:22 +02:00
|
|
|
lbrynet_log = os.path.join(data_dir, LOG_FILE_NAME)
|
2016-05-01 11:17:59 +02:00
|
|
|
log = logging.getLogger(__name__)
|
2016-07-25 20:04:30 +02:00
|
|
|
|
2016-04-21 04:02:52 +02:00
|
|
|
|
2016-09-27 20:18:35 +02:00
|
|
|
class DaemonServer(object):
|
2016-05-30 21:49:25 +02:00
|
|
|
def _setup_server(self, wallet):
|
|
|
|
self.root = LBRYindex(os.path.join(os.path.join(data_dir, "lbry-ui"), "active"))
|
2016-09-27 20:18:35 +02:00
|
|
|
self._api = Daemon(self.root, wallet_type=wallet)
|
2016-09-27 20:18:16 +02:00
|
|
|
self.root.putChild("view", HostedEncryptedFile(self._api))
|
|
|
|
self.root.putChild("upload", EncryptedFileUpload(self._api))
|
2016-04-21 04:02:52 +02:00
|
|
|
self.root.putChild(API_ADDRESS, self._api)
|
|
|
|
return defer.succeed(True)
|
|
|
|
|
2016-10-25 23:49:08 +02:00
|
|
|
def start(self, branch=DEFAULT_UI_BRANCH, user_specified=False,
|
|
|
|
branch_specified=False, wallet=None):
|
2016-06-02 02:52:15 +02:00
|
|
|
d = self._setup_server(wallet)
|
2016-05-30 21:49:25 +02:00
|
|
|
d.addCallback(lambda _: self._api.setup(branch, user_specified, branch_specified))
|
2016-04-21 04:02:52 +02:00
|
|
|
return d
|