Revision: 4319 Author: cosoleto Date: 2007-09-17 17:50:13 +0000 (Mon, 17 Sep 2007)
Log Message: ----------- Short path fix. Added shortpath() in wikipedia.py (thank you Russblau). Fix in copyright.put()
Modified Paths: -------------- trunk/pywikipedia/copyright.py trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/copyright.py =================================================================== --- trunk/pywikipedia/copyright.py 2007-09-17 15:39:18 UTC (rev 4318) +++ trunk/pywikipedia/copyright.py 2007-09-17 17:50:13 UTC (rev 4319) @@ -251,16 +251,12 @@ for page, path in exclusion_file_list(): try: if not os.path.exists(path): - print 'Creating file '%s' (%s)' % (path, page.aslink()) + print 'Creating file '%s' (%s)' % (wikipedia.shortpath(path), page.aslink()) force_update = True else: file_age = time.time() - os.path.getmtime(path) if file_age > 24 * 60 * 60: - short_path = path - if path.startswith(wikipedia.config.base_dir): - short_path = path[len(wikipedia.config.base_dir) - +len(os.path.sep) : ] - print 'Updating file '%s' (%s)' % (short_path, page.aslink()) + print 'Updating file '%s' (%s)' % (wikipedia.shortpath(path), page.aslink()) force_update = True except OSError: raise @@ -901,7 +897,7 @@ break except wikipedia.SpamfilterError, url: print "Spam filter" - text = re.sub(url[0], '<blacklist>' + url[0][7:], text) + text = re.sub(url[0], '<blacklist>' + url[0][url[0].index('://')+3:], text) except wikipedia.EditConflict: print "Edit conflict" raise wikipedia.EditConflict
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2007-09-17 15:39:18 UTC (rev 4318) +++ trunk/pywikipedia/wikipedia.py 2007-09-17 17:50:13 UTC (rev 4319) @@ -4448,6 +4448,15 @@ """ return makepath(os.path.join(config.base_dir, *filename))
+def shortpath(path): + """ + Short an absolute file path removing bot's base directory part if exists. + """ + shortpath = path + if path.startswith(config.base_dir): + shortpath = path[len(config.base_dir) + len(os.path.sep) : ] + return shortpath + ######################### # Interpret configuration ######################### @@ -4963,4 +4972,3 @@ print 'Pywikipediabot %s' % version.getversion() print 'Python %s' % sys.version doctest.testmod() -