From b41c5b5d5bade172b6b0e709eae1d9f305da3b86 Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Thu, 29 Oct 2009 10:41:20 -0200 Subject: [PATCH 1/2] fixed typo in intro/install doc (thanks phaithful) --- docs/intro/install.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/intro/install.rst b/docs/intro/install.rst index 0e6a0213e..6bb0fb6f0 100644 --- a/docs/intro/install.rst +++ b/docs/intro/install.rst @@ -214,16 +214,16 @@ Installing the development version 3. Make the ``scrapy-ctl.py`` script available On Unix-like systems, create a symbolic link to the file - ``scrapy-trunk/scrapy/bin/scrapy-ctl.py`` in a directory on your system path, + ``scrapy-trunk/bin/scrapy-ctl.py`` in a directory on your system path, such as ``/usr/local/bin``. For example:: - ln -s `pwd`/scrapy-trunk/scrapy/bin/scrapy-ctl.py /usr/local/bin + ln -s `pwd`/scrapy-trunk/bin/scrapy-ctl.py /usr/local/bin This simply lets you type ``scrapy-ctl.py`` from within any directory, rather than having to qualify the command with the full path to the file. On Windows systems, the same result can be achieved by copying the file - ``scrapy-trunk/scrapy/bin/scrapy-ctl.py`` to somewhere on your system path, + ``scrapy-trunk/bin/scrapy-ctl.py`` to somewhere on your system path, for example ``C:\Python25\Scripts``, which is customary for Python scripts. .. _Control Panel: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/sysdm_advancd_environmnt_addchange_variable.mspx From d5ae94df55cdf2a25422bd5ac040cc7d257b555b Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Sat, 31 Oct 2009 14:36:38 -0200 Subject: [PATCH 2/2] fixed bug when using log.start() with log level module constants instead of string names, and added regression tests --- scrapy/log.py | 15 ++++++++++++--- scrapy/tests/test_log.py | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 scrapy/tests/test_log.py diff --git a/scrapy/log.py b/scrapy/log.py index ecb7ef7d4..37018f07a 100644 --- a/scrapy/log.py +++ b/scrapy/log.py @@ -34,15 +34,24 @@ log_level = DEBUG started = False +def _get_log_level(level_name_or_id=None): + if level_name_or_id is None: + lvlname = settings['LOG_LEVEL'] or settings['LOGLEVEL'] + return globals()[lvlname] + elif isinstance(level_name_or_id, int) and 0 <= level_name_or_id <= 5: + return level_name_or_id + elif isinstance(level_name_or_id, basestring): + return globals()[level_name_or_id] + else: + raise ValueError("Unknown log level: %r" % level_name_or_id) + def start(logfile=None, loglevel=None, logstdout=None): """Initialize and start logging facility""" global log_level, started - # set loglevel - loglevel = loglevel or settings['LOG_LEVEL'] or settings['LOGLEVEL'] - log_level = globals()[loglevel] if loglevel else DEBUG if started or not settings.getbool('LOG_ENABLED'): return + log_level = _get_log_level(loglevel) started = True # set log observer diff --git a/scrapy/tests/test_log.py b/scrapy/tests/test_log.py new file mode 100644 index 000000000..ec9c1a2db --- /dev/null +++ b/scrapy/tests/test_log.py @@ -0,0 +1,17 @@ +import unittest + +from scrapy import log +from scrapy.conf import settings + +class ItemTest(unittest.TestCase): + + def test_get_log_level(self): + default_log_level = getattr(log, settings['LOG_LEVEL']) + self.assertEqual(log._get_log_level(), default_log_level) + self.assertEqual(log._get_log_level('WARNING'), log.WARNING) + self.assertEqual(log._get_log_level(log.WARNING), log.WARNING) + self.assertRaises(ValueError, log._get_log_level, 99999) + self.assertRaises(ValueError, log._get_log_level, object()) + +if __name__ == "__main__": + unittest.main()