From b9d6ebab6b0d9f05cda70fa267179108fde7bd70 Mon Sep 17 00:00:00 2001 From: Lukas Brabec Date: Jan 20 2014 10:50:41 +0000 Subject: testday-wiki.py config file --- diff --git a/fedocal/testdays-wiki.conf b/fedocal/testdays-wiki.conf new file mode 100644 index 0000000..a8ba7ec --- /dev/null +++ b/fedocal/testdays-wiki.conf @@ -0,0 +1,21 @@ +[user] +#name = yourFASusername +#passwd = yourpassword + +[wiki] + +api = https://fedoraproject.org/w/api.php + +url = :QA/test/Fedora_%s_test_days + +text: == Agenda (list view) == \n + This page is generated automaticaly, please do not change it manualy.\n + Generated from [https://apps.fedoraproject.org/calendar/QA/ Fedora Calendar] + using [https://apps.fedoraproject.org/calendar/api/meetings?calendar=QA Fedocal API]\n\n + \n + %s + \n + +[calendar] + +api = https://apps.fedoraproject.org/calendar/api/meetings?calendar=QA%s%s \ No newline at end of file diff --git a/fedocal/testdays-wiki.py b/fedocal/testdays-wiki.py index dce51cc..2dc9900 100755 --- a/fedocal/testdays-wiki.py +++ b/fedocal/testdays-wiki.py @@ -21,8 +21,14 @@ import re import sys import optparse +import ConfigParser - +## GLOBALS ## +#CONFIG_FILE = "/etc/fedora-qa/testdays-wiki.conf" +CONFIG_FILE = "testdays-wiki.conf" +CALENDAR_API = "https://apps.fedoraproject.org/calendar/api/meetings?calendar=QA%s%s" +WIKI_API = "https://fedoraproject.org/w/api.php" +WIKI_URL = ":QA/test/Fedora_%s_test_days" TEXT = """ == Agenda (list view) == \n This page is generated automaticaly, please do not change it manualy.\n @@ -33,11 +39,40 @@ using [https://apps.fedoraproject.org/calendar/api/meetings?calendar=QA Fedocal \n """ -#CONFIG_FILE = "/etc/fedora-qa/testdays-wiki.conf" +class Config: + def __init__(self, filename): + parser = ConfigParser.ConfigParser() + parser.read(filename) + try: + self.wiki_api = parser.get("wiki", "api") + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError), e: + self.wiki_api = WIKI_API + + try: + self.wiki_url = parser.get("wiki", "url") + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError), e: + self.wiki_url = WIKI_URL + + try: + self.text = parser.get("wiki", "text") + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError), e: + self.text = TEXT + + try: + self.calendar_api = parser.get("calendar", "api") + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError), e: + self.calendar_api = CALENDAR_API + + try: + self.username = parser.get("user", "name") + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError), e: + self.username = None + + try: + self.password = parser.get("user", "passwd") + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError), e: + self.password = None -CALENDAR_API = "https://apps.fedoraproject.org/calendar/api/meetings?calendar=QA%s%s" -WIKI_API = "https://fedoraproject.org/w/api.php" -WIKI_URL = ":QA/test/Fedora_%s_test_days" @@ -177,21 +212,26 @@ def parse_args(): def main(): + config = Config(CONFIG_FILE) + options = parse_args() if not options.releasever: print "No release version given." return - if not options.user: - print "No FAS username version given." - return - wiki_url = WIKI_URL % options.releasever + if not config.username: + if not options.user: + print "No FAS username version given." + return + + + wiki_url = config.wiki_url % options.releasever start_str = "&start="+options.start if options.start else "" end_str = "&end="+options.end if options.end else "" - api = ApiReader(CALENDAR_API % (start_str, end_str)) + api = ApiReader(config.calendar_api % (start_str, end_str)) api_data = api.read() @@ -214,8 +254,10 @@ def main(): text = TEXT % "\n\n".join(meeting_list) - wiki = FedoraWiki(WIKI_API) - if not wiki.login(options.user, getpass("password: ")): + wiki = FedoraWiki(config.wiki_api) + user = config.username if not options.user else options.user + password = getpass("password: ") if not config.password else config.password + if not wiki.login(user, password): print "Login fail" return