Here are the examples of the python api scrapy.utils.conf.closest_scrapy_cfg taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
4 Examples
3
Example 1
Project: scrapyrt Source File: cmdline.py
def find_scrapy_project(project):
project_config_path = closest_scrapy_cfg()
if not project_config_path:
raise RuntimeError('Cannot find scrapy.cfg file')
project_config = SafeConfigParser()
project_config.read(project_config_path)
try:
project_settings = project_config.get('settings', project)
except (NoSectionError, NoOptionError) as e:
raise RuntimeError(e.message)
if not project_settings:
raise RuntimeError('Cannot find scrapy project settings')
project_location = os.path.dirname(project_config_path)
sys.path.append(project_location)
return project_settings
3
Example 2
def inside_project():
scrapy_module = os.environ.get('SCRAPY_SETTINGS_MODULE')
if scrapy_module is not None:
try:
import_module(scrapy_module)
except ImportError as exc:
warnings.warn("Cannot import scrapy settings module %s: %s" % (scrapy_module, exc))
else:
return True
return bool(closest_scrapy_cfg())
3
Example 3
Project: scrapy Source File: project.py
def project_data_dir(project='default'):
"""Return the current project data dir, creating it if it doesn't exist"""
if not inside_project():
raise NotConfigured("Not inside a project")
cfg = get_config()
if cfg.has_option(DATADIR_CFG_SECTION, project):
d = cfg.get(DATADIR_CFG_SECTION, project)
else:
scrapy_cfg = closest_scrapy_cfg()
if not scrapy_cfg:
raise NotConfigured("Unable to find scrapy.cfg file to infer project data dir")
d = abspath(join(dirname(scrapy_cfg), '.scrapy'))
if not exists(d):
os.makedirs(d)
return d
3
Example 4
def _getsources(self):
sources = ['/etc/scrapyd/scrapyd.conf', r'c:\scrapyd\scrapyd.conf']
sources += sorted(glob.glob('/etc/scrapyd/conf.d/*'))
sources += ['scrapyd.conf']
sources += [expanduser('~/.scrapyd.conf')]
scrapy_cfg = closest_scrapy_cfg()
if scrapy_cfg:
sources.append(scrapy_cfg)
return sources