diff --git a/Vagrantfile b/Vagrantfile index b5b0d91..5c12bb8 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -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 diff --git a/app.py b/app.py index 79718c1..a964d73 100644 --- a/app.py +++ b/app.py @@ -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() diff --git a/reimagine/__init__.py b/reimagine/__init__.py index f78cd89..c9fa6c1 100644 --- a/reimagine/__init__.py +++ b/reimagine/__init__.py @@ -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/", methods=['POST']) +def rename(page): + pass + + +@app.route("/edit/", methods=['GET', 'POST']) +def edit(page): + pass + + +@app.route("/delete/") +def delete(page): + pass + + +@app.route("/create/") +def create(page): return render_template('page/create.html') + +@app.route("/") +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 diff --git a/reimagine/models.py b/reimagine/models.py new file mode 100644 index 0000000..6870486 --- /dev/null +++ b/reimagine/models.py @@ -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)) diff --git a/reimagine/templates/layout.html b/reimagine/templates/layout.html index 9da837a..35ca90e 100644 --- a/reimagine/templates/layout.html +++ b/reimagine/templates/layout.html @@ -6,14 +6,13 @@ - Fixed Top Navbar Example for Bootstrap + LastDB @@ -35,30 +34,13 @@ - Reimagine + LastDB @@ -66,19 +48,9 @@
- -
-

Navbar example

-

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.

-

To see the difference between static and fixed top navbars, just scroll.

-

- View navbar docs » -

-
- -
- + {% block body %}{% endblock %} + diff --git a/reimagine/templates/page/create.html b/reimagine/templates/page/create.html index 4c1da14..3ac9aea 100644 --- a/reimagine/templates/page/create.html +++ b/reimagine/templates/page/create.html @@ -1,6 +1,5 @@ {% extends 'layout.html' %} {% block body %} -Create Page {% endblock %} \ No newline at end of file diff --git a/reimagine/templates/page/page.html b/reimagine/templates/page/page.html new file mode 100644 index 0000000..4e33b04 --- /dev/null +++ b/reimagine/templates/page/page.html @@ -0,0 +1,6 @@ +{% extends 'layout.html' %} +{% block body %} + +{{ content }} + +{% endblock %} \ No newline at end of file diff --git a/reimagine/util.py b/reimagine/util.py new file mode 100644 index 0000000..d5cf2ad --- /dev/null +++ b/reimagine/util.py @@ -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) diff --git a/reimagine/wiki.py b/reimagine/wiki.py new file mode 100644 index 0000000..ebb8feb --- /dev/null +++ b/reimagine/wiki.py @@ -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 \ No newline at end of file diff --git a/srv/salt/nginx/init.sls b/srv/salt/nginx/init.sls new file mode 100644 index 0000000..c69ca47 --- /dev/null +++ b/srv/salt/nginx/init.sls @@ -0,0 +1,9 @@ +nginx: + pkg: + - installed + service: + - running + - enable: True + - reload: True + - require: + - pkg: nginx \ No newline at end of file diff --git a/srv/salt/reimagine/init.sls b/srv/salt/reimagine/init.sls new file mode 100644 index 0000000..4451857 --- /dev/null +++ b/srv/salt/reimagine/init.sls @@ -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 %} \ No newline at end of file diff --git a/srv/salt/rethinkdb/init.sls b/srv/salt/rethinkdb/init.sls index 1584c86..1cd63a2 100644 --- a/srv/salt/rethinkdb/init.sls +++ b/srv/salt/rethinkdb/init.sls @@ -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 diff --git a/srv/salt/rethinkdb/rdb0.conf b/srv/salt/rethinkdb/rdb0.conf new file mode 100644 index 0000000..26f1ea9 --- /dev/null +++ b/srv/salt/rethinkdb/rdb0.conf @@ -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 \ No newline at end of file diff --git a/srv/salt/supervisor/init.sls b/srv/salt/supervisor/init.sls new file mode 100644 index 0000000..4682722 --- /dev/null +++ b/srv/salt/supervisor/init.sls @@ -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 \ No newline at end of file diff --git a/srv/salt/supervisor/supervisord.conf b/srv/salt/supervisor/supervisord.conf new file mode 100644 index 0000000..1c99d29 --- /dev/null +++ b/srv/salt/supervisor/supervisord.conf @@ -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 \ No newline at end of file diff --git a/srv/salt/top.sls b/srv/salt/top.sls index 06b1f74..99d0b6b 100644 --- a/srv/salt/top.sls +++ b/srv/salt/top.sls @@ -4,3 +4,5 @@ base: - users - redis - rethinkdb + - reimagine + - supervisor \ No newline at end of file