mirror of
https://github.com/Garmelon/PFERD.git
synced 2025-07-12 14:12:30 +02:00
Compare commits
124 Commits
Author | SHA1 | Date | |
---|---|---|---|
eb01aa86cb | |||
3db186a978 | |||
4a5959fd58 | |||
1cbc2b717a | |||
da627ff929 | |||
c1b592ac29 | |||
eb0c956d32 | |||
ab0cb2d956 | |||
a117126389 | |||
e9f8901520 | |||
266812f90e | |||
533bc27439 | |||
0113a0ca10 | |||
40f8a05ad6 | |||
50b50513c6 | |||
df3514cd03 | |||
ad53185247 | |||
87b67e9271 | |||
b54b3b979c | |||
2184ac8040 | |||
b3d412360b | |||
dbc2553b11 | |||
68c398f1fe | |||
123a57beec | |||
d204dac8ce | |||
443f7fe839 | |||
0294ceb7d5 | |||
6f30c6583d | |||
467fc526e8 | |||
722d2eb393 | |||
6d44aac278 | |||
55a2de6b88 | |||
c0d6d8b229 | |||
635caa765d | |||
e69b55b349 | |||
07200bbde5 | |||
c020cccc64 | |||
259cfc20cc | |||
37b51a66d8 | |||
f47d2f11d8 | |||
1b6be6bd79 | |||
e1430e6298 | |||
5fdd40204b | |||
fb4631ba18 | |||
d72fc2760b | |||
4a51aaa4f5 | |||
66a5b1ba02 | |||
aa5a3a10bc | |||
d9b111cec2 | |||
345f52a1f6 | |||
ed24366aba | |||
46fb782798 | |||
846c29aee1 | |||
a5015fe9b1 | |||
616b0480f7 | |||
2f0e04ce13 | |||
bcc537468c | |||
694ffb4d77 | |||
af2cc1169a | |||
bc3fa36637 | |||
afbd03f777 | |||
b8fe25c580 | |||
a241672726 | |||
a8f76e9be7 | |||
b56475450d | |||
aa74604d29 | |||
d2e6d91880 | |||
602044ff1b | |||
31631fb409 | |||
00db348218 | |||
a709280cbf | |||
a99ddaa0cc | |||
ba3d299c05 | |||
07a21f80a6 | |||
f17b9b68f4 | |||
a2831fbea2 | |||
da72863b47 | |||
86e2e226dc | |||
7872fe5221 | |||
86947e4874 | |||
4f022e2d19 | |||
f47e7374d2 | |||
57ec51e95a | |||
0045124a4e | |||
9618aae83b | |||
33453ede2d | |||
e467b38d73 | |||
e9d2d05030 | |||
4bf0c972e6 | |||
4ee919625d | |||
d30f25ee97 | |||
10d9d74528 | |||
43c5453e10 | |||
eb4de8ae0c | |||
e32c1f000f | |||
5f527bc697 | |||
ced8b9a2d0 | |||
6f3cfd4396 | |||
462d993fbc | |||
a99356f2a2 | |||
eac2e34161 | |||
a82a0b19c2 | |||
90cb6e989b | |||
6289938d7c | |||
13b8c3d9c6 | |||
88afe64a92 | |||
6b2a657573 | |||
d6f38a61e1 | |||
ad3f4955f7 | |||
e42ab83d32 | |||
f9a3f9b9f2 | |||
ef7d5ea2d3 | |||
55ea304ff3 | |||
fee12b3d9e | |||
6673077397 | |||
742632ed8d | |||
544d45cbc5 | |||
86f79ff1f1 | |||
ee67f9f472 | |||
8ec3f41251 | |||
89be07d4d3 | |||
91200f3684 | |||
9ffd603357 | |||
80eeb8fe97 |
10
.github/workflows/build-and-release.yml
vendored
10
.github/workflows/build-and-release.yml
vendored
@ -14,12 +14,12 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
python: ["3.8"]
|
python: ["3.9"]
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python }}
|
python-version: ${{ matrix.python }}
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ jobs:
|
|||||||
run: mv dist/pferd* dist/pferd-${{ matrix.os }}
|
run: mv dist/pferd* dist/pferd-${{ matrix.os }}
|
||||||
|
|
||||||
- name: Upload binary
|
- name: Upload binary
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: Binaries
|
name: Binaries
|
||||||
path: dist/pferd-${{ matrix.os }}
|
path: dist/pferd-${{ matrix.os }}
|
||||||
@ -57,7 +57,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
|
|
||||||
- name: Download binaries
|
- name: Download binaries
|
||||||
uses: actions/download-artifact@v2
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: Binaries
|
name: Binaries
|
||||||
|
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,6 +3,7 @@
|
|||||||
/PFERD.egg-info/
|
/PFERD.egg-info/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
/.vscode/
|
/.vscode/
|
||||||
|
/.idea/
|
||||||
|
|
||||||
# pyinstaller
|
# pyinstaller
|
||||||
/pferd.spec
|
/pferd.spec
|
||||||
|
135
CHANGELOG.md
135
CHANGELOG.md
@ -22,6 +22,141 @@ ambiguous situations.
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
## 3.5.2 - 2024-04-14
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Crawling of personal desktop with ILIAS 8
|
||||||
|
- Crawling of empty personal desktops
|
||||||
|
|
||||||
|
## 3.5.1 - 2024-04-09
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Support for ILIAS 8
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Video name deduplication
|
||||||
|
|
||||||
|
## 3.5.0 - 2023-09-13
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- `no-delete-prompt-override` conflict resolution strategy
|
||||||
|
- Support for ILIAS learning modules
|
||||||
|
- `show_not_deleted` option to stop printing the "Not Deleted" status or report
|
||||||
|
message. This combines nicely with the `no-delete-prompt-override` strategy,
|
||||||
|
causing PFERD to mostly ignore local-only files.
|
||||||
|
- Support for mediacast video listings
|
||||||
|
- Crawling of files in info tab
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Remove size suffix for files in content pages
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Crawling of courses with the timeline view as the default tab
|
||||||
|
- Crawling of file and custom opencast cards
|
||||||
|
- Crawling of button cards without descriptions
|
||||||
|
- Abort crawling when encountering an unexpected ilias root page redirect
|
||||||
|
- Sanitize ascii control characters on Windows
|
||||||
|
- Crawling of paginated past meetings
|
||||||
|
- Ignore SCORM learning modules
|
||||||
|
|
||||||
|
## 3.4.3 - 2022-11-29
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Missing documentation for `forums` option
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Clear up error message shown when multiple paths are found to an element
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- IPD crawler unnecessarily appending trailing slashes
|
||||||
|
- Crawling opencast when ILIAS is set to English
|
||||||
|
|
||||||
|
## 3.4.2 - 2022-10-26
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Recognize and crawl content pages in cards
|
||||||
|
- Recognize and ignore surveys
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Forum crawling crashing when a thread has no messages at all
|
||||||
|
- Forum crawling crashing when a forum has no threads at all
|
||||||
|
- Ilias login failing in some cases
|
||||||
|
- Crawling of paginated future meetings
|
||||||
|
- IPD crawler handling of URLs without trailing slash
|
||||||
|
|
||||||
|
## 3.4.1 - 2022-08-17
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Download of page descriptions
|
||||||
|
- Forum download support
|
||||||
|
- `pass` authenticator
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Add `cpp` extension to default `link_regex` of IPD crawler
|
||||||
|
- Mention hrefs in IPD crawler's `--explain` output for users of `link_regex` option
|
||||||
|
- Simplify default IPD crawler `link_regex`
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- IPD crawler crashes on some sites
|
||||||
|
- Meeting name normalization for yesterday, today and tomorrow
|
||||||
|
- Crawling of meeting file previews
|
||||||
|
- Login with new login button html layout
|
||||||
|
- Descriptions for courses are now placed in the correct subfolder when
|
||||||
|
downloading the whole desktop
|
||||||
|
|
||||||
|
## 3.4.0 - 2022-05-01
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Message when Shibboleth entitlements need to be manually reviewed
|
||||||
|
- Links to unofficial packages and repology in the readme
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Increase minimum supported Python version to 3.9
|
||||||
|
- Support video listings with more columns
|
||||||
|
- Use UTF-8 when reading/writing the config file
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Crash during authentication when the Shibboleth session is still valid
|
||||||
|
|
||||||
|
## 3.3.1 - 2022-01-15
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- ILIAS login
|
||||||
|
- Local video cache if `windows_paths` is enabled
|
||||||
|
|
||||||
|
## 3.3.0 - 2022-01-09
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- A KIT IPD crawler
|
||||||
|
- Support for ILIAS cards
|
||||||
|
- (Rudimentary) support for content pages
|
||||||
|
- Support for multi-stream videos
|
||||||
|
- Support for ILIAS 7
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
- [Interpolation](https://docs.python.org/3/library/configparser.html#interpolation-of-values) in config file
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Crawling of recursive courses
|
||||||
|
- Crawling files directly placed on the personal desktop
|
||||||
|
- Ignore timestamps at the unix epoch as they crash on windows
|
||||||
|
|
||||||
|
## 3.2.0 - 2021-08-04
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- `--skip` command line option
|
||||||
|
- Support for ILIAS booking objects
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Using multiple path segments on left side of `-name->` now results in an
|
||||||
|
error. This was already forbidden by the documentation but silently accepted
|
||||||
|
by PFERD.
|
||||||
|
- More consistent path printing in some `--explain` messages
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Nondeterministic name deduplication due to ILIAS reordering elements
|
||||||
|
- More exceptions are handled properly
|
||||||
|
|
||||||
## 3.1.0 - 2021-06-13
|
## 3.1.0 - 2021-06-13
|
||||||
|
|
||||||
If your config file doesn't do weird things with transforms, it should continue
|
If your config file doesn't do weird things with transforms, it should continue
|
||||||
|
60
CONFIG.md
60
CONFIG.md
@ -4,11 +4,11 @@ A config file consists of sections. A section begins with a `[section]` header,
|
|||||||
which is followed by a list of `key = value` pairs. Comments must be on their
|
which is followed by a list of `key = value` pairs. Comments must be on their
|
||||||
own line and start with `#`. Multiline values must be indented beyond their key.
|
own line and start with `#`. Multiline values must be indented beyond their key.
|
||||||
Boolean values can be `yes` or `no`. For more details and some examples on the
|
Boolean values can be `yes` or `no`. For more details and some examples on the
|
||||||
format, see the [configparser documentation][1] ([basic interpolation][2] is
|
format, see the [configparser documentation][1] ([interpolation][2] is
|
||||||
enabled).
|
disabled).
|
||||||
|
|
||||||
[1]: <https://docs.python.org/3/library/configparser.html#supported-ini-file-structure> "Supported INI File Structure"
|
[1]: <https://docs.python.org/3/library/configparser.html#supported-ini-file-structure> "Supported INI File Structure"
|
||||||
[2]: <https://docs.python.org/3/library/configparser.html#configparser.BasicInterpolation> "BasicInterpolation"
|
[2]: <https://docs.python.org/3/library/configparser.html#interpolation-of-values> "Interpolation of values"
|
||||||
|
|
||||||
## The `DEFAULT` section
|
## The `DEFAULT` section
|
||||||
|
|
||||||
@ -26,6 +26,9 @@ default values for the other sections.
|
|||||||
`Added ...`) while running a crawler. (Default: `yes`)
|
`Added ...`) while running a crawler. (Default: `yes`)
|
||||||
- `report`: Whether PFERD should print a report of added, changed and deleted
|
- `report`: Whether PFERD should print a report of added, changed and deleted
|
||||||
local files for all crawlers before exiting. (Default: `yes`)
|
local files for all crawlers before exiting. (Default: `yes`)
|
||||||
|
- `show_not_deleted`: Whether PFERD should print messages in status and report
|
||||||
|
when a local-only file wasn't deleted. Combines nicely with the
|
||||||
|
`no-delete-prompt-override` conflict resolution strategy.
|
||||||
- `share_cookies`: Whether crawlers should share cookies where applicable. For
|
- `share_cookies`: Whether crawlers should share cookies where applicable. For
|
||||||
example, some crawlers share cookies if they crawl the same website using the
|
example, some crawlers share cookies if they crawl the same website using the
|
||||||
same account. (Default: `yes`)
|
same account. (Default: `yes`)
|
||||||
@ -36,7 +39,7 @@ Sections whose names start with `crawl:` are used to configure crawlers. The
|
|||||||
rest of the section name specifies the name of the crawler.
|
rest of the section name specifies the name of the crawler.
|
||||||
|
|
||||||
A crawler synchronizes a remote resource to a local directory. There are
|
A crawler synchronizes a remote resource to a local directory. There are
|
||||||
different types of crawlers for different kinds of resources, e. g. ILIAS
|
different types of crawlers for different kinds of resources, e.g. ILIAS
|
||||||
courses or lecture websites.
|
courses or lecture websites.
|
||||||
|
|
||||||
Each crawl section represents an instance of a specific type of crawler. The
|
Each crawl section represents an instance of a specific type of crawler. The
|
||||||
@ -53,7 +56,7 @@ common to all crawlers:
|
|||||||
crawler can still be executed manually using the `--crawler` or `-C` flags.
|
crawler can still be executed manually using the `--crawler` or `-C` flags.
|
||||||
(Default: `no`)
|
(Default: `no`)
|
||||||
- `output_dir`: The directory the crawler synchronizes files to. A crawler will
|
- `output_dir`: The directory the crawler synchronizes files to. A crawler will
|
||||||
never place any files outside of this directory. (Default: the crawler's name)
|
never place any files outside this directory. (Default: the crawler's name)
|
||||||
- `redownload`: When to download a file that is already present locally.
|
- `redownload`: When to download a file that is already present locally.
|
||||||
(Default: `never-smart`)
|
(Default: `never-smart`)
|
||||||
- `never`: If a file is present locally, it is not downloaded again.
|
- `never`: If a file is present locally, it is not downloaded again.
|
||||||
@ -75,6 +78,9 @@ common to all crawlers:
|
|||||||
using `prompt` and always choosing "yes".
|
using `prompt` and always choosing "yes".
|
||||||
- `no-delete`: Never delete local files, but overwrite local files if the
|
- `no-delete`: Never delete local files, but overwrite local files if the
|
||||||
remote file is different.
|
remote file is different.
|
||||||
|
- `no-delete-prompt-overwrite`: Never delete local files, but prompt to
|
||||||
|
overwrite local files if the remote file is different. Combines nicely
|
||||||
|
with the `show_not_deleted` option.
|
||||||
- `transform`: Rules for renaming and excluding certain files and directories.
|
- `transform`: Rules for renaming and excluding certain files and directories.
|
||||||
For more details, see [this section](#transformation-rules). (Default: empty)
|
For more details, see [this section](#transformation-rules). (Default: empty)
|
||||||
- `tasks`: The maximum number of concurrent tasks (such as crawling or
|
- `tasks`: The maximum number of concurrent tasks (such as crawling or
|
||||||
@ -136,6 +142,18 @@ crawler simulate a slower, network-based crawler.
|
|||||||
requests. (Default: `0.0`)
|
requests. (Default: `0.0`)
|
||||||
- `download_speed`: Download speed (in bytes per second) to simulate. (Optional)
|
- `download_speed`: Download speed (in bytes per second) to simulate. (Optional)
|
||||||
|
|
||||||
|
### The `kit-ipd` crawler
|
||||||
|
|
||||||
|
This crawler crawls a KIT-IPD page by url. The root page can be crawled from
|
||||||
|
outside the KIT network so you will be informed about any new/deleted files,
|
||||||
|
but downloading files requires you to be within. Adding a show delay between
|
||||||
|
requests is likely a good idea.
|
||||||
|
|
||||||
|
- `target`: URL to a KIT-IPD page
|
||||||
|
- `link_regex`: A regex that is matched against the `href` part of links. If it
|
||||||
|
matches, the given link is downloaded as a file. This is used to extract
|
||||||
|
files from KIT-IPD pages. (Default: `^.*?[^/]+\.(pdf|zip|c|cpp|java)$`)
|
||||||
|
|
||||||
### The `kit-ilias-web` crawler
|
### The `kit-ilias-web` crawler
|
||||||
|
|
||||||
This crawler crawls the KIT ILIAS instance.
|
This crawler crawls the KIT ILIAS instance.
|
||||||
@ -169,6 +187,7 @@ script once per day should be fine.
|
|||||||
redirect to the actual URL. Set to a negative value to disable the automatic
|
redirect to the actual URL. Set to a negative value to disable the automatic
|
||||||
redirect. (Default: `-1`)
|
redirect. (Default: `-1`)
|
||||||
- `videos`: Whether to download videos. (Default: `no`)
|
- `videos`: Whether to download videos. (Default: `no`)
|
||||||
|
- `forums`: Whether to download forum threads. (Default: `no`)
|
||||||
- `http_timeout`: The timeout (in seconds) for all HTTP requests. (Default:
|
- `http_timeout`: The timeout (in seconds) for all HTTP requests. (Default:
|
||||||
`20.0`)
|
`20.0`)
|
||||||
|
|
||||||
@ -211,6 +230,23 @@ is stored in the keyring.
|
|||||||
- `keyring_name`: The service name PFERD uses for storing credentials. (Default:
|
- `keyring_name`: The service name PFERD uses for storing credentials. (Default:
|
||||||
`PFERD`)
|
`PFERD`)
|
||||||
|
|
||||||
|
### The `pass` authenticator
|
||||||
|
|
||||||
|
This authenticator queries the [`pass` password manager][3] for a username and
|
||||||
|
password. It tries to be mostly compatible with [browserpass][4] and
|
||||||
|
[passff][5], so see those links for an overview of the format. If PFERD fails
|
||||||
|
to load your password, you can use the `--explain` flag to see why.
|
||||||
|
|
||||||
|
- `passname`: The name of the password to use (Required)
|
||||||
|
- `username_prefixes`: A comma-separated list of username line prefixes
|
||||||
|
(Default: `login,username,user`)
|
||||||
|
- `password_prefixes`: A comma-separated list of password line prefixes
|
||||||
|
(Default: `password,pass,secret`)
|
||||||
|
|
||||||
|
[3]: <https://www.passwordstore.org/> "Pass: The Standard Unix Password Manager"
|
||||||
|
[4]: <https://github.com/browserpass/browserpass-extension#organizing-password-store> "Organizing password store"
|
||||||
|
[5]: <https://github.com/passff/passff#multi-line-format> "Multi-line format"
|
||||||
|
|
||||||
### The `tfa` authenticator
|
### The `tfa` authenticator
|
||||||
|
|
||||||
This authenticator prompts the user on the console for a two-factor
|
This authenticator prompts the user on the console for a two-factor
|
||||||
@ -260,7 +296,7 @@ path matches `SOURCE`, it is renamed to `TARGET`.
|
|||||||
Example: `foo/bar --> baz`
|
Example: `foo/bar --> baz`
|
||||||
- Doesn't match `foo`, `a/foo/bar` or `foo/baz`
|
- Doesn't match `foo`, `a/foo/bar` or `foo/baz`
|
||||||
- Converts `foo/bar` into `baz`
|
- Converts `foo/bar` into `baz`
|
||||||
- Converts `foo/bar/wargl` into `bar/wargl`
|
- Converts `foo/bar/wargl` into `baz/wargl`
|
||||||
|
|
||||||
Example: `foo/bar --> !`
|
Example: `foo/bar --> !`
|
||||||
- Doesn't match `foo`, `a/foo/bar` or `foo/baz`
|
- Doesn't match `foo`, `a/foo/bar` or `foo/baz`
|
||||||
@ -304,12 +340,12 @@ is a regular expression and `TARGET` an f-string based template. If a path
|
|||||||
matches `SOURCE`, the output path is created using `TARGET` as template.
|
matches `SOURCE`, the output path is created using `TARGET` as template.
|
||||||
`SOURCE` is automatically anchored.
|
`SOURCE` is automatically anchored.
|
||||||
|
|
||||||
`TARGET` uses Python's [format string syntax][3]. The *n*-th capturing group can
|
`TARGET` uses Python's [format string syntax][6]. The *n*-th capturing group can
|
||||||
be referred to as `{g<n>}` (e. g. `{g3}`). `{g0}` refers to the original path.
|
be referred to as `{g<n>}` (e.g. `{g3}`). `{g0}` refers to the original path.
|
||||||
If capturing group *n*'s contents are a valid integer, the integer value is
|
If capturing group *n*'s contents are a valid integer, the integer value is
|
||||||
available as `{i<n>}` (e. g. `{i3}`). If capturing group *n*'s contents are a
|
available as `{i<n>}` (e.g. `{i3}`). If capturing group *n*'s contents are a
|
||||||
valid float, the float value is available as `{f<n>}` (e. g. `{f3}`). If a
|
valid float, the float value is available as `{f<n>}` (e.g. `{f3}`). If a
|
||||||
capturing group is not present (e. g. when matching the string `cd` with the
|
capturing group is not present (e.g. when matching the string `cd` with the
|
||||||
regex `(ab)?cd`), the corresponding variables are not defined.
|
regex `(ab)?cd`), the corresponding variables are not defined.
|
||||||
|
|
||||||
Python's format string syntax has rich options for formatting its arguments. For
|
Python's format string syntax has rich options for formatting its arguments. For
|
||||||
@ -325,7 +361,7 @@ Example: `f(oo+)/be?ar -re-> B{g1.upper()}H/fear`
|
|||||||
- Converts `fooooo/bear` into `BOOOOOH/fear`
|
- Converts `fooooo/bear` into `BOOOOOH/fear`
|
||||||
- Converts `foo/bar/baz` into `BOOH/fear/baz`
|
- Converts `foo/bar/baz` into `BOOH/fear/baz`
|
||||||
|
|
||||||
[3]: <https://docs.python.org/3/library/string.html#format-string-syntax> "Format String Syntax"
|
[6]: <https://docs.python.org/3/library/string.html#format-string-syntax> "Format String Syntax"
|
||||||
|
|
||||||
### The `-name-re->` arrow
|
### The `-name-re->` arrow
|
||||||
|
|
||||||
|
4
LICENSE
4
LICENSE
@ -1,4 +1,6 @@
|
|||||||
Copyright 2019-2020 Garmelon, I-Al-Istannen, danstooamerican, pavelzw, TheChristophe, Scriptim
|
Copyright 2019-2021 Garmelon, I-Al-Istannen, danstooamerican, pavelzw,
|
||||||
|
TheChristophe, Scriptim, thelukasprobst, Toorero,
|
||||||
|
Mr-Pine
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
@ -15,7 +15,7 @@ from .transformer import RuleParseError
|
|||||||
|
|
||||||
def load_config_parser(args: argparse.Namespace) -> configparser.ConfigParser:
|
def load_config_parser(args: argparse.Namespace) -> configparser.ConfigParser:
|
||||||
log.explain_topic("Loading config")
|
log.explain_topic("Loading config")
|
||||||
parser = configparser.ConfigParser()
|
parser = configparser.ConfigParser(interpolation=None)
|
||||||
|
|
||||||
if args.command is None:
|
if args.command is None:
|
||||||
log.explain("No CLI command specified, loading config from file")
|
log.explain("No CLI command specified, loading config from file")
|
||||||
@ -47,6 +47,8 @@ def configure_logging_from_args(args: argparse.Namespace) -> None:
|
|||||||
log.output_explain = args.explain
|
log.output_explain = args.explain
|
||||||
if args.status is not None:
|
if args.status is not None:
|
||||||
log.output_status = args.status
|
log.output_status = args.status
|
||||||
|
if args.show_not_deleted is not None:
|
||||||
|
log.output_not_deleted = args.show_not_deleted
|
||||||
if args.report is not None:
|
if args.report is not None:
|
||||||
log.output_report = args.report
|
log.output_report = args.report
|
||||||
|
|
||||||
@ -72,6 +74,8 @@ def configure_logging_from_config(args: argparse.Namespace, config: Config) -> N
|
|||||||
log.output_status = config.default_section.status()
|
log.output_status = config.default_section.status()
|
||||||
if args.report is None:
|
if args.report is None:
|
||||||
log.output_report = config.default_section.report()
|
log.output_report = config.default_section.report()
|
||||||
|
if args.show_not_deleted is None:
|
||||||
|
log.output_not_deleted = config.default_section.show_not_deleted()
|
||||||
except ConfigOptionError as e:
|
except ConfigOptionError as e:
|
||||||
log.error(str(e))
|
log.error(str(e))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@ -116,7 +120,7 @@ def main() -> None:
|
|||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pferd = Pferd(config, args.crawler)
|
pferd = Pferd(config, args.crawler, args.skip)
|
||||||
except PferdLoadError as e:
|
except PferdLoadError as e:
|
||||||
log.unlock()
|
log.unlock()
|
||||||
log.error(str(e))
|
log.error(str(e))
|
||||||
@ -159,3 +163,7 @@ def main() -> None:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
pferd.print_report()
|
pferd.print_report()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
@ -5,6 +5,7 @@ from ..config import Config
|
|||||||
from .authenticator import Authenticator, AuthError, AuthLoadError, AuthSection # noqa: F401
|
from .authenticator import Authenticator, AuthError, AuthLoadError, AuthSection # noqa: F401
|
||||||
from .credential_file import CredentialFileAuthenticator, CredentialFileAuthSection
|
from .credential_file import CredentialFileAuthenticator, CredentialFileAuthSection
|
||||||
from .keyring import KeyringAuthenticator, KeyringAuthSection
|
from .keyring import KeyringAuthenticator, KeyringAuthSection
|
||||||
|
from .pass_ import PassAuthenticator, PassAuthSection
|
||||||
from .simple import SimpleAuthenticator, SimpleAuthSection
|
from .simple import SimpleAuthenticator, SimpleAuthSection
|
||||||
from .tfa import TfaAuthenticator
|
from .tfa import TfaAuthenticator
|
||||||
|
|
||||||
@ -19,6 +20,8 @@ AUTHENTICATORS: Dict[str, AuthConstructor] = {
|
|||||||
CredentialFileAuthenticator(n, CredentialFileAuthSection(s), c),
|
CredentialFileAuthenticator(n, CredentialFileAuthSection(s), c),
|
||||||
"keyring": lambda n, s, c:
|
"keyring": lambda n, s, c:
|
||||||
KeyringAuthenticator(n, KeyringAuthSection(s)),
|
KeyringAuthenticator(n, KeyringAuthSection(s)),
|
||||||
|
"pass": lambda n, s, c:
|
||||||
|
PassAuthenticator(n, PassAuthSection(s)),
|
||||||
"simple": lambda n, s, c:
|
"simple": lambda n, s, c:
|
||||||
SimpleAuthenticator(n, SimpleAuthSection(s)),
|
SimpleAuthenticator(n, SimpleAuthSection(s)),
|
||||||
"tfa": lambda n, s, c:
|
"tfa": lambda n, s, c:
|
||||||
|
@ -20,8 +20,10 @@ class CredentialFileAuthenticator(Authenticator):
|
|||||||
|
|
||||||
path = config.default_section.working_dir() / section.path()
|
path = config.default_section.working_dir() / section.path()
|
||||||
try:
|
try:
|
||||||
with open(path) as f:
|
with open(path, encoding="utf-8") as f:
|
||||||
lines = list(f)
|
lines = list(f)
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
raise AuthLoadError(f"Credential file at {fmt_real_path(path)} is not encoded using UTF-8")
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
raise AuthLoadError(f"No credential file at {fmt_real_path(path)}") from e
|
raise AuthLoadError(f"No credential file at {fmt_real_path(path)}") from e
|
||||||
|
|
||||||
|
98
PFERD/auth/pass_.py
Normal file
98
PFERD/auth/pass_.py
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
from typing import List, Tuple
|
||||||
|
|
||||||
|
from ..logging import log
|
||||||
|
from .authenticator import Authenticator, AuthError, AuthSection
|
||||||
|
|
||||||
|
|
||||||
|
class PassAuthSection(AuthSection):
|
||||||
|
def passname(self) -> str:
|
||||||
|
if (value := self.s.get("passname")) is None:
|
||||||
|
self.missing_value("passname")
|
||||||
|
return value
|
||||||
|
|
||||||
|
def username_prefixes(self) -> List[str]:
|
||||||
|
value = self.s.get("username_prefixes", "login,username,user")
|
||||||
|
return [prefix.lower() for prefix in value.split(",")]
|
||||||
|
|
||||||
|
def password_prefixes(self) -> List[str]:
|
||||||
|
value = self.s.get("password_prefixes", "password,pass,secret")
|
||||||
|
return [prefix.lower() for prefix in value.split(",")]
|
||||||
|
|
||||||
|
|
||||||
|
class PassAuthenticator(Authenticator):
|
||||||
|
PREFIXED_LINE_RE = r"([a-zA-Z]+):\s?(.*)" # to be used with fullmatch
|
||||||
|
|
||||||
|
def __init__(self, name: str, section: PassAuthSection) -> None:
|
||||||
|
super().__init__(name)
|
||||||
|
|
||||||
|
self._passname = section.passname()
|
||||||
|
self._username_prefixes = section.username_prefixes()
|
||||||
|
self._password_prefixes = section.password_prefixes()
|
||||||
|
|
||||||
|
async def credentials(self) -> Tuple[str, str]:
|
||||||
|
log.explain_topic("Obtaining credentials from pass")
|
||||||
|
|
||||||
|
try:
|
||||||
|
log.explain(f"Calling 'pass show {self._passname}'")
|
||||||
|
result = subprocess.check_output(["pass", "show", self._passname], text=True)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
raise AuthError(f"Failed to get password info from {self._passname}: {e}")
|
||||||
|
|
||||||
|
prefixed = {}
|
||||||
|
unprefixed = []
|
||||||
|
for line in result.strip().splitlines():
|
||||||
|
if match := re.fullmatch(self.PREFIXED_LINE_RE, line):
|
||||||
|
prefix = match.group(1).lower()
|
||||||
|
value = match.group(2)
|
||||||
|
log.explain(f"Found prefixed line {line!r} with prefix {prefix!r}, value {value!r}")
|
||||||
|
if prefix in prefixed:
|
||||||
|
raise AuthError(f"Prefix {prefix} specified multiple times")
|
||||||
|
prefixed[prefix] = value
|
||||||
|
else:
|
||||||
|
log.explain(f"Found unprefixed line {line!r}")
|
||||||
|
unprefixed.append(line)
|
||||||
|
|
||||||
|
username = None
|
||||||
|
for prefix in self._username_prefixes:
|
||||||
|
log.explain(f"Looking for username at prefix {prefix!r}")
|
||||||
|
if prefix in prefixed:
|
||||||
|
username = prefixed[prefix]
|
||||||
|
log.explain(f"Found username {username!r}")
|
||||||
|
break
|
||||||
|
|
||||||
|
password = None
|
||||||
|
for prefix in self._password_prefixes:
|
||||||
|
log.explain(f"Looking for password at prefix {prefix!r}")
|
||||||
|
if prefix in prefixed:
|
||||||
|
password = prefixed[prefix]
|
||||||
|
log.explain(f"Found password {password!r}")
|
||||||
|
break
|
||||||
|
|
||||||
|
if password is None and username is None:
|
||||||
|
log.explain("No username and password found so far")
|
||||||
|
log.explain("Using first unprefixed line as password")
|
||||||
|
log.explain("Using second unprefixed line as username")
|
||||||
|
elif password is None:
|
||||||
|
log.explain("No password found so far")
|
||||||
|
log.explain("Using first unprefixed line as password")
|
||||||
|
elif username is None:
|
||||||
|
log.explain("No username found so far")
|
||||||
|
log.explain("Using first unprefixed line as username")
|
||||||
|
|
||||||
|
if password is None:
|
||||||
|
if not unprefixed:
|
||||||
|
log.explain("Not enough unprefixed lines left")
|
||||||
|
raise AuthError("Password could not be determined")
|
||||||
|
password = unprefixed.pop(0)
|
||||||
|
log.explain(f"Found password {password!r}")
|
||||||
|
|
||||||
|
if username is None:
|
||||||
|
if not unprefixed:
|
||||||
|
log.explain("Not enough unprefixed lines left")
|
||||||
|
raise AuthError("Username could not be determined")
|
||||||
|
username = unprefixed.pop(0)
|
||||||
|
log.explain(f"Found username {username!r}")
|
||||||
|
|
||||||
|
return username, password
|
@ -9,4 +9,5 @@
|
|||||||
|
|
||||||
from . import command_local # noqa: F401 imported but unused
|
from . import command_local # noqa: F401 imported but unused
|
||||||
from . import command_kit_ilias_web # noqa: F401 imported but unused
|
from . import command_kit_ilias_web # noqa: F401 imported but unused
|
||||||
|
from . import command_kit_ipd # noqa: F401 imported but unused
|
||||||
from .parser import PARSER, ParserLoadError, load_default_section # noqa: F401 imported but unused
|
from .parser import PARSER, ParserLoadError, load_default_section # noqa: F401 imported but unused
|
||||||
|
@ -62,6 +62,11 @@ GROUP.add_argument(
|
|||||||
action=BooleanOptionalAction,
|
action=BooleanOptionalAction,
|
||||||
help="crawl and download videos"
|
help="crawl and download videos"
|
||||||
)
|
)
|
||||||
|
GROUP.add_argument(
|
||||||
|
"--forums",
|
||||||
|
action=BooleanOptionalAction,
|
||||||
|
help="crawl and download forum posts"
|
||||||
|
)
|
||||||
GROUP.add_argument(
|
GROUP.add_argument(
|
||||||
"--http-timeout", "-t",
|
"--http-timeout", "-t",
|
||||||
type=float,
|
type=float,
|
||||||
@ -90,6 +95,8 @@ def load(
|
|||||||
section["link_redirect_delay"] = str(args.link_redirect_delay)
|
section["link_redirect_delay"] = str(args.link_redirect_delay)
|
||||||
if args.videos is not None:
|
if args.videos is not None:
|
||||||
section["videos"] = "yes" if args.videos else "no"
|
section["videos"] = "yes" if args.videos else "no"
|
||||||
|
if args.forums is not None:
|
||||||
|
section["forums"] = "yes" if args.forums else "no"
|
||||||
if args.http_timeout is not None:
|
if args.http_timeout is not None:
|
||||||
section["http_timeout"] = str(args.http_timeout)
|
section["http_timeout"] = str(args.http_timeout)
|
||||||
|
|
||||||
|
54
PFERD/cli/command_kit_ipd.py
Normal file
54
PFERD/cli/command_kit_ipd.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import argparse
|
||||||
|
import configparser
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from ..logging import log
|
||||||
|
from .parser import CRAWLER_PARSER, SUBPARSERS, load_crawler
|
||||||
|
|
||||||
|
SUBPARSER = SUBPARSERS.add_parser(
|
||||||
|
"kit-ipd",
|
||||||
|
parents=[CRAWLER_PARSER],
|
||||||
|
)
|
||||||
|
|
||||||
|
GROUP = SUBPARSER.add_argument_group(
|
||||||
|
title="kit ipd crawler arguments",
|
||||||
|
description="arguments for the 'kit-ipd' crawler",
|
||||||
|
)
|
||||||
|
GROUP.add_argument(
|
||||||
|
"--link-regex",
|
||||||
|
type=str,
|
||||||
|
metavar="REGEX",
|
||||||
|
help="href-matching regex to identify downloadable files"
|
||||||
|
)
|
||||||
|
GROUP.add_argument(
|
||||||
|
"target",
|
||||||
|
type=str,
|
||||||
|
metavar="TARGET",
|
||||||
|
help="url to crawl"
|
||||||
|
)
|
||||||
|
GROUP.add_argument(
|
||||||
|
"output",
|
||||||
|
type=Path,
|
||||||
|
metavar="OUTPUT",
|
||||||
|
help="output directory"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def load(
|
||||||
|
args: argparse.Namespace,
|
||||||
|
parser: configparser.ConfigParser,
|
||||||
|
) -> None:
|
||||||
|
log.explain("Creating config for command 'kit-ipd'")
|
||||||
|
|
||||||
|
parser["crawl:kit-ipd"] = {}
|
||||||
|
section = parser["crawl:kit-ipd"]
|
||||||
|
load_crawler(args, section)
|
||||||
|
|
||||||
|
section["type"] = "kit-ipd"
|
||||||
|
section["target"] = str(args.target)
|
||||||
|
section["output_dir"] = str(args.output)
|
||||||
|
if args.link_regex:
|
||||||
|
section["link_regex"] = str(args.link_regex)
|
||||||
|
|
||||||
|
|
||||||
|
SUBPARSER.set_defaults(command=load)
|
@ -181,6 +181,14 @@ PARSER.add_argument(
|
|||||||
help="only execute a single crawler."
|
help="only execute a single crawler."
|
||||||
" Can be specified multiple times to execute multiple crawlers"
|
" Can be specified multiple times to execute multiple crawlers"
|
||||||
)
|
)
|
||||||
|
PARSER.add_argument(
|
||||||
|
"--skip", "-S",
|
||||||
|
action="append",
|
||||||
|
type=str,
|
||||||
|
metavar="NAME",
|
||||||
|
help="don't execute this particular crawler."
|
||||||
|
" Can be specified multiple times to skip multiple crawlers"
|
||||||
|
)
|
||||||
PARSER.add_argument(
|
PARSER.add_argument(
|
||||||
"--working-dir",
|
"--working-dir",
|
||||||
type=Path,
|
type=Path,
|
||||||
@ -207,6 +215,11 @@ PARSER.add_argument(
|
|||||||
action=BooleanOptionalAction,
|
action=BooleanOptionalAction,
|
||||||
help="whether crawlers should share cookies where applicable"
|
help="whether crawlers should share cookies where applicable"
|
||||||
)
|
)
|
||||||
|
PARSER.add_argument(
|
||||||
|
"--show-not-deleted",
|
||||||
|
action=BooleanOptionalAction,
|
||||||
|
help="print messages in status and report when PFERD did not delete a local only file"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def load_default_section(
|
def load_default_section(
|
||||||
@ -225,6 +238,8 @@ def load_default_section(
|
|||||||
section["report"] = "yes" if args.report else "no"
|
section["report"] = "yes" if args.report else "no"
|
||||||
if args.share_cookies is not None:
|
if args.share_cookies is not None:
|
||||||
section["share_cookies"] = "yes" if args.share_cookies else "no"
|
section["share_cookies"] = "yes" if args.share_cookies else "no"
|
||||||
|
if args.show_not_deleted is not None:
|
||||||
|
section["show_not_deleted"] = "yes" if args.show_not_deleted else "no"
|
||||||
|
|
||||||
|
|
||||||
SUBPARSERS = PARSER.add_subparsers(title="crawlers")
|
SUBPARSERS = PARSER.add_subparsers(title="crawlers")
|
||||||
|
@ -82,6 +82,9 @@ class DefaultSection(Section):
|
|||||||
def report(self) -> bool:
|
def report(self) -> bool:
|
||||||
return self.s.getboolean("report", fallback=True)
|
return self.s.getboolean("report", fallback=True)
|
||||||
|
|
||||||
|
def show_not_deleted(self) -> bool:
|
||||||
|
return self.s.getboolean("show_not_deleted", fallback=True)
|
||||||
|
|
||||||
def share_cookies(self) -> bool:
|
def share_cookies(self) -> bool:
|
||||||
return self.s.getboolean("share_cookies", fallback=True)
|
return self.s.getboolean("share_cookies", fallback=True)
|
||||||
|
|
||||||
@ -120,7 +123,7 @@ class Config:
|
|||||||
# Using config.read_file instead of config.read because config.read
|
# Using config.read_file instead of config.read because config.read
|
||||||
# would just ignore a missing file and carry on.
|
# would just ignore a missing file and carry on.
|
||||||
try:
|
try:
|
||||||
with open(path) as f:
|
with open(path, encoding="utf-8") as f:
|
||||||
parser.read_file(f, source=str(path))
|
parser.read_file(f, source=str(path))
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
raise ConfigLoadError(path, "File does not exist")
|
raise ConfigLoadError(path, "File does not exist")
|
||||||
@ -128,6 +131,8 @@ class Config:
|
|||||||
raise ConfigLoadError(path, "That's a directory, not a file")
|
raise ConfigLoadError(path, "That's a directory, not a file")
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
raise ConfigLoadError(path, "Insufficient permissions")
|
raise ConfigLoadError(path, "Insufficient permissions")
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
raise ConfigLoadError(path, "File is not encoded using UTF-8")
|
||||||
|
|
||||||
def dump(self, path: Optional[Path] = None) -> None:
|
def dump(self, path: Optional[Path] = None) -> None:
|
||||||
"""
|
"""
|
||||||
@ -154,12 +159,12 @@ class Config:
|
|||||||
try:
|
try:
|
||||||
# x = open for exclusive creation, failing if the file already
|
# x = open for exclusive creation, failing if the file already
|
||||||
# exists
|
# exists
|
||||||
with open(path, "x") as f:
|
with open(path, "x", encoding="utf-8") as f:
|
||||||
self._parser.write(f)
|
self._parser.write(f)
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
print("That file already exists.")
|
print("That file already exists.")
|
||||||
if asyncio.run(prompt_yes_no("Overwrite it?", default=False)):
|
if asyncio.run(prompt_yes_no("Overwrite it?", default=False)):
|
||||||
with open(path, "w") as f:
|
with open(path, "w", encoding="utf-8") as f:
|
||||||
self._parser.write(f)
|
self._parser.write(f)
|
||||||
else:
|
else:
|
||||||
raise ConfigDumpError(path, "File already exists")
|
raise ConfigDumpError(path, "File already exists")
|
||||||
|
@ -5,6 +5,7 @@ from ..auth import Authenticator
|
|||||||
from ..config import Config
|
from ..config import Config
|
||||||
from .crawler import Crawler, CrawlError, CrawlerSection # noqa: F401
|
from .crawler import Crawler, CrawlError, CrawlerSection # noqa: F401
|
||||||
from .ilias import KitIliasWebCrawler, KitIliasWebCrawlerSection
|
from .ilias import KitIliasWebCrawler, KitIliasWebCrawlerSection
|
||||||
|
from .kit_ipd_crawler import KitIpdCrawler, KitIpdCrawlerSection
|
||||||
from .local_crawler import LocalCrawler, LocalCrawlerSection
|
from .local_crawler import LocalCrawler, LocalCrawlerSection
|
||||||
|
|
||||||
CrawlerConstructor = Callable[[
|
CrawlerConstructor = Callable[[
|
||||||
@ -19,4 +20,6 @@ CRAWLERS: Dict[str, CrawlerConstructor] = {
|
|||||||
LocalCrawler(n, LocalCrawlerSection(s), c),
|
LocalCrawler(n, LocalCrawlerSection(s), c),
|
||||||
"kit-ilias-web": lambda n, s, c, a:
|
"kit-ilias-web": lambda n, s, c, a:
|
||||||
KitIliasWebCrawler(n, KitIliasWebCrawlerSection(s), c, a),
|
KitIliasWebCrawler(n, KitIliasWebCrawlerSection(s), c, a),
|
||||||
|
"kit-ipd": lambda n, s, c, a:
|
||||||
|
KitIpdCrawler(n, KitIpdCrawlerSection(s), c),
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
from collections.abc import Awaitable, Coroutine
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path, PurePath
|
from pathlib import Path, PurePath
|
||||||
from typing import Any, Awaitable, Callable, Dict, List, Optional, Sequence, Set, Tuple, TypeVar
|
from typing import Any, Callable, Dict, List, Optional, Sequence, Set, Tuple, TypeVar
|
||||||
|
|
||||||
from ..auth import Authenticator
|
from ..auth import Authenticator
|
||||||
from ..config import Config, Section
|
from ..config import Config, Section
|
||||||
@ -47,16 +48,18 @@ def noncritical(f: Wrapped) -> Wrapped:
|
|||||||
try:
|
try:
|
||||||
f(*args, **kwargs)
|
f(*args, **kwargs)
|
||||||
except (CrawlWarning, OutputDirError, MarkDuplicateError, MarkConflictError) as e:
|
except (CrawlWarning, OutputDirError, MarkDuplicateError, MarkConflictError) as e:
|
||||||
|
crawler.report.add_warning(str(e))
|
||||||
log.warn(str(e))
|
log.warn(str(e))
|
||||||
crawler.error_free = False
|
crawler.error_free = False
|
||||||
except: # noqa: E722 do not use bare 'except'
|
except Exception as e:
|
||||||
crawler.error_free = False
|
crawler.error_free = False
|
||||||
|
crawler.report.add_error(str(e))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
return wrapper # type: ignore
|
return wrapper # type: ignore
|
||||||
|
|
||||||
|
|
||||||
AWrapped = TypeVar("AWrapped", bound=Callable[..., Awaitable[None]])
|
AWrapped = TypeVar("AWrapped", bound=Callable[..., Coroutine[Any, Any, Optional[Any]]])
|
||||||
|
|
||||||
|
|
||||||
def anoncritical(f: AWrapped) -> AWrapped:
|
def anoncritical(f: AWrapped) -> AWrapped:
|
||||||
@ -72,21 +75,25 @@ def anoncritical(f: AWrapped) -> AWrapped:
|
|||||||
Warning: Must only be applied to member functions of the Crawler class!
|
Warning: Must only be applied to member functions of the Crawler class!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
async def wrapper(*args: Any, **kwargs: Any) -> None:
|
async def wrapper(*args: Any, **kwargs: Any) -> Optional[Any]:
|
||||||
if not (args and isinstance(args[0], Crawler)):
|
if not (args and isinstance(args[0], Crawler)):
|
||||||
raise RuntimeError("@anoncritical must only applied to Crawler methods")
|
raise RuntimeError("@anoncritical must only applied to Crawler methods")
|
||||||
|
|
||||||
crawler = args[0]
|
crawler = args[0]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await f(*args, **kwargs)
|
return await f(*args, **kwargs)
|
||||||
except (CrawlWarning, OutputDirError, MarkDuplicateError, MarkConflictError) as e:
|
except (CrawlWarning, OutputDirError, MarkDuplicateError, MarkConflictError) as e:
|
||||||
log.warn(str(e))
|
log.warn(str(e))
|
||||||
crawler.error_free = False
|
crawler.error_free = False
|
||||||
except: # noqa: E722 do not use bare 'except'
|
crawler.report.add_warning(str(e))
|
||||||
|
except Exception as e:
|
||||||
crawler.error_free = False
|
crawler.error_free = False
|
||||||
|
crawler.report.add_error(str(e))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
return wrapper # type: ignore
|
return wrapper # type: ignore
|
||||||
|
|
||||||
|
|
||||||
@ -318,6 +325,7 @@ class Crawler(ABC):
|
|||||||
log.explain("Warnings or errors occurred during this run")
|
log.explain("Warnings or errors occurred during this run")
|
||||||
log.explain("Answer: No")
|
log.explain("Answer: No")
|
||||||
|
|
||||||
|
@anoncritical
|
||||||
async def run(self) -> None:
|
async def run(self) -> None:
|
||||||
"""
|
"""
|
||||||
Start the crawling process. Call this function if you want to use a
|
Start the crawling process. Call this function if you want to use a
|
||||||
|
@ -108,7 +108,7 @@ class HttpCrawler(Crawler):
|
|||||||
|
|
||||||
def _load_cookies_from_file(self, path: Path) -> None:
|
def _load_cookies_from_file(self, path: Path) -> None:
|
||||||
jar: Any = http.cookies.SimpleCookie()
|
jar: Any = http.cookies.SimpleCookie()
|
||||||
with open(path) as f:
|
with open(path, encoding="utf-8") as f:
|
||||||
for i, line in enumerate(f):
|
for i, line in enumerate(f):
|
||||||
# Names of headers are case insensitive
|
# Names of headers are case insensitive
|
||||||
if line[:11].lower() == "set-cookie:":
|
if line[:11].lower() == "set-cookie:":
|
||||||
@ -121,7 +121,7 @@ class HttpCrawler(Crawler):
|
|||||||
jar: Any = http.cookies.SimpleCookie()
|
jar: Any = http.cookies.SimpleCookie()
|
||||||
for morsel in self._cookie_jar:
|
for morsel in self._cookie_jar:
|
||||||
jar[morsel.key] = morsel
|
jar[morsel.key] = morsel
|
||||||
with open(path, "w") as f:
|
with open(path, "w", encoding="utf-8") as f:
|
||||||
f.write(jar.output(sep="\n"))
|
f.write(jar.output(sep="\n"))
|
||||||
f.write("\n") # A trailing newline is just common courtesy
|
f.write("\n") # A trailing newline is just common courtesy
|
||||||
|
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
import bs4
|
||||||
|
|
||||||
|
from PFERD.utils import soupify
|
||||||
|
|
||||||
_link_template_plain = "{{link}}"
|
_link_template_plain = "{{link}}"
|
||||||
_link_template_fancy = """
|
_link_template_fancy = """
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@ -94,6 +98,71 @@ _link_template_internet_shortcut = """
|
|||||||
URL={{link}}
|
URL={{link}}
|
||||||
""".strip()
|
""".strip()
|
||||||
|
|
||||||
|
_learning_module_template = """
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>{{name}}</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
.center-flex {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.nav {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<body class="center-flex">
|
||||||
|
{{body}}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def learning_module_template(body: bs4.Tag, name: str, prev: Optional[str], next: Optional[str]) -> str:
|
||||||
|
# Seems to be comments, ignore those.
|
||||||
|
for elem in body.select(".il-copg-mob-fullscreen-modal"):
|
||||||
|
elem.decompose()
|
||||||
|
|
||||||
|
nav_template = """
|
||||||
|
<div class="nav">
|
||||||
|
{{left}}
|
||||||
|
{{right}}
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
|
if prev and body.select_one(".ilc_page_lnav_LeftNavigation"):
|
||||||
|
text = body.select_one(".ilc_page_lnav_LeftNavigation").getText().strip()
|
||||||
|
left = f'<a href="{prev}">{text}</a>'
|
||||||
|
else:
|
||||||
|
left = "<span></span>"
|
||||||
|
|
||||||
|
if next and body.select_one(".ilc_page_rnav_RightNavigation"):
|
||||||
|
text = body.select_one(".ilc_page_rnav_RightNavigation").getText().strip()
|
||||||
|
right = f'<a href="{next}">{text}</a>'
|
||||||
|
else:
|
||||||
|
right = "<span></span>"
|
||||||
|
|
||||||
|
if top_nav := body.select_one(".ilc_page_tnav_TopNavigation"):
|
||||||
|
top_nav.replace_with(
|
||||||
|
soupify(nav_template.replace("{{left}}", left).replace("{{right}}", right).encode())
|
||||||
|
)
|
||||||
|
|
||||||
|
if bot_nav := body.select_one(".ilc_page_bnav_BottomNavigation"):
|
||||||
|
bot_nav.replace_with(soupify(nav_template.replace(
|
||||||
|
"{{left}}", left).replace("{{right}}", right).encode())
|
||||||
|
)
|
||||||
|
|
||||||
|
body = body.prettify()
|
||||||
|
return _learning_module_template.replace("{{body}}", body).replace("{{name}}", name)
|
||||||
|
|
||||||
|
|
||||||
class Links(Enum):
|
class Links(Enum):
|
||||||
IGNORE = "ignore"
|
IGNORE = "ignore"
|
||||||
@ -102,24 +171,24 @@ class Links(Enum):
|
|||||||
INTERNET_SHORTCUT = "internet-shortcut"
|
INTERNET_SHORTCUT = "internet-shortcut"
|
||||||
|
|
||||||
def template(self) -> Optional[str]:
|
def template(self) -> Optional[str]:
|
||||||
if self == self.FANCY:
|
if self == Links.FANCY:
|
||||||
return _link_template_fancy
|
return _link_template_fancy
|
||||||
elif self == self.PLAINTEXT:
|
elif self == Links.PLAINTEXT:
|
||||||
return _link_template_plain
|
return _link_template_plain
|
||||||
elif self == self.INTERNET_SHORTCUT:
|
elif self == Links.INTERNET_SHORTCUT:
|
||||||
return _link_template_internet_shortcut
|
return _link_template_internet_shortcut
|
||||||
elif self == self.IGNORE:
|
elif self == Links.IGNORE:
|
||||||
return None
|
return None
|
||||||
raise ValueError("Missing switch case")
|
raise ValueError("Missing switch case")
|
||||||
|
|
||||||
def extension(self) -> Optional[str]:
|
def extension(self) -> Optional[str]:
|
||||||
if self == self.FANCY:
|
if self == Links.FANCY:
|
||||||
return ".html"
|
return ".html"
|
||||||
elif self == self.PLAINTEXT:
|
elif self == Links.PLAINTEXT:
|
||||||
return ".txt"
|
return ".txt"
|
||||||
elif self == self.INTERNET_SHORTCUT:
|
elif self == Links.INTERNET_SHORTCUT:
|
||||||
return ".url"
|
return ".url"
|
||||||
elif self == self.IGNORE:
|
elif self == Links.IGNORE:
|
||||||
return None
|
return None
|
||||||
raise ValueError("Missing switch case")
|
raise ValueError("Missing switch case")
|
||||||
|
|
||||||
|
91
PFERD/crawl/ilias/ilias_html_cleaner.py
Normal file
91
PFERD/crawl/ilias/ilias_html_cleaner.py
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
from bs4 import BeautifulSoup, Comment, Tag
|
||||||
|
|
||||||
|
_STYLE_TAG_CONTENT = """
|
||||||
|
.ilc_text_block_Information {
|
||||||
|
background-color: #f5f7fa;
|
||||||
|
}
|
||||||
|
div.ilc_text_block_Standard {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
span.ilc_text_inline_Strong {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.accordion-head {
|
||||||
|
background-color: #f5f7fa;
|
||||||
|
padding: 0.5rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
br.visible-break {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
article {
|
||||||
|
margin: 0.5rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
padding: 1em;
|
||||||
|
grid-template-columns: 1fr min(60rem, 90%) 1fr;
|
||||||
|
line-height: 1.2;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
_ARTICLE_WORTHY_CLASSES = [
|
||||||
|
"ilc_text_block_Information",
|
||||||
|
"ilc_section_Attention",
|
||||||
|
"ilc_section_Link",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def insert_base_markup(soup: BeautifulSoup) -> BeautifulSoup:
|
||||||
|
head = soup.new_tag("head")
|
||||||
|
soup.insert(0, head)
|
||||||
|
|
||||||
|
simplecss_link: Tag = soup.new_tag("link")
|
||||||
|
# <link rel="stylesheet" href="https://cdn.simplecss.org/simple.css">
|
||||||
|
simplecss_link["rel"] = "stylesheet"
|
||||||
|
simplecss_link["href"] = "https://cdn.simplecss.org/simple.css"
|
||||||
|
head.append(simplecss_link)
|
||||||
|
|
||||||
|
# Basic style tags for compat
|
||||||
|
style: Tag = soup.new_tag("style")
|
||||||
|
style.append(_STYLE_TAG_CONTENT)
|
||||||
|
head.append(style)
|
||||||
|
|
||||||
|
return soup
|
||||||
|
|
||||||
|
|
||||||
|
def clean(soup: BeautifulSoup) -> BeautifulSoup:
|
||||||
|
for block in soup.find_all(class_=lambda x: x in _ARTICLE_WORTHY_CLASSES):
|
||||||
|
block.name = "article"
|
||||||
|
|
||||||
|
for block in soup.find_all("h3"):
|
||||||
|
block.name = "div"
|
||||||
|
|
||||||
|
for block in soup.find_all("h1"):
|
||||||
|
block.name = "h3"
|
||||||
|
|
||||||
|
for block in soup.find_all(class_="ilc_va_ihcap_VAccordIHeadCap"):
|
||||||
|
block.name = "h3"
|
||||||
|
block["class"] += ["accordion-head"]
|
||||||
|
|
||||||
|
for dummy in soup.select(".ilc_text_block_Standard.ilc_Paragraph"):
|
||||||
|
children = list(dummy.children)
|
||||||
|
if not children:
|
||||||
|
dummy.decompose()
|
||||||
|
if len(children) > 1:
|
||||||
|
continue
|
||||||
|
if isinstance(type(children[0]), Comment):
|
||||||
|
dummy.decompose()
|
||||||
|
|
||||||
|
for hrule_imposter in soup.find_all(class_="ilc_section_Separator"):
|
||||||
|
hrule_imposter.insert(0, soup.new_tag("hr"))
|
||||||
|
|
||||||
|
return soup
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
170
PFERD/crawl/kit_ipd_crawler.py
Normal file
170
PFERD/crawl/kit_ipd_crawler.py
Normal file
@ -0,0 +1,170 @@
|
|||||||
|
import os
|
||||||
|
import re
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from pathlib import PurePath
|
||||||
|
from typing import Awaitable, List, Optional, Pattern, Set, Tuple, Union
|
||||||
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
|
from bs4 import BeautifulSoup, Tag
|
||||||
|
|
||||||
|
from ..config import Config
|
||||||
|
from ..logging import ProgressBar, log
|
||||||
|
from ..output_dir import FileSink
|
||||||
|
from ..utils import soupify
|
||||||
|
from .crawler import CrawlError
|
||||||
|
from .http_crawler import HttpCrawler, HttpCrawlerSection
|
||||||
|
|
||||||
|
|
||||||
|
class KitIpdCrawlerSection(HttpCrawlerSection):
|
||||||
|
def target(self) -> str:
|
||||||
|
target = self.s.get("target")
|
||||||
|
if not target:
|
||||||
|
self.missing_value("target")
|
||||||
|
|
||||||
|
if not target.startswith("https://"):
|
||||||
|
self.invalid_value("target", target, "Should be a URL")
|
||||||
|
|
||||||
|
return target
|
||||||
|
|
||||||
|
def link_regex(self) -> Pattern[str]:
|
||||||
|
regex = self.s.get("link_regex", r"^.*?[^/]+\.(pdf|zip|c|cpp|java)$")
|
||||||
|
return re.compile(regex)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(unsafe_hash=True)
|
||||||
|
class KitIpdFile:
|
||||||
|
name: str
|
||||||
|
url: str
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class KitIpdFolder:
|
||||||
|
name: str
|
||||||
|
files: List[KitIpdFile]
|
||||||
|
|
||||||
|
def explain(self) -> None:
|
||||||
|
log.explain_topic(f"Folder {self.name!r}")
|
||||||
|
for file in self.files:
|
||||||
|
log.explain(f"File {file.name!r} (href={file.url!r})")
|
||||||
|
|
||||||
|
def __hash__(self) -> int:
|
||||||
|
return self.name.__hash__()
|
||||||
|
|
||||||
|
|
||||||
|
class KitIpdCrawler(HttpCrawler):
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
section: KitIpdCrawlerSection,
|
||||||
|
config: Config,
|
||||||
|
):
|
||||||
|
super().__init__(name, section, config)
|
||||||
|
self._url = section.target()
|
||||||
|
self._file_regex = section.link_regex()
|
||||||
|
|
||||||
|
async def _run(self) -> None:
|
||||||
|
maybe_cl = await self.crawl(PurePath("."))
|
||||||
|
if not maybe_cl:
|
||||||
|
return
|
||||||
|
|
||||||
|
tasks: List[Awaitable[None]] = []
|
||||||
|
|
||||||
|
async with maybe_cl:
|
||||||
|
for item in await self._fetch_items():
|
||||||
|
if isinstance(item, KitIpdFolder):
|
||||||
|
tasks.append(self._crawl_folder(item))
|
||||||
|
else:
|
||||||
|
# Orphan files are placed in the root folder
|
||||||
|
tasks.append(self._download_file(PurePath("."), item))
|
||||||
|
|
||||||
|
await self.gather(tasks)
|
||||||
|
|
||||||
|
async def _crawl_folder(self, folder: KitIpdFolder) -> None:
|
||||||
|
path = PurePath(folder.name)
|
||||||
|
if not await self.crawl(path):
|
||||||
|
return
|
||||||
|
|
||||||
|
tasks = [self._download_file(path, file) for file in folder.files]
|
||||||
|
|
||||||
|
await self.gather(tasks)
|
||||||
|
|
||||||
|
async def _download_file(self, parent: PurePath, file: KitIpdFile) -> None:
|
||||||
|
element_path = parent / file.name
|
||||||
|
maybe_dl = await self.download(element_path)
|
||||||
|
if not maybe_dl:
|
||||||
|
return
|
||||||
|
|
||||||
|
async with maybe_dl as (bar, sink):
|
||||||
|
await self._stream_from_url(file.url, sink, bar)
|
||||||
|
|
||||||
|
async def _fetch_items(self) -> Set[Union[KitIpdFile, KitIpdFolder]]:
|
||||||
|
page, url = await self.get_page()
|
||||||
|
elements: List[Tag] = self._find_file_links(page)
|
||||||
|
items: Set[Union[KitIpdFile, KitIpdFolder]] = set()
|
||||||
|
|
||||||
|
for element in elements:
|
||||||
|
folder_label = self._find_folder_label(element)
|
||||||
|
if folder_label:
|
||||||
|
folder = self._extract_folder(folder_label, url)
|
||||||
|
if folder not in items:
|
||||||
|
items.add(folder)
|
||||||
|
folder.explain()
|
||||||
|
else:
|
||||||
|
file = self._extract_file(element, url)
|
||||||
|
items.add(file)
|
||||||
|
log.explain_topic(f"Orphan file {file.name!r} (href={file.url!r})")
|
||||||
|
log.explain("Attributing it to root folder")
|
||||||
|
|
||||||
|
return items
|
||||||
|
|
||||||
|
def _extract_folder(self, folder_tag: Tag, url: str) -> KitIpdFolder:
|
||||||
|
files: List[KitIpdFile] = []
|
||||||
|
name = folder_tag.getText().strip()
|
||||||
|
|
||||||
|
container: Tag = folder_tag.findNextSibling(name="table")
|
||||||
|
for link in self._find_file_links(container):
|
||||||
|
files.append(self._extract_file(link, url))
|
||||||
|
|
||||||
|
return KitIpdFolder(name, files)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _find_folder_label(file_link: Tag) -> Optional[Tag]:
|
||||||
|
enclosing_table: Tag = file_link.findParent(name="table")
|
||||||
|
if enclosing_table is None:
|
||||||
|
return None
|
||||||
|
return enclosing_table.findPreviousSibling(name=re.compile("^h[1-6]$"))
|
||||||
|
|
||||||
|
def _extract_file(self, link: Tag, url: str) -> KitIpdFile:
|
||||||
|
url = self._abs_url_from_link(url, link)
|
||||||
|
name = os.path.basename(url)
|
||||||
|
return KitIpdFile(name, url)
|
||||||
|
|
||||||
|
def _find_file_links(self, tag: Union[Tag, BeautifulSoup]) -> List[Tag]:
|
||||||
|
return tag.findAll(name="a", attrs={"href": self._file_regex})
|
||||||
|
|
||||||
|
def _abs_url_from_link(self, url: str, link_tag: Tag) -> str:
|
||||||
|
return urljoin(url, link_tag.get("href"))
|
||||||
|
|
||||||
|
async def _stream_from_url(self, url: str, sink: FileSink, bar: ProgressBar) -> None:
|
||||||
|
async with self.session.get(url, allow_redirects=False) as resp:
|
||||||
|
if resp.status == 403:
|
||||||
|
raise CrawlError("Received a 403. Are you within the KIT network/VPN?")
|
||||||
|
if resp.content_length:
|
||||||
|
bar.set_total(resp.content_length)
|
||||||
|
|
||||||
|
async for data in resp.content.iter_chunked(1024):
|
||||||
|
sink.file.write(data)
|
||||||
|
bar.advance(len(data))
|
||||||
|
|
||||||
|
sink.done()
|
||||||
|
|
||||||
|
async def get_page(self) -> Tuple[BeautifulSoup, str]:
|
||||||
|
async with self.session.get(self._url) as request:
|
||||||
|
# The web page for Algorithmen für Routenplanung contains some
|
||||||
|
# weird comments that beautifulsoup doesn't parse correctly. This
|
||||||
|
# hack enables those pages to be crawled, and should hopefully not
|
||||||
|
# cause issues on other pages.
|
||||||
|
content = (await request.read()).decode("utf-8")
|
||||||
|
content = re.sub(r"<!--.*?-->", "", content)
|
||||||
|
return soupify(content.encode("utf-8")), str(request.url)
|
@ -14,7 +14,7 @@ def name_variants(path: PurePath) -> Iterator[PurePath]:
|
|||||||
|
|
||||||
|
|
||||||
class Deduplicator:
|
class Deduplicator:
|
||||||
FORBIDDEN_CHARS = '<>:"/\\|?*'
|
FORBIDDEN_CHARS = '<>:"/\\|?*' + "".join([chr(i) for i in range(0, 32)])
|
||||||
FORBIDDEN_NAMES = {
|
FORBIDDEN_NAMES = {
|
||||||
"CON", "PRN", "AUX", "NUL",
|
"CON", "PRN", "AUX", "NUL",
|
||||||
"COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
|
"COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
|
||||||
@ -56,6 +56,12 @@ class Deduplicator:
|
|||||||
log.explain(f"Changed path to {fmt_path(new_path)} for windows compatibility")
|
log.explain(f"Changed path to {fmt_path(new_path)} for windows compatibility")
|
||||||
return new_path
|
return new_path
|
||||||
|
|
||||||
|
def fixup_path(self, path: PurePath) -> PurePath:
|
||||||
|
"""Fixes up the path for windows, if enabled. Returns the path unchanged otherwise."""
|
||||||
|
if self._windows_paths:
|
||||||
|
return self._fixup_for_windows(path)
|
||||||
|
return path
|
||||||
|
|
||||||
def mark(self, path: PurePath) -> PurePath:
|
def mark(self, path: PurePath) -> PurePath:
|
||||||
if self._windows_paths:
|
if self._windows_paths:
|
||||||
path = self._fixup_for_windows(path)
|
path = self._fixup_for_windows(path)
|
||||||
|
@ -5,7 +5,7 @@ from contextlib import asynccontextmanager, contextmanager
|
|||||||
# TODO In Python 3.9 and above, ContextManager is deprecated
|
# TODO In Python 3.9 and above, ContextManager is deprecated
|
||||||
from typing import AsyncIterator, ContextManager, Iterator, List, Optional
|
from typing import AsyncIterator, ContextManager, Iterator, List, Optional
|
||||||
|
|
||||||
from rich.console import Console, RenderGroup
|
from rich.console import Console, Group
|
||||||
from rich.live import Live
|
from rich.live import Live
|
||||||
from rich.markup import escape
|
from rich.markup import escape
|
||||||
from rich.panel import Panel
|
from rich.panel import Panel
|
||||||
@ -59,6 +59,7 @@ class Log:
|
|||||||
# Whether different parts of the output are enabled or disabled
|
# Whether different parts of the output are enabled or disabled
|
||||||
self.output_explain = False
|
self.output_explain = False
|
||||||
self.output_status = True
|
self.output_status = True
|
||||||
|
self.output_not_deleted = True
|
||||||
self.output_report = True
|
self.output_report = True
|
||||||
|
|
||||||
def _update_live(self) -> None:
|
def _update_live(self) -> None:
|
||||||
@ -68,7 +69,7 @@ class Log:
|
|||||||
if self._download_progress.task_ids:
|
if self._download_progress.task_ids:
|
||||||
elements.append(self._download_progress)
|
elements.append(self._download_progress)
|
||||||
|
|
||||||
group = RenderGroup(*elements) # type: ignore
|
group = Group(*elements)
|
||||||
self._live.update(group)
|
self._live.update(group)
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
@ -197,7 +198,7 @@ directly or as a GitHub issue: https://github.com/Garmelon/PFERD/issues/new
|
|||||||
if self.output_explain:
|
if self.output_explain:
|
||||||
self.print(f" {escape(text)}")
|
self.print(f" {escape(text)}")
|
||||||
|
|
||||||
def status(self, style: str, action: str, text: str) -> None:
|
def status(self, style: str, action: str, text: str, suffix: str = "") -> None:
|
||||||
"""
|
"""
|
||||||
Print a status update while crawling. Allows markup in the "style"
|
Print a status update while crawling. Allows markup in the "style"
|
||||||
argument which will be applied to the "action" string.
|
argument which will be applied to the "action" string.
|
||||||
@ -205,7 +206,18 @@ directly or as a GitHub issue: https://github.com/Garmelon/PFERD/issues/new
|
|||||||
|
|
||||||
if self.output_status:
|
if self.output_status:
|
||||||
action = escape(f"{action:<{self.STATUS_WIDTH}}")
|
action = escape(f"{action:<{self.STATUS_WIDTH}}")
|
||||||
self.print(f"{style}{action}[/] {escape(text)}")
|
self.print(f"{style}{action}[/] {escape(text)} {suffix}")
|
||||||
|
|
||||||
|
def not_deleted(self, style: str, action: str, text: str, suffix: str = "") -> None:
|
||||||
|
"""
|
||||||
|
Print a message for a local only file that wasn't
|
||||||
|
deleted while crawling. Allows markup in the "style"
|
||||||
|
argument which will be applied to the "action" string.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if self.output_status and self.output_not_deleted:
|
||||||
|
action = escape(f"{action:<{self.STATUS_WIDTH}}")
|
||||||
|
self.print(f"{style}{action}[/] {escape(text)} {suffix}")
|
||||||
|
|
||||||
def report(self, text: str) -> None:
|
def report(self, text: str) -> None:
|
||||||
"""
|
"""
|
||||||
@ -215,6 +227,14 @@ directly or as a GitHub issue: https://github.com/Garmelon/PFERD/issues/new
|
|||||||
if self.output_report:
|
if self.output_report:
|
||||||
self.print(text)
|
self.print(text)
|
||||||
|
|
||||||
|
def report_not_deleted(self, text: str) -> None:
|
||||||
|
"""
|
||||||
|
Print a report for a local only file that wasn't deleted after crawling. Allows markup.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if self.output_report and self.output_not_deleted:
|
||||||
|
self.print(text)
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def _bar(
|
def _bar(
|
||||||
self,
|
self,
|
||||||
|
@ -44,6 +44,7 @@ class OnConflict(Enum):
|
|||||||
LOCAL_FIRST = "local-first"
|
LOCAL_FIRST = "local-first"
|
||||||
REMOTE_FIRST = "remote-first"
|
REMOTE_FIRST = "remote-first"
|
||||||
NO_DELETE = "no-delete"
|
NO_DELETE = "no-delete"
|
||||||
|
NO_DELETE_PROMPT_OVERWRITE = "no-delete-prompt-overwrite"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_string(string: str) -> "OnConflict":
|
def from_string(string: str) -> "OnConflict":
|
||||||
@ -51,7 +52,7 @@ class OnConflict(Enum):
|
|||||||
return OnConflict(string)
|
return OnConflict(string)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ValueError("must be one of 'prompt', 'local-first',"
|
raise ValueError("must be one of 'prompt', 'local-first',"
|
||||||
" 'remote-first', 'no-delete'")
|
" 'remote-first', 'no-delete', 'no-delete-prompt-overwrite'")
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -231,7 +232,10 @@ class OutputDirectory:
|
|||||||
stat = local_path.stat()
|
stat = local_path.stat()
|
||||||
|
|
||||||
remote_newer = None
|
remote_newer = None
|
||||||
if mtime := heuristics.mtime:
|
|
||||||
|
# Python on Windows crashes when faced with timestamps around the unix epoch
|
||||||
|
if heuristics.mtime and (os.name != "nt" or heuristics.mtime.year > 1970):
|
||||||
|
mtime = heuristics.mtime
|
||||||
remote_newer = mtime.timestamp() > stat.st_mtime
|
remote_newer = mtime.timestamp() > stat.st_mtime
|
||||||
if remote_newer:
|
if remote_newer:
|
||||||
log.explain("Remote file seems to be newer")
|
log.explain("Remote file seems to be newer")
|
||||||
@ -261,7 +265,7 @@ class OutputDirectory:
|
|||||||
on_conflict: OnConflict,
|
on_conflict: OnConflict,
|
||||||
path: PurePath,
|
path: PurePath,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
if on_conflict == OnConflict.PROMPT:
|
if on_conflict in {OnConflict.PROMPT, OnConflict.NO_DELETE_PROMPT_OVERWRITE}:
|
||||||
async with log.exclusive_output():
|
async with log.exclusive_output():
|
||||||
prompt = f"Replace {fmt_path(path)} with remote file?"
|
prompt = f"Replace {fmt_path(path)} with remote file?"
|
||||||
return await prompt_yes_no(prompt, default=False)
|
return await prompt_yes_no(prompt, default=False)
|
||||||
@ -280,7 +284,7 @@ class OutputDirectory:
|
|||||||
on_conflict: OnConflict,
|
on_conflict: OnConflict,
|
||||||
path: PurePath,
|
path: PurePath,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
if on_conflict == OnConflict.PROMPT:
|
if on_conflict in {OnConflict.PROMPT, OnConflict.NO_DELETE_PROMPT_OVERWRITE}:
|
||||||
async with log.exclusive_output():
|
async with log.exclusive_output():
|
||||||
prompt = f"Recursively delete {fmt_path(path)} and replace with remote file?"
|
prompt = f"Recursively delete {fmt_path(path)} and replace with remote file?"
|
||||||
return await prompt_yes_no(prompt, default=False)
|
return await prompt_yes_no(prompt, default=False)
|
||||||
@ -300,7 +304,7 @@ class OutputDirectory:
|
|||||||
path: PurePath,
|
path: PurePath,
|
||||||
parent: PurePath,
|
parent: PurePath,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
if on_conflict == OnConflict.PROMPT:
|
if on_conflict in {OnConflict.PROMPT, OnConflict.NO_DELETE_PROMPT_OVERWRITE}:
|
||||||
async with log.exclusive_output():
|
async with log.exclusive_output():
|
||||||
prompt = f"Delete {fmt_path(parent)} so remote file {fmt_path(path)} can be downloaded?"
|
prompt = f"Delete {fmt_path(parent)} so remote file {fmt_path(path)} can be downloaded?"
|
||||||
return await prompt_yes_no(prompt, default=False)
|
return await prompt_yes_no(prompt, default=False)
|
||||||
@ -327,7 +331,7 @@ class OutputDirectory:
|
|||||||
return False
|
return False
|
||||||
elif on_conflict == OnConflict.REMOTE_FIRST:
|
elif on_conflict == OnConflict.REMOTE_FIRST:
|
||||||
return True
|
return True
|
||||||
elif on_conflict == OnConflict.NO_DELETE:
|
elif on_conflict in {OnConflict.NO_DELETE, OnConflict.NO_DELETE_PROMPT_OVERWRITE}:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# This should never be reached
|
# This should never be reached
|
||||||
@ -492,7 +496,7 @@ class OutputDirectory:
|
|||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
log.status("[bold bright_magenta]", "Not deleted", fmt_path(pure))
|
log.not_deleted("[bold bright_magenta]", "Not deleted", fmt_path(pure))
|
||||||
self._report.not_delete_file(pure)
|
self._report.not_delete_file(pure)
|
||||||
|
|
||||||
def load_prev_report(self) -> None:
|
def load_prev_report(self) -> None:
|
||||||
@ -500,7 +504,7 @@ class OutputDirectory:
|
|||||||
try:
|
try:
|
||||||
self._prev_report = Report.load(self._report_path)
|
self._prev_report = Report.load(self._report_path)
|
||||||
log.explain("Loaded report successfully")
|
log.explain("Loaded report successfully")
|
||||||
except (OSError, json.JSONDecodeError, ReportLoadError) as e:
|
except (OSError, UnicodeDecodeError, json.JSONDecodeError, ReportLoadError) as e:
|
||||||
log.explain("Failed to load report")
|
log.explain("Failed to load report")
|
||||||
log.explain(str(e))
|
log.explain(str(e))
|
||||||
|
|
||||||
|
@ -15,13 +15,13 @@ class PferdLoadError(Exception):
|
|||||||
|
|
||||||
|
|
||||||
class Pferd:
|
class Pferd:
|
||||||
def __init__(self, config: Config, cli_crawlers: Optional[List[str]]):
|
def __init__(self, config: Config, cli_crawlers: Optional[List[str]], cli_skips: Optional[List[str]]):
|
||||||
"""
|
"""
|
||||||
May throw PferdLoadError.
|
May throw PferdLoadError.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self._config = config
|
self._config = config
|
||||||
self._crawlers_to_run = self._find_crawlers_to_run(config, cli_crawlers)
|
self._crawlers_to_run = self._find_crawlers_to_run(config, cli_crawlers, cli_skips)
|
||||||
|
|
||||||
self._authenticators: Dict[str, Authenticator] = {}
|
self._authenticators: Dict[str, Authenticator] = {}
|
||||||
self._crawlers: Dict[str, Crawler] = {}
|
self._crawlers: Dict[str, Crawler] = {}
|
||||||
@ -65,16 +65,30 @@ class Pferd:
|
|||||||
|
|
||||||
return crawlers_to_run
|
return crawlers_to_run
|
||||||
|
|
||||||
def _find_crawlers_to_run(self, config: Config, cli_crawlers: Optional[List[str]]) -> List[str]:
|
def _find_crawlers_to_run(
|
||||||
|
self,
|
||||||
|
config: Config,
|
||||||
|
cli_crawlers: Optional[List[str]],
|
||||||
|
cli_skips: Optional[List[str]],
|
||||||
|
) -> List[str]:
|
||||||
log.explain_topic("Deciding which crawlers to run")
|
log.explain_topic("Deciding which crawlers to run")
|
||||||
|
|
||||||
|
crawlers: List[str]
|
||||||
if cli_crawlers is None:
|
if cli_crawlers is None:
|
||||||
log.explain("No crawlers specified on CLI")
|
log.explain("No crawlers specified on CLI")
|
||||||
log.explain("Running crawlers specified in config")
|
log.explain("Running crawlers specified in config")
|
||||||
return self._find_config_crawlers(config)
|
crawlers = self._find_config_crawlers(config)
|
||||||
else:
|
else:
|
||||||
log.explain("Crawlers specified on CLI")
|
log.explain("Crawlers specified on CLI")
|
||||||
return self._find_cli_crawlers(config, cli_crawlers)
|
crawlers = self._find_cli_crawlers(config, cli_crawlers)
|
||||||
|
|
||||||
|
skips = {f"crawl:{name}" for name in cli_skips} if cli_skips else set()
|
||||||
|
for crawler in crawlers:
|
||||||
|
if crawler in skips:
|
||||||
|
log.explain(f"Skipping crawler {crawler!r}")
|
||||||
|
crawlers = [crawler for crawler in crawlers if crawler not in skips]
|
||||||
|
|
||||||
|
return crawlers
|
||||||
|
|
||||||
def _load_authenticators(self) -> None:
|
def _load_authenticators(self) -> None:
|
||||||
for name, section in self._config.auth_sections():
|
for name, section in self._config.auth_sections():
|
||||||
@ -166,7 +180,15 @@ class Pferd:
|
|||||||
log.report(f" [bold bright_magenta]Deleted[/] {fmt_path(path)}")
|
log.report(f" [bold bright_magenta]Deleted[/] {fmt_path(path)}")
|
||||||
for path in sorted(crawler.report.not_deleted_files):
|
for path in sorted(crawler.report.not_deleted_files):
|
||||||
something_changed = True
|
something_changed = True
|
||||||
log.report(f" [bold bright_magenta]Not deleted[/] {fmt_path(path)}")
|
log.report_not_deleted(f" [bold bright_magenta]Not deleted[/] {fmt_path(path)}")
|
||||||
|
|
||||||
|
for warning in crawler.report.encountered_warnings:
|
||||||
|
something_changed = True
|
||||||
|
log.report(f" [bold bright_red]Warning[/] {warning}")
|
||||||
|
|
||||||
|
for error in crawler.report.encountered_errors:
|
||||||
|
something_changed = True
|
||||||
|
log.report(f" [bold bright_red]Error[/] {error}")
|
||||||
|
|
||||||
if not something_changed:
|
if not something_changed:
|
||||||
log.report(" Nothing changed")
|
log.report(" Nothing changed")
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
from pathlib import Path, PurePath
|
from pathlib import Path, PurePath
|
||||||
from typing import Any, Dict, List, Set
|
from typing import Any, Dict, List, Optional, Set
|
||||||
|
|
||||||
|
|
||||||
class ReportLoadError(Exception):
|
class ReportLoadError(Exception):
|
||||||
@ -68,6 +68,13 @@ class Report:
|
|||||||
# Files that should have been deleted by the cleanup but weren't
|
# Files that should have been deleted by the cleanup but weren't
|
||||||
self.not_deleted_files: Set[PurePath] = set()
|
self.not_deleted_files: Set[PurePath] = set()
|
||||||
|
|
||||||
|
# Custom crawler-specific data
|
||||||
|
self.custom: Dict[str, Any] = dict()
|
||||||
|
|
||||||
|
# Encountered errors and warnings
|
||||||
|
self.encountered_warnings: List[str] = []
|
||||||
|
self.encountered_errors: List[str] = []
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_list_of_strs(data: Dict[str, Any], key: str) -> List[str]:
|
def _get_list_of_strs(data: Dict[str, Any], key: str) -> List[str]:
|
||||||
result: Any = data.get(key, [])
|
result: Any = data.get(key, [])
|
||||||
@ -81,13 +88,22 @@ class Report:
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _get_str_dictionary(data: Dict[str, Any], key: str) -> Dict[str, Any]:
|
||||||
|
result: Dict[str, Any] = data.get(key, {})
|
||||||
|
|
||||||
|
if not isinstance(result, dict):
|
||||||
|
raise ReportLoadError(f"Incorrect format: {key!r} is not a dictionary")
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls, path: Path) -> "Report":
|
def load(cls, path: Path) -> "Report":
|
||||||
"""
|
"""
|
||||||
May raise OSError, JsonDecodeError, ReportLoadError.
|
May raise OSError, UnicodeDecodeError, JsonDecodeError, ReportLoadError.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with open(path) as f:
|
with open(path, encoding="utf-8") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
if not isinstance(data, dict):
|
if not isinstance(data, dict):
|
||||||
@ -108,6 +124,9 @@ class Report:
|
|||||||
self.delete_file(PurePath(elem))
|
self.delete_file(PurePath(elem))
|
||||||
for elem in self._get_list_of_strs(data, "not_deleted"):
|
for elem in self._get_list_of_strs(data, "not_deleted"):
|
||||||
self.not_delete_file(PurePath(elem))
|
self.not_delete_file(PurePath(elem))
|
||||||
|
self.custom = self._get_str_dictionary(data, "custom")
|
||||||
|
self.encountered_errors = self._get_list_of_strs(data, "encountered_errors")
|
||||||
|
self.encountered_warnings = self._get_list_of_strs(data, "encountered_warnings")
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@ -124,9 +143,12 @@ class Report:
|
|||||||
"changed": [str(path) for path in sorted(self.changed_files)],
|
"changed": [str(path) for path in sorted(self.changed_files)],
|
||||||
"deleted": [str(path) for path in sorted(self.deleted_files)],
|
"deleted": [str(path) for path in sorted(self.deleted_files)],
|
||||||
"not_deleted": [str(path) for path in sorted(self.not_deleted_files)],
|
"not_deleted": [str(path) for path in sorted(self.not_deleted_files)],
|
||||||
|
"custom": self.custom,
|
||||||
|
"encountered_warnings": self.encountered_warnings,
|
||||||
|
"encountered_errors": self.encountered_errors,
|
||||||
}
|
}
|
||||||
|
|
||||||
with open(path, "w") as f:
|
with open(path, "w", encoding="utf-8") as f:
|
||||||
json.dump(data, f, indent=2, sort_keys=True)
|
json.dump(data, f, indent=2, sort_keys=True)
|
||||||
f.write("\n") # json.dump doesn't do this
|
f.write("\n") # json.dump doesn't do this
|
||||||
|
|
||||||
@ -190,3 +212,27 @@ class Report:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
self.not_deleted_files.add(path)
|
self.not_deleted_files.add(path)
|
||||||
|
|
||||||
|
def add_custom_value(self, key: str, value: Any) -> None:
|
||||||
|
"""
|
||||||
|
Adds a custom value under the passed key, overwriting any existing
|
||||||
|
"""
|
||||||
|
self.custom[key] = value
|
||||||
|
|
||||||
|
def get_custom_value(self, key: str) -> Optional[Any]:
|
||||||
|
"""
|
||||||
|
Retrieves a custom value for the given key.
|
||||||
|
"""
|
||||||
|
return self.custom.get(key)
|
||||||
|
|
||||||
|
def add_error(self, error: str) -> None:
|
||||||
|
"""
|
||||||
|
Adds an error to this report's error list.
|
||||||
|
"""
|
||||||
|
self.encountered_errors.append(error)
|
||||||
|
|
||||||
|
def add_warning(self, warning: str) -> None:
|
||||||
|
"""
|
||||||
|
Adds a warning to this report's warning list.
|
||||||
|
"""
|
||||||
|
self.encountered_warnings.append(warning)
|
||||||
|
@ -41,9 +41,11 @@ TransformResult = Optional[Union[Transformed, Ignored]]
|
|||||||
@dataclass
|
@dataclass
|
||||||
class Rule:
|
class Rule:
|
||||||
left: str
|
left: str
|
||||||
|
left_index: int
|
||||||
name: str
|
name: str
|
||||||
head: ArrowHead
|
head: ArrowHead
|
||||||
right: RightSide
|
right: RightSide
|
||||||
|
right_index: int
|
||||||
|
|
||||||
def right_result(self, path: PurePath) -> Union[str, Transformed, Ignored]:
|
def right_result(self, path: PurePath) -> Union[str, Transformed, Ignored]:
|
||||||
if isinstance(self.right, str):
|
if isinstance(self.right, str):
|
||||||
@ -345,6 +347,7 @@ def parse_eol(line: Line) -> None:
|
|||||||
|
|
||||||
def parse_rule(line: Line) -> Rule:
|
def parse_rule(line: Line) -> Rule:
|
||||||
parse_zero_or_more_spaces(line)
|
parse_zero_or_more_spaces(line)
|
||||||
|
left_index = line.index
|
||||||
left = parse_left(line)
|
left = parse_left(line)
|
||||||
|
|
||||||
parse_one_or_more_spaces(line)
|
parse_one_or_more_spaces(line)
|
||||||
@ -354,19 +357,19 @@ def parse_rule(line: Line) -> Rule:
|
|||||||
line.expect("-")
|
line.expect("-")
|
||||||
head = parse_arrow_head(line)
|
head = parse_arrow_head(line)
|
||||||
|
|
||||||
index = line.index
|
right_index = line.index
|
||||||
right: RightSide
|
right: RightSide
|
||||||
try:
|
try:
|
||||||
parse_zero_or_more_spaces(line)
|
parse_zero_or_more_spaces(line)
|
||||||
parse_eol(line)
|
parse_eol(line)
|
||||||
right = Empty()
|
right = Empty()
|
||||||
except RuleParseError:
|
except RuleParseError:
|
||||||
line.index = index
|
line.index = right_index
|
||||||
parse_one_or_more_spaces(line)
|
parse_one_or_more_spaces(line)
|
||||||
right = parse_right(line)
|
right = parse_right(line)
|
||||||
parse_eol(line)
|
parse_eol(line)
|
||||||
|
|
||||||
return Rule(left, name, head, right)
|
return Rule(left, left_index, name, head, right, right_index)
|
||||||
|
|
||||||
|
|
||||||
def parse_transformation(line: Line) -> Transformation:
|
def parse_transformation(line: Line) -> Transformation:
|
||||||
@ -377,6 +380,9 @@ def parse_transformation(line: Line) -> Transformation:
|
|||||||
elif rule.name == "exact":
|
elif rule.name == "exact":
|
||||||
return ExactTf(rule)
|
return ExactTf(rule)
|
||||||
elif rule.name == "name":
|
elif rule.name == "name":
|
||||||
|
if len(PurePath(rule.left).parts) > 1:
|
||||||
|
line.index = rule.left_index
|
||||||
|
raise RuleParseError(line, "Expected name, not multiple segments")
|
||||||
return RenamingPartsTf(ExactTf(rule))
|
return RenamingPartsTf(ExactTf(rule))
|
||||||
elif rule.name == "re":
|
elif rule.name == "re":
|
||||||
return RenamingParentsTf(ExactReTf(rule))
|
return RenamingParentsTf(ExactReTf(rule))
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
NAME = "PFERD"
|
NAME = "PFERD"
|
||||||
VERSION = "3.1.0"
|
VERSION = "3.5.2"
|
||||||
|
13
README.md
13
README.md
@ -17,7 +17,7 @@ Binaries for Linux, Windows and Mac can be downloaded directly from the
|
|||||||
|
|
||||||
### With pip
|
### With pip
|
||||||
|
|
||||||
Ensure you have at least Python 3.8 installed. Run the following command to
|
Ensure you have at least Python 3.9 installed. Run the following command to
|
||||||
install PFERD or upgrade it to the latest version:
|
install PFERD or upgrade it to the latest version:
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -26,6 +26,17 @@ $ pip install --upgrade git+https://github.com/Garmelon/PFERD@latest
|
|||||||
|
|
||||||
The use of [venv](https://docs.python.org/3/library/venv.html) is recommended.
|
The use of [venv](https://docs.python.org/3/library/venv.html) is recommended.
|
||||||
|
|
||||||
|
### With package managers
|
||||||
|
|
||||||
|
Unofficial packages are available for:
|
||||||
|
- [AUR](https://aur.archlinux.org/packages/pferd)
|
||||||
|
- [brew](https://formulae.brew.sh/formula/pferd)
|
||||||
|
- [conda-forge](https://github.com/conda-forge/pferd-feedstock)
|
||||||
|
- [nixpkgs](https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/misc/pferd/default.nix)
|
||||||
|
- [PyPi](https://pypi.org/project/pferd)
|
||||||
|
|
||||||
|
See also PFERD's [repology page](https://repology.org/project/pferd/versions).
|
||||||
|
|
||||||
## Basic usage
|
## Basic usage
|
||||||
|
|
||||||
PFERD can be run directly from the command line with no config file. Run `pferd
|
PFERD can be run directly from the command line with no config file. Run `pferd
|
||||||
|
27
flake.lock
generated
Normal file
27
flake.lock
generated
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1708979614,
|
||||||
|
"narHash": "sha256-FWLWmYojIg6TeqxSnHkKpHu5SGnFP5um1uUjH+wRV6g=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "b7ee09cf5614b02d289cd86fcfa6f24d4e078c2a",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-23.11",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
41
flake.nix
Normal file
41
flake.nix
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
{
|
||||||
|
description = "Tool for downloading course-related files from ILIAS";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs }:
|
||||||
|
let
|
||||||
|
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
|
||||||
|
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
packages = forAllSystems (system:
|
||||||
|
let pkgs = import nixpkgs { inherit system; };
|
||||||
|
in
|
||||||
|
rec {
|
||||||
|
default = pkgs.python3Packages.buildPythonApplication rec {
|
||||||
|
pname = "pferd";
|
||||||
|
# Performing black magic
|
||||||
|
# Don't worry, I sacrificed enough goats for the next few years
|
||||||
|
version = (pkgs.lib.importTOML ./PFERD/version.py).VERSION;
|
||||||
|
format = "pyproject";
|
||||||
|
|
||||||
|
src = ./.;
|
||||||
|
|
||||||
|
nativeBuildInputs = with pkgs.python3Packages; [
|
||||||
|
setuptools
|
||||||
|
];
|
||||||
|
|
||||||
|
propagatedBuildInputs = with pkgs.python3Packages; [
|
||||||
|
aiohttp
|
||||||
|
beautifulsoup4
|
||||||
|
rich
|
||||||
|
keyring
|
||||||
|
certifi
|
||||||
|
];
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
12
setup.cfg
12
setup.cfg
@ -4,13 +4,13 @@ version = attr: PFERD.version.VERSION
|
|||||||
|
|
||||||
[options]
|
[options]
|
||||||
packages = find:
|
packages = find:
|
||||||
python_requires = >=3.8
|
python_requires = >=3.9
|
||||||
install_requires =
|
install_requires =
|
||||||
aiohttp>=3.7.4.post0
|
aiohttp>=3.8.1
|
||||||
beautifulsoup4>=4.9.3
|
beautifulsoup4>=4.10.0
|
||||||
rich>=10.1.0
|
rich>=11.0.0
|
||||||
keyring>=23.0.1
|
keyring>=23.5.0
|
||||||
certifi>=2020.12.5
|
certifi>=2021.10.8
|
||||||
|
|
||||||
[options.entry_points]
|
[options.entry_points]
|
||||||
console_scripts =
|
console_scripts =
|
||||||
|
Reference in New Issue
Block a user