2018-11-27 09:52:27 +01:00
|
|
|
#!/bin/env python3
|
|
|
|
|
2018-11-24 09:27:33 +01:00
|
|
|
import PFERD
|
|
|
|
import asyncio
|
|
|
|
import logging
|
|
|
|
import pathlib
|
2018-11-26 18:06:46 +01:00
|
|
|
import re
|
|
|
|
import sys
|
2018-11-24 09:27:33 +01:00
|
|
|
|
2018-11-26 18:06:46 +01:00
|
|
|
logging.basicConfig(level=logging.INFO, format=PFERD.LOG_FORMAT)
|
2018-11-24 09:27:33 +01:00
|
|
|
|
|
|
|
base_dir = PFERD.get_base_dir(__file__)
|
|
|
|
|
2018-11-26 18:06:46 +01:00
|
|
|
def gbi_filter(path):
|
|
|
|
# Tutorien rausfiltern
|
2018-11-27 09:52:27 +01:00
|
|
|
if path.parts[:1] == ("Tutoriumsfolien",):
|
|
|
|
if path.parts[1:] == (): return True
|
|
|
|
if path.parts[1:2] == ("Tutorium 15",): return True
|
|
|
|
return False
|
2018-11-24 09:27:33 +01:00
|
|
|
|
2018-11-26 18:06:46 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
def gbi_transform(path):
|
|
|
|
# Übungsblätter in Blätter/blatt_xx.pdf
|
2018-11-27 09:52:27 +01:00
|
|
|
new_path = PFERD.move(path, ("Übungsblätter",), ("Blätter",))
|
|
|
|
if new_path is not None:
|
2018-11-26 18:06:46 +01:00
|
|
|
|
2018-11-27 09:52:27 +01:00
|
|
|
match = re.match(r"(\d+).aufgaben.pdf", new_path.name)
|
2018-11-26 18:06:46 +01:00
|
|
|
if match:
|
|
|
|
number = int(match.group(1))
|
2018-11-27 09:52:27 +01:00
|
|
|
return PFERD.rename(new_path, f"blatt_{number:02}.pdf")
|
2018-11-26 18:06:46 +01:00
|
|
|
|
2018-11-27 09:52:27 +01:00
|
|
|
match = re.match(r"(\d+).loesungen.pdf", new_path.name)
|
2018-11-26 18:06:46 +01:00
|
|
|
if match:
|
|
|
|
number = int(match.group(1))
|
2018-11-27 09:52:27 +01:00
|
|
|
return PFERD.rename(new_path, f"loesung_{number:02}.pdf")
|
2018-11-26 18:06:46 +01:00
|
|
|
|
2018-11-27 09:52:27 +01:00
|
|
|
return new_path
|
2018-11-26 18:06:46 +01:00
|
|
|
|
|
|
|
# Folien in Folien/*
|
2018-11-27 09:52:27 +01:00
|
|
|
new_path = PFERD.move(path, ("Vorlesung: Folien",), ("Folien",))
|
|
|
|
if new_path is not None: return new_path
|
2018-11-26 18:06:46 +01:00
|
|
|
|
|
|
|
# Skripte in Skripte/*
|
2018-11-27 09:52:27 +01:00
|
|
|
new_path = PFERD.move(path, ("Vorlesung: Skript",), ("Skripte",))
|
|
|
|
if new_path is not None: return new_path
|
2018-11-24 09:27:33 +01:00
|
|
|
|
2018-11-26 18:06:46 +01:00
|
|
|
# Übungsfolien in Übung/*
|
2018-11-27 09:52:27 +01:00
|
|
|
new_path = PFERD.move(path, ("große Übung: Folien",), ("Übung",))
|
|
|
|
if new_path is not None: return new_path
|
2018-11-24 09:27:33 +01:00
|
|
|
|
2018-11-26 18:06:46 +01:00
|
|
|
# Tutoriumsfolien in Tutorium/*
|
2018-11-27 09:52:27 +01:00
|
|
|
new_path = PFERD.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")
|
2018-12-05 12:44:11 +01:00
|
|
|
if new_path.name == "GBI_Tut_7 (1).pdf":
|
|
|
|
return PFERD.rename(new_path, "GBI_Tut_7.pdf")
|
2018-11-27 09:52:27 +01:00
|
|
|
|
|
|
|
return new_path
|
2018-11-26 18:06:46 +01:00
|
|
|
|
|
|
|
return path
|
|
|
|
|
|
|
|
def hm1_transform(path):
|
|
|
|
if path.match("blatt*.pdf"):
|
2018-11-27 09:52:27 +01:00
|
|
|
new_path = PFERD.move(path, (), ("Blätter",))
|
2018-11-26 18:06:46 +01:00
|
|
|
|
2018-11-27 09:52:27 +01:00
|
|
|
match = re.match(r"blatt(\d+).pdf", new_path.name)
|
2018-11-26 18:06:46 +01:00
|
|
|
if match:
|
|
|
|
number = int(match.group(1))
|
2018-11-27 09:52:27 +01:00
|
|
|
return PFERD.rename(new_path, f"blatt_{number:02}.pdf")
|
2018-11-26 18:06:46 +01:00
|
|
|
|
2018-11-27 09:52:27 +01:00
|
|
|
match = re.match(r"blatt(\d+).loesungen.pdf", new_path.name)
|
2018-11-26 18:06:46 +01:00
|
|
|
if match:
|
|
|
|
number = int(match.group(1))
|
2018-11-27 09:52:27 +01:00
|
|
|
return PFERD.rename(new_path, f"loesung_{number:02}.pdf")
|
2018-11-26 18:06:46 +01:00
|
|
|
|
2018-11-27 09:52:27 +01:00
|
|
|
return new_path
|
2018-11-26 18:06:46 +01:00
|
|
|
|
|
|
|
return path
|
2018-11-24 09:27:33 +01:00
|
|
|
|
2018-11-26 14:39:06 +01:00
|
|
|
def la1_filter(path):
|
2018-11-26 18:06:46 +01:00
|
|
|
# Tutorien rausfitern
|
2018-11-27 09:52:27 +01:00
|
|
|
if path.parts[:1] == ("Tutorien",):
|
|
|
|
if path.parts[1:] == (): return True
|
|
|
|
if path.parts[1:2] == ("Tutorium 03 - Philipp Faller",): return True
|
|
|
|
return False
|
2018-11-26 18:06:46 +01:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def la1_transform(path):
|
|
|
|
# Alle Übungsblätter in Blätter/blatt_xx.pdf
|
|
|
|
# Alles andere Übungsmaterial in Blätter/*
|
2018-11-27 09:52:27 +01:00
|
|
|
new_path = PFERD.move(path, ("Übungen",), ("Blätter",))
|
|
|
|
if new_path is not None:
|
2018-11-26 18:06:46 +01:00
|
|
|
|
2018-11-27 09:52:27 +01:00
|
|
|
match = re.match(r"Blatt(\d+).pdf", new_path.name)
|
2018-11-26 18:06:46 +01:00
|
|
|
if match:
|
|
|
|
number = int(match.group(1))
|
2018-11-27 09:52:27 +01:00
|
|
|
return PFERD.rename(new_path, f"blatt_{number:02}.pdf")
|
2018-11-26 18:06:46 +01:00
|
|
|
|
2018-12-05 12:44:11 +01:00
|
|
|
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")
|
|
|
|
|
2018-11-27 09:52:27 +01:00
|
|
|
return new_path
|
2018-11-26 18:06:46 +01:00
|
|
|
|
|
|
|
# Alles Tutoriengedöns in Tutorium/*
|
2018-11-27 09:52:27 +01:00
|
|
|
new_path = PFERD.move(path, ("Tutorien","Tutorium 03 - Philipp Faller"), ("Tutorium",))
|
|
|
|
if new_path is not None:
|
|
|
|
if new_path.name == "tut2.pdf":
|
|
|
|
return PFERD.rename(new_path, "Tut2.pdf")
|
|
|
|
|
|
|
|
return new_path
|
2018-11-26 18:06:46 +01:00
|
|
|
|
|
|
|
# Übungs-Gedöns in Übung/*
|
2018-12-14 10:28:29 +01:00
|
|
|
new_path = PFERD.move(path, ("Informatikervorlesung", "Übungsfolien"), ("Übung",))
|
|
|
|
if new_path is not None:
|
|
|
|
return new_path
|
2018-11-26 18:06:46 +01:00
|
|
|
|
|
|
|
# Vorlesungsfolien-Gedöns in Folien/*
|
2018-12-14 10:28:29 +01:00
|
|
|
new_path = PFERD.move(path, ("Informatikervorlesung", "Folien.Notizen"), ("Folien",))
|
|
|
|
if new_path is not None:
|
|
|
|
return new_path
|
|
|
|
|
|
|
|
# Rest in Hauptverzeichnis
|
|
|
|
new_path = PFERD.move(path, ("Informatikervorlesung",), ())
|
|
|
|
if new_path is not None:
|
|
|
|
return new_path
|
2018-11-26 18:06:46 +01:00
|
|
|
|
|
|
|
return path
|
|
|
|
|
|
|
|
def prog_filter(path):
|
|
|
|
# Tutorien rausfiltern
|
2018-11-27 09:52:27 +01:00
|
|
|
if path.parts[:1] == ("Tutorien",): return False
|
2018-11-26 14:39:06 +01:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
2018-11-26 18:06:46 +01:00
|
|
|
def prog_transform(path):
|
|
|
|
# Übungsblätter in Blätter/*
|
2018-11-27 09:52:27 +01:00
|
|
|
new_path = PFERD.move(path, ("Übungen",), ("Blätter",))
|
|
|
|
if new_path is not None: return new_path
|
2018-11-26 18:06:46 +01:00
|
|
|
|
|
|
|
# Folien in Folien/*
|
2018-11-27 09:52:27 +01:00
|
|
|
new_path = PFERD.move(path, ("Vorlesungsmaterial",), ("Folien",))
|
2018-11-27 11:26:44 +01:00
|
|
|
if new_path is not None:
|
|
|
|
if new_path.name == "00.1_Begruessung.pdf":
|
|
|
|
return PFERD.rename(new_path, "00-01_Begruessung.pdf")
|
|
|
|
if new_path.name == "00.2_Organisatorisches.pdf":
|
|
|
|
return PFERD.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 new_path
|
2018-11-26 18:06:46 +01:00
|
|
|
|
|
|
|
return path
|
2018-11-26 14:39:06 +01:00
|
|
|
|
2018-11-26 18:06:46 +01:00
|
|
|
async def main(args):
|
|
|
|
args = [arg.lower() for arg in args]
|
|
|
|
|
|
|
|
ffm = PFERD.FfM(base_dir)
|
2018-11-26 14:39:06 +01:00
|
|
|
ilias = PFERD.ILIAS(base_dir, "cookie_jar")
|
2018-11-29 10:28:44 +01:00
|
|
|
norbert = PFERD.Norbert(base_dir)
|
2018-11-26 18:06:46 +01:00
|
|
|
|
|
|
|
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)
|
2018-11-29 10:28:44 +01:00
|
|
|
if not args or "norbert" in args:
|
|
|
|
await norbert.synchronize("Prog-Tut")
|
2018-11-26 18:06:46 +01:00
|
|
|
|
|
|
|
await ffm.close()
|
2018-11-26 14:39:06 +01:00
|
|
|
await ilias.close()
|
2018-11-29 10:28:44 +01:00
|
|
|
await norbert.close()
|
2018-11-24 09:27:33 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2018-11-26 18:06:46 +01:00
|
|
|
args = sys.argv[1:]
|
|
|
|
asyncio.run(main(args))
|