Exemplo n.º 1
0
    def test_base_basedir_abspath(self):
        import os
        import tempfile
        from coopy.base import init_system, init_persistent_system, CoopyProxy
        from coopy.journal import DiskJournal

        dummy = init_persistent_system(Wiki, basedir='wiki/')

        current_dir = os.path.abspath(os.getcwd())
        self.assertEquals([current_dir + "/wiki/"],
                          dummy.basedir_abspath())

        dummy.close()

        dir1 = tempfile.mkdtemp()
        dir2 = tempfile.mkdtemp()

        j1 = DiskJournal(dir1, os.getcwd())
        j2 = DiskJournal(dir2, os.getcwd())

        subscribers = [j1, j2]

        dummy2 = init_system(Wiki, subscribers)
        self.assertTrue(dir1 in dummy2.basedir_abspath())
        self.assertTrue(dir2 in dummy2.basedir_abspath())
Exemplo n.º 2
0
 def _save_tickets(self):
     availables = []
     wallet = init_persistent_system(Wallet(), basedir=self.db)
     for item in self.tickets:
         ticket = Ticket(**item)
         available = wallet.add_ticket(ticket)
         wallet.take_snapshot()
         if available:
             availables.append(available)
     return availables
Exemplo n.º 3
0
 def _save_tickets(self):
     availables = []
     wallet = init_persistent_system(Wallet(), basedir=self.db)
     for item in self.tickets:
         ticket = Ticket(**item)
         available = wallet.add_ticket(ticket)
         wallet.take_snapshot()
         if available:
             availables.append(available)
     return availables
Exemplo n.º 4
0
    def test_base_persistent(self):
        import os
        from coopy.base import init_persistent_system, CoopyProxy

        dummy = init_persistent_system(Wiki, basedir='wiki/')

        files = os.listdir('wiki/')
        self.assertTrue('snapshot_000000000000002.dat' in files)
        self.assertEquals(dummy.__class__, CoopyProxy)
        self.assertEquals(len(dummy.publisher.subscribers), 1)

        dummy.close()
Exemplo n.º 5
0
from users import User, Realm, UserWrapper

import logging
log = logging.getLogger(__name__)

config = Config('settings.ini')
app = Flask(__name__)
app.secret_key = config('SECRET_KEY').encode('utf-8')
app.logger.addHandler(logging.StreamHandler())
login_manager = LoginManager()
login_manager.session_protection = "strong"
login_manager.init_app(app)

users = None
if six.PY3:
    root = init_persistent_system(Tree(), basedir="main3")
    root.add('main')
    users = init_persistent_system(Realm('users3'))
else:
    root = init_persistent_system(Tree(), basedir="main")
    if not root.has('main'):
        root.add('main')
    users = init_persistent_system(Realm('users'))

@login_manager.user_loader
def load_user(userid):
    user = users.users[userid]
    return UserWrapper(userid, userid, active=True)

def authenticate(username, password):
    return users.authenticate(username, password)
Exemplo n.º 6
0
import os
import sys

from neurotic.domain import TestReportRepository
from neurotic.utils import color, OK, ERROR
from coopy.base import init_persistent_system

repository = init_persistent_system(TestReportRepository,
                                    basedir="build_history")


def main():
    mod = __import__(__name__).command_line
    if len(sys.argv) == 1:
        show_last_run()
    else:
        function = getattr(mod, sys.argv[1])(sys.argv[2:])


def web(paths):
    from neurotic.wsgi_app import app
    app.run(debug=True)


def console_history(paths):
    repository.show_history()


def last_fails(paths):
    for failed in repository.last_run_failed_tests():
        print(failed)
Exemplo n.º 7
0
import os

from coopy.base import init_persistent_system
from flask import Flask, jsonify, render_template
from flask.json import JSONEncoder

from neurotic.domain import TestReportRepository

app = Flask(__name__)
app.json_encoder_class = JSONEncoder

repository = init_persistent_system(TestReportRepository,
                                    basedir="build_history")

@app.route("/")
def main():
    return '''
<!doctype html>
<html ng-app="neurotic">
  <head>
    <link href="/static/bootstrap.min.css" rel="stylesheet">
    <link href="/static/grid.css" rel="stylesheet">
    <script src="/static/moment.min.js"></script>
    <script src="/static/angular.min.js"></script>
    <script src="/static/underscore-min.js"></script>
    <script src="/static/ace/ace.js" type="text/javascript" charset="utf-8"></script>
    <script src="/static/neurotic.js"></script>
    <style type="text/css" media="screen">
    body {
        margin-top: 50px;
    }
Exemplo n.º 8
0
import os

from coopy.base import init_persistent_system
from riobus import RioBus

from flask import Flask, jsonify, render_template
from collections import OrderedDict

app = Flask(__name__)

riobus = init_persistent_system(RioBus())

@app.route("/")
def main():
    return render_template('index.html', lines=riobus.lines)

@app.route("/all_json")
def main_json():
    return jsonify(riobus.formated_lines)

@app.route("/line/html/<line_id>")
def html_line(line_id):
    line = riobus.lines[line_id]
    return render_template('detail.html', line=line)

@app.route("/line/<line_id>")
def line(line_id):
    return jsonify(riobus.lines[line_id])

@app.route("/street_search/<nome>")
def search(nome):
Exemplo n.º 9
0
import logging
import re

from decouple import Config
from coopy.base import init_persistent_system
from flask import Flask, abort, request, render_template, redirect, jsonify

from domain import URLShortner

log = logging.getLogger(__name__)

config = Config('settings.ini')
app = Flask(__name__)
app.secret_key = config('SECRET_KEY').encode('utf-8')
app.logger.addHandler(logging.StreamHandler())
system = init_persistent_system(URLShortner())
MAIN_SITE = "http://loogi.ca"


@app.route('/')
def main_site():
    return render_template('index.html')


@app.route('/ranking')
def ranking():
    return render_template('ranking.html')


@app.route('/urls/')
def urls():
Exemplo n.º 10
0
# -*- coding: utf-8 -*-

from coopy.base import init_persistent_system
from flask import Flask, jsonify, render_template, request, flash

from loogica.domain import EmailRepository, ValidationError, PollRepository
from loogica.forms import UserForm

app = Flask(__name__)
user_repo = init_persistent_system(EmailRepository(),
                                   basedir="emailrepository")
poll_repo = init_persistent_system(PollRepository())


@app.route("/")
def main():
    return render_template('index.html')


@app.route("/participar", methods=['GET', 'POST'])
def create_user():
    if request.method == "GET":
        form = UserForm()
        return render_template('quero-participar.html', form=form)

    form = UserForm(request.form)
    errors = None

    if form.validate():
        try:
            user_repo.add_user(form.name.data, form.email.data)
Exemplo n.º 11
0
# -*- coding: utf-8 -*-

from coopy.base import init_persistent_system
from flask import Flask, jsonify, render_template, request, flash

from loogica.domain import EmailRepository, ValidationError, PollRepository
from loogica.forms import UserForm

app = Flask(__name__)
user_repo = init_persistent_system(EmailRepository(), basedir="emailrepository")
poll_repo = init_persistent_system(PollRepository())

@app.route("/")
def main():
    return render_template('index.html')

@app.route("/participar", methods=['GET', 'POST'])
def create_user():
    if request.method == "GET":
        form = UserForm()
        return render_template('quero-participar.html', form=form)

    form = UserForm(request.form)
    errors = None

    if form.validate():
        try:
            user_repo.add_user(form.name.data, form.email.data)
            flash('Seu usuário foi cadastrado com sucesso')
            return render_template('quero-participar-cadastrado.html')
        except ValidationError as ve:
Exemplo n.º 12
0
from flask import Flask, jsonify
from coopy.base import init_persistent_system

from domain import UserRepo
from streamer import HashtagStreamer

try:
    from settings import *
except ImportError:
    KEY = 'PUT_YOUR_KEY_HERE'
    SECRET = 'PUT_YOUR_SECRET_HERE'
    TOKEN = 'GET_YOURSELF_A_TOKEN'
    TOKEN_SECRET = 'GET_YOURSELF_A_SECRET'
    HASHTAG = 'YOUR_HASHTAG'

user_repo = init_persistent_system(UserRepo())
app = Flask(__name__)

@app.route('/graph.json')
def retrieve_graph():
    response = user_repo.retrieve_as_graph()
    return jsonify(**response)


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

twitter = Twython(KEY, SECRET, TOKEN, TOKEN_SECRET)
stream = HashtagStreamer(HASHTAG, user_repo, twitter, KEY, SECRET, TOKEN, TOKEN_SECRET)
stream.statuses.filter(track=['#' + HASHTAG])
Exemplo n.º 13
0
Arquivo: web.py Projeto: loogica/urlsh
import logging
import re

from decouple import Config
from coopy.base import init_persistent_system
from flask import Flask, abort, request, render_template, redirect, jsonify

from domain import URLShortner

log = logging.getLogger(__name__)

config = Config('settings.ini')
app = Flask(__name__)
app.secret_key = config('SECRET_KEY').encode('utf-8')
app.logger.addHandler(logging.StreamHandler())
system = init_persistent_system(URLShortner())
MAIN_SITE = "http://loogi.ca"

@app.route('/')
def main_site():
    return render_template('index.html')

@app.route('/ranking')
def ranking():
    return render_template('ranking.html')

@app.route('/urls/')
def urls():
    return jsonify(system.urls)

@app.route('/add_url/', methods=['POST'])