mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
8e8c1c031a | |||
55678d7fee | |||
a57ee8b96b | |||
e367da925e | |||
77a109bb7e | |||
a3e1864a26 |
@ -22,7 +22,7 @@ class CookieJar:
|
||||
if cookie_file is None:
|
||||
self._cookies = LWPCookieJar()
|
||||
else:
|
||||
self._cookies = LWPCookieJar(cookie_file)
|
||||
self._cookies = LWPCookieJar(str(cookie_file.resolve()))
|
||||
|
||||
@property
|
||||
def cookies(self) -> LWPCookieJar:
|
||||
|
@ -67,7 +67,7 @@ class KitShibbolethAuthenticator(IliasAuthenticator):
|
||||
while not self._login_successful(soup):
|
||||
# Searching the form here so that this fails before asking for
|
||||
# credentials rather than after asking.
|
||||
form = soup.find("form", {"class": "form2", "method": "post"})
|
||||
form = soup.find("form", {"class": "full content", "method": "post"})
|
||||
action = form["action"]
|
||||
|
||||
# Equivalent: Enter credentials in
|
||||
|
@ -84,9 +84,13 @@ class IliasDownloader:
|
||||
session: requests.Session,
|
||||
authenticator: IliasAuthenticator,
|
||||
strategy: IliasDownloadStrategy,
|
||||
timeout: int = 5
|
||||
):
|
||||
"""
|
||||
Create a new IliasDownloader.
|
||||
|
||||
The timeout applies to the download request only, as bwcloud uses IPv6
|
||||
and requests has a problem with that: https://github.com/psf/requests/issues/5522
|
||||
"""
|
||||
|
||||
self._tmp_dir = tmp_dir
|
||||
@ -94,6 +98,7 @@ class IliasDownloader:
|
||||
self._session = session
|
||||
self._authenticator = authenticator
|
||||
self._strategy = strategy
|
||||
self._timeout = timeout
|
||||
|
||||
def download_all(self, infos: List[IliasDownloadInfo]) -> None:
|
||||
"""
|
||||
@ -137,7 +142,7 @@ class IliasDownloader:
|
||||
PRETTY.warning(f"Could not download {str(info.path)!r} as I got no URL :/")
|
||||
return True
|
||||
|
||||
with self._session.get(url, stream=True) as response:
|
||||
with self._session.get(url, stream=True, timeout=self._timeout) as response:
|
||||
content_type = response.headers["content-type"]
|
||||
has_content_disposition = "content-disposition" in response.headers
|
||||
|
||||
|
@ -5,6 +5,7 @@ A organizer is bound to a single directory.
|
||||
|
||||
import filecmp
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path, PurePath
|
||||
from typing import List, Optional, Set
|
||||
@ -44,6 +45,15 @@ class Organizer(Location):
|
||||
(e.g. update the timestamp), the path is also returned in this case.
|
||||
In all other cases (ignored, not overwritten, etc.) this method returns None.
|
||||
"""
|
||||
# Windows limits the path length to 260 for *some* historical reason
|
||||
# If you want longer paths, you will have to add the "\\?\" prefix in front of
|
||||
# your path...
|
||||
# See:
|
||||
# https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation
|
||||
if os.name == 'nt':
|
||||
src_absolute = Path("\\\\?\\" + str(src.resolve()))
|
||||
dst_absolute = Path("\\\\?\\" + str(self.resolve(dst)))
|
||||
else:
|
||||
src_absolute = src.resolve()
|
||||
dst_absolute = self.resolve(dst)
|
||||
|
||||
|
@ -72,7 +72,8 @@ class Pferd(Location):
|
||||
dir_filter: IliasDirectoryFilter,
|
||||
transform: Transform,
|
||||
download_strategy: IliasDownloadStrategy,
|
||||
clean: bool = True
|
||||
timeout: int,
|
||||
clean: bool = True,
|
||||
) -> Organizer:
|
||||
# pylint: disable=too-many-locals
|
||||
cookie_jar = CookieJar(to_path(cookies) if cookies else None)
|
||||
@ -81,7 +82,8 @@ class Pferd(Location):
|
||||
organizer = Organizer(self.resolve(to_path(target)))
|
||||
|
||||
crawler = IliasCrawler(base_url, session, authenticator, dir_filter)
|
||||
downloader = IliasDownloader(tmp_dir, organizer, session, authenticator, download_strategy)
|
||||
downloader = IliasDownloader(tmp_dir, organizer, session,
|
||||
authenticator, download_strategy, timeout)
|
||||
|
||||
cookie_jar.load_cookies()
|
||||
info = crawl_function(crawler)
|
||||
@ -112,6 +114,7 @@ class Pferd(Location):
|
||||
password: Optional[str] = None,
|
||||
download_strategy: IliasDownloadStrategy = download_modified_or_new,
|
||||
clean: bool = True,
|
||||
timeout: int = 5,
|
||||
) -> Organizer:
|
||||
"""
|
||||
Synchronizes a folder with the ILIAS instance of the KIT.
|
||||
@ -137,6 +140,8 @@ class Pferd(Location):
|
||||
be downloaded. Can save bandwidth and reduce the number of requests.
|
||||
(default: {download_modified_or_new})
|
||||
clean {bool} -- Whether to clean up when the method finishes.
|
||||
timeout {int} -- The download timeout for opencast videos. Sadly needed due to a
|
||||
requests bug.
|
||||
"""
|
||||
# This authenticator only works with the KIT ilias instance.
|
||||
authenticator = KitShibbolethAuthenticator(username=username, password=password)
|
||||
@ -152,6 +157,7 @@ class Pferd(Location):
|
||||
transform=transform,
|
||||
download_strategy=download_strategy,
|
||||
clean=clean,
|
||||
timeout=timeout
|
||||
)
|
||||
|
||||
self._download_summary.merge(organizer.download_summary)
|
||||
@ -175,6 +181,7 @@ class Pferd(Location):
|
||||
password: Optional[str] = None,
|
||||
download_strategy: IliasDownloadStrategy = download_modified_or_new,
|
||||
clean: bool = True,
|
||||
timeout: int = 5,
|
||||
) -> Organizer:
|
||||
"""
|
||||
Synchronizes a folder with the ILIAS instance of the KIT. This method will crawl the ILIAS
|
||||
@ -199,6 +206,8 @@ class Pferd(Location):
|
||||
be downloaded. Can save bandwidth and reduce the number of requests.
|
||||
(default: {download_modified_or_new})
|
||||
clean {bool} -- Whether to clean up when the method finishes.
|
||||
timeout {int} -- The download timeout for opencast videos. Sadly needed due to a
|
||||
requests bug.
|
||||
"""
|
||||
# This authenticator only works with the KIT ilias instance.
|
||||
authenticator = KitShibbolethAuthenticator(username=username, password=password)
|
||||
@ -214,6 +223,7 @@ class Pferd(Location):
|
||||
transform=transform,
|
||||
download_strategy=download_strategy,
|
||||
clean=clean,
|
||||
timeout=timeout
|
||||
)
|
||||
|
||||
self._download_summary.merge(organizer.download_summary)
|
||||
|
@ -19,7 +19,7 @@ Ensure that you have at least Python 3.8 installed.
|
||||
To install PFERD or update your installation to the latest version, run this
|
||||
wherever you want to install or have already installed PFERD:
|
||||
```
|
||||
$ pip install git+https://github.com/Garmelon/PFERD@v2.2.0
|
||||
$ pip install git+https://github.com/Garmelon/PFERD@v2.3.0
|
||||
```
|
||||
|
||||
The use of [venv] is recommended.
|
||||
@ -42,8 +42,8 @@ $ mkdir Vorlesungen
|
||||
$ cd Vorlesungen
|
||||
$ python3 -m venv .venv
|
||||
$ .venv/bin/activate
|
||||
$ pip install git+https://github.com/Garmelon/PFERD@v2.2.0
|
||||
$ curl -O https://raw.githubusercontent.com/Garmelon/PFERD/v2.2.0/example_config.py
|
||||
$ pip install git+https://github.com/Garmelon/PFERD@v2.3.0
|
||||
$ curl -O https://raw.githubusercontent.com/Garmelon/PFERD/v2.3.0/example_config.py
|
||||
$ python3 example_config.py
|
||||
$ deactivate
|
||||
```
|
||||
|
Reference in New Issue
Block a user