mirror of https://github.com/scrapy/scrapy.git
Simplified get_spider_list_from_eggfile() function now that it doesn't need to chdir to a custom directory (Scrapy now works when it's unable to create the SQLite database)
This commit is contained in:
parent
31bbcc9476
commit
5bdffadbe3
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue