default repo

This commit is contained in:
scragg 2013-09-30 09:34:16 -05:00
parent 32e152a2a7
commit 10b74fbc4f
4 changed files with 32 additions and 13 deletions

View file

@ -2,20 +2,21 @@ import config
import redis
import logging
import rethinkdb as rdb
import os
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, path
from wiki import Wiki
from util import mkdir_safe
app = Flask(__name__)
app.config.update(config.flask)
app.debug = (config.ENV is not 'PROD')
app.secret_key = config.secret_key
app.static_path = sep + 'static'
app.static_path = os.sep + 'static'
app.session_interface = RedisSessionInterface()
bcrypt = Bcrypt(app)
@ -29,13 +30,26 @@ 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'])
conn = rdb.connect(config.db['host'], config.db['port'], db=config.db['dbname'])
if not config.db['dbname'] in rdb.db_list().run(conn) and config.ENV is not 'PROD':
# Create default db and repo
print "Creating DB %s" % config.db['dbname']
rdb.db_create(config.db['dbname']).run(conn)
for tbl in ['sites', 'users', 'pages']:
rdb.table_create(tbl).run(conn)
repo_dir = config.repos['dir'] + "/" + config.repos['main']
repo = Gittle(repo_dir)
mkdir_safe(repo_dir)
if not repo.has_index():
repo.init(repo_dir)
from models import Site
site = Site.get_by_name(".")
w = Wiki(site.get('repo'))
w = Wiki(repo_dir)
def redirect_url():

View file

@ -1,4 +1,5 @@
from reimagine import rdb, conn
import rethinkdb as rdb
from reimagine import conn
def get_one(cur):
@ -7,9 +8,7 @@ def get_one(cur):
class BaseModel():
__db__ = None
__table__ = None
_rdb = rdb
_conn = conn
def __init__(self):
@ -17,14 +16,13 @@ class BaseModel():
@classmethod
def filter(cls, f, limit=None):
q = cls._rdb.db(cls.__db__).table(cls.__table__).filter(f)
q = rdb.table(cls.__table__).filter(f)
if limit:
q.limit(int(limit))
return q.run(cls._conn)
class Site(BaseModel):
__db__ = 'lastdb'
__table__ = 'sites'
@classmethod

View file

@ -2,6 +2,12 @@ import re
import os
def mkdir_safe(path):
if path and not(os.path.exists(path)):
os.makedirs(path)
return path
def extract_path(file_path):
if not file_path:
return None

View file

@ -18,7 +18,7 @@ nodaemon = false
minfds = 1024
minprocs = 200
umask = 022
user = deploy
user = root
identifier = supervisor
directory = /tmp
nocleanup = true
@ -29,4 +29,5 @@ strip_ansi = false
command=/usr/bin/python /vagrant/app.py
[program:rethinkdb]
command=/usr/bin/rethinkdb --config-file /etc/rethinkdb/rdb0.conf
command=/usr/bin/rethinkdb --config-file /etc/rethinkdb/rdb0.conf
user=root