Commits

Gregory Petukhov committed 9c81fae

Do not raise Exception in `grab` scripts if settings module is found and default settings module name is used, use completely default settings in this case

  • Participants
  • Parent commits 743a5b6

Comments (0)

Files changed (3)

 from argparse import ArgumentParser
 import logging
 from grab.tools.lock import assert_lock
-import time
-import traceback
-from datetime import datetime, timedelta
+from grab.tools.logs import default_logging
 import sys 
-from grab.tools.logs import default_logging
-from grab import Grab
-import sys 
-#import setup_django
 from grab.util.config import build_global_config
 
 logger = logging.getLogger('grab.cli')

File grab/util/config.py

+import os
+
 from copy import deepcopy
 from grab.util import default_config
 from grab.util.module import import_string
 
 def build_global_config(settings_mod_path='settings'):
     config = Config()
-    config.update_with_path(settings_mod_path)
-    config.update_with_object(default_config.default_config, only_new_keys=True)
-    return config
+    try:
+        config.update_with_path(settings_mod_path)
+    except ImportError:
+        # do not raise exception if settings_mod_path is default
+        # and no settings.py file found in current directory
+        if (settings_mod_path == 'settings' and
+            not os.path.exists(os.path.join(os.path.realpath(os.getcwd()), 'settings.py'))):
+            pass
+        else:
+            raise
+    else:
+        config.update_with_object(default_config.default_config, only_new_keys=True)
+        return config
 
 
 def build_spider_config(spider_name, global_config=None):

File grab/util/default_config.py

     GRAB_TASK_TRY_LIMIT = 10
     GRAB_DISPLAY_TIMING = True
     GRAB_DISPLAY_STATS = True
+    GRAB_ACTIVATE_VIRTUALENV = False
 
 default_config = DefaultConfig()