Commit 993e8242 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Add docstrings for main binary

parent 5ec6800b
...@@ -10,6 +10,11 @@ You can use the demo instance [here](http://dgenies.toulouse.inra.fr). ...@@ -10,6 +10,11 @@ You can use the demo instance [here](http://dgenies.toulouse.inra.fr).
Or you can install your own instance. The install documentation is available [here](http://dgenies.toulouse.inra.fr/install). Or you can install your own instance. The install documentation is available [here](http://dgenies.toulouse.inra.fr/install).
Documentation
-------------
Full documentation, including code API, is available [here](https://dgenies.readthedocs.io/en/latest/index.html).
How to cite? How to cite?
------------ ------------
......
#!/usr/bin/env python3 #!/usr/bin/env python3
"""
D-Genies main binary
- Launch D-Genies server
- manage crons
- clear jobs and data
"""
import os import os
import argparse import argparse
import webbrowser import webbrowser
...@@ -17,6 +25,15 @@ config = AppConfigReader() ...@@ -17,6 +25,15 @@ config = AppConfigReader()
def parse_args(): def parse_args():
"""
Parse arguments given from the user
:return:
* [0] action to do (run, clear, gallery, ...)
* [1] arguments object
:rtype: (str, argparse.Namespace)
"""
parser = argparse.ArgumentParser(description="Manage dgenies application") parser = argparse.ArgumentParser(description="Manage dgenies application")
subparsers = parser.add_subparsers(dest="subparser_name") subparsers = parser.add_subparsers(dest="subparser_name")
...@@ -89,6 +106,16 @@ def parse_args(): ...@@ -89,6 +106,16 @@ def parse_args():
def start_browser(host, port, app): def start_browser(host, port, app):
"""
Start browser when the server is runned
:param host: host on which the server is launched
:type host: str
:param port: port on which the server is launched
:type port: int
:param app: Flask app object
:type app: Flask
"""
web_url = "http://{0}:{1}".format(host, port) web_url = "http://{0}:{1}".format(host, port)
status_code = -1 status_code = -1
tries = 0 tries = 0
...@@ -109,6 +136,22 @@ def start_browser(host, port, app): ...@@ -109,6 +136,22 @@ def start_browser(host, port, app):
def run(mode="standalone", debug=False, host="127.0.0.1", port=5000, no_crons=False, no_browser=False): def run(mode="standalone", debug=False, host="127.0.0.1", port=5000, no_crons=False, no_browser=False):
"""
Run server
:param mode: webserver or standalone
:type mode: str
:param debug: True to enable debug mode
:type debug: bool
:param host: host on which run rhe server
:type host: str
:param port: port on which run the server
:type port: int
:param no_crons: True to disable crons
:type no_crons: bool
:param no_browser: True to don't launch the browser after server starts
:type no_browser: bool
"""
os.environ['DISABLE_CRONS'] = "True" if no_crons else "False" os.environ['DISABLE_CRONS'] = "True" if no_crons else "False"
if debug: if debug:
os.environ['LOGS'] = "True" os.environ['LOGS'] = "True"
...@@ -125,12 +168,18 @@ def run(mode="standalone", debug=False, host="127.0.0.1", port=5000, no_crons=Fa ...@@ -125,12 +168,18 @@ def run(mode="standalone", debug=False, host="127.0.0.1", port=5000, no_crons=Fa
def clear_crons(): def clear_crons():
"""
Clear crons
"""
from dgenies.lib.crons import Crons from dgenies.lib.crons import Crons
crons = Crons(None, True) crons = Crons(None, True)
crons.clear() crons.clear()
def clear_logs(): def clear_logs():
"""
Clear logs
"""
if hasattr(config, "log_dir"): if hasattr(config, "log_dir"):
log_files = glob(os.path.join(config.log_dir, "*.log")) log_files = glob(os.path.join(config.log_dir, "*.log"))
for file in log_files: for file in log_files:
...@@ -141,6 +190,11 @@ def clear_logs(): ...@@ -141,6 +190,11 @@ def clear_logs():
def clear_jobs(max_data_age=7, web=False): def clear_jobs(max_data_age=7, web=False):
"""
Clear jobs
:param max_data_age: max age for jobs before removing them
:param web: True if webserver mode
"""
upload_folder = config.upload_folder upload_folder = config.upload_folder
app_data = config.app_data app_data = config.app_data
now = time.time() now = time.time()
...@@ -190,6 +244,20 @@ def clear_jobs(max_data_age=7, web=False): ...@@ -190,6 +244,20 @@ def clear_jobs(max_data_age=7, web=False):
def add_to_gallery(id_job, name, picture, query, target): def add_to_gallery(id_job, name, picture, query, target):
"""
Add a job to the gallery
:param id_job: job id
:type id_job: str
:param name: name of the sample
:type name: str
:param picture: picture filename
:type picture: str
:param query: query name
:type query: str
:param target: target name
:type target: str
"""
from dgenies.database import Gallery, Job from dgenies.database import Gallery, Job
from peewee import DoesNotExist from peewee import DoesNotExist
try: try:
...@@ -207,6 +275,13 @@ def add_to_gallery(id_job, name, picture, query, target): ...@@ -207,6 +275,13 @@ def add_to_gallery(id_job, name, picture, query, target):
def del_from_gallery_by_id(id_job): def del_from_gallery_by_id(id_job):
"""
Remove a job, by id
:param id_job: id of the job to delete
:return: list of pictures files to delete
:rtype: list
"""
from dgenies.database import Gallery, Job from dgenies.database import Gallery, Job
items = Gallery.select().join(Job).where(Job.id_job == id_job) items = Gallery.select().join(Job).where(Job.id_job == id_job)
list_pictures = [] list_pictures = []
...@@ -217,6 +292,13 @@ def del_from_gallery_by_id(id_job): ...@@ -217,6 +292,13 @@ def del_from_gallery_by_id(id_job):
def del_from_gallery_by_name(name): def del_from_gallery_by_name(name):
"""
Remove a job, by name
:param name: name of the job to delete
:return: list of pictures files to delete
:rtype: list
"""
from dgenies.database import Gallery from dgenies.database import Gallery
items = Gallery.select().where(Gallery.name == name) items = Gallery.select().where(Gallery.name == name)
list_pictures = [] list_pictures = []
......
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