From 7303be2cd562de9f17696866f1b27bf208407d1a Mon Sep 17 00:00:00 2001 From: genericname462 Date: Tue, 5 May 2015 17:51:05 +0200 Subject: [PATCH 1/2] Basic user interface Better settings management --- update.py.better_example | 80 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 update.py.better_example diff --git a/update.py.better_example b/update.py.better_example new file mode 100755 index 0000000..70d2037 --- /dev/null +++ b/update.py.better_example @@ -0,0 +1,80 @@ +#!/usr/bin/python3 +import tudown + +user = '' +passwd = '' + + +path = "./" +sample_entry = {"id": "example", + "url": "http://example.org/ss15", + "files": [(r"regex_to_match", "folder_to_save_to")], + "user": user, + "passwd": passwd + } + +theo = {"id": "theo_skript", + "url": "http://wwwmayr.informatik.tu-muenchen.de/lehre/2015SS/theo/", + "files": [('2015-theo\.pdf', 'Skript'), + ('2015-\d{2}-\d{2}\.pdf', 'Skript')], + "user": user, + "passwd": passwd + } + +config_list = [sample_entry, theo] + + +def main(arg): + if arg == "list": + for item in config_list: + print(item) + return 0 + if arg == 'all': + for item in config_list: + tudown.main(item["url"], item["files"]) + return 0 + + item = next((item for item in config_list if item["id"] == arg), None) + if item: + tudown.main(item["url"], item["files"]) + return 0 + else: + print("config not found, \'list\' to list all") + return -1 + + + # # +--------+ + # # | Skript | + # # +--------+ + # + # url = 'http://wwwmayr.informatik.tu-muenchen.de/lehre/2015SS/theo/' + # + # files = [ + # ('2015-theo\.pdf', 'Skript'), + # ('2015-\d{2}-\d{2}\.pdf', 'Skript'), + # ] + # + # tudown.main(url, files) + # + # # +-------+ + # # | Übung | + # # +-------+ + # + # url = 'http://wwwmayr.informatik.tu-muenchen.de/lehre/2015SS/theo/uebung/' + # + # files = [ + # ('ue\d{2}\.pdf', 'Übungsblätter'), + # ('lo\d{2}_HA\.pdf', 'Lösungsblätter'), + # ('theo15zue\d{2}_druck\.pdf', 'Skript/ZÜ'), + # ] + # + # tudown.main(url, files, user=user, passwd=passwd) + + +if __name__ == '__main__': + import sys + if len(sys.argv) < 2: + print("Specify id to update, \'all\' to update all, \'list\' to list all configs") + sys.exit(-1) + else: + main(sys.argv[1]) \ No newline at end of file From 97ff9612f3485a7cb302ce4f363324a32bbcac28 Mon Sep 17 00:00:00 2001 From: genericname462 Date: Tue, 5 May 2015 18:14:25 +0200 Subject: [PATCH 2/2] Fixed line ending --- update.py.better_example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update.py.better_example b/update.py.better_example index 70d2037..c728446 100755 --- a/update.py.better_example +++ b/update.py.better_example @@ -77,4 +77,4 @@ if __name__ == '__main__': print("Specify id to update, \'all\' to update all, \'list\' to list all configs") sys.exit(-1) else: - main(sys.argv[1]) \ No newline at end of file + main(sys.argv[1])