2021-05-23 13:26:40 +02:00
|
|
|
import argparse
|
|
|
|
import configparser
|
|
|
|
from pathlib import Path
|
|
|
|
|
2021-05-25 11:58:41 +02:00
|
|
|
from ..crawl.ilias.file_templates import Links
|
2021-05-26 10:52:04 +02:00
|
|
|
from ..logging import log
|
2021-05-25 11:58:41 +02:00
|
|
|
from .parser import CRAWLER_PARSER, SUBPARSERS, BooleanOptionalAction, load_crawler, show_value_error
|
2021-05-23 13:26:40 +02:00
|
|
|
|
|
|
|
SUBPARSER = SUBPARSERS.add_parser(
|
|
|
|
"kit-ilias-web",
|
|
|
|
parents=[CRAWLER_PARSER],
|
|
|
|
)
|
|
|
|
|
|
|
|
GROUP = SUBPARSER.add_argument_group(
|
2021-05-25 14:12:19 +02:00
|
|
|
title="kit-ilias-web crawler arguments",
|
2021-05-23 13:26:40 +02:00
|
|
|
description="arguments for the 'kit-ilias-web' crawler",
|
|
|
|
)
|
|
|
|
GROUP.add_argument(
|
|
|
|
"target",
|
|
|
|
type=str,
|
|
|
|
metavar="TARGET",
|
2021-05-25 14:12:19 +02:00
|
|
|
help="course id, 'desktop', or ILIAS URL to crawl"
|
2021-05-23 13:26:40 +02:00
|
|
|
)
|
|
|
|
GROUP.add_argument(
|
|
|
|
"output",
|
|
|
|
type=Path,
|
|
|
|
metavar="OUTPUT",
|
|
|
|
help="output directory"
|
|
|
|
)
|
|
|
|
GROUP.add_argument(
|
2021-05-25 14:12:19 +02:00
|
|
|
"--username", "-u",
|
2021-05-23 13:26:40 +02:00
|
|
|
type=str,
|
2021-05-25 14:12:19 +02:00
|
|
|
metavar="USERNAME",
|
2021-05-23 13:26:40 +02:00
|
|
|
help="user name for authentication"
|
|
|
|
)
|
2021-05-23 23:04:18 +02:00
|
|
|
GROUP.add_argument(
|
|
|
|
"--keyring",
|
|
|
|
action=BooleanOptionalAction,
|
|
|
|
help="use the system keyring to store and retrieve passwords"
|
|
|
|
)
|
2021-05-25 11:58:41 +02:00
|
|
|
GROUP.add_argument(
|
|
|
|
"--links",
|
|
|
|
type=show_value_error(Links.from_string),
|
|
|
|
metavar="OPTION",
|
2021-05-25 14:12:19 +02:00
|
|
|
help="how to represent external links"
|
2021-05-25 11:58:41 +02:00
|
|
|
)
|
2021-05-23 13:26:40 +02:00
|
|
|
GROUP.add_argument(
|
2021-05-25 14:12:19 +02:00
|
|
|
"--link-redirect-delay",
|
2021-05-23 13:26:40 +02:00
|
|
|
type=int,
|
|
|
|
metavar="SECONDS",
|
2021-05-25 14:12:19 +02:00
|
|
|
help="time before 'fancy' links redirect to to their target (-1 to disable)"
|
|
|
|
)
|
|
|
|
GROUP.add_argument(
|
|
|
|
"--videos",
|
|
|
|
action=BooleanOptionalAction,
|
|
|
|
help="crawl and download videos"
|
2021-05-23 13:26:40 +02:00
|
|
|
)
|
2021-05-23 23:40:28 +02:00
|
|
|
GROUP.add_argument(
|
2021-05-25 14:12:19 +02:00
|
|
|
"--http-timeout", "-t",
|
2021-05-23 23:40:28 +02:00
|
|
|
type=float,
|
|
|
|
metavar="SECONDS",
|
2021-05-25 14:12:19 +02:00
|
|
|
help="timeout for all HTTP requests"
|
2021-05-23 23:40:28 +02:00
|
|
|
)
|
2021-05-23 13:26:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
def load(
|
|
|
|
args: argparse.Namespace,
|
|
|
|
parser: configparser.ConfigParser,
|
|
|
|
) -> None:
|
2021-05-26 10:52:04 +02:00
|
|
|
log.explain("Creating config for command 'kit-ilias-web'")
|
|
|
|
|
2021-05-25 14:12:19 +02:00
|
|
|
parser["crawl:ilias"] = {}
|
|
|
|
section = parser["crawl:ilias"]
|
2021-05-23 13:26:40 +02:00
|
|
|
load_crawler(args, section)
|
|
|
|
|
|
|
|
section["type"] = "kit-ilias-web"
|
|
|
|
section["target"] = str(args.target)
|
|
|
|
section["output_dir"] = str(args.output)
|
2021-05-25 14:12:19 +02:00
|
|
|
section["auth"] = "auth:ilias"
|
2021-05-25 11:58:41 +02:00
|
|
|
if args.links is not None:
|
|
|
|
section["links"] = str(args.links.value)
|
2021-05-25 14:12:19 +02:00
|
|
|
if args.link_redirect_delay is not None:
|
|
|
|
section["link_redirect_delay"] = str(args.link_redirect_delay)
|
2021-05-23 13:26:40 +02:00
|
|
|
if args.videos is not None:
|
2021-05-25 14:12:19 +02:00
|
|
|
section["videos"] = "yes" if args.videos else "no"
|
2021-05-23 23:40:28 +02:00
|
|
|
if args.http_timeout is not None:
|
|
|
|
section["http_timeout"] = str(args.http_timeout)
|
2021-05-23 13:26:40 +02:00
|
|
|
|
2021-05-25 14:12:19 +02:00
|
|
|
parser["auth:ilias"] = {}
|
|
|
|
auth_section = parser["auth:ilias"]
|
|
|
|
auth_section["type"] = "simple"
|
|
|
|
if args.username is not None:
|
|
|
|
auth_section["username"] = args.username
|
2021-05-23 23:04:18 +02:00
|
|
|
if args.keyring:
|
|
|
|
auth_section["type"] = "keyring"
|
2021-05-23 13:26:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
SUBPARSER.set_defaults(command=load)
|