From a7bc3fdbe043fa4a08bbc79b2441fb2e6fdfae5f Mon Sep 17 00:00:00 2001
From: Tue Herlau <tuhe@dtu.dk>
Date: Fri, 22 Sep 2023 15:26:27 +0200
Subject: [PATCH] Updates to handin/handout dates

---
 requirements.txt                              |  3 +-
 setup.py                                      |  9 +++--
 src/coursebox.egg-info/PKG-INFO               |  2 +-
 src/coursebox.egg-info/requires.txt           |  1 +
 src/coursebox/admin/gitlab.py                 | 29 ++++++++++------
 src/coursebox/core/info.py                    |  4 +--
 src/coursebox/core/info_paths.py              |  3 ++
 .../material/homepage_lectures_exercises.py   | 33 ++++++++++++-------
 8 files changed, 53 insertions(+), 31 deletions(-)

diff --git a/requirements.txt b/requirements.txt
index 6391557..14848f0 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -8,6 +8,7 @@ pexpect
 matplotlib
 numpy
 pycode_similar
-jinjafy
+# jinjafy
 beamer-slider
 tinydb
+python-gitlab
diff --git a/setup.py b/setup.py
index 94d0444..6c26e53 100644
--- a/setup.py
+++ b/setup.py
@@ -4,18 +4,16 @@
 """
 Windows> py -m build && twine upload dist/*
 Linux> python -m build && python -m twine upload dist/*
-
 """
 
 import setuptools
-import pkg_resources
 
 with open("README.md", "r", encoding="utf-8") as fh:
     long_description = fh.read()
-# beamer-slider
+
 setuptools.setup(
     name="coursebox",
-    version="0.1.18.13",
+    version="0.1.18.20",
     author="Tue Herlau",
     author_email="tuhe@dtu.dk",
     description="A course management system currently used at DTU",
@@ -34,5 +32,6 @@ setuptools.setup(
     package_dir={"": "src"},
     packages=setuptools.find_packages(where="src"),
     python_requires=">=3.8",
-    install_requires=['numpy','pycode_similar','tika','openpyxl', 'xlwings','matplotlib','langdetect','beamer-slider','tinydb'],
+    install_requires=['numpy','pycode_similar','tika','openpyxl', 'xlwings','matplotlib','langdetect',
+                      'beamer-slider','tinydb', 'python-gitlab'],
 )
diff --git a/src/coursebox.egg-info/PKG-INFO b/src/coursebox.egg-info/PKG-INFO
index 635ffde..ceb4f44 100644
--- a/src/coursebox.egg-info/PKG-INFO
+++ b/src/coursebox.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 2.1
 Name: coursebox
-Version: 0.1.18.13
+Version: 0.1.18.19
 Summary: A course management system currently used at DTU
 Home-page: https://lab.compute.dtu.dk/tuhe/coursebox
 Author: Tue Herlau
diff --git a/src/coursebox.egg-info/requires.txt b/src/coursebox.egg-info/requires.txt
index 0a85667..7e1958d 100644
--- a/src/coursebox.egg-info/requires.txt
+++ b/src/coursebox.egg-info/requires.txt
@@ -7,3 +7,4 @@ matplotlib
 langdetect
 beamer-slider
 tinydb
+python-gitlab
diff --git a/src/coursebox/admin/gitlab.py b/src/coursebox/admin/gitlab.py
index 159d589..b406f70 100644
--- a/src/coursebox/admin/gitlab.py
+++ b/src/coursebox/admin/gitlab.py
@@ -1,3 +1,5 @@
+import datetime
+
 import gitlab
 import gitlab.const
 from urllib.parse import urlparse
@@ -27,17 +29,24 @@ def sync_tas_with_git():
     for i in p.invitations.list():
         print("Invited", i.invite_email.split("@"))
 
-    if False:
-        inv = p.invitations.create({
-            "email": "fmry@dtu.dk",
-            "access_level": gitlab.const.AccessLevel.MAINTAINER,
-        })
-        inv.save()
+    if True:
+        for i in info['instructors']:
+            # i = info['instructors'][2]
+            if i['email'].split("@")[0].strip() in all_tas:
+                print("TA found already", i['name'], i['email'])
+            else:
+                import datetime
+                expires = datetime.datetime.now() + datetime.timedelta(days=30*5+14)
+                expires_str =expires.strftime('%A %b %d, %Y at %H:%M GMT')
+
+                inv = p.invitations.create({
+                    "email": i['email'], # '"fmry@dtu.dk",
+                    "access_level": gitlab.const.AccessLevel.MAINTAINER,
+                    "expires_at": expires_str,
+                })
+                inv.save()
+                print("Inviting...", i['email'], i['name'])
 
-    #
-    #
-    #
-    #
     # for p in gl.projects.list(iterator=True):
     #     prs.append(p)
     # for p in prs:
diff --git a/src/coursebox/core/info.py b/src/coursebox/core/info.py
index efe3a41..ae0efee 100644
--- a/src/coursebox/core/info.py
+++ b/src/coursebox/core/info.py
@@ -429,7 +429,7 @@ def class_information(verbose=False,
             if 'id' in r:
                 d['reports'][r['id']] = r
                 r['handin'] = get_lecture_date(r['handin'], delta_days=int(d['handin_day_delta']))
-                r['handout'] = get_lecture_date(r['handout'], delta_days=0)
+                r['handout'] = get_lecture_date(r['handout'], delta_days=int(d.get('handout_day_delta', 0)))
                 r['exercises'] = [e.strip() for e in r['exercises'].split(",") if len(e.strip()) > 0]
 
     ice = xlsx_to_dicts(paths['information.xlsx'], sheet='ce', as_dict_list=True)
@@ -495,7 +495,7 @@ def _save_info_cache():
                     known[id] = f"s{len(known):6d}".replace(" ", "0")
                 d = d.replace(id, known[id])
         elif isinstance(d, dict):
-            for k, v in d.items():
+            for k, v in d.copy().items():
                 d[_remove_ids(k)] = _remove_ids(v)
         elif isinstance(d, list):
             d = [_remove_ids(k) for k in d]
diff --git a/src/coursebox/core/info_paths.py b/src/coursebox/core/info_paths.py
index a775779..cc07d6e 100644
--- a/src/coursebox/core/info_paths.py
+++ b/src/coursebox/core/info_paths.py
@@ -72,6 +72,9 @@ def get_paths():
     if not os.path.isdir(paths['book']):
         paths['book'] =  root_02450public + "/Notes/Latex"
 
+    # if 'book' in paths and os.path.isdir(paths['book']):
+    #     pass
+
     if os.path.exists(os.path.dirname(paths['instructor_project_evaluations'])):
         if not os.path.isdir(paths['instructor_project_evaluations']):
             os.mkdir(paths['instructor_project_evaluations'])
diff --git a/src/coursebox/material/homepage_lectures_exercises.py b/src/coursebox/material/homepage_lectures_exercises.py
index 7206669..727363b 100644
--- a/src/coursebox/material/homepage_lectures_exercises.py
+++ b/src/coursebox/material/homepage_lectures_exercises.py
@@ -92,11 +92,16 @@ def make_lectures(week=None, mode=0, gather_pdf_out=True, gather_sixup=True, mak
     mode = HANDOUT = 2: version handed out to students.
     """
     assert mode in [PRESENTATION, NOTES, HANDOUT]
-
     paths = get_paths()
+    info = class_information()
+    if 'lecture_notes_tex' in info:
+        book_pdf = paths['02450public'] + "/" + info['lecture_notes_tex'][:-4] + ".pdf"
+    else:
+        book_pdf = paths['book'] + "/02002_Notes.pdf"
+
     if os.path.exists(paths['book']):
         book_frontpage_png = paths['shared']+"/figures/book.png" #paths['lectures']+"/static/book.png"
-        slide_to_image(paths['book'] + "/02450_Book.pdf", book_frontpage_png, page_to_take=1)
+        slide_to_image(book_pdf, book_frontpage_png, page_to_take=1)
         shutil.copy(paths['book'] + "/book_preamble.tex", paths['shared'])
     info = class_information()
     jinjafy_shared_templates_dir(paths, info) # Compile templates in shared/templates
@@ -389,10 +394,12 @@ def fix_shared(paths, output_dir, pdf2png=False,dosvg=True,verbose=False, compil
     # update_source_cache = False
     source_extra = {}
     for rel in source:
-        if rel.endswith(".svg") and source[rel]['modified'] and dosvg:
-            pdf_file = svg2pdf(shared_base + "/"+rel, crop=True, text_to_path=True)
-            rel = os.path.relpath(pdf_file, shared_base)
-            source_extra[rel] = dict(mtime=os.path.getmtime(pdf_file), hash=hash_file_(pdf_file), modified=True)
+        if rel.endswith(".svg"):
+            pdf_ = shared_base + "/"+rel[:-4] + ".pdf"
+            if (source[rel]['modified'] or not os.path.isfile(pdf_)) and dosvg:
+                pdf_file = svg2pdf(shared_base + "/"+rel, crop=True, text_to_path=True)
+                rel = os.path.relpath(pdf_file, shared_base)
+                source_extra[rel] = dict(mtime=os.path.getmtime(pdf_file), hash=hash_file_(pdf_file), modified=True)
 
     for k, v in source_extra.items():
         source[k] = v
@@ -415,12 +422,14 @@ def fix_shared(paths, output_dir, pdf2png=False,dosvg=True,verbose=False, compil
 
     if pdf2png:
         for rel in target:
-            if rel.endswith(".pdf") and target[rel]['modified']:
-                # print("pdf2png: ")
-                png = convert.pdf2png(output_dir + "/" + rel, verbose=True)
-                target[rel]['modified'] = False
-                target[rel]['hash'] = hash_file_(output_dir + "/" + rel)
-                target[rel]['mtime'] = os.path.getmtime(output_dir + "/" + rel)
+            if rel.endswith(".pdf"):
+                png_target = output_dir + "/" + rel[:-4] + ".png"
+                if target[rel]['modified'] or not os.path.isfile(png_target):
+                    # print("pdf2png: ")
+                    png = convert.pdf2png(output_dir + "/" + rel, verbose=True)
+                    target[rel]['modified'] = False
+                    target[rel]['hash'] = hash_file_(output_dir + "/" + rel)
+                    target[rel]['mtime'] = os.path.getmtime(output_dir + "/" + rel)
 
     with open(shared_base + "/sharedcache.pkl", 'wb') as f:
         pickle.dump(source, f)
-- 
GitLab