mirror of
https://github.com/Garmelon/PFERD.git
synced 2026-04-12 07:25:04 +02:00
Move "sanitize_windows_path" to PFERD.transform
This commit is contained in:
parent
98834c9c95
commit
cd90a60dee
2 changed files with 19 additions and 14 deletions
16
sync_url.py
16
sync_url.py
|
|
@ -5,27 +5,17 @@ A simple script to download a course by name from ILIAS.
|
|||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path, PurePath
|
||||
from typing import Optional
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from PFERD import Pferd
|
||||
from PFERD.cookie_jar import CookieJar
|
||||
from PFERD.ilias import (IliasCrawler, IliasElementType,
|
||||
KitShibbolethAuthenticator)
|
||||
from PFERD.transform import sanitize_windows_path
|
||||
from PFERD.utils import to_path
|
||||
|
||||
|
||||
def sanitize_path(path: PurePath) -> Optional[PurePath]:
|
||||
# Escape windows illegal path characters
|
||||
if os.name == 'nt':
|
||||
sanitized_parts = [re.sub(r'[<>:"/|?]', "_", x) for x in list(path.parts)]
|
||||
return PurePath(*sanitized_parts)
|
||||
return path
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--test-run", action="store_true")
|
||||
|
|
@ -71,7 +61,7 @@ def main() -> None:
|
|||
full_url=args.url,
|
||||
cookies=args.cookies,
|
||||
dir_filter=dir_filter,
|
||||
transform=sanitize_path
|
||||
transform=sanitize_windows_path
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue