Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
This script captures such output. It should be run whenever there is
a major change in the contract between stages
"""
import shutil, os, sys
# move up a directory
sys.path.insert(0, os.path.split(sys.path[0])[0])
os.chdir(sys.path[0])
# copy spider output to splice input
import planet
from planet import spider, config
planet.getLogger('CRITICAL',None)
config.load('tests/data/spider/config.ini')
spider.spiderPlanet()
if os.path.exists('tests/data/splice/cache'):
shutil.rmtree('tests/data/splice/cache')
shutil.move('tests/work/spider/cache', 'tests/data/splice/cache')
source=open('tests/data/spider/config.ini')
dest1=open('tests/data/splice/config.ini', 'w')
dest1.write(source.read().replace('/work/spider/', '/data/splice/'))
dest1.close()
source.seek(0)
dest2=open('tests/work/apply_config.ini', 'w')
dest2.write(source.read().replace('[Planet]', '''[Planet]
output_theme = asf
output_dir = tests/work/apply'''))
dest2.close()
def test_xslt_filter(self):
config.load('tests/data/filter/translate.ini')
testfile = 'tests/data/filter/category-one.xml'
input = open(testfile).read()
output = shell.run(config.filters()[0], input, mode="filter")
dom = xml.dom.minidom.parseString(output)
catterm = dom.getElementsByTagName('category')[0].getAttribute('term')
self.assertEqual('OnE', catterm)
def test_recursive(self):
config.load('tests/data/config/foaf-deep.ini')
feeds = config.subscriptions()
feeds.sort()
self.assertEqual(['http://api.flickr.com/services/feeds/photos_public.gne?id=77366516@N00',
'http://del.icio.us/rss/eliast', 'http://del.icio.us/rss/leef',
'http://del.icio.us/rss/rubys', 'http://intertwingly.net/blog/atom.xml',
'http://thefigtrees.net/lee/life/atom.xml',
'http://torrez.us/feed/rdf'], feeds)
def setUp(self):
config.load('tests/data/config/rlist-csv.ini')
def eval_config(self, name):
# read the test case
try:
testcase = open(testfiles % (name,'ini'))
data = testcase.read()
description, expect = self.desc_config_re.search(data).groups()
testcase.close()
except:
raise RuntimeError, "can't parse %s" % name
# map to template info
config.load(testfiles % (name,'ini'))
results = tmpl.template_info("")
# verify the results
if not self.simple_re.match(expect):
self.assertTrue(eval(expect, results), expect)
else:
lhs, rhs = self.simple_re.match(expect).groups()
self.assertEqual(eval(rhs), eval(lhs, results))
def test_excerpt_lorem_ipsum_summary(self):
testfile = 'tests/data/filter/excerpt-lorem-ipsum.xml'
config.load('tests/data/filter/excerpt-lorem-ipsum.ini')
config.parser.set('excerpt.py', 'target', 'atom:summary')
output = open(testfile).read()
for filter in config.filters():
output = shell.run(filter, output, mode="filter")
dom = xml.dom.minidom.parseString(output)
excerpt = dom.getElementsByTagName('summary')[0]
self.assertEqual(u'Lorem ipsum dolor sit amet, consectetuer ' +
u'adipiscing elit. Nullam velit. Vivamus tincidunt, erat ' +
u'in \u2026', excerpt.firstChild.firstChild.nodeValue)
def test_django_date_type(self):
config.load('tests/data/filter/django/test.ini')
results = dj.tmpl.template_info("")
self.assertEqual(type(results['date']), datetime.datetime)
def setUp(self):
config.load('tests/data/config/rlist-config.ini')
elif arg == "-n" or arg == "--only-if-new":
only_if_new = 1
elif arg == "-x" or arg == "--expunge":
expunge = 1
elif arg == "-d" or arg == "--debug-splice":
debug_splice = 1
elif arg == "--no-publish":
no_publish = 1
elif arg.startswith("-"):
print >>sys.stderr, "Unknown option:", arg
sys.exit(1)
else:
config_file = arg
from planet import config
config.load(config_file)
if verbose:
import planet
planet.getLogger('DEBUG',config.log_format())
if not offline:
from planet import spider
try:
spider.spiderPlanet(only_if_new=only_if_new)
except Exception, e:
print e
from planet import splice
doc = splice.splice()
if debug_splice:
#!/usr/bin/env python
# coding=utf-8
"""
Main program to run just the splice portion of planet
"""
from __future__ import print_function
import os.path
import sys
from planet import config, publish
if __name__ == '__main__':
if len(sys.argv) == 2 and os.path.isfile(sys.argv[1]):
config.load(sys.argv[1])
publish.publish(config)
else:
print("Usage:")
print(" python %s config.ini" % sys.argv[0])