reduce deps

This commit is contained in:
Hellowlol 2020-04-27 22:12:18 +03:00
parent 437eea8dfc
commit 8ac2edb3f6
6 changed files with 16 additions and 14 deletions

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import json import json
import threading import threading
import websocket
from plexapi import log from plexapi import log
@ -40,6 +40,11 @@ class AlertListener(threading.Thread):
self._ws = None self._ws = None
def run(self): def run(self):
try:
import websocket
except ImportError:
log.warning("Can't use the AlertListener without websocket")
return
# create the websocket connection # create the websocket connection
url = self._server.url(self.key, includeToken=True).replace('http', 'ws') url = self._server.url(self.key, includeToken=True).replace('http', 'ws')
log.info('Starting AlertListener: %s', url) log.info('Starting AlertListener: %s', url)

View file

@ -44,11 +44,6 @@ try:
except ImportError: except ImportError:
from xml.etree import ElementTree from xml.etree import ElementTree
try:
from unittest.mock import patch, MagicMock
except ImportError:
from mock import patch, MagicMock
def makedirs(name, mode=0o777, exist_ok=False): def makedirs(name, mode=0o777, exist_ok=False):
""" Mimicks os.makedirs() from Python 3. """ """ Mimicks os.makedirs() from Python 3. """

View file

@ -11,7 +11,11 @@ from threading import Event, Thread
import requests import requests
from plexapi import compat from plexapi import compat
from plexapi.exceptions import NotFound from plexapi.exceptions import NotFound
from tqdm import tqdm
try:
from tqdm import tqdm
except ImportError:
tqdm = None
log = logging.getLogger('plexapi') log = logging.getLogger('plexapi')
@ -294,17 +298,17 @@ def download(url, token, filename=None, savepath=None, session=None, chunksize=4
# save the file to disk # save the file to disk
log.info('Downloading: %s', fullpath) log.info('Downloading: %s', fullpath)
if showstatus: # pragma: no cover if showstatus and tqdm: # pragma: no cover
total = int(response.headers.get('content-length', 0)) total = int(response.headers.get('content-length', 0))
bar = tqdm(unit='B', unit_scale=True, total=total, desc=filename) bar = tqdm(unit='B', unit_scale=True, total=total, desc=filename)
with open(fullpath, 'wb') as handle: with open(fullpath, 'wb') as handle:
for chunk in response.iter_content(chunk_size=chunksize): for chunk in response.iter_content(chunk_size=chunksize):
handle.write(chunk) handle.write(chunk)
if showstatus: if showstatus and tqdm:
bar.update(len(chunk)) bar.update(len(chunk))
if showstatus: # pragma: no cover if showstatus and tqdm: # pragma: no cover
bar.close() bar.close()
# check we want to unzip the contents # check we want to unzip the contents
if fullpath.endswith('zip') and unpack: if fullpath.endswith('zip') and unpack:

View file

@ -3,6 +3,3 @@
# pip install -r requirements.txt # pip install -r requirements.txt
#--------------------------------------------------------- #---------------------------------------------------------
requests requests
tqdm
websocket-client
mock; python_version < '3.3'

View file

@ -15,6 +15,8 @@ sphinx
sphinxcontrib-napoleon sphinxcontrib-napoleon
tqdm tqdm
websocket-client websocket-client
mock; python_version < '3.3'
# Installing sphinx-rtd-theme directly from github above is used until a point release # Installing sphinx-rtd-theme directly from github above is used until a point release
# above 0.4.3 is released. https://github.com/readthedocs/sphinx_rtd_theme/issues/739 # above 0.4.3 is released. https://github.com/readthedocs/sphinx_rtd_theme/issues/739

View file

@ -9,7 +9,6 @@ import pytest
import requests import requests
from plexapi import compat from plexapi import compat
from plexapi.client import PlexClient from plexapi.client import PlexClient
from plexapi.compat import MagicMock, patch
from plexapi.myplex import MyPlexAccount from plexapi.myplex import MyPlexAccount
from plexapi.server import PlexServer from plexapi.server import PlexServer