remove repeated log code
This commit is contained in:
parent
40437e4a82
commit
6f9ec2fa66
9 changed files with 41 additions and 81 deletions
|
@ -3,10 +3,12 @@ import os
|
|||
import sys
|
||||
from appdirs import user_data_dir
|
||||
|
||||
|
||||
LINUX = 1
|
||||
DARWIN = 2
|
||||
WINDOWS = 3
|
||||
|
||||
|
||||
if sys.platform.startswith("darwin"):
|
||||
platform = DARWIN
|
||||
default_download_directory = os.path.join(os.path.expanduser("~"), 'Downloads')
|
||||
|
@ -228,6 +230,23 @@ class Config(DefaultSettings):
|
|||
return "http://%s:%i" % (DEFAULT_SETTINGS.API_INTERFACE, self.api_port)
|
||||
|
||||
|
||||
def get_data_dir():
|
||||
if sys.platform != "darwin":
|
||||
data_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
||||
else:
|
||||
data_dir = user_data_dir("LBRY")
|
||||
if not os.path.isdir(data_dir):
|
||||
os.mkdir(data_dir)
|
||||
|
||||
|
||||
def get_log_filename():
|
||||
"""Return the log file for this platform.
|
||||
|
||||
Also ensure the containing directory exists
|
||||
"""
|
||||
return os.path.join(get_data_dir(), settings.LOG_FILE_NAME)
|
||||
|
||||
|
||||
# TODO: don't load the configuration automatically. The configuration
|
||||
# should be loaded at runtime, not at module import time. Module
|
||||
# import should have no side-effects. This is also bad because
|
||||
|
|
|
@ -7,7 +7,6 @@ import platform
|
|||
import sys
|
||||
import traceback
|
||||
|
||||
import appdirs
|
||||
import base58
|
||||
import requests
|
||||
from requests_futures.sessions import FuturesSession
|
||||
|
@ -208,25 +207,6 @@ def configure_logging(file_name, console, verbose=None):
|
|||
handler.addFilter(LoggerNameFilter(verbose))
|
||||
|
||||
|
||||
def get_log_file():
|
||||
"""Return the log file for this platform.
|
||||
|
||||
Also ensure the containing directory exists
|
||||
"""
|
||||
if sys.platform != "darwin":
|
||||
log_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
||||
else:
|
||||
log_dir = appdirs.user_data_dir("LBRY")
|
||||
|
||||
try:
|
||||
os.mkdir(log_dir)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
lbrynet_log = os.path.join(log_dir, settings.LOG_FILE_NAME)
|
||||
return lbrynet_log
|
||||
|
||||
|
||||
class LoggerNameFilter(object):
|
||||
"""Filter a log record based on its name.
|
||||
|
||||
|
|
|
@ -272,7 +272,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
self.ui_version = None
|
||||
self.ip = None
|
||||
self.first_run = None
|
||||
self.log_file = log_support.get_log_file()
|
||||
self.log_file = conf.get_log_file()
|
||||
self.current_db_revision = 1
|
||||
self.session = None
|
||||
self.first_run_after_update = False
|
||||
|
@ -281,7 +281,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
# TODO: this should probably be passed into the daemon, or
|
||||
# possibly have the entire log upload functionality taken out
|
||||
# of the daemon, but I don't want to deal with that now
|
||||
self.log_uploader = log_support.LogUploader.load('lbrynet', log_support.get_log_file())
|
||||
self.log_uploader = log_support.LogUploader.load('lbrynet', conf.get_log_file())
|
||||
|
||||
self.analytics_manager = None
|
||||
self.lbryid = PENDING_LBRY_ID
|
||||
|
|
|
@ -11,6 +11,7 @@ from jsonrpc.proxy import JSONRPCProxy
|
|||
|
||||
from lbrynet.lbrynet_daemon.auth.auth import PasswordChecker, HttpPasswordRealm
|
||||
from lbrynet.lbrynet_daemon.auth.util import initialize_api_key_file
|
||||
from lbrynet import conf
|
||||
from lbrynet.core import log_support
|
||||
from lbrynet.core import utils
|
||||
from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer
|
||||
|
@ -68,7 +69,7 @@ def start():
|
|||
args = parser.parse_args()
|
||||
|
||||
utils.setup_certs_for_windows()
|
||||
lbrynet_log = log_support.get_log_file()
|
||||
lbrynet_log = conf.get_log_file()
|
||||
log_support.configure_logging(lbrynet_log, args.logtoconsole, args.verbose)
|
||||
|
||||
to_pass = {}
|
||||
|
|
|
@ -1,29 +1,20 @@
|
|||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
from appdirs import user_data_dir
|
||||
from twisted.internet import defer
|
||||
|
||||
from lbrynet.lbrynet_daemon.Daemon import Daemon
|
||||
from lbrynet.lbrynet_daemon.Resources import LBRYindex, HostedEncryptedFile, EncryptedFileUpload
|
||||
from lbrynet.conf import settings
|
||||
|
||||
|
||||
# TODO: omg, this code is essentially duplicated in Daemon
|
||||
if sys.platform != "darwin":
|
||||
data_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
||||
else:
|
||||
data_dir = user_data_dir("LBRY")
|
||||
if not os.path.isdir(data_dir):
|
||||
os.mkdir(data_dir)
|
||||
|
||||
lbrynet_log = os.path.join(data_dir, settings.LOG_FILE_NAME)
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DaemonServer(object):
|
||||
def _setup_server(self):
|
||||
self.root = LBRYindex(os.path.join(os.path.join(data_dir, "lbry-ui"), "active"))
|
||||
ui_path = os.path.join(get_data_dir(), "lbry-ui", "active")
|
||||
self.root = LBRYindex(ui_path)
|
||||
self._api = Daemon(self.root)
|
||||
self.root.putChild("view", HostedEncryptedFile(self._api))
|
||||
self.root.putChild("upload", EncryptedFileUpload(self._api))
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
from copy import deepcopy
|
||||
from appdirs import user_data_dir
|
||||
from twisted.internet import defer
|
||||
from twisted.internet.task import LoopingCall
|
||||
|
||||
|
@ -20,28 +18,24 @@ DOWNLOAD_TIMEOUT_CODE = 'timeout'
|
|||
DOWNLOAD_RUNNING_CODE = 'running'
|
||||
DOWNLOAD_STOPPED_CODE = 'stopped'
|
||||
STREAM_STAGES = [
|
||||
(INITIALIZING_CODE, 'Initializing...'),
|
||||
(DOWNLOAD_METADATA_CODE, 'Downloading metadata'),
|
||||
(DOWNLOAD_RUNNING_CODE, 'Started stream'),
|
||||
(DOWNLOAD_STOPPED_CODE, 'Paused stream'),
|
||||
(DOWNLOAD_TIMEOUT_CODE, 'Stream timed out')
|
||||
]
|
||||
(INITIALIZING_CODE, 'Initializing...'),
|
||||
(DOWNLOAD_METADATA_CODE, 'Downloading metadata'),
|
||||
(DOWNLOAD_RUNNING_CODE, 'Started stream'),
|
||||
(DOWNLOAD_STOPPED_CODE, 'Paused stream'),
|
||||
(DOWNLOAD_TIMEOUT_CODE, 'Stream timed out')
|
||||
]
|
||||
|
||||
if sys.platform != "darwin":
|
||||
log_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
||||
else:
|
||||
log_dir = user_data_dir("LBRY")
|
||||
|
||||
if not os.path.isdir(log_dir):
|
||||
os.mkdir(log_dir)
|
||||
|
||||
lbrynet_log = os.path.join(log_dir, settings.LOG_FILE_NAME)
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class GetStream(object):
|
||||
def __init__(self, sd_identifier, session, wallet, lbry_file_manager, exchange_rate_manager,
|
||||
max_key_fee, data_rate=0.5, timeout=settings.download_timeout, download_directory=None, file_name=None):
|
||||
def __init__(self, sd_identifier, session, wallet,
|
||||
lbry_file_manager, exchange_rate_manager,
|
||||
max_key_fee, data_rate=0.5, timeout=None,
|
||||
download_directory=None, file_name=None):
|
||||
if timeout is None:
|
||||
timeout = settings.download_timeout
|
||||
self.wallet = wallet
|
||||
self.resolved_name = None
|
||||
self.description = None
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import logging
|
||||
import mimetypes
|
||||
import os
|
||||
import sys
|
||||
import random
|
||||
|
||||
from appdirs import user_data_dir
|
||||
from twisted.internet import threads, defer, reactor
|
||||
|
||||
from lbrynet.core.Error import InsufficientFundsError
|
||||
from lbrynet.lbryfilemanager.EncryptedFileCreator import create_lbry_file
|
||||
|
@ -13,17 +12,8 @@ from lbrynet.metadata.Metadata import Metadata
|
|||
from lbrynet.lbryfilemanager.EncryptedFileDownloader import ManagedEncryptedFileDownloader
|
||||
from lbrynet import reflector
|
||||
from lbrynet.conf import settings
|
||||
from twisted.internet import threads, defer, reactor
|
||||
|
||||
if sys.platform != "darwin":
|
||||
log_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
||||
else:
|
||||
log_dir = user_data_dir("LBRY")
|
||||
|
||||
if not os.path.isdir(log_dir):
|
||||
os.mkdir(log_dir)
|
||||
|
||||
lbrynet_log = os.path.join(log_dir, settings.LOG_FILE_NAME)
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
|
|
@ -15,15 +15,7 @@ from lbryum.version import LBRYUM_VERSION as lbryum_version
|
|||
from zipfile import ZipFile
|
||||
from appdirs import user_data_dir
|
||||
|
||||
if sys.platform != "darwin":
|
||||
log_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
||||
else:
|
||||
log_dir = user_data_dir("LBRY")
|
||||
|
||||
if not os.path.isdir(log_dir):
|
||||
os.mkdir(log_dir)
|
||||
|
||||
lbrynet_log = os.path.join(log_dir, settings.LOG_FILE_NAME)
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
|
|
@ -25,17 +25,8 @@ from lbrynet.conf import settings
|
|||
from packaging.uri_handler.LBRYURIHandler import LBRYURIHandler
|
||||
|
||||
|
||||
# TODO: omg, this code is essentially duplicated in LBRYDaemon
|
||||
data_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
||||
if not os.path.isdir(data_dir):
|
||||
os.mkdir(data_dir)
|
||||
|
||||
lbrynet_log = os.path.join(data_dir, settings.LOG_FILE_NAME)
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
if getattr(sys, 'frozen', False) and os.name == "nt":
|
||||
os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(os.path.dirname(sys.executable), "cacert.pem")
|
||||
|
||||
|
||||
def test_internet_connection():
|
||||
return utils.check_connection()
|
||||
|
@ -290,7 +281,9 @@ def main(lbry_name=None):
|
|||
sys.exit(1)
|
||||
reactor.run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
utils.setup_certs_for_windows()
|
||||
lbry_daemon = JSONRPCProxy.from_url(settings.API_CONNECTION_STRING)
|
||||
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue