Raise error when egg is corrupt in activate_egg(). Use a more descriptive name for temporary dirs in get_spider_list_from_eggfile(). Make scrapyd webservice pass egg_runner to get_spider_list_from_eggfile()

This commit is contained in:
Pablo Hoffman 2010-11-05 11:24:33 -02:00
parent de4909faca
commit 31bbcc9476
2 changed files with 8 additions and 3 deletions

View File

@ -8,7 +8,7 @@ def get_spider_list_from_eggfile(eggfile, project, eggrunner='scrapyd.eggrunner'
# FIXME: we use a temporary directory here to avoid permissions problems
# when running as system service, as "scrapy list" command tries to write
# the scrapy.db sqlite database in current directory
tmpdir = mkdtemp()
tmpdir = mkdtemp(prefix='eggs-%s-' % project)
try:
with NamedTemporaryFile(suffix='.egg', dir=tmpdir) as f:
shutil.copyfileobj(eggfile, f)
@ -32,7 +32,10 @@ def activate_egg(eggpath):
to activate a Scrapy egg file. Don't use it from other code as it may
leave unwanted side effects.
"""
d = pkg_resources.find_distributions(eggpath).next()
try:
d = pkg_resources.find_distributions(eggpath).next()
except StopIteration:
raise ValueError("Unknown or corrupt egg")
d.activate()
settings_module = d.get_entry_info('scrapy', 'settings').module_name
os.environ['SCRAPY_SETTINGS_MODULE'] = settings_module

View File

@ -68,7 +68,8 @@ class ListSpiders(WsResource):
project = txrequest.args['project'][0]
eggstorage = self.root.app.getComponent(IEggStorage)
_, eggf = eggstorage.get(project)
spiders = get_spider_list_from_eggfile(eggf, project)
spiders = get_spider_list_from_eggfile(eggf, project, \
eggrunner=self.root.egg_runner)
return {"status": "ok", "spiders": spiders}
class DeleteProject(WsResource):
@ -96,6 +97,7 @@ class Root(Resource):
def __init__(self, config, app):
Resource.__init__(self)
self.debug = config.getboolean('debug', False)
self.eggrunner = config.get('egg_runner')
self.app = app
self.putChild('schedule.json', Schedule(self))
self.putChild('addversion.json', AddVersion(self))