Add ROOT_DIR, TEMPLATE_DIR to config.py. Make paths platform-independent. Add template/ to bottle TEMPLATE_PATH (you can add bots/ this way after complete refactoring). Rename tests to work with pytests. Change setup.py to run pytests.

refactoring
cookietime--yay 2019-03-06 15:39:08 +01:00
parent f5f741a5c2
commit 9906346691
16 changed files with 56 additions and 32 deletions

2
setup.cfg Normal file
View File

@ -0,0 +1,2 @@
[aliases]
test=pytest

View File

@ -1,20 +1,37 @@
from setuptools import setup
import sys
import os
PACKAGE_NAME = "ticketfrei"
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), PACKAGE_NAME))
setup(
name='ticketfrei',
name=PACKAGE_NAME,
version='',
packages=['ticketfrei'],
packages=[
PACKAGE_NAME
],
url='https://github.com/ticketfrei/ticketfrei',
license='ISC',
author='',
author_email='',
description='',
setup_requires=[
'pytest-runner',
],
install_requires=[
'bottle',
'jwt',
'mastodon.py',
'gitpython',
'pyjwt',
'Markdown',
'Mastodon.py',
'pylibscrypt',
'pytoml',
'tweepy',
'twx',
],
tests_require=[
'pytest',
],
)

View File

@ -1,6 +1,9 @@
import pytoml as toml
import os
ROOT_DIR = os.path.dirname(os.path.realpath(__file__))
TEMPLATE_DIR = os.path.join(ROOT_DIR, 'template', '')
STATIC_DIR = os.path.join(ROOT_DIR, 'static', '')
def load_env():
"""
@ -9,7 +12,7 @@ def load_env():
:return: config dictionary of dictionaries.
"""
with open('config.toml.example') as defaultconf:
with open(os.path.join(ROOT_DIR, 'config.toml.example')) as defaultconf:
configdict = toml.load(defaultconf)
try:
@ -71,7 +74,7 @@ def load_env():
# read config in TOML format (https://github.com/toml-lang/toml#toml)
try:
with open('config.toml') as configfile:
with open(os.path.join(ROOT_DIR, 'config.toml')) as configfile:
config = toml.load(configfile)
except FileNotFoundError:
config = load_env()

View File

@ -2,7 +2,7 @@
import bottle
from os import listdir, path
from bottle import get, post, redirect, request, response, view
from config import config
from config import config, STATIC_DIR, TEMPLATE_DIR
from db import db
import logging
import tweepy
@ -19,13 +19,13 @@ def url(route):
@get('/')
@view('template/propaganda.tpl')
@view('propaganda.tpl')
def propaganda():
pass
@post('/register')
@view('template/register.tpl')
@view('register.tpl')
def register_post():
try:
email = request.forms['email']
@ -55,7 +55,7 @@ def register_post():
@get('/confirm/<city>/<token>')
@view('template/propaganda.tpl')
@view('propaganda.tpl')
def confirm(city, token):
# check whether city already exists
if db.by_city(city):
@ -76,7 +76,7 @@ def version():
@post('/login')
@view('template/login.tpl')
@view('login.tpl')
def login_post():
# check login
try:
@ -102,7 +102,7 @@ def city_page(city, info=None):
@get('/city/mail/<city>')
@view('template/mail.tpl')
@view('mail.tpl')
def display_mail_page(city):
user = db.by_city(city)
return user.state()
@ -139,34 +139,34 @@ def unsubscribe(token):
@get('/settings')
@view('template/settings.tpl')
@view('settings.tpl')
def settings(user):
return user.state()
@post('/settings/markdown')
@view('template/settings.tpl')
@view('settings.tpl')
def update_markdown(user):
user.set_markdown(request.forms['markdown'])
return user.state()
@post('/settings/mail_md')
@view('template/settings.tpl')
@view('settings.tpl')
def update_mail_md(user):
user.set_mail_md(request.forms['mail_md'])
return user.state()
@post('/settings/goodlist')
@view('template/settings.tpl')
@view('settings.tpl')
def update_trigger_patterns(user):
user.set_trigger_words(request.forms['goodlist'])
return user.state()
@post('/settings/blocklist')
@view('template/settings.tpl')
@view('settings.tpl')
def update_badwords(user):
user.set_badwords(request.forms['blocklist'])
return user.state()
@ -187,12 +187,12 @@ def register_telegram(user):
@get('/static/<filename:path>')
def static(filename):
return bottle.static_file(filename, root='static')
return bottle.static_file(filename, root=STATIC_DIR)
@get('/guides/<filename:path>')
def guides(filename):
return bottle.static_file(filename, root='guides')
# IS THIS USED?
#@get('/guides/<filename:path>')
#def guides(filename):
# return bottle.static_file(filename, root='guides')
@get('/logout/')
@ -269,6 +269,8 @@ fh = logging.FileHandler(config['log']['log_frontend'])
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)
# TODO change TEMPLATE_PATH to BOTS_DIR after refactoring
bottle.TEMPLATE_PATH.insert(0, TEMPLATE_DIR)
application = bottle.default_app()
bottle.install(SessionPlugin('/'))

View File

@ -1,4 +1,4 @@
% rebase('template/wrapper.tpl')
% rebase('wrapper.tpl')
<%
import markdown as md

View File

@ -1,2 +1,2 @@
% rebase('template/wrapper.tpl', title='Login')
% include('template/login-plain.tpl')
% rebase('wrapper.tpl', title='Login')
% include('login-plain.tpl')

View File

@ -1,4 +1,4 @@
% rebase('template/wrapper.tpl')
% rebase('wrapper.tpl')
<%
import markdown as md

View File

@ -1,4 +1,4 @@
% rebase('template/wrapper.tpl')
% rebase('wrapper.tpl')
% if defined('info'):
<div class="ui-widget">
<div class="ui-state-highlight ui-corner-all" style="padding: 0.7em;">
@ -7,7 +7,7 @@
</div>
<br>
% end
% include('template/login-plain.tpl')
% include('login-plain.tpl')
<h1>Features</h1>
<p>
Don't pay for public transport. Instead, warn each other
@ -45,7 +45,7 @@
share it with us, so others can use it, too!</li>
</ul></li>
</ul>
% include('template/register-plain.tpl')
% include('register-plain.tpl')
<h2>Our Mission</h2>
<p>
Public transportation is meant to provide an easy and

View File

@ -1,4 +1,4 @@
% rebase('template/wrapper.tpl', title='Register')
% rebase('wrapper.tpl', title='Register')
% if defined('info'):
<div class="ui-widget">
<div class="ui-state-highlight ui-corner-all" style="padding: 0.7em;">
@ -6,5 +6,5 @@
</div>
</div>
% else:
% include('template/register-plain.tpl')
% include('register-plain.tpl')
% end

View File

@ -1,4 +1,4 @@
% rebase('template/wrapper.tpl')
% rebase('wrapper.tpl')
<a href="/logout/"><button>Logout</button></a>
% if enabled: