Commit 161d2be2 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Refactor + improve performances

parent 3adeffd5
import requests
import json
import os
import threading
from dgenies.config_reader import AppConfigReader
class Latest:
def __init__(self):
self.latest = ""
self.win32 = ""
config = AppConfigReader()
self._save_latest = os.path.join(config.config_dir, ".latest")
self.load()
def load(self):
if os.path.exists(self._save_latest):
with open(self._save_latest, "r") as latest_f:
self.latest = latest_f.readline().rstrip()
self.win32 = latest_f.readline().rstrip()
if self.latest == "" or self.win32 == "":
self.update()
else:
self.update_async()
else:
self.update()
def update_async(self):
thread = threading.Timer(1, self.update)
thread.start()
def update(self):
try:
call = requests.get("https://api.github.com/repos/genotoul-bioinfo/dgenies/releases/latest")
if call.ok:
release = json.loads(call.content.decode("utf-8"))
if "tag_name" in release:
self.latest = release["tag_name"][1:]
for asset in release["assets"]:
if asset["name"].endswith(".exe"):
self.win32 = asset["browser_download_url"]
break
except ConnectionError:
pass
else:
self._write_update()
def _write_update(self):
if self.latest != "" or self.win32 != "":
with open(self._save_latest, "w") as latest_f:
latest_f.write("\n".join([self.latest, self.win32]))
......@@ -17,6 +17,7 @@ from dgenies.lib.job_manager import JobManager
from dgenies.lib.functions import Functions, ALLOWED_EXTENSIONS
from dgenies.lib.upload_file import UploadFile
from dgenies.lib.fasta import Fasta
from dgenies.lib.latest import Latest
from dgenies.tools import Tools
from markdown import Markdown
from markdown.extensions.toc import TocExtension
......@@ -28,24 +29,6 @@ if MODE == "webserver":
from peewee import DoesNotExist
def get_latest_version():
latest = ""
win32 = ""
try:
call = requests.get("https://api.github.com/repos/genotoul-bioinfo/dgenies/releases/latest")
if call.ok:
release = json.loads(call.content.decode("utf-8"))
if "tag_name" in release:
latest = release["tag_name"][1:]
for asset in release["assets"]:
if asset["name"].endswith(".exe"):
win32 = asset["browser_download_url"]
break
except ConnectionError:
pass
return latest, win32
@app.context_processor
def global_templates_variables():
return {
......@@ -343,7 +326,8 @@ def get_file(file, gzip=False): # pragma: no cover
@app.route("/documentation/run", methods=['GET'])
def documentation_run():
version = get_latest_version()[0]
latest = Latest()
version = latest.latest
with open(os.path.join(app_folder, "md", "doc_run.md"), "r", encoding='utf-8') as install_instr:
content = install_instr.read()
env = Environment()
......@@ -407,13 +391,13 @@ def documentation_dotplot():
@app.route("/install", methods=['GET'])
def install():
latest, win32 = get_latest_version()
latest = Latest()
with open(os.path.join(app_folder, "md", "INSTALL.md"), "r", encoding='utf-8') as install_instr:
content = install_instr.read()
env = Environment()
template = env.from_string(content)
content = template.render(version=latest, win32=win32)
content = template.render(version=latest.latest, win32=latest.win32)
md = Markdown(extensions=[TocExtension(baselevel=1)])
content = Markup(md.convert(content))
toc = Markup(md.toc)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment