Write out the reading list in canonical form (i.e. in ConfigParser format)

This commit is contained in:
Sam Ruby 2006-08-31 01:04:20 -04:00
parent b3cc073231
commit 357e47f3d6
2 changed files with 16 additions and 12 deletions

View File

@ -168,22 +168,30 @@ def load(config_file):
for list in reading_lists: for list in reading_lists:
cache_filename = filename(config.cache_lists_directory(), list) cache_filename = filename(config.cache_lists_directory(), list)
try: try:
import urllib import urllib, StringIO
data=urllib.urlopen(list).read()
# read once to verify
data=StringIO.StringIO(urllib.urlopen(list).read())
cached_config = ConfigParser()
opml.opml2config(data, cached_config)
if not cached_config.sections(): raise Exception
# write to cache
cache = open(cache_filename, 'w') cache = open(cache_filename, 'w')
cache.write(data) cached_config.write(cache)
cache.close() cache.close()
# re-parse and proceed
log.debug("Using %s readinglist", list) log.debug("Using %s readinglist", list)
data.seek(0)
opml.opml2config(data, parser)
except: except:
try: try:
cache = open(cache_filename) parser.read(cache_filename)
data = cache.read()
cache.close()
log.info("Using cached %s readinglist", list) log.info("Using cached %s readinglist", list)
except: except:
log.exception("Unable to read %s readinglist", list) log.exception("Unable to read %s readinglist", list)
continue continue
opml.opml2config(data, parser)
# planet.foaf.foaf2config(data, list, config) # planet.foaf.foaf2config(data, list, config)
def cache_sources_directory(): def cache_sources_directory():

View File

@ -40,12 +40,8 @@ class ReadingListTest(unittest.TestCase):
cache = glob(os.path.join(workdir,'lists','*')) cache = glob(os.path.join(workdir,'lists','*'))
self.assertTrue(1,len(cache)) self.assertTrue(1,len(cache))
file = open(cache[0])
data = file.read()
file.close()
parser = ConfigParser() parser = ConfigParser()
opml.opml2config(data, parser) parser.read(cache[0])
feeds = [split(feed)[1] for feed in parser.sections()] feeds = [split(feed)[1] for feed in parser.sections()]
feeds.sort() feeds.sort()