mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
[sync_url] Sanitize path names on windows
This commit is contained in:
parent
9c4759103a
commit
f2aba970fd
16
sync_url.py
16
sync_url.py
@ -5,16 +5,27 @@ A simple script to download a course by name from ILIAS.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path, PurePath
|
||||
from typing import Optional
|
||||
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 re_rename
|
||||
from PFERD.utils import to_path
|
||||
|
||||
|
||||
def sanitize_path(path: PurePath) -> Optional[PurePath]:
|
||||
# Escape windows illegal path characters
|
||||
if os.name == 'nt':
|
||||
return PurePath(re.sub(r'[<>:"/\\|?]', "", str(path)))
|
||||
return path
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--test-run", action="store_true")
|
||||
@ -59,7 +70,8 @@ def main() -> None:
|
||||
target=folder,
|
||||
full_url=args.url,
|
||||
cookies=args.cookies,
|
||||
dir_filter=dir_filter
|
||||
dir_filter=dir_filter,
|
||||
transform=sanitize_path
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user