multiple changes

This commit is contained in:
www
2021-01-11 18:45:03 +00:00
parent 14ca632137
commit 3d3474a2e1
24 changed files with 3517 additions and 83 deletions

2
.dockerignore Normal file
View File

@@ -0,0 +1,2 @@
_archiv/*
.env/*

4
.gitignore vendored
View File

@@ -5,4 +5,6 @@ __pycache__
key.py key.py
*.pyc *.pyc
*.yaml *.yaml
packages/* packages/*
.eggs/*
*.pyc

6
Dockerfile.theia Normal file
View File

@@ -0,0 +1,6 @@
from theiaide/theia-python:latest
run apt-get update && apt-get -y install libgs-dev
COPY ./requirements.txt .
run pip3 install --upgrade pip && pip3 install -r requirements.txt && pip3 install pytest pylint bandit flake8 black pytest-django six pytest-mock
COPY . .
ENTRYPOINT node /home/theia/src-gen/backend/main.js /home/project/.theia-workspace --hostname=0.0.0.0

12
build_dev_docker_images Executable file
View File

@@ -0,0 +1,12 @@
#/bin/bash
export REGISTRY="docker.triton2.fet.at"
# Build a development Image with Theia and all content
docker build -f Dockerfile.theia -t $REGISTRY/andisdev:latest .
docker push $REGISTRY/andisdev
# Build Solr Server Image
echo "Building SOLR Server Image Solrfet"
cd services/solr_server
docker build -t $REGISTRY/solrfet:latest .

4
data/stuff.txt Normal file
View File

@@ -0,0 +1,4 @@
asdfwef
wefweg
advgwegfawegewaf awfewfawefgae fgaergae

75
docker-compose.dev.yml Normal file
View File

@@ -0,0 +1,75 @@
version: '3'
services:
solr:
image: my_fet_solr
build: ./services/solr_server
ports:
- "8980:8983"
volumes:
- data:/var/solr
command:
- solr-precreate
- core
- /opt/solr/server/solr/configsets/fetconfig
solrprotocol:
image: my_fet_solr
build: ./services/solr_server
ports:
- "8980:8983"
volumes:
- data:/var/solr
command:
- solr-precreate
- core
- /opt/solr/server/solr/configsets/fetconfig
etherpadsql:
image: jbergstroem/mariadb-alpine
environment:
SKIP_INNODB: "no"
MYSQL_DATABASE: etherpaddb
MYSQL_USER: user
MYSQL_PASSWORD: hgu
MYSQL_COLLATION: utf8_general_ci
MYSQL_CHARSET: utf8
volumes:
- ep-mysql-volume:/var/lib/mysql
etherpad:
image: etherpad/etherpad
environment:
DB_TYPE: mysql
DB_HOST: etherpadsql
DB_PORT: 3306
DB_NAME: etherpaddb
DB_USER: user
DB_PASS: hgu
DB_CHARSET: utf8
TRUST_PROXY: "true"
REQUIRE_SESSION: "true"
depends_on:
- etherpadsql
volumes:
- ./services/etherpad/APIKEY.txt:/opt/etherpad-lite/APIKEY.txt
ports:
- "9101:9001"
nginx:
image: nginx:alpine
volumes:
- ./services/nginx/default.conf:/etc/nginx/conf.d/default.conf
ports:
- "5000:80"
# bot:
# image: bot
# build: .
# environment:
# TARGET: https://andis.2020.fet.at
# SOLR_HOST: http://solr:8983
# ports:
# - "5000:5000"
theia:
image: theiaide/theia-python:latest
volumes:
- .:/home/project
- ../packages:/home/packages
volumes:
data:
ep-mysql-volume:

View File

@@ -10,7 +10,8 @@ logger.debug("Starting Test ...")
ep=EtherpadLiteLazyAPI( ep=EtherpadLiteLazyAPI(
url="http://etherpad:9101", url="http://etherpad:9101",
keyfile="etherpad/APIKEY.txt", exturl="https://bot.2020.fet.at/etherpad/",
keyfile="services/etherpad/APIKEY.txt",
groupmapper="fetwiki" groupmapper="fetwiki"
) )

14
example1.log Normal file
View File

@@ -0,0 +1,14 @@
INFO:root:sdf
INFO:sdf:sdf3
INFO:wiki.api:connecting
INFO:wiki.api:apikey:
INFO:wiki.api:Can't get connection to Etherpad Server. Error: HTTP Error 401: Unauthorized
INFO:wiki.api:connecting
INFO:wiki.api:apikey:
INFO:wiki.api:Can't get connection to Etherpad Server. Error: HTTP Error 401: Unauthorized
INFO:wiki.api:connecting
INFO:wiki.api:apikey:
INFO:wiki.api:Can't get connection to Etherpad Server. Error: HTTP Error 401: Unauthorized
INFO:wiki.api:connecting
INFO:wiki.api:apikey:
INFO:wiki.api:Can't get connection to Etherpad Server. Error: HTTP Error 401: Unauthorized

View File

@@ -5,7 +5,7 @@ import re
from flask import redirect, url_for, send_from_directory from flask import redirect, url_for, send_from_directory
from .pth import pth from .pth import pth
import bs4 import bs4
from urllib.parse import urljoin
bp = Blueprint("internfiles", __name__, url_prefix="/internfiles") bp = Blueprint("internfiles", __name__, url_prefix="/internfiles")
@@ -35,9 +35,10 @@ class Folder:
def load_file_and_folder(path: str = ""): def load_file_and_folder(path: str = ""):
f, directory = (None, None) f, directory = (None, None)
path = pth(path) path = pth(path)
datapath = pth("/mnt/save/daten") datapath = pth("./data")
filepath = datapath + path filepath = datapath + path
if not os.path.isdir(datapath):
return None, None
if not str(path) == "" and not (filepath in datapath): if not str(path) == "" and not (filepath in datapath):
return None, None return None, None
@@ -56,14 +57,17 @@ def load_file_and_folder(path: str = ""):
def web(path=""): def web(path=""):
f, d = load_file_and_folder(path) f, d = load_file_and_folder(path)
if not f and not d.p == path: if not f and not d.p == path:
return redirect(url_for("internfiles.web", path=d.p), code=302) path=urljoin("https://bot.2020.fet.at",url_for(".web", path=d.p))
print(f"url for :{path}")
return redirect(path, code=302)
text = None text = None
print("Accessing internfiles.web path %s"% path)
if f and f.endswith(".txt"): if f and f.endswith(".txt"):
text = os.path.abspath(f) text = os.path.abspath(f)
with open(os.path.abspath(f), "r", encoding='utf-8') as fh: with open(os.path.abspath(f), "r", encoding='utf-8') as fh:
text = (fh.read()) text = (fh.read())
text = re.sub("\\n\s*\\n", "<br>", text) text = re.sub(r"\\n\s*\\n", "<br>", text)
#text=bs4.BeautifulSoup(text).text #text=bs4.BeautifulSoup(text).text
elif f: elif f:
return send_from_directory(str(f - 1), str(f[-1])) return send_from_directory(str(f - 1), str(f[-1]))

View File

@@ -1,20 +1,41 @@
'''Settings für das interne Experimentierprojekt
TARGET '2020.fet.at'
URL_HOSTNAME 'bot.fet.at'
SOLR_HOST 'solr:8930'
ETHERPAD_API
ETHERPAD_EXT
ETHERPAD_KEYFILE
ETHERPAD_GROUP
CHATFILE Speicherpfad für Chats 'chats.yaml'
USERFILE Speicerpfad für User 'users.yaml'
'''
import environ import environ
STUFF="sdf"
env = environ.Env( env = environ.Env(
SOLR_HOST=(str, "http://localhost:8980"), TARGET=(str, "https://alpha.2020.fet.at") CHATFILE=(str, "chats.yaml"),
USERFILE=(str, "users.yaml"),
TARGET=(str, "https://alpha.2020.fet.at"),
URL_HOSTNAME=(str, "bot.2020.fet.at"),
SOLR_HOST=(str, "http://solr:8983"),
) )
SOLR_HOST = env("SOLR_HOST")
CHATFILE = env("CHATFILE")
USERFILE = env("USERFILE")
TARGET = env("TARGET")
URL_HOSTNAME = env("URL_HOSTNAME")
TARGET=env("TARGET") ETHERPAD_API = ("http://etherpad:9001",)
SOLR_HOST=env("SOLR_HOST") ETHERPAD_EXT = ("https://bot.2020.fet.at/etherpad/",)
env=environ.Env( ETHERPAD_KEYFILE = ("services/etherpad/APIKEY.txt",)
CHATFILE=(str,"chats.yaml"), ETHERPAD_GROUP = "fetwiki"
USERFILE=(str,"users.yaml"),
TARGET=(str,"https://alpha.2020.fet.at"),
URL_HOSTNAME=(str, "bot.2020.fet.at" ),
)
CHATFILE= env('CHATFILE')
USERFILE=env('USERFILE')
TARGET=env('TARGET')
URL_HOSTNAME=env('URL_HOSTNAME')

196
static/icons/fileicon.css Normal file
View File

@@ -0,0 +1,196 @@
/*
Fileicon icon font: Fileicon
Creation date: 30/08/2016 13:13
*/
@font-face {
font-family: "Fileicon";
src: url("/static/icons/fileicon.eot");
src: url("/static/icons/fileicon.eot?#iefix") format("embedded-opentype"),
url("/static/icons/fileicon.woff") format("woff"),
url("/static/icons/fileicon.ttf") format("truetype"),
url("/static/icons/fileicon.svg#Fileicon") format("svg");
font-weight: normal;
font-style: normal;
}
@media screen and (-webkit-min-device-pixel-ratio:0) {
@font-face {
font-family: "fileicon";
src: url("/static/icons/fileicon.svg#Fileicon") format("svg");
}
}
[class^="fileicon-"]:before, [class*=" fileicon-"]:before,
[class^="fileicon-"]:after, [class*=" fileicon-"]:after {
font-family: Fileicon;
font-size: 20px;
font-style: normal;
margin-left: 20px;
}
.fileicon-ae:before { content: "\f100"; }
.fileicon-agenda:before { content: "\f101"; }
.fileicon-ai:before { content: "\f102"; }
.fileicon-ai-1:before { content: "\f103"; }
.fileicon-ai-2:before { content: "\f104"; }
.fileicon-alignment:before { content: "\f105"; }
.fileicon-apk:before { content: "\f106"; }
.fileicon-au:before { content: "\f107"; }
.fileicon-br:before { content: "\f108"; }
.fileicon-browser:before { content: "\f109"; }
.fileicon-browser-1:before { content: "\f10a"; }
.fileicon-browser-10:before { content: "\f10b"; }
.fileicon-browser-11:before { content: "\f10c"; }
.fileicon-browser-12:before { content: "\f10d"; }
.fileicon-browser-13:before { content: "\f10e"; }
.fileicon-browser-14:before { content: "\f10f"; }
.fileicon-browser-15:before { content: "\f110"; }
.fileicon-browser-16:before { content: "\f111"; }
.fileicon-browser-17:before { content: "\f112"; }
.fileicon-browser-18:before { content: "\f113"; }
.fileicon-browser-19:before { content: "\f114"; }
.fileicon-browser-2:before { content: "\f115"; }
.fileicon-browser-20:before { content: "\f116"; }
.fileicon-browser-21:before { content: "\f117"; }
.fileicon-browser-22:before { content: "\f118"; }
.fileicon-browser-23:before { content: "\f119"; }
.fileicon-browser-24:before { content: "\f11a"; }
.fileicon-browser-25:before { content: "\f11b"; }
.fileicon-browser-26:before { content: "\f11c"; }
.fileicon-browser-27:before { content: "\f11d"; }
.fileicon-browser-28:before { content: "\f11e"; }
.fileicon-browser-3:before { content: "\f11f"; }
.fileicon-browser-4:before { content: "\f120"; }
.fileicon-browser-5:before { content: "\f121"; }
.fileicon-browser-6:before { content: "\f122"; }
.fileicon-browser-7:before { content: "\f123"; }
.fileicon-browser-8:before { content: "\f124"; }
.fileicon-browser-9:before { content: "\f125"; }
.fileicon-card:before { content: "\f126"; }
.fileicon-certification:before { content: "\f127"; }
.fileicon-coding:before { content: "\f128"; }
.fileicon-css:before { content: "\f129"; }
.fileicon-doc:before { content: "\f12a"; }
.fileicon-dw:before { content: "\f12b"; }
.fileicon-fi:before { content: "\f12c"; }
.fileicon-file:before { content: "\f12d"; }
.fileicon-file-1:before { content: "\f12e"; }
.fileicon-file-10:before { content: "\f12f"; }
.fileicon-file-11:before { content: "\f130"; }
.fileicon-file-2:before { content: "\f131"; }
.fileicon-file-3:before { content: "\f132"; }
.fileicon-file-4:before { content: "\f133"; }
.fileicon-file-5:before { content: "\f134"; }
.fileicon-file-6:before { content: "\f135"; }
.fileicon-file-7:before { content: "\f136"; }
.fileicon-file-8:before { content: "\f137"; }
.fileicon-file-9:before { content: "\f138"; }
.fileicon-files:before { content: "\f139"; }
.fileicon-files-1:before { content: "\f13a"; }
.fileicon-files-10:before { content: "\f13b"; }
.fileicon-files-11:before { content: "\f13c"; }
.fileicon-files-12:before { content: "\f13d"; }
.fileicon-files-13:before { content: "\f13e"; }
.fileicon-files-14:before { content: "\f13f"; }
.fileicon-files-15:before { content: "\f140"; }
.fileicon-files-2:before { content: "\f141"; }
.fileicon-files-3:before { content: "\f142"; }
.fileicon-files-4:before { content: "\f143"; }
.fileicon-files-5:before { content: "\f144"; }
.fileicon-files-6:before { content: "\f145"; }
.fileicon-files-7:before { content: "\f146"; }
.fileicon-files-8:before { content: "\f147"; }
.fileicon-files-9:before { content: "\f148"; }
.fileicon-folder:before { content: "\f149"; }
.fileicon-folder-1:before { content: "\f14a"; }
.fileicon-folder-10:before { content: "\f14b"; }
.fileicon-folder-11:before { content: "\f14c"; }
.fileicon-folder-2:before { content: "\f14d"; }
.fileicon-folder-3:before { content: "\f14e"; }
.fileicon-folder-4:before { content: "\f14f"; }
.fileicon-folder-5:before { content: "\f150"; }
.fileicon-folder-6:before { content: "\f151"; }
.fileicon-folder-7:before { content: "\f152"; }
.fileicon-folder-8:before { content: "\f153"; }
.fileicon-folder-9:before { content: "\f154"; }
.fileicon-fw:before { content: "\f155"; }
.fileicon-home:before { content: "\f156"; }
.fileicon-home-1:before { content: "\f157"; }
.fileicon-home-2:before { content: "\f158"; }
.fileicon-house:before { content: "\f159"; }
.fileicon-house-1:before { content: "\f15a"; }
.fileicon-house-2:before { content: "\f15b"; }
.fileicon-house-3:before { content: "\f15c"; }
.fileicon-house-4:before { content: "\f15d"; }
.fileicon-house-5:before { content: "\f15e"; }
.fileicon-house-6:before { content: "\f15f"; }
.fileicon-house-7:before { content: "\f160"; }
.fileicon-house-8:before { content: "\f161"; }
.fileicon-id:before { content: "\f162"; }
.fileicon-ipa:before { content: "\f163"; }
.fileicon-jpg:before { content: "\f164"; }
.fileicon-left-align:before { content: "\f165"; }
.fileicon-music-file:before { content: "\f166"; }
.fileicon-newspaper:before { content: "\f167"; }
.fileicon-pdf:before { content: "\f168"; }
.fileicon-php:before { content: "\f169"; }
.fileicon-placeholder:before { content: "\f16a"; }
.fileicon-placeholder-1:before { content: "\f16b"; }
.fileicon-placeholder-10:before { content: "\f16c"; }
.fileicon-placeholder-11:before { content: "\f16d"; }
.fileicon-placeholder-2:before { content: "\f16e"; }
.fileicon-placeholder-3:before { content: "\f16f"; }
.fileicon-placeholder-4:before { content: "\f170"; }
.fileicon-placeholder-5:before { content: "\f171"; }
.fileicon-placeholder-6:before { content: "\f172"; }
.fileicon-placeholder-7:before { content: "\f173"; }
.fileicon-placeholder-8:before { content: "\f174"; }
.fileicon-placeholder-9:before { content: "\f175"; }
.fileicon-png:before { content: "\f176"; }
.fileicon-ppt:before { content: "\f177"; }
.fileicon-pr:before { content: "\f178"; }
.fileicon-ps:before { content: "\f179"; }
.fileicon-ps-1:before { content: "\f17a"; }
.fileicon-report:before { content: "\f17b"; }
.fileicon-report-1:before { content: "\f17c"; }
.fileicon-report-10:before { content: "\f17d"; }
.fileicon-report-11:before { content: "\f17e"; }
.fileicon-report-2:before { content: "\f17f"; }
.fileicon-report-3:before { content: "\f180"; }
.fileicon-report-4:before { content: "\f181"; }
.fileicon-report-5:before { content: "\f182"; }
.fileicon-report-6:before { content: "\f183"; }
.fileicon-report-7:before { content: "\f184"; }
.fileicon-report-8:before { content: "\f185"; }
.fileicon-report-9:before { content: "\f186"; }
.fileicon-server:before { content: "\f187"; }
.fileicon-server-1:before { content: "\f188"; }
.fileicon-server-2:before { content: "\f189"; }
.fileicon-server-3:before { content: "\f18a"; }
.fileicon-server-4:before { content: "\f18b"; }
.fileicon-server-5:before { content: "\f18c"; }
.fileicon-server-6:before { content: "\f18d"; }
.fileicon-server-7:before { content: "\f18e"; }
.fileicon-server-8:before { content: "\f18f"; }
.fileicon-sg:before { content: "\f190"; }
.fileicon-sitemap:before { content: "\f191"; }
.fileicon-sitemap-1:before { content: "\f192"; }
.fileicon-sitemap-2:before { content: "\f193"; }
.fileicon-sitemap-3:before { content: "\f194"; }
.fileicon-storage:before { content: "\f195"; }
.fileicon-storage-1:before { content: "\f196"; }
.fileicon-storage-2:before { content: "\f197"; }
.fileicon-txt:before { content: "\f198"; }
.fileicon-video-file:before { content: "\f199"; }
.fileicon-video-file-1:before { content: "\f19a"; }
.fileicon-video-file-2:before { content: "\f19b"; }
.fileicon-video-file-3:before { content: "\f19c"; }
.fileicon-video-file-4:before { content: "\f19d"; }
.fileicon-video-file-5:before { content: "\f19e"; }
.fileicon-video-file-6:before { content: "\f19f"; }
.fileicon-video-file-7:before { content: "\f1a0"; }
.fileicon-video-file-8:before { content: "\f1a1"; }
.fileicon-viewer:before { content: "\f1a2"; }
.fileicon-xls:before { content: "\f1a3"; }
.fileicon-zip:before { content: "\f1a4"; }

BIN
static/icons/fileicon.eot Normal file

Binary file not shown.

1280
static/icons/fileicon.html Normal file

File diff suppressed because it is too large Load Diff

1726
static/icons/fileicon.svg Normal file

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 345 KiB

BIN
static/icons/fileicon.ttf Normal file

Binary file not shown.

BIN
static/icons/fileicon.woff Normal file

Binary file not shown.

View File

@@ -1,8 +1,14 @@
{% extends "layout.html" %} {% extends "layout.html" %}
{% block content %}<br> {% block content %}<br>
<h1>asdf</h1> <h1>{{dir.p}}</h1>
{{dir.p}}
<ul> <ul>
{% for f in dir.dirs %}
<li> .<i class="fileicon-folder-1"></i><a href="{{url_for('internfiles.web', path=path+f)}}">
{{f}}</a></li>
{% endfor %}</ul>
<ul aria-label="You are here:" role="navigation" class="breadcrumbs">
{% for b in dir.bookmarks %}<li> {% for b in dir.bookmarks %}<li>
<a href="{{url_for('internfiles.web', path=b)}}"> <a href="{{url_for('internfiles.web', path=b)}}">
{{b or "Home"}}</a></li> {{b or "Home"}}</a></li>
@@ -12,15 +18,10 @@
{{text|safe}}<br><br> {{text|safe}}<br><br>
<ul> <ul>
{% for f in dir.files %} {% for f in dir.files %}
<li>
{{f}} <a href="{{url_for('internfiles.web', path=path+f)}}">
{{f}}</a></li>
{% endfor %}</ul>
<ul>
{% for f in dir.dirs %}
<li><a href="{{url_for('internfiles.web', path=path+f)}}"> <li><a href="{{url_for('internfiles.web', path=path+f)}}">
{{f}}</a></li> {{f}}</a></li>
{% endfor %}</ul> {% endfor %}</ul>
{% endblock %} {% endblock %}

View File

@@ -9,7 +9,7 @@
<title>FET Search</title> <title>FET Search</title>
<meta http-equiv="Content-Security-Policy" content="default-src * https://*.2020.fet.at *.2020.fet.at; style-src 'self' 'unsafe-inline'; script-src 'self'"> <meta http-equiv="Content-Security-Policy" content="default-src * https://*.2020.fet.at *.2020.fet.at; style-src 'self' 'unsafe-inline'; script-src 'self'">
<link rel="stylesheet" type="text/css" href="/static/icons/fileicon.css">
<link rel="stylesheet" href="{{ url_for('static', filename='app.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='app.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='extra.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='extra.css') }}">

View File

@@ -21,29 +21,27 @@ import internfiles
#logging.basicConfig(level=logging.INFO) #logging.basicConfig(level=logging.INFO)
URL_HOSTNAME='bot.2020.fet.at' URL_HOSTNAME='bot.2020.fet.at'
os.environ['URL_HOSTNAME']='bot.2020.fet.at' os.environ['URL_HOSTNAME'] = 'bot.2020.fet.at'
app=Flask(__name__) app = Flask(__name__)
chat_id='108021014' chat_id = '108021014'
bot = Teleflask(API_KEY) bot = Teleflask(API_KEY)
bot.init_app(app) bot.init_app(app)
chats=ChatManager(bot.bot) chats=ChatManager(bot.bot)
solr=SolrFet2020() solr=SolrFet2020()
#app.config['SERVER_NAME'] = 'bot.2020.fet.at'
@app.route('/') @app.route('/')
def home(): def home():
query=request.args.get("query") query=request.args.get("query")
if query: if query:
links,hits=solr.search(query) links,_=solr.search(query)
else: else:
links=None links=None
return render_template("search.html", query=query, results=links) return render_template("search.html", query=query, results=links)
@app.route('/send/<text>')
def send(text=None):
bot.bot.send_message(chat_id, text)
return "Text: %s <br> %s" % (text,request.headers)
@app.route('/send/<chat_id>/<text>') @app.route('/send/<chat_id>/<text>')
def send_to(chat_id,text=None): def send_to(chat_id,text=None):
@@ -83,7 +81,7 @@ def download_file(url):
def bot_update(update): def bot_update(update):
from pytgbot.api_types.receivable.updates import Update from pytgbot.api_types.receivable.updates import Update
assert isinstance(update, Update) if not isinstance(update, Update): raise TypeError("Update needs to be of Type update")
print(yaml.dump(update.to_array())) print(yaml.dump(update.to_array()))
chats.process_update(update) chats.process_update(update)

View File

@@ -1,6 +1,29 @@
from contextlib import contextmanager
class A(): class A():
def b(self): def b(self):
return "Hello" return "Hello"
@property
def cm(self):
@contextmanager
def stuff():
print("start")
try:
yield None
#yield 2
except Exception:
pass
print("end")
return stuff
def p(self):
with self.cm() as i:
print(f"{i} middle")
raise Exception
a=A() a=A()
print(callable(getattr(a,"b")))
print(getattr(a, "b")())
a.p()

5
tests/test_solr.py Normal file
View File

@@ -0,0 +1,5 @@
import pytest
def test_true():
assert True

46
tests/test_wiki.py Normal file
View File

@@ -0,0 +1,46 @@
"test des kleinen Wiki Systems"
import pytest
import wiki
@pytest.fixture
def pages():
w=wiki.PageManager(file="")
w.from_dict({
"home": {},
"home/hello":{},
"home/hello2":{"path":"homehello"}
})
return w
class TestPageAttribute:
def test_id(self,pages):
assert pages["home"].id=="home"
def test_page_hello(pages):
assert isinstance(pages["home"],wiki.Page)
class TestPageParsing:
def test_leave_html(self):
t="<b>Hello</b><ul><li>sf</li></ul>"
tout, entities=wiki.parse_intern_page(t)
assert t==tout
def test_replacebrakcets_html(self):
t="<b>Hello</b><ul><li>[uj]</li></ul>"
tout, entities=wiki.parse_intern_page(t)
assert not t==tout
assert tout=='<b>Hello</b><ul><li><a href="/wiki/uj">uj</a></li></ul>'
def test_replace_tags_html(self):
t="<b>Hello</b><ul><li>#uj</li></ul>"
tout, entities=wiki.parse_intern_page(t)
assert not t==tout
assert tout=='<b>Hello</b><ul><li><a href="/tag/uj">#uj</a></li></ul>'
def test_replace_tags_inentities(self):
t="<b>Hello</b><ul><li>#uj</li></ul>"
tout, entities=wiki.parse_intern_page(t)
assert "uj" in entities["tags"]

View File

@@ -1,20 +1,22 @@
#from misc import SaveFileMapping, SaveFileObject # from misc import SaveFileMapping, SaveFileObject
from .api import EtherpadLiteLazyAPI from .api import EtherpadLiteLazyAPI
from slugify import slugify from slugify import slugify
from lazymappingstorage import LazyMappingStorage, LazyStorageObject from lazymappingstorage import LazyMappingStorage, LazyStorageObject
from flask import Blueprint, make_response, render_template from flask import Blueprint, make_response, render_template
import bs4 import bs4
import re import re
from dataclasses import dataclass from dataclasses import dataclass
from anytree import NodeMixin from anytree import NodeMixin
import settings
ep=EtherpadLiteLazyAPI( # import html
url="http://etherpad:9101",
exturl="https://bot.2020.fet.at/etherpad/",
keyfile="services/etherpad/APIKEY.txt",
groupmapper="fetwiki"
)
ep = EtherpadLiteLazyAPI(
url=settings.ETHERPAD_API,
exturl=settings.ETHERPAD_EXT,
keyfile=settings.ETHERPAD_KEYFILE,
groupmapper=settings.ETHERPAD_GROUP,
)
def clean_path(path): def clean_path(path):
@@ -23,56 +25,72 @@ def clean_path(path):
def parse_intern_page(text): def parse_intern_page(text):
if not text: return text if not text:
return text
soup = bs4.BeautifulSoup(text, "html.parser") soup = bs4.BeautifulSoup(text, "html.parser")
textNodes = soup.findAll(text=True) textNodes = soup.findAll(text=True)
if not textNodes: return text
for textNode in textNodes:
text = re.sub('\[(\w+)\]','replaced!!!: - \g<1> - ',textNode)
text = re.sub('^(\w+)\:\s?(.+)$','config param - \g<1> : \g<2> ',text)
text = re.sub('(#[\w-]+)\s$','TAG( \g<1> ) ',text)
print(text)
textNode.replaceWith(text)
return str(soup) entities = {
"internallinks": re.findall(r"\[(\w+)\]", text),
"tags": re.findall(r"#([\w-]+)\s?", text),
}
if not textNodes:
return text
for textNode in textNodes:
text = re.sub(r"\[(\w+)\]", r'<a href="/wiki/\g<1>">\g<1></a>', str(textNode))
# text = re.sub(r"^(\w+)\:\s?(.+)$",'config param - \g<1> : \g<2> ',text)
text = re.sub(r"#([\w-]+)\s?", r'<a href="/tag/\g<1>">#\g<1></a>', text)
print(text)
textNode.replaceWith(bs4.BeautifulSoup(text, "html.parser"))
return str(soup), entities
@dataclass @dataclass
class Page(LazyStorageObject, NodeMixin): class Page(LazyStorageObject, NodeMixin):
path: str=None path: str = None
count: int=1 count: int = 1
@property @property
def id(self): def id(self):
return slugify(self.path) return slugify(self.path)
@property @property
def editlink(self): def editlink(self):
return ep.getPadLink(self.id) return ep.getPadLink(self.id)
@property @property
def content(self): def content(self):
return parse_intern_page(ep.getPadHTML(self.id)) return parse_intern_page(ep.getPadHTML(self.id))
class PageManager(LazyMappingStorage): class PageManager(LazyMappingStorage):
filename="pages.yaml" filename = "pages.yaml"
object_class=Page object_class = Page
def __getitem__(self,key):
def __getitem__(self, key):
o = super().__getitem__(clean_path(key)) o = super().__getitem__(clean_path(key))
o.path = clean_path(key) o.path = clean_path(key)
if not o.path=="": if not o.path == "":
o.parent=self["/".join(o.path.split("/")[:-1])] o.parent = self["/".join(o.path.split("/")[:-1])]
return o return o
def __setitem__(self,key,value):
super().__setitem__(clean_path(key),value)
pages=PageManager() def __setitem__(self, key, value):
bp = Blueprint('wiki', __name__, url_prefix='/wiki') super().__setitem__(clean_path(key), value)
@bp.route('/')
@bp.route('/<path:path>') pages = PageManager()
bp = Blueprint("wiki", __name__, url_prefix="/wiki")
@bp.route("/")
@bp.route("/<path:path>")
def web(path=""): def web(path=""):
page=pages[path] page = pages[path]
pages.to_file() pages.to_file()
response=make_response(render_template("wiki.html", page=page)) response = make_response(render_template("wiki.html", page=page))
response.set_cookie("sessionID",str(ep.getSessionID("andis")),path="/etherpad") response.set_cookie("sessionID", str(ep.getSessionID("andis")), path="/etherpad")
return response return response

View File

@@ -99,7 +99,7 @@ class EtherpadLiteLazyAPI():
def getPadLink(self,padID): def getPadLink(self,padID):
if padID is None: return "#" if padID is None: return "#"
if not self.connect(): return "#" if not self.connect(): return "#notconnected"
return urllib.parse.urljoin(self.exturl, 'p/' + self.group["groupID"] + '$' + str(padID)) return urllib.parse.urljoin(self.exturl, 'p/' + self.group["groupID"] + '$' + str(padID))
def getSessionID(self, username): def getSessionID(self, username):