<s> import os <EOL> from six . moves import cPickle as pickle <EOL> import warnings <EOL> from importlib import import_module <EOL> from os . path import join , dirname , abspath , isabs , exists <EOL> from scrapy . utils . conf import closest_scrapy_cfg , get_config , init_env <EOL> from scrapy . settings import Settings <EOL> from scrapy . exceptions import NotConfigured <EOL> ENVVAR = '<STR_LIT>' <EOL> DATADIR_CFG_SECTION = '<STR_LIT>' <EOL> def inside_project ( ) : <EOL> scrapy_module = os . environ . get ( '<STR_LIT>' ) <EOL> if scrapy_module is not None : <EOL> try : <EOL> import_module ( scrapy_module ) <EOL> except ImportError as exc : <EOL> warnings . warn ( "<STR_LIT>" % ( scrapy_module , exc ) ) <EOL> else : <EOL> return True <EOL> return bool ( closest_scrapy_cfg ( ) ) <EOL> def project_data_dir ( project = '<STR_LIT:default>' ) : <EOL> """<STR_LIT>""" <EOL> if not inside_project ( ) : <EOL> raise NotConfigured ( "<STR_LIT>" ) <EOL> cfg = get_config ( ) <EOL> if cfg . has_option ( DATADIR_CFG_SECTION , project ) : <EOL> d = cfg . get ( DATADIR_CFG_SECTION , project ) <EOL> else : <EOL> scrapy_cfg = closest_scrapy_cfg ( ) <EOL> if not scrapy_cfg : <EOL> raise NotConfigured ( "<STR_LIT>" ) <EOL> d = abspath ( join ( dirname ( scrapy_cfg ) , '<STR_LIT>' ) ) <EOL> if not exists ( d ) : <EOL> os . makedirs ( d ) <EOL> return d <EOL> def data_path ( path , createdir = False ) : <EOL> """<STR_LIT>""" <EOL> if not isabs ( path ) : <EOL> path = join ( project_data_dir ( ) , path ) <EOL> if createdir and not exists ( path ) : <EOL> os . makedirs ( path ) <EOL> return path <EOL> def get_project_settings ( ) : <EOL> if ENVVAR not in os . environ : <EOL> project = os . environ . get ( '<STR_LIT>' , '<STR_LIT:default>' ) <EOL> init_env ( project ) <EOL> settings = Settings ( ) <EOL> settings_module_path = os . environ . get ( ENVVAR ) <EOL> if settings_module_path : <EOL> settings . setmodule ( settings_module_path , priority = '<STR_LIT>' ) <EOL> pickled_settings = os . environ . get ( "<STR_LIT>" ) <EOL> if pickled_settings : <EOL> settings . setdict ( pickle . loads ( pickled_settings ) , priority = '<STR_LIT>' ) <EOL> env_overrides = { k [ <NUM_LIT:7> : ] : v for k , v in os . environ . items ( ) if <EOL> k . startswith ( '<STR_LIT>' ) } <EOL> if env_overrides : <EOL> settings . setdict ( env_overrides , priority = '<STR_LIT>' ) <EOL> return settings </s>
