create missing directories for 'part-directory'
also some code improvements regarding downloader config values
This commit is contained in:
@@ -112,7 +112,11 @@ downloader.part-directory
|
||||
=========== =====
|
||||
Type ``string``
|
||||
Default ``null``
|
||||
Description Path to an existing directory to store ``.part`` files in.
|
||||
Description Alternate location for ``.part`` files.
|
||||
|
||||
Missing directories will be created as needed.
|
||||
If this value is ``null``, ``.part`` files are going to be stored
|
||||
alongside the actual output files.
|
||||
=========== =====
|
||||
|
||||
|
||||
|
||||
@@ -11,19 +11,29 @@
|
||||
import os
|
||||
import time
|
||||
import logging
|
||||
from .. import config, util
|
||||
|
||||
|
||||
class DownloaderBase():
|
||||
"""Base class for downloaders"""
|
||||
scheme = ""
|
||||
retries = 1
|
||||
part = True
|
||||
partdir = None
|
||||
|
||||
def __init__(self, session, output):
|
||||
self.session = session
|
||||
self.out = output
|
||||
self.log = logging.getLogger("download")
|
||||
self.downloading = False
|
||||
self.part = self.config("part", True)
|
||||
self.partdir = self.config("part-directory")
|
||||
|
||||
if self.partdir:
|
||||
self.partdir = util.expand_path(self.partdir)
|
||||
os.makedirs(self.partdir, exist_ok=True)
|
||||
|
||||
def config(self, key, default=None):
|
||||
"""Interpolate config value for 'key'"""
|
||||
return config.interpolate(("downloader", self.scheme, key), default)
|
||||
|
||||
def download(self, url, pathfmt):
|
||||
"""Download the resource at 'url' and write it to a file-like object"""
|
||||
|
||||
@@ -10,23 +10,18 @@
|
||||
|
||||
import mimetypes
|
||||
from .common import DownloaderBase
|
||||
from .. import config, util
|
||||
|
||||
|
||||
def _conf(key, default=None):
|
||||
return config.interpolate(("downloader", "http", key), default)
|
||||
from .. import util
|
||||
|
||||
|
||||
class Downloader(DownloaderBase):
|
||||
retries = _conf("retries", 5)
|
||||
timeout = _conf("timeout", 30)
|
||||
verify = _conf("verify", True)
|
||||
part = _conf("part", True)
|
||||
partdir = util.expand_path(_conf("part-directory"))
|
||||
scheme = "http"
|
||||
|
||||
def __init__(self, session, output):
|
||||
DownloaderBase.__init__(self, session, output)
|
||||
self.response = None
|
||||
self.retries = self.config("retries", 5)
|
||||
self.timeout = self.config("timeout", 30)
|
||||
self.verify = self.config("verify", True)
|
||||
|
||||
def connect(self, url, offset):
|
||||
headers = {}
|
||||
|
||||
@@ -9,16 +9,10 @@
|
||||
"""Downloader module for text: URLs"""
|
||||
|
||||
from .common import DownloaderBase
|
||||
from .. import config, util
|
||||
|
||||
|
||||
def _conf(key, default=None):
|
||||
return config.interpolate(("downloader", "text", key), default)
|
||||
|
||||
|
||||
class Downloader(DownloaderBase):
|
||||
part = _conf("part", True)
|
||||
partdir = util.expand_path(_conf("part-directory"))
|
||||
scheme = "text"
|
||||
|
||||
def __init__(self, session, output):
|
||||
DownloaderBase.__init__(self, session, output)
|
||||
|
||||
Reference in New Issue
Block a user