pferd/example_config.py

330 lines
12 KiB
Python
Raw Normal View History

#!/bin/env python3
import PFERD
import asyncio
import logging
import pathlib
2018-11-26 18:06:46 +01:00
import re
import sys
2018-11-26 18:06:46 +01:00
logging.basicConfig(level=logging.INFO, format=PFERD.LOG_FORMAT)
base_dir = PFERD.get_base_dir(__file__)
2019-04-25 10:32:25 +02:00
# Semester 1
2018-11-26 18:06:46 +01:00
def gbi_filter(path):
2019-04-25 10:32:25 +02:00
# Tutorien rausfiltern
if path.parts[:1] == ("Tutoriumsfolien",):
if path.parts[1:] == (): return True
if path.parts[1:2] == ("Tutorium 15",): return True
return False
2019-04-25 10:32:25 +02:00
return True
2018-11-26 18:06:46 +01:00
def gbi_transform(path):
2019-04-25 10:32:25 +02:00
# Übungsblätter in Blätter/blatt_xx.pdf
new_path = PFERD.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")
2018-11-26 18:06:46 +01:00
2019-04-25 10:32:25 +02:00
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")
2018-11-26 18:06:46 +01:00
2019-04-25 10:32:25 +02:00
return new_path
2018-11-26 18:06:46 +01:00
2019-04-25 10:32:25 +02:00
# Folien in Folien/*
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
2019-04-25 10:32:25 +02:00
# Skripte in Skripte/*
new_path = PFERD.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")
2018-11-26 18:06:46 +01:00
2019-04-25 10:32:25 +02:00
return new_path
2019-04-25 10:32:25 +02:00
# Übungsfolien in Übung/*
new_path = PFERD.move(path, ("große Übung: Folien",), ("Übung",))
if new_path is not None: return new_path
2019-04-25 10:32:25 +02:00
# Tutoriumsfolien in Tutorium/*
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")
if new_path.name == "GBI_Tut_7 (1).pdf":
return PFERD.rename(new_path, "GBI_Tut_7.pdf")
2019-04-25 10:32:25 +02:00
return new_path
2018-11-26 18:06:46 +01:00
2019-04-25 10:32:25 +02:00
return path
2018-11-26 18:06:46 +01:00
def hm1_transform(path):
2019-04-25 10:32:25 +02:00
match = re.match(r"blatt(\d+).pdf", path.name)
if match:
new_path = PFERD.move(path, (), ("Blätter",))
number = int(match.group(1))
return PFERD.rename(new_path, f"blatt_{number:02}.pdf")
2018-11-26 18:06:46 +01:00
2019-04-25 10:32:25 +02:00
match = re.match(r"blatt(\d+).loesungen.pdf", path.name)
if match:
new_path = PFERD.move(path, (), ("Blätter",))
number = int(match.group(1))
return PFERD.rename(new_path, f"loesung_{number:02}.pdf")
2018-11-26 18:06:46 +01:00
2019-04-25 10:32:25 +02:00
return path
2018-11-26 14:39:06 +01:00
def la1_filter(path):
2019-04-25 10:32:25 +02:00
# Tutorien rausfitern
if path.parts[:1] == ("Tutorien",):
if path.parts[1:] == (): return True
if path.parts[1:2] == ("Tutorium 03 - Philipp Faller",): return True
if path.parts[1:2] == ("Tutorium 23 - Sebastian Faller",): return True
return False
2018-11-26 18:06:46 +01:00
2019-04-25 10:32:25 +02:00
return True
2018-11-26 18:06:46 +01:00
def la1_transform(path):
2019-04-25 10:32:25 +02:00
# Alle Übungsblätter in Blätter/blatt_xx.pdf
# Alles andere Übungsmaterial in Blätter/*
new_path = PFERD.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")
2018-11-26 18:06:46 +01:00
2019-04-25 10:32:25 +02: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-26 18:06:46 +01:00
2019-04-25 10:32:25 +02:00
return new_path
2018-12-05 12:44:11 +01:00
2019-04-25 10:32:25 +02:00
# Alles Tutoriengedöns von Philipp in Tutorium/Philipp/*
new_path = PFERD.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")
2018-11-26 18:06:46 +01:00
2019-04-25 10:32:25 +02:00
return new_path
2019-04-25 10:32:25 +02:00
# Alles Tutoriengedöns von Sebastian in Tutorium/Sebastian/*
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 1"), ("Tutorium","Sebastian", "tut01"))
if new_path is not None: return new_path
2018-11-26 18:06:46 +01:00
2019-04-25 10:32:25 +02:00
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 2", "aufgaben.pdf"), ("Tutorium","Sebastian", "tut02.pdf"))
if new_path is not None: return new_path
2019-02-08 13:56:24 +01:00
2019-04-25 10:32:25 +02:00
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 3", "aufgaben.pdf"), ("Tutorium","Sebastian", "tut03.pdf"))
if new_path is not None: return new_path
2019-02-08 13:56:24 +01:00
2019-04-25 10:32:25 +02:00
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 4", "aufgaben.pdf"), ("Tutorium","Sebastian", "tut04.pdf"))
if new_path is not None: return new_path
2019-02-08 13:56:24 +01:00
2019-04-25 10:32:25 +02:00
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 5", "aufgaben.pdf"), ("Tutorium","Sebastian", "tut05.pdf"))
if new_path is not None: return new_path
2019-02-08 13:56:24 +01:00
2019-04-25 10:32:25 +02:00
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 6", "aufgaben.pdf"), ("Tutorium","Sebastian", "tut06.pdf"))
if new_path is not None: return new_path
2019-02-08 13:56:24 +01:00
2019-04-25 10:32:25 +02:00
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 7", "tut7.pdf"), ("Tutorium","Sebastian", "tut07.pdf"))
if new_path is not None: return new_path
2019-02-08 13:56:24 +01:00
2019-04-25 10:32:25 +02:00
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 8", "tut8.pdf"), ("Tutorium","Sebastian", "tut08.pdf"))
if new_path is not None: return new_path
2019-02-08 13:56:24 +01:00
2019-04-25 10:32:25 +02:00
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 9", "tut9.pdf"), ("Tutorium","Sebastian", "tut09.pdf"))
if new_path is not None: return new_path
2019-02-08 13:56:24 +01:00
2019-04-25 10:32:25 +02:00
if path.parts == ("Tutorien","Tutorium 23 - Sebastian Faller", "Tutorium 10", "tut10.pdf"): return None
2019-02-08 13:56:24 +01:00
2019-04-25 10:32:25 +02:00
new_path = PFERD.move(path, ("Tutorien","Tutorium 23 - Sebastian Faller"), ("Tutorium","Sebastian"))
if new_path is not None:
return new_path
2019-02-08 13:56:24 +01:00
2019-04-25 10:32:25 +02:00
# Übungs-Gedöns in Übung/*
new_path = PFERD.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")
2019-02-08 13:56:24 +01:00
2019-04-25 10:32:25 +02:00
return new_path
2018-11-26 18:06:46 +01:00
2019-04-25 10:32:25 +02:00
# Vorlesungsfolien-Gedöns in Folien/*
new_path = PFERD.move(path, ("Informatikervorlesung", "Folien.Notizen"), ("Folien",))
if new_path is not None:
return new_path
2019-04-25 10:32:25 +02:00
# Rest in Hauptverzeichnis
new_path = PFERD.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")
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")
2019-02-08 13:56:24 +01:00
2019-04-25 10:32:25 +02:00
return new_path
2018-11-26 18:06:46 +01:00
2019-04-25 10:32:25 +02:00
return path
2018-11-26 18:06:46 +01:00
def prog_filter(path):
2019-04-25 10:32:25 +02:00
# Tutorien rausfiltern
if path.parts[:1] == ("Tutorien",): return False
2018-11-26 14:39:06 +01:00
2019-04-25 10:32:25 +02:00
return True
2018-11-26 14:39:06 +01:00
2018-11-26 18:06:46 +01:00
def prog_transform(path):
2019-04-25 10:32:25 +02:00
# Übungsblätter in Blätter/*
new_path = PFERD.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 new_path
# Folien in Folien/*
new_path = PFERD.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")
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")
if new_path.name == "13_Finden_und_ Beheben_von_Fehlern.pdf":
return PFERD.rename(new_path, "13_Finden_und_Beheben_von_Fehlern.pdf")
return new_path
return path
# Semester 2
def algo1_filter(path):
# Tutorien rausfiltern
if path.parts[:1] == ("Tutorien",):
if path.parts[1:] == (): return True
#if path.parts[1:2] == ("Tutorium 15",): return True
return False
return True
def algo1_transform(path):
# Folien in Folien/*
new_path = PFERD.move(path, ("Vorlesungsfolien",), ("Folien",))
if new_path is not None:
return new_path
return path
def hm2_transform(path):
match = re.match(r"blatt(\d+).pdf", path.name)
if match:
new_path = PFERD.move(path, (), ("Blätter",))
number = int(match.group(1))
return PFERD.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",))
number = int(match.group(1))
return PFERD.rename(new_path, f"loesung_{number:02}.pdf")
return path
def la2_filter(path):
# Tutorien rausfiltern
if path.parts[:1] == ("Tutorien",):
if path.parts[1:] == (): return True
#if path.parts[1:2] == ("Tutorium 15",): return True
return False
return True
def la2_transform(path):
# Folien in Folien/*
new_path = PFERD.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",))
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 new_path
return path
def swt1_filter(path):
# Tutorien rausfiltern
if path.parts[:1] == ("Tutorien",):
if path.parts[1:] == (): return True
#if path.parts[1:2] == ("Tutorium 15",): return True
return False
return True
def swt1_transform(path):
# Folien in Folien/*
new_path = PFERD.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",))
if new_path is not None: return new_path
2018-11-26 18:06:46 +01:00
2019-04-25 10:32:25 +02:00
return path
2018-11-26 14:39:06 +01:00
2018-11-26 18:06:46 +01:00
async def main(args):
2019-04-25 10:32:25 +02:00
args = [arg.lower() for arg in args]
ffm = PFERD.FfM(base_dir)
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")
# 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)
await ffm.close()
await ilias.close()
await norbert.close()
if __name__ == "__main__":
2019-04-25 10:32:25 +02:00
args = sys.argv[1:]
asyncio.run(main(args))