Skip to content

Commit

Permalink
Try to extract Ring from the project.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfermigier committed Jan 7, 2011
1 parent 6d1fff3 commit bd270c8
Show file tree
Hide file tree
Showing 43 changed files with 99 additions and 230 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -2,6 +2,11 @@ syntax:glob

env
data
scratch
build
dist
Ring.egg-info

*.pyc
.idea
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion INSTALL.txt
Expand Up @@ -27,6 +27,6 @@ $ make serve

b. Crawl the feed with:

$ ./crawl.sh
$ ./ring.sh crawl

(You might want to set up a crontab).
4 changes: 4 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,4 @@
include *.txt
recursive-include ring/static *
recursive-include ring/templates *
recursive-include docs *.txt
18 changes: 11 additions & 7 deletions Makefile
@@ -1,18 +1,18 @@
.PHONY: test serve crawl run setup-env
.PHONY: test serve crawl run setup-env install

test: env data
PATH=env/bin:$(PATH) nosetests -v

serve: env data
PATH=env/bin:$(PATH) python src/server.py

data:
mkdir data
./ring.sh serve

run: serve

crawl: env
./crawl.sh
crawl: env data
./ring.sh crawl

data:
mkdir data

env:
pip install --upgrade -s -E env -r dependencies.txt
Expand All @@ -28,6 +28,10 @@ clean:
superclean: clean
rm -rf data/* env

install:
python setup.py install


push:
rsync -avz -e ssh src Makefile *.txt crawl.sh ring.cfg \
gtll@oss4cloud.org:/var/www/gtll-2.0/
2 changes: 1 addition & 1 deletion ROADMAP.txt
Expand Up @@ -11,7 +11,7 @@ Focus: get the basic functionalities out.

- File logging
- Simple regex-based filters

- Web scrapping

V. 0.2
------
Expand Down
4 changes: 0 additions & 4 deletions crawl.sh

This file was deleted.

1 change: 1 addition & 0 deletions ring.cfg
@@ -1,6 +1,7 @@
[META]
# Your planet's name
name=Planet GTLL
subtitle=Nouvelles de l'Žcosystme du libre en IdF
# Link to the main page
link=http://www.gt-logiciel-libre.org/
# Your name
Expand Down
6 changes: 6 additions & 0 deletions ring.sh
@@ -0,0 +1,6 @@
#!/bin/sh

# Manual launcher for development mode

./env/bin/python ring/__init__.py $*

28 changes: 28 additions & 0 deletions ring/__init__.py
@@ -0,0 +1,28 @@
"""Entry point for the ring project.
"""

__author__ = 'fermigier'
__doc__ = """Usage: 'ring serve' or 'ring crawl'"""

import sys
import server
import crawler

def usage():
print __doc__

def main():
if len(sys.argv) != 2:
usage()
sys.exit(1)

if sys.argv[1] == 'serve':
server.main()
elif sys.argv[1] == 'crawl':
crawler.main()
else:
usage()
sys.exit(1)

if __name__ == "__main__":
main()
5 changes: 4 additions & 1 deletion src/config.py → ring/config.py
@@ -1,3 +1,6 @@
"""Config reader.
"""

import ConfigParser
import os

Expand All @@ -7,5 +10,5 @@
os.stat(DEFAULT_CONFIG)
_config.read(DEFAULT_CONFIG)

def config():
def get_config():
return _config
10 changes: 7 additions & 3 deletions src/crawler.py → ring/crawler.py
@@ -1,5 +1,7 @@
#!/usr/bin/env python
"""Crawler for ring.
Responsible for
"""
import config
from models import Feed

Expand All @@ -22,7 +24,9 @@ def crawl(self):
print "Crawling", source
source.crawl()


if __name__ == '__main__':
def main():
crawler = Crawler()
crawler.crawl()

if __name__ == '__main__':
main()
14 changes: 10 additions & 4 deletions src/models.py → ring/models.py
@@ -1,22 +1,28 @@
"""
Models for persistent objects.
"""
from pprint import pprint

import time
import feedparser
import os

from sqlalchemy import Column, String, Integer
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker


# TODO: move to config.
ENGINE = "sqlite:///data/ring.db"

# SQLAlchemy initialisation

Base = declarative_base()
engine = create_engine('sqlite:///data/ring.db')
if ENGINE.startswith("sqlite:///data/") and not os.path.exists("data"):
os.mkdir("data")
engine = create_engine(ENGINE)
Session = sessionmaker(bind=engine)

# Abstract base class

class Entry(Base):
__tablename__ = "entry"
Expand All @@ -39,7 +45,6 @@ def __init__(self, **kw):
setattr(self, k, v)



class Feed(Base):
__tablename__ = "feed"

Expand All @@ -55,6 +60,7 @@ def __init__(self, **kw):
for k, v in kw.items():
setattr(self, k, v)

# TODO:move to crawler.
def crawl(self):
session = Session()
raw_feed = feedparser.parse(self.url)
Expand Down
17 changes: 12 additions & 5 deletions src/server.py → ring/server.py
Expand Up @@ -9,9 +9,14 @@
from werkzeug.contrib.atom import AtomFeed

from models import Entry, Session
from config import get_config

config = get_config()


# Constants (might go into a config file)
from ring.config import config

MAX_ENTRIES = 12

# Real constants
Expand All @@ -24,7 +29,7 @@

# Use /media instead of default /static because /static is already used.
app = Flask(__name__, static_path='/media')

app.jinja_loader.searchpath = ['./templates'] + app.jinja_loader.searchpath

@app.before_request
def connect_db():
Expand All @@ -43,9 +48,8 @@ def home():

@app.route('/rss')
def feed():
feed = AtomFeed("Planete GTLL", feed_url=request.url,
url=request.host_url,
subtitle="Nouvelles de l'écosystème du libre en IdF")
feed = AtomFeed(config.name, url=config.link, feed_url=request.url,
subtitle=config.subtitile)
for e in get_entries():
feed.add(title=e.title, content=e.content, content_type='text/html',
author=e.author, url=e.link, id=e.id,
Expand Down Expand Up @@ -105,6 +109,9 @@ def age(t):
return "%d years ago" % (dt/YEAR)


if __name__ == '__main__':
def main():
app.run(debug=True)

if __name__ == '__main__':
main()

File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 9 additions & 6 deletions setup.py
@@ -1,3 +1,6 @@
"""Build & packaging script for Ring.
"""

from setuptools import setup, find_packages

VERSION = '0.1.0'
Expand Down Expand Up @@ -25,15 +28,15 @@ def params():
license = 'LGPL'

packages = find_packages(exclude=['ez_setup'])
#namespace_packages = ['twistranet']
print packages

#namespace_packages = ['ring']
include_package_data = True
zip_safe = False
install_requires = open("dependencies.txt").read().split('\n')
entry_points = """
# -*- Entry points: -*-
[console_scripts]
ring=ring:main
"""
entry_points = {
'console_scripts': ['ring = ring:main'],
}
return locals()


Expand Down

0 comments on commit bd270c8

Please sign in to comment.