Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Load configuration only once

  • Loading branch information...
commit c610c937200c4284c21df14d8e65f0bc5d48de83 1 parent 5d7bd64
Sam Ruby authored
View
7 planet.py
@@ -41,14 +41,17 @@
else:
config_file = arg
+ from planet import config
+ config.load(config_file)
+
if verbose:
import planet
planet.getLogger('DEBUG')
if not offline:
from planet import spider
- spider.spiderPlanet(config_file)
+ spider.spiderPlanet()
from planet import splice
- doc = splice.splice(config_file)
+ doc = splice.splice()
splice.apply(doc.toxml('utf-8'))
View
3  planet/spider.py
@@ -180,9 +180,8 @@ def spiderFeed(feed):
write(output, cache_file)
os.utime(cache_file, (mtime, mtime))
-def spiderPlanet(configFile):
+def spiderPlanet():
""" Spider (fetch) an entire planet """
- config.load(configFile)
log = planet.getLogger(config.log_level())
planet.setTimeout(config.feed_timeout())
View
3  planet/splice.py
@@ -5,10 +5,9 @@
from reconstitute import createTextElement, date
from spider import filename
-def splice(configFile):
+def splice():
""" Splice together a planet from a cache of entries """
import planet
- config.load(configFile)
log = planet.getLogger(config.log_level())
log.info("Loading cached data")
View
5 spider.py
@@ -8,12 +8,13 @@
if __name__ == '__main__':
+ config.load(sys.argv[1])
+
if len(sys.argv) == 2:
# spider all feeds
- spider.spiderPlanet(sys.argv[1])
+ spider.spiderPlanet()
elif len(sys.argv) > 2:
# spider selected feeds
- config.load(sys.argv[1])
for feed in sys.argv[2:]:
spider.spiderFeed(feed)
else:
View
7 splice.py
@@ -5,14 +5,13 @@
import os.path
import sys
-from planet import splice
+from planet import splice, config
if __name__ == '__main__':
if len(sys.argv) == 2 and os.path.isfile(sys.argv[1]):
- # at the moment, we don't have template support, so we cheat and
- # simply insert a XSLT processing instruction
- doc = splice.splice(sys.argv[1])
+ config.load(sys.argv[1])
+ doc = splice.splice()
splice.apply(doc.toxml('utf-8'))
else:
print "Usage:"
View
3  tests/test_spider.py
@@ -66,7 +66,8 @@ def test_spiderUpdate(self):
self.test_spiderFeed()
def test_spiderPlanet(self):
- spiderPlanet(configfile)
+ config.load(configfile)
+ spiderPlanet()
files = glob.glob(workdir+"/*")
# verify that exactly eight files + 1 source dir were produced
View
5 tests/test_splice.py
@@ -1,14 +1,15 @@
#!/usr/bin/env python
import unittest
-from planet.splice import splice
+from planet.splice import splice, config
configfile = 'tests/data/splice/config.ini'
class SpliceTest(unittest.TestCase):
def test_splice(self):
- doc = splice(configfile)
+ config.load(configfile)
+ doc = splice()
self.assertEqual(12,len(doc.getElementsByTagName('entry')))
self.assertEqual(4,len(doc.getElementsByTagName('planet:source')))
self.assertEqual(16,len(doc.getElementsByTagName('planet:name')))
Please sign in to comment.
Something went wrong with that request. Please try again.