Permalink
Browse files

Added setuptools and version.

  • Loading branch information...
David Cramer
David Cramer committed Sep 5, 2009
1 parent f6b6f85 commit 442e342df41ac30511308d2261ca9c2e0ca74642
Showing with 130 additions and 66 deletions.
  1. +3 −1 .gitignore
  2. +9 −0 LICENSE
  3. +2 −0 MANIFEST.in
  4. +27 −65 feedreader/__init__.py
  5. +69 −0 feedreader/feedreader.py
  6. +20 −0 setup.py
View
@@ -1 +1,3 @@
-*.pyc
+*.pyc
+/build
+/dist
View
@@ -0,0 +1,9 @@
+Copyright (c) 2009, David Cramer <dcramer@gmail.com>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -0,0 +1,2 @@
+include setup.py README.rst LICENSE MANIFEST.in
+global-exclude *~
View
@@ -1,69 +1,31 @@
-import lxml.objectify
-import httplib
-import urlparse
+import os.path
-from feedreader.utils.dates import *
-from feedreader.feeds import InvalidFeed
+__all__ = ('__version__', '__build__')
-__all__ = ('ParseError', 'InvalidFeed', 'from_string', 'from_url', 'from_file', 'parse_date')
+__version__ = (0, 1)
-# TODO: change the feeds to a registration model
-from feedreader.feeds.atom10 import Atom10Feed
-from feedreader.feeds.rss20 import RSS20Feed
-
-feeds = (RSS20Feed, Atom10Feed)
-
-ACCEPT_HEADER = "application/atom+xml,application/rdf+xml,application/rss+xml,application/x-netcdf,application/xml;q=0.9,text/xml;q=0.2,*/*;q=0.1"
-
-USER_AGENT = 'py-feedreader'
-
-class ParseError(Exception): pass
-
-def _from_parsed(parsed):
- for feed in feeds:
- try:
- result = feed(parsed)
- except InvalidFeed:
- pass
- else:
- return result
- raise InvalidFeed(parsed.tag)
-
-def from_string(data, *args, **kwargs):
- parsed = lxml.objectify.fromstring(data, *args, **kwargs)
- return _from_parsed(parsed)
-
-def from_file(fp, *args, **kwargs):
- parsed = lxml.objectify.parse(fp, **kwargs).getroot()
- return _from_parsed(parsed)
-
-def from_url(url, **kwargs):
- url = urlparse.urlparse(url)
- if url.scheme == 'https':
- conn = httplib.HTTPSConnection
- elif url.scheme == 'http':
- conn = httplib.HTTPConnection
- else:
- raise NotImplementedError
-
- base_url = '%s://%s' % (url.scheme, url.hostname)
-
- headers = {
- 'User-Agent': USER_AGENT,
- 'Accept': ACCEPT_HEADER,
- }
- connection = conn(url.hostname)
- method = kwargs.pop('method', 'GET').upper()
- if method == 'GET':
- path, query = url.path + '?' + url.query, ''
- else:
- path, query = url.path, url.query
- connection.request(method, path, query, headers)
+def _get_git_revision(path):
+ revision_file = os.path.join(path, 'refs', 'heads', 'master')
+ if not os.path.exists(revision_file):
+ return None
+ fh = open(revision_file, 'r')
try:
- response = connection.getresponse()
- except httplib.BadStatusLine, exc:
- raise ParseError('Bad status line: %s' % (exc,))
-
- if response.status != 200:
- raise ParseError('%s %s' % (response.status, response.reason))
- return from_file(response, base_url=base_url)
+ return fh.read()
+ finally:
+ fh.close()
+
+def get_revision():
+ """
+ :returns: Revision number of this branch/checkout, if available. None if
+ no revision number can be determined.
+ """
+ package_dir = os.path.dirname(__file__)
+ checkout_dir = os.path.normpath(os.path.join(package_dir, '..'))
+ path = os.path.join(checkout_dir, '.git')
+ if os.path.exists(path):
+ return _get_git_revision(path)
+ return None
+
+__build__ = get_revision()
+
+from feedreader import *
View
@@ -0,0 +1,69 @@
+import lxml.objectify
+import httplib
+import urlparse
+
+from feedreader.utils.dates import *
+from feedreader.feeds import InvalidFeed
+
+__all__ = ('ParseError', 'InvalidFeed', 'from_string', 'from_url', 'from_file', 'parse_date')
+
+# TODO: change the feeds to a registration model
+from feedreader.feeds.atom10 import Atom10Feed
+from feedreader.feeds.rss20 import RSS20Feed
+
+feeds = (RSS20Feed, Atom10Feed)
+
+ACCEPT_HEADER = "application/atom+xml,application/rdf+xml,application/rss+xml,application/x-netcdf,application/xml;q=0.9,text/xml;q=0.2,*/*;q=0.1"
+
+USER_AGENT = 'py-feedreader'
+
+class ParseError(Exception): pass
+
+def _from_parsed(parsed):
+ for feed in feeds:
+ try:
+ result = feed(parsed)
+ except InvalidFeed:
+ pass
+ else:
+ return result
+ raise InvalidFeed(parsed.tag)
+
+def from_string(data, *args, **kwargs):
+ parsed = lxml.objectify.fromstring(data, *args, **kwargs)
+ return _from_parsed(parsed)
+
+def from_file(fp, *args, **kwargs):
+ parsed = lxml.objectify.parse(fp, **kwargs).getroot()
+ return _from_parsed(parsed)
+
+def from_url(url, **kwargs):
+ url = urlparse.urlparse(url)
+ if url.scheme == 'https':
+ conn = httplib.HTTPSConnection
+ elif url.scheme == 'http':
+ conn = httplib.HTTPConnection
+ else:
+ raise NotImplementedError
+
+ base_url = '%s://%s' % (url.scheme, url.hostname)
+
+ headers = {
+ 'User-Agent': USER_AGENT,
+ 'Accept': ACCEPT_HEADER,
+ }
+ connection = conn(url.hostname)
+ method = kwargs.pop('method', 'GET').upper()
+ if method == 'GET':
+ path, query = url.path + '?' + url.query, ''
+ else:
+ path, query = url.path, url.query
+ connection.request(method, path, query, headers)
+ try:
+ response = connection.getresponse()
+ except httplib.BadStatusLine, exc:
+ raise ParseError('Bad status line: %s' % (exc,))
+
+ if response.status != 200:
+ raise ParseError('%s %s' % (response.status, response.reason))
+ return from_file(response, base_url=base_url)
View
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+
+from setuptools import setup, find_packages
+
+import feedreader
+
+setup(
+ name='feedreader',
+ version=".".join(map(str, idmapper.__version__)),
+ author='David Cramer',
+ author_email='dcramer@gmail.com',
+ url='http://github.com/dcramer/feedreader',
+ install_requires=[
+ 'lxml',
+ 'python-dateutil',
+ ],
+ description = 'An identify mapper for the Django ORM',
+ packages=find_packages(),
+ include_package_data=True,
+)

0 comments on commit 442e342

Please sign in to comment.