Browse Source

Move get_from_url to sabnzbd.misc

pull/1067/head
Safihre 8 years ago
parent
commit
a6f6d88ab9
  1. 4
      SABnzbd.py
  2. 9
      sabnzbd/misc.py
  3. 11
      sabnzbd/newsunpack.py
  4. 4
      sabnzbd/utils/upload.py

4
SABnzbd.py

@ -87,7 +87,7 @@ import sabnzbd.interface
from sabnzbd.constants import *
import sabnzbd.newsunpack
from sabnzbd.misc import real_path, \
check_latest_version, exit_sab, \
check_latest_version, exit_sab, get_from_url, \
split_host, get_ext, create_https_certificates, \
windows_variant, ip_extract, set_serv_parms, get_serv_parms, globber_full
from sabnzbd.panic import panic_tmpl, panic_port, panic_host, \
@ -657,7 +657,7 @@ def is_sabnzbd_running(url):
url = '%s&mode=version' % (url)
# Do this without certificate verification, few installations will have that
prev = sabnzbd.set_https_verification(False)
ver = sabnzbd.newsunpack.get_from_url(url)
ver = get_from_url(url)
sabnzbd.set_https_verification(prev)
return (ver and (re.search(r'\d+\.\d+\.', ver) or ver.strip() == sabnzbd.__version__))
except:

9
sabnzbd/misc.py

@ -33,6 +33,7 @@ import datetime
import fnmatch
import stat
import inspect
import urllib2
from urlparse import urlparse
import sabnzbd
@ -840,6 +841,14 @@ def split_host(srv):
return (host, port)
def get_from_url(url):
""" Retrieve URL and return content """
try:
return urllib2.urlopen(url).read()
except:
return None
def check_mount(path):
""" Return False if volume isn't mounted on Linux or OSX
Retry 6 times with an interval of 1 sec.

11
sabnzbd/newsunpack.py

@ -2309,17 +2309,6 @@ def list2cmdline(lst):
return ' '.join(nlst)
def get_from_url(url):
""" Retrieve URL and return content
`timeout` sets non-standard timeout
"""
import urllib2
try:
return urllib2.urlopen(url).read()
except:
return None
def is_sevenfile(path):
""" Return True if path has proper extension and 7Zip is installed """
return SEVEN_COMMAND and os.path.splitext(path)[1].lower() == '.7z'

4
sabnzbd/utils/upload.py

@ -24,7 +24,7 @@ import logging
import os
from sabnzbd.encoding import unicoder
import sabnzbd.cfg as cfg
from sabnzbd.misc import get_ext, get_filename
from sabnzbd.misc import get_ext, get_filename, get_from_url
import sabnzbd.newsunpack
from sabnzbd.constants import VALID_ARCHIVES
@ -47,7 +47,7 @@ def upload_file(url, fp):
password = cfg.password()
if username and password:
url = '%s&ma_username=%s&ma_password=%s' % (url, username, password)
sabnzbd.newsunpack.get_from_url(url)
get_from_url(url)
except:
logging.error("Failed to upload file: %s", fp)
logging.info("Traceback: ", exc_info=True)

Loading…
Cancel
Save