added models, wiki class, util funcs, layout files, view files

This commit is contained in:
Matthew Scragg 2013-09-28 16:09:02 -05:00
parent 967815bda5
commit 26137047cd
16 changed files with 238 additions and 48 deletions

3
Vagrantfile vendored
View file

@ -11,5 +11,6 @@ end
Vagrant::Config.run do |config|
config.vm.forward_port 80, 8000
config.vm.forward_port 10001, 10001
config.vm.forward_port 10000, 10000
config.vm.forward_port 20000, 20000
end

2
app.py
View file

@ -5,4 +5,4 @@ from reimagine import app
if __name__ == '__main__':
app.logger.setLevel(logging.INFO)
pywsgi.WSGIServer(('', 9999), app).serve_forever()
pywsgi.WSGIServer(('', 10000), app).serve_forever()

View file

@ -1,13 +1,15 @@
import config
import redis
import logging
from flask import Flask, request, render_template, url_for
import rethinkdb as rdb
from flask import Flask, request, render_template, url_for, redirect
from flask.ext.bcrypt import Bcrypt
from flask.ext.login import LoginManager
from flask.ext.assets import Environment
from session import RedisSessionInterface
from gittle import Gittle
from os import sep
from os import sep, path
from wiki import Wiki
app = Flask(__name__)
app.config.update(config.flask)
@ -27,6 +29,14 @@ assets.directory = app.static_folder
cache = redis.StrictRedis(host=config.cache['host'], port=config.cache['port'])
conn = rdb.connect(config.db['host'], config.db['port'])
from models import Site
site = Site.get_by_name(".")
wiki = Wiki(site.get('repo'))
def redirect_url():
return request.args.get('next') or request.referrer or url_for('index')
@ -42,13 +52,41 @@ def page_error(e):
logging.exception(e)
return render_template('errors/500.html'), 500
@app.route("/")
def root():
repo = Gittle('/tmp/testgit')
if repo.has_commits():
pass
print repo.diff
return redirect('/Home')
@app.route("/rename/<page>", methods=['POST'])
def rename(page):
pass
@app.route("/edit/<page>", methods=['GET', 'POST'])
def edit(page):
pass
@app.route("/delete/<page>")
def delete(page):
pass
@app.route("/create/<page>")
def create(page):
return render_template('page/create.html')
@app.route("/<page>")
def render(page):
file_path = site.get('repo') + "/" + page.lower() + ".md"
if path.isfile(file_path):
f = open(file_path)
content = f.read()
f.close()
return render_template('page/page.html', content=content)
else:
return redirect('/create/'+page)
import ratelimit

32
reimagine/models.py Normal file
View file

@ -0,0 +1,32 @@
from reimagine import rdb, conn
def get_one(cur):
res = cur.chunks[0]
return res[0] if len(res) else None
class BaseModel():
__db__ = None
__table__ = None
_rdb = rdb
_conn = conn
def __init__(self):
pass
@classmethod
def filter(cls, f, limit=None):
q = cls._rdb.db(cls.__db__).table(cls.__table__).filter(f)
if limit:
q.limit(int(limit))
return q.run(cls._conn)
class Site(BaseModel):
__db__ = 'lastdb'
__table__ = 'sites'
@classmethod
def get_by_name(cls, name):
return get_one(cls.filter({'name': name}, limit=1))

View file

@ -6,14 +6,13 @@
<meta name="description" content="">
<meta name="author" content="">
<title>Fixed Top Navbar Example for Bootstrap</title>
<title>LastDB</title>
<link href="/static/css/cerulean.bootstrap.min.css" rel="stylesheet">
<link href="/static/css/font-awesome.min.css" rel="stylesheet">
<style>
body {
min-height: 2000px;
padding-top: 70px;
}
</style>
@ -35,30 +34,13 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Reimagine</a>
<a class="navbar-brand" href="#">LastDB</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li><a href="#">Separated link</a></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="../navbar/">Default</a></li>
<li><a href="../navbar-static-top/">Static top</a></li>
<li class="active"><a href="./">Fixed top</a></li>
<li><a href="/login">Login</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
@ -66,19 +48,9 @@
<div class="container">
<!-- Main component for a primary marketing message or call to action -->
<div class="jumbotron">
<h1>Navbar example</h1>
<p>This example is a quick exercise to illustrate how the default, static and fixed to top navbar work. It includes the responsive CSS and HTML, so it also adapts to your viewport and device.</p>
<p>To see the difference between static and fixed top navbars, just scroll.</p>
<p>
<a class="btn btn-lg btn-primary" href="../../components/#navbar">View navbar docs &raquo;</a>
</p>
</div>
</div> <!-- /container -->
{% block body %}{% endblock %}
</div>
<script src="/static/js/jquery.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
</body>

View file

@ -1,6 +1,5 @@
{% extends 'layout.html' %}
{% block body %}
Create Page
{% endblock %}

View file

@ -0,0 +1,6 @@
{% extends 'layout.html' %}
{% block body %}
{{ content }}
{% endblock %}

32
reimagine/util.py Normal file
View file

@ -0,0 +1,32 @@
import re
import os
def extract_path(file_path):
if not file_path:
return None
last_slash = file_path.rindex("/")
if last_slash:
return file_path[0, last_slash]
def clean_path(path):
if path:
if path[0] != '/':
path.insert(0, '/')
return re.sub(r"//+", '/')
def extract_name(file_path):
if file_path[-1] == "/":
return None
return os.path.basename(file_path)
def clean_url(url):
if not url:
return url
url = url.replace('%2F', '/')
url = re.sub(r"^/+", "", url)
return re.sub(r"//+", '/', url)

22
reimagine/wiki.py Normal file
View file

@ -0,0 +1,22 @@
from gittle import Gittle
import os
class Wiki():
path = None
base_path = '/'
default_ref = 'master'
default_committer_name = 'Anon'
default_committer_email = 'anon@anon.anon'
index_page = 'Home'
def __init__(self, path, **kwargs):
self.path = path
def write_page(self, name):
name = name.replace(" ", "-")
def rename_page(self, page, rename, commit={}):
pass
def page_exists(self, name):
return None

9
srv/salt/nginx/init.sls Normal file
View file

@ -0,0 +1,9 @@
nginx:
pkg:
- installed
service:
- running
- enable: True
- reload: True
- require:
- pkg: nginx

View file

@ -0,0 +1,15 @@
python-pkgs:
pkg.installed:
- pkgs:
- python-dev
- python-pip
- build-essential
{% for pkg in ['tornado', 'pyzmq', 'itsdangerous', 'boto', 'redis', 'simplejson', 'sockjs-tornado', 'flask', 'flask-bcrypt', 'flask-login', 'flask-assets', 'gittle', 'gevent' ] %}
{{ pkg }}-pip:
pip:
- name: {{ pkg }}
- installed
- require:
- pkg.installed: python-pkgs
{% endfor %}

View file

@ -3,14 +3,11 @@ rethink-repo:
- ppa: rethinkdb/ppa
rethinkdb:
user.present:
- shell: /bin/bash
- home: /home/rethinkdb
pkg:
- installed
service:
- running
- enable: True
- reload: True
- require:
- pkg: rethinkdb
python-pip:
pkg.installed
@ -26,3 +23,7 @@ rethinkdb-pip:
- pkg: python-pip
- pkg: rethinkdb
- pkg: build-essential
/etc/rethinkdb/rdb0.conf:
file.managed:
- source: salt://rethinkdb/rdb0.conf

View file

@ -0,0 +1,10 @@
runuser=rethinkdb
rungroup=rethinkdb
pid-file=/home/rethinkdb/rdb0/rethinkdb.pid
directory=/home/rethinkdb/rdb0
bind=all
driver-port=28015
cluster-port=29015
port-offset=0
http-port=20000
cores=2

View file

@ -0,0 +1,19 @@
/etc/supervisord.conf:
file.managed:
- source: salt://supervisor/supervisord.conf
supervisor-pip:
pip:
- name: supervisor
- installed
- require:
- pkg.installed: python-pip
supervisor-run:
cmd.run:
- unless: test -e /tmp/supervisord.pid
- name: /usr/local/bin/supervisord
- require:
- file.managed: /etc/supervisord.conf
- file.managed: /etc/rethinkdb/rdb0.conf

View file

@ -0,0 +1,32 @@
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[unix_http_server]
file = /tmp/supervisor.sock
chmod = 0777
[supervisorctl]
serverurl = unix:///tmp/supervisor.sock
[supervisord]
logfile = /tmp/supervisord.log
logfile_maxbytes = 50MB
logfile_backups=10
loglevel = info
pidfile = /tmp/supervisord.pid
nodaemon = false
minfds = 1024
minprocs = 200
umask = 022
user = deploy
identifier = supervisor
directory = /tmp
nocleanup = true
childlogdir = /tmp
strip_ansi = false
[program:reimagine]
command=/usr/bin/python /vagrant/app.py
[program:rethinkdb]
command=/usr/bin/rethinkdb --config-file /etc/rethinkdb/rdb0.conf

View file

@ -4,3 +4,5 @@ base:
- users
- redis
- rethinkdb
- reimagine
- supervisor