Commit 05e4f698 authored by Ana Guerrero López's avatar Ana Guerrero López

Import Upstream version 4.4

parent 4e9cf685
Metadata-Version: 1.0
Name: IMDbPY
Version: 4.4
Summary: Python package to access the IMDb's database
Home-page: http://imdbpy.sf.net/
Author: Davide Alberani
Author-email: da@erlug.linux.it
License: GPL
Download-URL: http://imdbpy.sf.net/?page=download
Description: IMDbPY is a Python package useful to retrieve and
manage the data of the IMDb movie database about movies, people,
characters and companies.
Platform-independent and written in pure Python (and few C lines),
it can retrieve data from both the IMDb's web server and a local copy
of the whole database.
IMDbPY package can be very easily used by programmers and developers
to provide access to the IMDb's data to their programs.
Some simple example scripts - useful for the end users - are included
in this package; other IMDbPY-based programs are available at the
home page: http://imdbpy.sf.net/
Keywords: imdb,movie,people,database,cinema,film,person,cast,actor,actress,director,sql,character,company,svn,package,plain text data files,keywords,top250,bottom100,xml
Platform: any
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Environment :: Web Environment
Classifier: Environment :: Handhelds/PDA's
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: End Users/Desktop
Classifier: License :: OSI Approved :: GNU General Public License (GPL)
Classifier: Natural Language :: English
Classifier: Programming Language :: Python
Classifier: Programming Language :: C
Classifier: Operating System :: OS Independent
Classifier: Topic :: Database :: Front-Ends
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
MANIFEST.in
ez_setup.py
setup.cfg
setup.py
./bin/get_character.py
./bin/get_company.py
./bin/get_first_character.py
./bin/get_first_company.py
./bin/get_first_movie.py
./bin/get_first_person.py
./bin/get_keyword.py
./bin/get_movie.py
./bin/get_person.py
./bin/get_top_bottom_movies.py
./bin/imdbpy2sql.py
./bin/search_character.py
./bin/search_company.py
./bin/search_keyword.py
./bin/search_movie.py
./bin/search_person.py
IMDbPY.egg-info/PKG-INFO
IMDbPY.egg-info/SOURCES.txt
IMDbPY.egg-info/dependency_links.txt
IMDbPY.egg-info/not-zip-safe
IMDbPY.egg-info/requires.txt
IMDbPY.egg-info/top_level.txt
bin/get_character.py
bin/get_company.py
bin/get_first_character.py
bin/get_first_company.py
bin/get_first_movie.py
bin/get_first_person.py
bin/get_keyword.py
bin/get_movie.py
bin/get_person.py
bin/get_top_bottom_movies.py
bin/imdbpy2sql.py
bin/search_character.py
bin/search_company.py
bin/search_keyword.py
bin/search_movie.py
bin/search_person.py
docs/AUTHOR.txt
docs/CONTRIBUTORS.txt
docs/CREDITS.txt
docs/Changelog.txt
docs/DISCLAIMER.txt
docs/FAQS.txt
docs/GPL.txt
docs/INSTALL.txt
docs/LICENSE.txt
docs/README.adult
docs/README.companies
docs/README.currentRole
docs/README.devel
docs/README.info2xml
docs/README.keywords
docs/README.local
docs/README.locale
docs/README.logging
docs/README.mobile
docs/README.newparsers
docs/README.package
docs/README.redesign
docs/README.series
docs/README.sqldb
docs/README.txt
docs/README.users
docs/README.utf8
docs/TODO.txt
docs/imdbpy.cfg
docs/imdbpy44.dtd
docs/imdbpyPowered.png
docs/imdbpyico.png
docs/imdbpyico.xpm
docs/imdbpyico16x16.ico
docs/imdbpyico32x32.ico
docs/imdbpywin.bmp
imdb/Character.py
imdb/Company.py
imdb/Movie.py
imdb/Person.py
imdb/__init__.py
imdb/_compat.py
imdb/_exceptions.py
imdb/_logging.py
imdb/articles.py
imdb/helpers.py
imdb/utils.py
imdb/locale/__init__.py
imdb/locale/generatepot.py
imdb/locale/imdbpy-en.po
imdb/locale/imdbpy-it.po
imdb/locale/imdbpy-tr.po
imdb/locale/imdbpy.pot
imdb/locale/msgfmt.py
imdb/locale/msgfmt.pyc
imdb/locale/rebuildmo.py
imdb/locale/rebuildmo.pyc
imdb/locale/en/LC_MESSAGES/imdbpy.mo
imdb/locale/it/LC_MESSAGES/imdbpy.mo
imdb/locale/tr/LC_MESSAGES/imdbpy.mo
imdb/parser/__init__.py
imdb/parser/http/__init__.py
imdb/parser/http/characterParser.py
imdb/parser/http/companyParser.py
imdb/parser/http/movieParser.py
imdb/parser/http/personParser.py
imdb/parser/http/searchCharacterParser.py
imdb/parser/http/searchCompanyParser.py
imdb/parser/http/searchKeywordParser.py
imdb/parser/http/searchMovieParser.py
imdb/parser/http/searchPersonParser.py
imdb/parser/http/topBottomParser.py
imdb/parser/http/utils.py
imdb/parser/http/bsouplxml/__init__.py
imdb/parser/http/bsouplxml/_bsoup.py
imdb/parser/http/bsouplxml/bsoupxpath.py
imdb/parser/http/bsouplxml/etree.py
imdb/parser/http/bsouplxml/html.py
imdb/parser/mobile/__init__.py
imdb/parser/sql/__init__.py
imdb/parser/sql/alchemyadapter.py
imdb/parser/sql/cutils.c
imdb/parser/sql/dbschema.py
imdb/parser/sql/objectadapter.py
\ No newline at end of file
SQLObject
SQLAlchemy
sqlalchemy-migrate
lxml
\ No newline at end of file
Metadata-Version: 1.0
Name: IMDbPY
Version: 4.4
Summary: Python package to access the IMDb's database
Home-page: http://imdbpy.sf.net/
Author: Davide Alberani
Author-email: da@erlug.linux.it
License: GPL
Download-URL: http://imdbpy.sf.net/?page=download
Description: IMDbPY is a Python package useful to retrieve and
manage the data of the IMDb movie database about movies, people,
characters and companies.
Platform-independent and written in pure Python (and few C lines),
it can retrieve data from both the IMDb's web server and a local copy
of the whole database.
IMDbPY package can be very easily used by programmers and developers
to provide access to the IMDb's data to their programs.
Some simple example scripts - useful for the end users - are included
in this package; other IMDbPY-based programs are available at the
home page: http://imdbpy.sf.net/
Keywords: imdb,movie,people,database,cinema,film,person,cast,actor,actress,director,sql,character,company,svn,package,plain text data files,keywords,top250,bottom100,xml
Platform: any
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Environment :: Web Environment
Classifier: Environment :: Handhelds/PDA's
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: End Users/Desktop
Classifier: License :: OSI Approved :: GNU General Public License (GPL)
Classifier: Natural Language :: English
Classifier: Programming Language :: Python
Classifier: Programming Language :: C
Classifier: Operating System :: OS Independent
Classifier: Topic :: Database :: Front-Ends
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
......@@ -135,7 +135,6 @@ try:
'mysql-innodb', 'ms-sqlserver',
'sqlite-transactions',
'fix-old-style-titles',
#'do-not-fix-old-style-titles',
'mysql-force-myisam', 'orm',
'csv=', 'csv-ext=', 'help'])
except getopt.error, e:
......@@ -176,9 +175,6 @@ for opt in optlist:
USE_ORM = opt[1].split(',')
elif opt[0] == '--fix-old-style-titles':
warnings.warn('The --fix-old-style-titles argument is obsolete.')
# FIX_OLD_STYLE_TITLES = True
#elif opt[0] == '--do-not-fix-old-style-titles':
# FIX_OLD_STYLE_TITLES = False
elif opt[0] in ('-h', '--help'):
print HELP
sys.exit(0)
......@@ -384,17 +380,17 @@ class CSVCursor(object):
if lobFN:
lobFN = os.path.basename(lobFN)
else:
tFD = open(os.path.join(CSV_DIR, tName + self.csvExt), 'w')
tFD = open(os.path.join(CSV_DIR, tName + self.csvExt), 'wb')
self._fdPool[tName] = tFD
if doLOB:
lobFN = '%s.lob' % tName
lobFD = open(os.path.join(CSV_DIR, lobFN), 'w')
lobFD = open(os.path.join(CSV_DIR, lobFN), 'wb')
self._lobFDPool[tName] = lobFD
buildLine = self.buildLine
tableToAddID = False
if tName in ('cast_info', 'movie_info', 'person_info',
'movie_companies', 'movie_link', 'aka_name',
'complete_cast', 'movie_info_idx'):
'complete_cast', 'movie_info_idx', 'movie_keyword'):
tableToAddID = tName
if tName not in self._counters:
self._counters[tName] = 1
......@@ -1011,7 +1007,7 @@ class MoviesCache(_BaseCache):
episodeOf = self.addUnique(stitle)
del t['episode of']
year = self.movieYear.get(v)
if year is not None:
if year is not None and year != '????':
try: t['year'] = int(year)
except ValueError: pass
elif kind in ('tv series', 'tv mini series'):
......@@ -1326,6 +1322,12 @@ class SQLData(dict):
converter=self.converter)
newdata._recursionLevel = self._recursionLevel
newflushEvery = self.flushEvery / 2
if newflushEvery < 1:
print 'WARNING recursion level exceded trying to flush data'
print 'WARNING this batch of data is lost.'
self.clear()
self.counter = self.counterInit
return
self.flushEvery = newflushEvery
newdata.flushEvery = newflushEvery
popitem = self.popitem
......@@ -2723,8 +2725,6 @@ def run():
t('loadCSVFiles()')
t('TOTAL TIME TO INSERT/WRITE DATA', sinceBegin=True)
#print 'TOTAL TIME TO INSERT/WRITE DATA: %d minutes, %d seconds' % \
# divmod(int(time.time())-BEGIN_TIME, 60)
executeCustomQueries('BEFORE_INDEXES')
......@@ -2743,8 +2743,6 @@ def run():
executeCustomQueries('END')
t('FINAL', sinceBegin=True)
#print 'DONE! (in %d minutes, %d seconds)' % \
# divmod(int(time.time())-BEGIN_TIME, 60)
_HEARD = 0
......
......@@ -31,6 +31,8 @@ I'd like to thank the following people for their help:
* James Rubino for many bug reports.
* Cesare Lasorella for a bug report about newer versions of SQLObject.
* Andre LeBlanc for a bug report about airing date of tv series episodes.
* neonrush for a bug parsing Malcolm McDowell filmography!
......
Changelog for IMDbPY
====================
* What's the new in release 4.4 "Gandhi" (06 Jan 2010)
[general]
- introduced a logging facility; see README.logging.
- the 'http' and 'mobile' should be a lot more robust.
[http]
- fixes for the n-th set of changes to IMDb's HTML.
- improvements to perfect-match searches.
- slightly simplified the parsers for search results.
[mobile]
- fixes for the n-th set of changes to IMDb's HTML.
- slightly simplified the parsers for search results.
[sql]
- movies' keywords are now correctly imported, using CSV files.
- minor fixes to handle crap in the plain text data files.
- removed an outdate parameter passed to SQLObject.
- made imdbpy2sql.py more robust in some corner-cases.
- fixes for the Windows environment.
* What's the new in release 4.3 "Public Enemies" (18 Nov 2009)
[general]
- the installer now takes care of .mo files.
......@@ -10,7 +32,7 @@
- updated the DTD.
[http]
- fixed a log of bugs introduced by the new IMDb.com design.
- fixed a lot of bugs introduced by the new IMDb.com design.
- nicer handling of HTTP 404 response code.
- fixed parsers for top250 and bottom100 lists.
- fixed a bug parsing AKAs.
......
......@@ -15,8 +15,9 @@ Sections in this file:
imdb (package)
|
+-> _exceptions
+-> _articles
+-> _compat
+-> _exceptions
+-> Movie
+-> Person
+-> Character
......@@ -58,8 +59,11 @@ imdb (package)
Description:
imdb (package): contains the IMDb function, the IMDbBase class and imports
the IMDbError exception class.
_articles: defines some functions and data useful to smartly guess the
language of a movie title (internally used).
_compat: compatibility functions and class for some strange environments
(internally used).
_exceptions: defines the exceptions internally used.
_compat: compatibility functions and class for some strange environments.
Movie: contains the Movie class, used to describe and manage a movie.
Person: contains the Person class, used to describe and manage a person.
Character: contains the Character class, used to describe and manage
......
LOGGING
=======
Since version 4.4 IMDbPY provides a logging facility, using the
powerful "logging" module.
You can find documentation about it here:
http://docs.python.org/library/logging.html
By default information are logged on standard error; you can read
on the module documentation how to stream them elsewhere.
The default logging level is "warning"; this can be changed
modifying the "loggingLevel" key of your imdbpy.cfg file.
......@@ -278,6 +278,25 @@ Other keys that contain list of companies are: production companies, special
effects, sound mix, special effects companies, miscellaneous companies,
distributors.
Converting a title to its 'Title, The' canonical format, IMDbPY does
some assumptions about what is an article and what not, and this could
lead to some wrong canonical titles. E.g.: "Hard, Die" instead of
"Die Hard", since 'Die' is guessed as an article (and it is, in Germany...)
To solve this problem, there are other keys, "smart canonical title",
"smart long imdb canonical title", "smart canonical series title",
"smart canonical episode title" which can be used to do a better job
converting a title into its canonical format.
It works, but it needs to know something about articles in various
languages: if you want to help, see the LANG_ARTICLES and _LANG_COUNTRIES
dictionaries in the '_articles' module.
To know what the language in which a movie title is assumed to be,
call its 'guessLanguage' method (it will return None, if unable to guess).
If you want to force a given language instead of the guessed one, you
can call its 'smartCanonicalTitle', setting the 'lang' argument
appropriately.
THE Person CLASS
================
......
......@@ -69,9 +69,7 @@ SVN command to download the latest development version:
[OTHER REQUIRED MODULES]
Obviously SQLObject and SQLAlchemy can access databases only through other
specific modules/packages, that you need to have installed (e.g.:
python-mysqldb for MySQL, python-psycopg for PostgreSQL, python-sqlite
for SQLite and so on).
'mysql-python' for MySQL, 'psycopg' for PostgreSQL, and so on).
SQL DATABASE INSTALLATION
......@@ -179,6 +177,14 @@ The imdbpy2sql.py will print a lot of debug information on standard output;
you can save it in a file, appending (without quotes) "2>&1 | tee output.txt"
[Microsoft Windows paths]
It's much safer, in a Microsoft Windows environment, to use full paths
for the values of the '-c' and '-d' arguments, complete with drive letter.
The best thing is to use _UNIX_ path separator, and to add a leading
separator. E.g.:
-d C:/path/to/imdb_files/ -c C:/path/to/csv_tmp_files/
[MySQL]
In general, if you get an embarrassingly high numbero of "TOO MANY DATA
... SPLITTING" lines, consider increasing max_allowed_packet (in the
......@@ -358,7 +364,7 @@ does.
=========
Keep in mind that actually only MySQL, PostgreSQL and IBM DB2 are
currently supported. Moreover, you may incur in problems (e.g.: your
supported. Moreover, you may incur in problems (e.g.: your
postgres _server_ process must have reading access to the directory
you're storing the CSV files).
......@@ -366,4 +372,6 @@ To create (and import) a set of CSV files, run imdbpy2sql.py with the
syntax:
./imdbpy2sql.py -d /dir/with/plainTextDataFiles/ -u URI -c /directory/where/to/store/CSVfiles
The created files will be imported near the end of the imdbpy2sql.py
processing; notice that after that, you can safely cancel these files.
......@@ -34,6 +34,11 @@ the "README.devel" file. ;-)
Everything you need to do is to run, as the root user, the command:
# python setup.py install
IMDbPY itself can be installed through easy_install and pip,
with - respectively - these commands (as root):
easy_install IMDbPY
pip install IMDbPY
If, for some reason, it doesn't work, you can copy the "./imdb"
directory in the local site-packages directory of the python
major version you're using, but remember that you'll not satisfy
......@@ -41,9 +46,8 @@ the required dependencies and neither compile the optional C module,
so use this as your very last resort.
To know what major version of python you've installed, run:
$ python -V
It should return a string like "Python 2.3.5"; in this example
the major version is "2.3".
It should return a string like "Python 2.6.1"; in this example
the major version is "2.6".
Now copy the "./imdb" directory:
# cp -r ./imdb /usr/local/lib/python{MAJORVERSION}/site-packages/
......@@ -71,6 +75,17 @@ You can exclude the unwanted one with:
If you specify both, --without-sql is implied.
SVN VERSION
===========
The best thing is always to use a package for your distribution,
or use easy_install or pip to install the latest release, but it
goes without saying that sometimes you need the very latest version
(keep in mind that the IMDb site is a moving target...).
In this case, you can always use the SVN version, available here:
http://imdbpy.sourceforge.net/?page=download#svn
HELP
====
......
......@@ -7,6 +7,7 @@ NOTE: it's always time to clean the code! <g>
[general]
* improve the logging facility.
* Write better summary() methods for Movie, Person, Character
and Company classes.
* Some portions of code are poorly commented.
......@@ -75,10 +76,6 @@ NOTE: it's always time to clean the code! <g>
* Serious confusion about handling XML/HTML/SGML char references; there
are too many fixes for special cases, and a better understanding of how
lxml and BeautifulSoup behave is required.
* There's a known bug using IMDbPY with Python 2.0 and 2.1:
it fails to retrieve web pages, raising the httplib.UnknownTransferEncoding
exception, if a proxy is used; unset the HTTP_PROXY environment variable
or call the imdbObject.set_proxy(None) method.
* If the access through the proxy fails, is it possible to
automatically try without? It doesn't seem easy...
* Access to the "my IMDb" functions for registered users would
......@@ -116,12 +113,15 @@ Again: if there's something that bother you, write some code.
It's free software, after all.
Things to do:
* command line options to only populate the CSV files and to only
upload the CSV files.
* The imdbpy2sql.py script MUST be run on a database with empty tables;
unfortunately so far a SQL installation can't be "updated" without
recreating the database from scratch.
IMDb releases also "diff" files to keep the plain text files updated;
it would be wonderful to directly use these diff files to upgrade the
SQL database, but I think this is a nearly impossible task.
A lot of attempts were made in this direction, always failing.
* There are a lot of things to do to improve SQLAlchemy support (especially
in terms of performances); see FIXME/TODO/XXX notices in the code.
* The pysqlite2.dbapi2.OperationalError exception is raise when SQLite
......
......@@ -58,4 +58,13 @@ accessSystem = http
# a comma, to express order preference. Valid values: "sqlobject", "sqlalchemy"
#useORM = sqlobject,sqlalchemy
# Set the threshold for logging messages.
# Can be one of "debug", "info", "warning", "error", "critical" (default:
# "warning").
#loggingLevel = debug
# Path to a configuration file for the logging facility;
# see: http://docs.python.org/library/logging.html#configuring-logging
#loggingConfig = ~/.imdbpy-logger.cfg
<!--
XML Document Type Definition for IMDbPY 4.3.
XML Document Type Definition for IMDbPY 4.4.
http://imdbpy.sf.net/dtd/imdbpy43.dtd
http://imdbpy.sf.net/dtd/imdbpy44.dtd
Copyright 2009 H. Turgut Uyar <uyar@tekir.org>
2009 Davide Alberani <da@erlug.linux.it>
......@@ -230,12 +230,15 @@
| archive-footage
| biography
| episodes
| feature
| filmography
| headshot
| introduction
| long-imdb-name
| name
| quotes
| tv
| video
)*>
<!ATTLIST character id CDATA #IMPLIED>
......@@ -679,6 +682,7 @@
<!ELEMENT death-notes (#PCDATA)>
<!ELEMENT episode-title (#PCDATA)>
<!ELEMENT external-reviews (item)*>
<!ELEMENT feature (movie)*>
<!ELEMENT headshot (#PCDATA)>
<!ELEMENT height (#PCDATA)>
<!ELEMENT imdbindex (#PCDATA)>
......@@ -707,6 +711,8 @@
<!ELEMENT synopsis (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT top-250-rank (#PCDATA)>
<!ELEMENT tv (movie)*>
<!ELEMENT video (movie)*>
<!ELEMENT votes (#PCDATA)>
<!ELEMENT votes-distribution (#PCDATA)>
<!ELEMENT year (#PCDATA | item)*>
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
......@@ -6,7 +6,7 @@ a person from the IMDb database.
It can fetch data through different media (e.g.: the IMDb web pages,
a SQL database, etc.)
Copyright 2004-2009 Davide Alberani <da@erlug.linux.it>
Copyright 2004-2010 Davide Alberani <da@erlug.linux.it>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -25,15 +25,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
__all__ = ['IMDb', 'IMDbError', 'Movie', 'Person', 'Character', 'Company',
'available_access_systems']
__version__ = VERSION = '4.3svn20091117'
__version__ = VERSION = '4.4'
# Import compatibility module (importing it is enough).
import _compat
import sys, os, ConfigParser
import sys, os, ConfigParser, logging
from types import MethodType
from imdb import Movie, Person, Character, Company
import imdb._logging
from imdb._exceptions import IMDbError, IMDbDataAccessError
from imdb.utils import build_title, build_name, build_company_name
......@@ -162,6 +163,18 @@ def IMDb(accessSystem=None, *arguments, **keywords):
# wrong: ignore everything and pretend we were called with
# the 'http' accessSystem.
accessSystem = 'http'
if 'loggingLevel' in keywords:
imdb._logging.setLevel(keywords['loggingLevel'])
del keywords['loggingLevel']
if 'loggingConfig' in keywords:
logCfg = keywords['loggingConfig']
del keywords['loggingConfig']
try:
import logging.config
logging.config.fileConfig(os.path.expanduser(logCfg))
except Exception, e:
import warnings
warnings.warn('unable to read logger config: %s' % e)
if accessSystem in ('http', 'web', 'html'):
from parser.http import IMDbHTTPAccessSystem
return IMDbHTTPAccessSystem(*arguments, **keywords)
......@@ -226,6 +239,9 @@ class IMDbBase:
# in the subclasses).
accessSystem = 'UNKNOWN'
# Top-level logger for IMDbPY.
_imdb_logger = logging.getLogger('imdbpy')
def __init__(self, defaultModFunct=None, results=20, keywordsResults=100,
*arguments, **keywords):
"""Initialize the access system.
......@@ -694,7 +710,14 @@ class IMDbBase:
(prefix, i.replace(' ', '_')))
except AttributeError:
raise IMDbDataAccessError, 'unknown information set "%s"' % i
ret = method(mopID)
try:
ret = method(mopID)
except Exception, e:
self._imdb_logger.critical('caught an exception retrieving ' \
'or parsing "%s" info set for mopID ' \
'"%s" (accessSystem: %s)',
i, mopID, mop.accessSystem, exc_info=True)
ret = {}
keys = None
if 'data' in ret:
res.update(ret['data'])
......@@ -703,8 +726,6 @@ class IMDbBase:
if 'info sets' in ret:
for ri in ret['info sets']:
mop.add_to_current_info(ri, keys, mainInfoset=i)
# So that only the 'main' required info set is set.
#mop.update_infoset_map(i, keys)
else:
mop.add_to_current_info(i, keys)
if 'titlesRefs' in ret:
......
......@@ -3,7 +3,7 @@ _exceptions module (imdb package).
This module provides the exception hierarchy used by the imdb package.
Copyright 2004, 2005 Davide Alberani <da@erlug.linux.it>
Copyright 2004-2009 Davide Alberani <da@erlug.linux.it>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -20,9 +20,20 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
import logging
class IMDbError(Exception):
"""Base class for every exception raised by the imdb package."""
pass
_logger = logging.getLogger('imdbpy')
def __init__(self, *args, **kwargs):
"""Initialize the exception and pass the message to the log system."""
# Every raised exception also dispatch a critical log.
self._logger.critical('%s exception raised; args: %s; kwds: %s',
self.__class__.__name__, args, kwargs,
exc_info=True)
super(IMDbError, self).__init__(*args, **kwargs)
class IMDbDataAccessError(IMDbError):
"""Exception raised when is not possible to access needed data."""
......
"""
_logging module (imdb package).
This module provides the logging facilities used by the imdb package.
Copyright 2009-2010 Davide Alberani <da@erlug.linux.it>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
import logging
LEVELS = {'debug': logging.DEBUG,
'info': logging.INFO,
'warn': logging.WARNING,
'warning': logging.WARNING,
'error': logging.ERROR,
'critical': logging.CRITICAL}
imdbpyLogger = logging.getLogger('imdbpy')
imdbpyStreamHandler = logging.StreamHandler()
imdbpyFormatter = logging.Formatter('%(asctime)s %(levelname)s [%(name)s]' \
' %(pathname)s:%(lineno)d: %(message)s')
imdbpyStreamHandler.setFormatter(imdbpyFormatter)
imdbpyLogger.addHandler(imdbpyStreamHandler)
def setLevel(level):
"""Set logging level for the main logger."""
level = level.lower().strip()
imdbpyLogger.setLevel(LEVELS.get(level, logging.NOTSET))
imdbpyLogger.log(imdbpyLogger.level, 'set logging threshold to "%s"',
logging.getLevelName(imdbpyLogger.level))
#imdbpyLogger.setLevel(logging.DEBUG)
# It can be an idea to have a single function to log and warn:
#import warnings
#def log_and_warn(msg, args=None, logger=None, level=None):
# """Log the message and issue a warning."""