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.

This commit is contained in:
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 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( setup(
name='ticketfrei', name=PACKAGE_NAME,
version='', version='',
packages=['ticketfrei'], packages=[
PACKAGE_NAME
],
url='https://github.com/ticketfrei/ticketfrei', url='https://github.com/ticketfrei/ticketfrei',
license='ISC', license='ISC',
author='', author='',
author_email='', author_email='',
description='', description='',
setup_requires=[
'pytest-runner',
],
install_requires=[ install_requires=[
'bottle', 'bottle',
'jwt', 'gitpython',
'mastodon.py', 'pyjwt',
'Markdown',
'Mastodon.py',
'pylibscrypt', 'pylibscrypt',
'pytoml', 'pytoml',
'tweepy', 'tweepy',
'twx',
],
tests_require=[
'pytest',
], ],
) )

View file

@ -1,6 +1,9 @@
import pytoml as toml import pytoml as toml
import os 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(): def load_env():
""" """
@ -9,7 +12,7 @@ def load_env():
:return: config dictionary of dictionaries. :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) configdict = toml.load(defaultconf)
try: try:
@ -71,7 +74,7 @@ def load_env():
# read config in TOML format (https://github.com/toml-lang/toml#toml) # read config in TOML format (https://github.com/toml-lang/toml#toml)
try: try:
with open('config.toml') as configfile: with open(os.path.join(ROOT_DIR, 'config.toml')) as configfile:
config = toml.load(configfile) config = toml.load(configfile)
except FileNotFoundError: except FileNotFoundError:
config = load_env() config = load_env()

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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