diff --git a/doc/changelog.txt b/doc/changelog.txt index 7b4fb4690..5b46a5397 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -1,5 +1,11 @@ Dosage 2.16 (released xx.xx.xxxx) +Fixes: +- output: Don't crash when HTML output is run more than once + per day. + Closes: GH bug #78 + + Dosage 2.15 (released 3.7.2014) Features: diff --git a/dosagelib/events.py b/dosagelib/events.py index 013b5a001..9d698781d 100644 --- a/dosagelib/events.py +++ b/dosagelib/events.py @@ -139,8 +139,8 @@ class HtmlEventHandler(EventHandler): def fnFromDate(self, date): """Get filename from date.""" - fn = time.strftime('comics-%Y%m%d.html', date) - fn = os.path.join(self.basepath, 'html', fn) + fn = time.strftime('comics-%Y%m%d', date) + fn = os.path.join(self.basepath, 'html', fn + ".html") fn = os.path.abspath(fn) return fn @@ -155,13 +155,21 @@ class HtmlEventHandler(EventHandler): fn = self.fnFromDate(today) if os.path.exists(fn): - raise ValueError('output file %r already exists' % fn) + out.warn('HTML output file %r already exists' % fn) + out.warn('the page link of previous run will skip this file') + out.warn('try to generate HTML output only once per day') + fn = util.getNonexistingFile(fn) d = os.path.dirname(fn) if not os.path.isdir(d): os.makedirs(d) - yesterdayUrl = self.getUrlFromFilename(self.fnFromDate(yesterday)) + try: + fn_yesterday = self.fnFromDate(yesterday) + fn_yesterday = util.getExistingFile(fn_yesterday) + yesterdayUrl = self.getUrlFromFilename(fn_yesterday) + except ValueError: + yesterdayUrl = None tomorrowUrl = self.getUrlFromFilename(self.fnFromDate(tomorrow)) self.html = codecs.open(fn, 'w', self.encoding) @@ -173,10 +181,10 @@ class HtmlEventHandler(EventHandler):