mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
aba8d46d26 | |||
77056e6f8d | |||
064f12c14c | |||
2eb834afc3 | |||
d468a45662 | |||
50e25346e5 | |||
67da4e69fa | |||
da602366f8 | |||
2016f61bf8 | |||
59c278da2c | |||
c72e92db18 | |||
44b4204517 | |||
11b9ff66e4 | |||
d730d0064c | |||
ae6cc40fb5 | |||
0891e7f1bc | |||
571c2a6c98 | |||
2d7a2b2d53 | |||
8550d1101c | |||
fd71dc6f6e | |||
d48cbebbd4 | |||
bc018fffde | |||
9693e1d968 | |||
5e9ecd3ce1 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,3 +10,4 @@ pyvenv.cfg
|
||||
|
||||
.tmp/
|
||||
pip-selfcheck.json
|
||||
.mypy_cache/
|
||||
|
@ -1,12 +1,37 @@
|
||||
import logging
|
||||
|
||||
from .ffm import *
|
||||
from .ilias import *
|
||||
from .norbert import *
|
||||
from .ti import *
|
||||
from .utils import *
|
||||
|
||||
__all__ = []
|
||||
__all__ = ["STYLE", "FORMAT", "DATE_FORMAT", "FORMATTER", "enable_logging"]
|
||||
|
||||
__all__ += ffm.__all__
|
||||
__all__ += ilias.__all__
|
||||
__all__ += norbert.__all__
|
||||
__all__ += ti.__all__
|
||||
__all__ += utils.__all__
|
||||
|
||||
LOG_FORMAT = "[%(levelname)s] %(message)s"
|
||||
STYLE = "{"
|
||||
FORMAT = "[{levelname:<7}] {message}"
|
||||
DATE_FORMAT = "%F %T"
|
||||
|
||||
FORMATTER = logging.Formatter(
|
||||
fmt=FORMAT,
|
||||
datefmt=DATE_FORMAT,
|
||||
style=STYLE,
|
||||
)
|
||||
|
||||
def enable_logging(name="PFERD", level=logging.INFO):
|
||||
handler = logging.StreamHandler()
|
||||
handler.setFormatter(FORMATTER)
|
||||
|
||||
logger = logging.getLogger(name)
|
||||
logger.setLevel(level)
|
||||
logger.addHandler(handler)
|
||||
|
||||
# This should be logged by our own handler, and not the root logger's
|
||||
# default handler, so we don't pass it on to the root logger.
|
||||
logger.propagate = False
|
||||
|
@ -8,10 +8,11 @@ import bs4
|
||||
import requests
|
||||
|
||||
from .organizer import Organizer
|
||||
from .utils import stream_to_path
|
||||
from .utils import stream_to_path, PrettyLogger
|
||||
|
||||
__all__ = ["FfM"]
|
||||
logger = logging.getLogger(__name__)
|
||||
pretty = PrettyLogger(logger)
|
||||
|
||||
class FfM:
|
||||
BASE_URL = "http://www.math.kit.edu/"
|
||||
@ -23,7 +24,7 @@ class FfM:
|
||||
self._session = requests.Session()
|
||||
|
||||
def synchronize(self, urlpart, to_dir, transform=lambda x: x):
|
||||
logging.info(f" Synchronizing {urlpart} to {to_dir} using the FfM synchronizer.")
|
||||
pretty.starting_synchronizer(to_dir, "FfM", urlpart)
|
||||
|
||||
sync_path = pathlib.Path(self.base_path, to_dir)
|
||||
|
||||
|
@ -4,15 +4,15 @@ import logging
|
||||
import pathlib
|
||||
import re
|
||||
|
||||
import bs4
|
||||
|
||||
from .ilias_authenticators import ShibbolethAuthenticator
|
||||
from .organizer import Organizer
|
||||
from .utils import PrettyLogger
|
||||
|
||||
__all__ = ["ILIAS"]
|
||||
__all__ = ["Ilias"]
|
||||
logger = logging.getLogger(__name__)
|
||||
pretty = PrettyLogger(logger)
|
||||
|
||||
class ILIAS:
|
||||
class Ilias:
|
||||
FILE_RE = re.compile(r"goto\.php\?target=(file_\d+_download)")
|
||||
DIR_RE = re.compile(r"ilias\.php\?ref_id=(\d+)")
|
||||
|
||||
@ -22,7 +22,7 @@ class ILIAS:
|
||||
self._auth = ShibbolethAuthenticator(base_path / cookie_file)
|
||||
|
||||
def synchronize(self, ref_id, to_dir, transform=lambda x: x, filter=lambda x: True):
|
||||
logging.info(f" Synchronizing ref_id {ref_id} to {to_dir} using the ILIAS synchronizer.")
|
||||
pretty.starting_synchronizer(to_dir, "ILIAS", f"ref_id {ref_id}")
|
||||
|
||||
sync_path = pathlib.Path(self.base_path, to_dir)
|
||||
orga = Organizer(self.base_path, sync_path)
|
||||
|
@ -27,7 +27,11 @@ class ShibbolethAuthenticator:
|
||||
"application/pdf",
|
||||
"application/zip",
|
||||
"application/msword",
|
||||
"application/vnd.wolfram.nb",
|
||||
"application/octet-stream",
|
||||
"application/excel",
|
||||
"text/xml",
|
||||
"text/xml;charset=UTF-8",
|
||||
"text/plain",
|
||||
"image/jpeg",
|
||||
"image/png",
|
||||
|
@ -9,12 +9,11 @@ import bs4
|
||||
import requests
|
||||
|
||||
from .organizer import Organizer
|
||||
from .utils import rename, stream_to_path
|
||||
from .utils import rename, stream_to_path, PrettyLogger
|
||||
|
||||
__all__ = [
|
||||
"Norbert",
|
||||
]
|
||||
__all__ = ["Norbert"]
|
||||
logger = logging.getLogger(__name__)
|
||||
pretty = PrettyLogger(logger)
|
||||
|
||||
class Norbert:
|
||||
BASE_URL = "https://studwww.informatik.kit.edu/~s_blueml/"
|
||||
@ -26,7 +25,7 @@ class Norbert:
|
||||
self._session = requests.Session()
|
||||
|
||||
def synchronize(self, to_dir, transform=lambda x: x, unzip=lambda _: True):
|
||||
logging.info(f" Synchronizing to {to_dir} using the Norbert synchronizer.")
|
||||
pretty.starting_synchronizer(to_dir, "Norbert")
|
||||
|
||||
sync_path = pathlib.Path(self.base_path, to_dir)
|
||||
orga = Organizer(self.base_path, sync_path)
|
||||
|
@ -7,6 +7,7 @@ from . import utils
|
||||
|
||||
__all__ = ["Organizer"]
|
||||
logger = logging.getLogger(__name__)
|
||||
pretty = utils.PrettyLogger(logger)
|
||||
|
||||
class Organizer:
|
||||
def __init__(self, base_dir, sync_dir):
|
||||
@ -64,7 +65,7 @@ class Organizer:
|
||||
|
||||
if to_path.exists():
|
||||
if filecmp.cmp(from_path, to_path, shallow=False):
|
||||
logger.info(f"Ignored {to_path}")
|
||||
pretty.ignored_file(to_path)
|
||||
|
||||
# remember path for later reference
|
||||
self._added_files.add(to_path.resolve())
|
||||
@ -73,9 +74,9 @@ class Organizer:
|
||||
# No further action needed, especially not overwriting symlinks...
|
||||
return
|
||||
else:
|
||||
logger.info(f"Different file at {to_path}")
|
||||
pretty.modified_file(to_path)
|
||||
else:
|
||||
logger.info(f"New file at {to_path}")
|
||||
pretty.new_file(to_path)
|
||||
|
||||
# copy the file from from_path to sync_dir/to_path
|
||||
# If the file being replaced was a symlink, the link itself is overwritten,
|
||||
|
111
PFERD/ti.py
Normal file
111
PFERD/ti.py
Normal file
@ -0,0 +1,111 @@
|
||||
# Fakultät für Mathematik (FfM)
|
||||
|
||||
import getpass
|
||||
import logging
|
||||
import pathlib
|
||||
import re
|
||||
|
||||
import bs4
|
||||
import requests
|
||||
|
||||
from .organizer import Organizer
|
||||
from .utils import stream_to_path, PrettyLogger
|
||||
|
||||
__all__ = ["Ti"]
|
||||
logger = logging.getLogger(__name__)
|
||||
pretty = PrettyLogger(logger)
|
||||
|
||||
class Ti:
|
||||
BASE_URL = "http://ti.ira.uka.de/"
|
||||
FILE_RE = re.compile(r"^.+\.pdf$")
|
||||
|
||||
def __init__(self, base_path):
|
||||
self.base_path = base_path
|
||||
|
||||
self._session = requests.Session()
|
||||
self._credentials = None
|
||||
|
||||
def synchronize(self, urlpart, to_dir, transform=lambda x: x,
|
||||
filter=lambda x: True):
|
||||
pretty.starting_synchronizer(to_dir, "Ti", urlpart)
|
||||
|
||||
sync_path = pathlib.Path(self.base_path, to_dir)
|
||||
|
||||
orga = Organizer(self.base_path, sync_path)
|
||||
orga.clean_temp_dir()
|
||||
|
||||
self._reset_credentials()
|
||||
|
||||
available = self._find_available(urlpart)
|
||||
|
||||
for name, address in sorted(available.items()):
|
||||
path = pathlib.PurePath(name)
|
||||
if filter(path):
|
||||
self._crawl(urlpart + address, path, orga, transform)
|
||||
else:
|
||||
loggwe.info(f"Skipping {name}/")
|
||||
|
||||
orga.clean_sync_dir()
|
||||
orga.clean_temp_dir()
|
||||
|
||||
self._reset_credentials()
|
||||
|
||||
def _find_available(self, urlpart):
|
||||
url = self.BASE_URL + urlpart
|
||||
r = self._session.get(url)
|
||||
soup = bs4.BeautifulSoup(r.text, "html.parser")
|
||||
|
||||
available = {}
|
||||
|
||||
if soup.find(href="./Vorlesung/Vorlesung.php"):
|
||||
logger.info("Found Folien/")
|
||||
available["Folien"] = "/Vorlesung/"
|
||||
if soup.find(href="./Uebungen/Uebungen.php"):
|
||||
logger.info("Found Blätter/")
|
||||
available["Blätter"] = "/Uebungen/"
|
||||
if soup.find(href="./Tutorien/Tutorien.php"):
|
||||
logger.info("Found Tutorien/")
|
||||
available["Tutorien"] = "/Tutorien/"
|
||||
|
||||
return available
|
||||
|
||||
def _crawl(self, urlpart, path, orga, transform):
|
||||
url = self.BASE_URL + urlpart
|
||||
r = self._session.get(url)
|
||||
soup = bs4.BeautifulSoup(r.text, "html.parser")
|
||||
|
||||
for filelink in soup.find_all("a", href=self.FILE_RE):
|
||||
filepath = path / filelink["href"]
|
||||
fileurl = url + "/" + filelink["href"]
|
||||
|
||||
new_path = transform(filepath)
|
||||
if new_path is None:
|
||||
continue
|
||||
logger.debug(f"Transformed from {filepath} to {new_path}")
|
||||
|
||||
temp_path = orga.temp_file()
|
||||
self._download(fileurl, temp_path)
|
||||
orga.add_file(temp_path, new_path)
|
||||
|
||||
|
||||
def _get_credentials(self):
|
||||
if self._credentials is None:
|
||||
print("Please enter Ti credentials.")
|
||||
username = getpass.getpass(prompt="Username: ")
|
||||
password = getpass.getpass(prompt="Password: ")
|
||||
self._credentials = (username, password)
|
||||
return self._credentials
|
||||
|
||||
def _reset_credentials(self):
|
||||
self._credentials = None
|
||||
|
||||
def _download(self, url, to_path):
|
||||
while True:
|
||||
username, password = self._get_credentials()
|
||||
with self._session.get(url, stream=True, auth=(username, password)) as r:
|
||||
if r.ok:
|
||||
stream_to_path(r, to_path)
|
||||
return
|
||||
else:
|
||||
print("Incorrect credentials.")
|
||||
self._reset_credentials()
|
@ -1,5 +1,8 @@
|
||||
import os
|
||||
import sys
|
||||
import pathlib
|
||||
from colorama import Style
|
||||
from colorama import Fore
|
||||
|
||||
__all__ = [
|
||||
"get_base_dir",
|
||||
@ -8,6 +11,7 @@ __all__ = [
|
||||
"stream_to_path",
|
||||
"ContentTypeException",
|
||||
"FileNotFoundException",
|
||||
"PrettyLogger",
|
||||
]
|
||||
|
||||
def get_base_dir(script_file):
|
||||
@ -26,8 +30,35 @@ def stream_to_path(response, to_path, chunk_size=1024**2):
|
||||
for chunk in response.iter_content(chunk_size=chunk_size):
|
||||
fd.write(chunk)
|
||||
|
||||
def isOutputPipe():
|
||||
"""Returns whether this program's output is attached to a pipe.
|
||||
"""
|
||||
return sys.stdout.isatty
|
||||
|
||||
class ContentTypeException(Exception):
|
||||
pass
|
||||
|
||||
class FileNotFoundException(Exception):
|
||||
pass
|
||||
|
||||
class PrettyLogger:
|
||||
|
||||
def __init__(self, logger):
|
||||
self.logger = logger
|
||||
|
||||
def modified_file(self, file_name):
|
||||
self.logger.info(f"{Fore.MAGENTA}{Style.BRIGHT}Modified {file_name}.{Style.RESET_ALL}")
|
||||
|
||||
def new_file(self, file_name):
|
||||
self.logger.info(f"{Fore.GREEN}{Style.BRIGHT}Created {file_name}.{Style.RESET_ALL}")
|
||||
|
||||
def ignored_file(self, file_name):
|
||||
self.logger.info(f"{Style.DIM}Ignored {file_name}.{Style.RESET_ALL}")
|
||||
|
||||
def starting_synchronizer(self, target_directory, synchronizer_name, subject=None):
|
||||
subject_str = f"{subject} " if subject else ""
|
||||
self.logger.info("")
|
||||
self.logger.info((
|
||||
f"{Fore.CYAN}{Style.BRIGHT}Synchronizing {subject_str}to {target_directory}"
|
||||
f" using the {synchronizer_name} synchronizer.{Style.RESET_ALL}"
|
||||
))
|
||||
|
36
README.md
36
README.md
@ -1,12 +1,40 @@
|
||||
# PFERD (**P**rogramm **F**ür's **E**infache **R**unterladen von **D**ateien)
|
||||
# PFERD
|
||||
|
||||
**P**rogramm zum **F**lotten, **E**infachen **R**unterladen von **D**ateien
|
||||
|
||||
## Installation
|
||||
|
||||
Ensure that you have at least Python 3.7 installed.
|
||||
Ensure that you have at least Python 3.7 installed (3.6 might also work, didn't
|
||||
test it though).
|
||||
|
||||
To install PFERD or update your installation to the latest version, run:
|
||||
To install PFERD or update your installation to the latest version, run this
|
||||
wherever you want to install/have installed PFERD:
|
||||
```
|
||||
$ pip install git+https://github.com/Garmelon/PFERD@v0.1.0
|
||||
$ pip install git+https://github.com/Garmelon/PFERD@v1.1.5
|
||||
```
|
||||
|
||||
The use of [venv](https://docs.python.org/3/library/venv.html) is recommended.
|
||||
|
||||
## Example setup
|
||||
|
||||
In this example, `python3` refers to at least Python 3.7.
|
||||
|
||||
A full example setup and initial use could look like:
|
||||
```
|
||||
$ mkdir Vorlesungen
|
||||
$ cd Vorlesungen
|
||||
$ python3 -m venv .
|
||||
$ . bin/activate
|
||||
$ pip install git+https://github.com/Garmelon/PFERD@v1.1.5
|
||||
$ curl -O https://raw.githubusercontent.com/Garmelon/PFERD/master/example_config.py
|
||||
$ python3 example_config.py
|
||||
$ deactivate
|
||||
```
|
||||
|
||||
Subsequent runs of the program might look like:
|
||||
```
|
||||
$ cd Vorlesungen
|
||||
$ . bin/activate
|
||||
$ python3 example_config.py
|
||||
$ deactivate
|
||||
```
|
||||
|
@ -1,15 +1,15 @@
|
||||
#!/bin/env python3
|
||||
|
||||
import PFERD
|
||||
import asyncio
|
||||
import logging
|
||||
import pathlib
|
||||
import re
|
||||
import sys
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format=PFERD.LOG_FORMAT)
|
||||
import PFERD
|
||||
from PFERD.utils import get_base_dir, move, rename
|
||||
|
||||
base_dir = PFERD.get_base_dir(__file__)
|
||||
#PFERD.enable_logging(logging.DEBUG)
|
||||
PFERD.enable_logging()
|
||||
|
||||
base_dir = get_base_dir(__file__)
|
||||
|
||||
# Semester 1
|
||||
|
||||
@ -24,44 +24,44 @@ def gbi_filter(path):
|
||||
|
||||
def gbi_transform(path):
|
||||
# Übungsblätter in Blätter/blatt_xx.pdf
|
||||
new_path = PFERD.move(path, ("Übungsblätter",), ("Blätter",))
|
||||
new_path = move(path, ("Übungsblätter",), ("Blätter",))
|
||||
if new_path is not None:
|
||||
|
||||
match = re.match(r"(\d+).aufgaben.pdf", new_path.name)
|
||||
if match:
|
||||
number = int(match.group(1))
|
||||
return PFERD.rename(new_path, f"blatt_{number:02}.pdf")
|
||||
return rename(new_path, f"blatt_{number:02}.pdf")
|
||||
|
||||
match = re.match(r"(\d+).loesungen.pdf", new_path.name)
|
||||
if match:
|
||||
number = int(match.group(1))
|
||||
return PFERD.rename(new_path, f"loesung_{number:02}.pdf")
|
||||
return rename(new_path, f"loesung_{number:02}.pdf")
|
||||
|
||||
return new_path
|
||||
|
||||
# Folien in Folien/*
|
||||
new_path = PFERD.move(path, ("Vorlesung: Folien",), ("Folien",))
|
||||
new_path = move(path, ("Vorlesung: Folien",), ("Folien",))
|
||||
if new_path is not None: return new_path
|
||||
|
||||
# Skripte in Skripte/*
|
||||
new_path = PFERD.move(path, ("Vorlesung: Skript",), ("Skripte",))
|
||||
new_path = move(path, ("Vorlesung: Skript",), ("Skripte",))
|
||||
if new_path is not None:
|
||||
if new_path.name == "k-21-relationen-skript.pdf":
|
||||
return PFERD.rename(new_path, "21-relationen-skript.pdf")
|
||||
return rename(new_path, "21-relationen-skript.pdf")
|
||||
|
||||
return new_path
|
||||
|
||||
# Übungsfolien in Übung/*
|
||||
new_path = PFERD.move(path, ("große Übung: Folien",), ("Übung",))
|
||||
new_path = move(path, ("große Übung: Folien",), ("Übung",))
|
||||
if new_path is not None: return new_path
|
||||
|
||||
# Tutoriumsfolien in Tutorium/*
|
||||
new_path = PFERD.move(path, ("Tutoriumsfolien","Tutorium 15"), ("Tutorium",))
|
||||
new_path = move(path, ("Tutoriumsfolien","Tutorium 15"), ("Tutorium",))
|
||||
if new_path is not None:
|
||||
if new_path.name == "GBI_Tut_2 (1).pdf":
|
||||
return PFERD.rename(new_path, "GBI_Tut_2.pdf")
|
||||
return rename(new_path, "GBI_Tut_2.pdf")
|
||||
if new_path.name == "GBI_Tut_7 (1).pdf":
|
||||
return PFERD.rename(new_path, "GBI_Tut_7.pdf")
|
||||
return rename(new_path, "GBI_Tut_7.pdf")
|
||||
|
||||
return new_path
|
||||
|
||||
@ -70,15 +70,15 @@ def gbi_transform(path):
|
||||
def hm1_transform(path):
|
||||
match = re.match(r"blatt(\d+).pdf", path.name)
|
||||
if match:
|
||||
new_path = PFERD.move(path, (), ("Blätter",))
|
||||
new_path = move(path, (), ("Blätter",))
|
||||
number = int(match.group(1))
|
||||
return PFERD.rename(new_path, f"blatt_{number:02}.pdf")
|
||||
return rename(new_path, f"blatt_{number:02}.pdf")
|
||||
|
||||
match = re.match(r"blatt(\d+).loesungen.pdf", path.name)
|
||||
if match:
|
||||
new_path = PFERD.move(path, (), ("Blätter",))
|
||||
new_path = move(path, (), ("Blätter",))
|
||||
number = int(match.group(1))
|
||||
return PFERD.rename(new_path, f"loesung_{number:02}.pdf")
|
||||
return rename(new_path, f"loesung_{number:02}.pdf")
|
||||
|
||||
return path
|
||||
|
||||
@ -95,82 +95,82 @@ def la1_filter(path):
|
||||
def la1_transform(path):
|
||||
# Alle Übungsblätter in Blätter/blatt_xx.pdf
|
||||
# Alles andere Übungsmaterial in Blätter/*
|
||||
new_path = PFERD.move(path, ("Übungen",), ("Blätter",))
|
||||
new_path = move(path, ("Übungen",), ("Blätter",))
|
||||
if new_path is not None:
|
||||
|
||||
match = re.match(r"Blatt(\d+).pdf", new_path.name)
|
||||
if match:
|
||||
number = int(match.group(1))
|
||||
return PFERD.rename(new_path, f"blatt_{number:02}.pdf")
|
||||
return rename(new_path, f"blatt_{number:02}.pdf")
|
||||
|
||||
if new_path.name == "Lösungen zu Blatt 1, Aufgabe 1 und Blatt 2, Aufgabe 4..pdf":
|
||||
return PFERD.rename(new_path, "Lösungen zu Blatt 1, Aufgabe 1 und Blatt 2, Aufgabe 4.pdf")
|
||||
return rename(new_path, "Lösungen zu Blatt 1, Aufgabe 1 und Blatt 2, Aufgabe 4.pdf")
|
||||
|
||||
return new_path
|
||||
|
||||
# Alles Tutoriengedöns von Philipp in Tutorium/Philipp/*
|
||||
new_path = PFERD.move(path, ("Tutorien","Tutorium 03 - Philipp Faller"), ("Tutorium","Philipp"))
|
||||
new_path = move(path, ("Tutorien","Tutorium 03 - Philipp Faller"), ("Tutorium","Philipp"))
|
||||
if new_path is not None:
|
||||
if new_path.name == "tut2.pdf":
|
||||
return PFERD.rename(new_path, "Tut2.pdf")
|
||||
return rename(new_path, "Tut2.pdf")
|
||||
|
||||
return new_path
|
||||
|
||||
# Alles Tutoriengedöns von Sebastian in Tutorium/Sebastian/*
|
||||
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 1"), ("Tutorium","Sebastian", "tut01"))
|
||||
new_path = move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 1"), ("Tutorium","Sebastian", "tut01"))
|
||||
if new_path is not None: return new_path
|
||||
|
||||
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 2", "aufgaben.pdf"), ("Tutorium","Sebastian", "tut02.pdf"))
|
||||
new_path = move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 2", "aufgaben.pdf"), ("Tutorium","Sebastian", "tut02.pdf"))
|
||||
if new_path is not None: return new_path
|
||||
|
||||
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 3", "aufgaben.pdf"), ("Tutorium","Sebastian", "tut03.pdf"))
|
||||
new_path = move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 3", "aufgaben.pdf"), ("Tutorium","Sebastian", "tut03.pdf"))
|
||||
if new_path is not None: return new_path
|
||||
|
||||
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 4", "aufgaben.pdf"), ("Tutorium","Sebastian", "tut04.pdf"))
|
||||
new_path = move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 4", "aufgaben.pdf"), ("Tutorium","Sebastian", "tut04.pdf"))
|
||||
if new_path is not None: return new_path
|
||||
|
||||
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 5", "aufgaben.pdf"), ("Tutorium","Sebastian", "tut05.pdf"))
|
||||
new_path = move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 5", "aufgaben.pdf"), ("Tutorium","Sebastian", "tut05.pdf"))
|
||||
if new_path is not None: return new_path
|
||||
|
||||
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 6", "aufgaben.pdf"), ("Tutorium","Sebastian", "tut06.pdf"))
|
||||
new_path = move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 6", "aufgaben.pdf"), ("Tutorium","Sebastian", "tut06.pdf"))
|
||||
if new_path is not None: return new_path
|
||||
|
||||
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 7", "tut7.pdf"), ("Tutorium","Sebastian", "tut07.pdf"))
|
||||
new_path = move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 7", "tut7.pdf"), ("Tutorium","Sebastian", "tut07.pdf"))
|
||||
if new_path is not None: return new_path
|
||||
|
||||
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 8", "tut8.pdf"), ("Tutorium","Sebastian", "tut08.pdf"))
|
||||
new_path = move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 8", "tut8.pdf"), ("Tutorium","Sebastian", "tut08.pdf"))
|
||||
if new_path is not None: return new_path
|
||||
|
||||
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 9", "tut9.pdf"), ("Tutorium","Sebastian", "tut09.pdf"))
|
||||
new_path = move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 9", "tut9.pdf"), ("Tutorium","Sebastian", "tut09.pdf"))
|
||||
if new_path is not None: return new_path
|
||||
|
||||
if path.parts == ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 10", "tut10.pdf"): return None
|
||||
|
||||
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller"), ("Tutorium","Sebastian"))
|
||||
new_path = move(path, ("Tutorien","Tutorium 23 - Sebastian Faller"), ("Tutorium","Sebastian"))
|
||||
if new_path is not None:
|
||||
return new_path
|
||||
|
||||
# Übungs-Gedöns in Übung/*
|
||||
new_path = PFERD.move(path, ("Informatikervorlesung", "Übungsfolien"), ("Übung",))
|
||||
new_path = move(path, ("Informatikervorlesung", "Übungsfolien"), ("Übung",))
|
||||
if new_path is not None:
|
||||
if new_path.name == "Übung_06_ausgewählte Folien.pdf":
|
||||
return PFERD.rename(new_path, "Übung_06_ausgewählte_Folien.pdf")
|
||||
return rename(new_path, "Übung_06_ausgewählte_Folien.pdf")
|
||||
|
||||
return new_path
|
||||
|
||||
# Vorlesungsfolien-Gedöns in Folien/*
|
||||
new_path = PFERD.move(path, ("Informatikervorlesung", "Folien.Notizen"), ("Folien",))
|
||||
new_path = move(path, ("Informatikervorlesung", "Folien.Notizen"), ("Folien",))
|
||||
if new_path is not None:
|
||||
return new_path
|
||||
|
||||
# Rest in Hauptverzeichnis
|
||||
new_path = PFERD.move(path, ("Informatikervorlesung",), ())
|
||||
new_path = move(path, ("Informatikervorlesung",), ())
|
||||
if new_path is not None:
|
||||
# Rename filenames that are invalid on FAT systems
|
||||
if new_path.name == "Evaluationsergebnisse: Übung.pdf":
|
||||
return PFERD.rename(new_path, "Evaluationsergebnisse_Übung.pdf")
|
||||
return rename(new_path, "Evaluationsergebnisse_Übung.pdf")
|
||||
if new_path.name == "Skript \"Lineare Algebra\" von Stefan Kühnlein.pdf":
|
||||
return PFERD.rename(new_path, "Skript Lineare Algebra von Stefan kühnlein.pdf")
|
||||
return rename(new_path, "Skript Lineare Algebra von Stefan kühnlein.pdf")
|
||||
|
||||
return new_path
|
||||
|
||||
@ -184,24 +184,24 @@ def prog_filter(path):
|
||||
|
||||
def prog_transform(path):
|
||||
# Übungsblätter in Blätter/*
|
||||
new_path = PFERD.move(path, ("Übungen",), ("Blätter",))
|
||||
new_path = move(path, ("Übungen",), ("Blätter",))
|
||||
if new_path is not None:
|
||||
if new_path.name == "assignmen04.pdf":
|
||||
return PFERD.rename(new_path, "assignment04.pdf")
|
||||
return rename(new_path, "assignment04.pdf")
|
||||
|
||||
return new_path
|
||||
|
||||
# Folien in Folien/*
|
||||
new_path = PFERD.move(path, ("Vorlesungsmaterial",), ("Folien",))
|
||||
new_path = move(path, ("Vorlesungsmaterial",), ("Folien",))
|
||||
if new_path is not None:
|
||||
if new_path.name == "00.1_Begruessung.pdf":
|
||||
return PFERD.rename(new_path, "00-01_Begruessung.pdf")
|
||||
return rename(new_path, "00-01_Begruessung.pdf")
|
||||
if new_path.name == "00.2_Organisatorisches.pdf":
|
||||
return PFERD.rename(new_path, "00-02_Organisatorisches.pdf")
|
||||
return rename(new_path, "00-02_Organisatorisches.pdf")
|
||||
if new_path.name == "01-01_ Einfache-Programme.pdf":
|
||||
return PFERD.rename(new_path, "01-01_Einfache_Programme.pdf")
|
||||
return rename(new_path, "01-01_Einfache_Programme.pdf")
|
||||
if new_path.name == "13_Finden_und_ Beheben_von_Fehlern.pdf":
|
||||
return PFERD.rename(new_path, "13_Finden_und_Beheben_von_Fehlern.pdf")
|
||||
return rename(new_path, "13_Finden_und_Beheben_von_Fehlern.pdf")
|
||||
|
||||
return new_path
|
||||
|
||||
@ -220,7 +220,7 @@ def algo1_filter(path):
|
||||
|
||||
def algo1_transform(path):
|
||||
# Folien in Folien/*
|
||||
new_path = PFERD.move(path, ("Vorlesungsfolien",), ("Folien",))
|
||||
new_path = move(path, ("Vorlesungsfolien",), ("Folien",))
|
||||
if new_path is not None:
|
||||
return new_path
|
||||
|
||||
@ -229,15 +229,15 @@ def algo1_transform(path):
|
||||
def hm2_transform(path):
|
||||
match = re.match(r"blatt(\d+).pdf", path.name)
|
||||
if match:
|
||||
new_path = PFERD.move(path, (), ("Blätter",))
|
||||
new_path = move(path, (), ("Blätter",))
|
||||
number = int(match.group(1))
|
||||
return PFERD.rename(new_path, f"blatt_{number:02}.pdf")
|
||||
return rename(new_path, f"blatt_{number:02}.pdf")
|
||||
|
||||
match = re.match(r"blatt(\d+).loesungen.pdf", path.name)
|
||||
if match:
|
||||
new_path = PFERD.move(path, (), ("Blätter",))
|
||||
new_path = move(path, (), ("Blätter",))
|
||||
number = int(match.group(1))
|
||||
return PFERD.rename(new_path, f"loesung_{number:02}.pdf")
|
||||
return rename(new_path, f"loesung_{number:02}.pdf")
|
||||
|
||||
return path
|
||||
|
||||
@ -252,18 +252,18 @@ def la2_filter(path):
|
||||
|
||||
def la2_transform(path):
|
||||
# Folien in Folien/*
|
||||
new_path = PFERD.move(path, ("Vorlesungsmaterial",), ("Folien",))
|
||||
new_path = move(path, ("Vorlesungsmaterial",), ("Folien",))
|
||||
if new_path is not None: return new_path
|
||||
|
||||
# Alle Übungsblätter in Blätter/blatt_xx.pdf
|
||||
# Alles andere Übungsmaterial in Blätter/*
|
||||
new_path = PFERD.move(path, ("Übungen",), ("Blätter",))
|
||||
new_path = move(path, ("Übungen",), ("Blätter",))
|
||||
if new_path is not None:
|
||||
|
||||
match = re.match(r"Blatt(\d+).pdf", new_path.name)
|
||||
if match:
|
||||
number = int(match.group(1))
|
||||
return PFERD.rename(new_path, f"blatt_{number:02}.pdf")
|
||||
return rename(new_path, f"blatt_{number:02}.pdf")
|
||||
|
||||
return new_path
|
||||
|
||||
@ -280,50 +280,63 @@ def swt1_filter(path):
|
||||
|
||||
def swt1_transform(path):
|
||||
# Folien in Folien/*
|
||||
new_path = PFERD.move(path, ("Vorlesungsmaterial",), ("Folien",))
|
||||
new_path = move(path, ("Vorlesungsmaterial",), ("Folien",))
|
||||
if new_path is not None: return new_path
|
||||
|
||||
# Übungsblätter in Blätter/*
|
||||
new_path = PFERD.move(path, ("Übungen",), ("Blätter",))
|
||||
new_path = move(path, ("Übungen",), ("Blätter",))
|
||||
if new_path is not None: return new_path
|
||||
|
||||
return path
|
||||
|
||||
async def main(args):
|
||||
# Main part of the config
|
||||
|
||||
def main(args):
|
||||
args = [arg.lower() for arg in args]
|
||||
|
||||
ffm = PFERD.FfM(base_dir)
|
||||
ilias = PFERD.ILIAS(base_dir, "cookie_jar")
|
||||
ilias = PFERD.Ilias(base_dir, "cookie_jar")
|
||||
norbert = PFERD.Norbert(base_dir)
|
||||
|
||||
# Semester 1
|
||||
|
||||
# if not args or "gbi" in args:
|
||||
# await ilias.synchronize("855240", "GBI", transform=gbi_transform, filter=gbi_filter)
|
||||
# if not args or "hm1" in args:
|
||||
# await ffm.synchronize("iana2/lehre/hm1info2018w", "HM1", transform=hm1_transform)
|
||||
# if not args or "la1" in args:
|
||||
# await ilias.synchronize("874938", "LA1", transform=la1_transform, filter=la1_filter)
|
||||
# if not args or "prog" in args:
|
||||
# await ilias.synchronize("851237", "Prog", transform=prog_transform, filter=prog_filter)
|
||||
# if not args or "norbert" in args:
|
||||
# await norbert.synchronize("Prog-Tut")
|
||||
if not args or "gbi" in args:
|
||||
ilias.synchronize("855240", "GBI",
|
||||
transform=gbi_transform, filter=gbi_filter)
|
||||
|
||||
if not args or "hm1" in args:
|
||||
ffm.synchronize("iana2/lehre/hm1info2018w", "HM1",
|
||||
transform=hm1_transform)
|
||||
|
||||
if not args or "la1" in args:
|
||||
ilias.synchronize("874938", "LA1",
|
||||
transform=la1_transform, filter=la1_filter)
|
||||
|
||||
if not args or "prog" in args:
|
||||
ilias.synchronize("851237", "Prog",
|
||||
transform=prog_transform, filter=prog_filter)
|
||||
|
||||
if not args or "norbert" in args:
|
||||
norbert.synchronize("Prog-Tut")
|
||||
|
||||
# Semester 2
|
||||
|
||||
if not args or "algo1" in args:
|
||||
await ilias.synchronize("959260", "Algo1", transform=algo1_transform, filter=algo1_filter)
|
||||
if not args or "hm2" in args:
|
||||
await ffm.synchronize("iana2/lehre/hm2info2019s", "HM2", transform=hm2_transform)
|
||||
if not args or "la2" in args:
|
||||
await ilias.synchronize("950588", "LA2", transform=la2_transform, filter=la2_filter)
|
||||
if not args or "swt1" in args:
|
||||
await ilias.synchronize("945596", "SWT1", transform=swt1_transform, filter=swt1_filter)
|
||||
ilias.synchronize("959260", "Algo1",
|
||||
transform=algo1_transform, filter=algo1_filter)
|
||||
|
||||
await ffm.close()
|
||||
await ilias.close()
|
||||
await norbert.close()
|
||||
if not args or "hm2" in args:
|
||||
ffm.synchronize("iana2/lehre/hm2info2019s", "HM2",
|
||||
transform=hm2_transform)
|
||||
|
||||
if not args or "la2" in args:
|
||||
ilias.synchronize("950588", "LA2",
|
||||
transform=la2_transform, filter=la2_filter)
|
||||
|
||||
if not args or "swt1" in args:
|
||||
ilias.synchronize("945596", "SWT1",
|
||||
transform=swt1_transform, filter=swt1_filter)
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = sys.argv[1:]
|
||||
asyncio.run(main(args))
|
||||
main(args)
|
||||
|
Reference in New Issue
Block a user