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:
cache_filename = filename(config.cache_lists_directory(), list)
try:
import urllib
data=urllib.urlopen(list).read()
import urllib, StringIO
# 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.write(data)
cached_config.write(cache)
cache.close()
# re-parse and proceed
log.debug("Using %s readinglist", list)
data.seek(0)
opml.opml2config(data, parser)
except:
try:
cache = open(cache_filename)
data = cache.read()
cache.close()
parser.read(cache_filename)
log.info("Using cached %s readinglist", list)
except:
log.exception("Unable to read %s readinglist", list)
continue
opml.opml2config(data, parser)
# planet.foaf.foaf2config(data, list, config)
def cache_sources_directory():

View File

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