diff --git a/scrapyd/eggutils.py b/scrapyd/eggutils.py index d25969d68..4a34029f1 100644 --- a/scrapyd/eggutils.py +++ b/scrapyd/eggutils.py @@ -2,30 +2,23 @@ from __future__ import with_statement import os, sys, shutil, pkg_resources from subprocess import Popen, PIPE -from tempfile import NamedTemporaryFile, mkdtemp +from tempfile import NamedTemporaryFile 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(prefix='eggs-%s-' % project) - try: - with NamedTemporaryFile(suffix='.egg', dir=tmpdir) as f: - shutil.copyfileobj(eggfile, f) - f.flush() - eggfile.seek(0) - pargs = [sys.executable, '-m', eggrunner, 'list'] - env = os.environ.copy() - env['SCRAPY_PROJECT'] = project - env['SCRAPY_EGGFILE'] = f.name - proc = Popen(pargs, stdout=PIPE, stderr=PIPE, cwd=tmpdir, env=env) - out, err = proc.communicate() - if proc.returncode: - msg = err or out or 'unknown error' - raise RuntimeError(msg.splitlines()[-1]) - return out.splitlines() - finally: - shutil.rmtree(tmpdir) + with NamedTemporaryFile(suffix='.egg') as f: + shutil.copyfileobj(eggfile, f) + f.flush() + eggfile.seek(0) + pargs = [sys.executable, '-m', eggrunner, 'list'] + env = os.environ.copy() + env['SCRAPY_PROJECT'] = project + env['SCRAPY_EGGFILE'] = f.name + proc = Popen(pargs, stdout=PIPE, stderr=PIPE, env=env) + out, err = proc.communicate() + if proc.returncode: + msg = err or out or 'unknown error' + raise RuntimeError(msg.splitlines()[-1]) + return out.splitlines() def activate_egg(eggpath): """Activate a Scrapy egg file. This is meant to be used from egg runners