Skip to content

Commit

Permalink
Merge pull request #222 from BenediktMKuehne/new-version
Browse files Browse the repository at this point in the history
New version
  • Loading branch information
BenediktMKuehne authored Dec 18, 2024
2 parents 94bf947 + 996a39d commit 26b4f3a
Show file tree
Hide file tree
Showing 31 changed files with 568 additions and 291 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ on:

jobs:
lint:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- name: Checkout Branch
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install dependencies for linting
run: |
sudo apt-get update -y
sudo apt-get install -y python3-dev npm pycodestyle python3-pylint-django bandit
sudo apt-get install -y python3-dev npm pycodestyle bandit pylint
sudo npm install -g jshint
- name: Install Python, pipenv and Pipfile packages
uses: palewire/install-python-pipenv-pipfile@v2
uses: palewire/install-python-pipenv-pipfile@v4
with:
python-version: '3.10'
- name: Make dirs
Expand Down
2 changes: 1 addition & 1 deletion .pycodestylerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[pycodestyle]
count = False
ignore = E226, E501, W605, E402, E722
ignore = E226, E501, W605, E402, E722, W503
max-line-length = 120
statistics = True
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ confidence=
#
# Kubeflow disables string-interpolation because we are starting to use f
# style strings
disable=C0115,C0114,C0116,W0703,W0603,R1705,W0511 # TODO remove W0511
disable=C0115,C0114,C0116,W0703,W0603,R1705,W0511,R0914,R0915 # TODO remove W0511
#import-star-module-level,old-octal-literal,oct-method,print-statement,unpacking-in-except,
#parameter-unpacking,backtick,old-raise-syntax,old-ne-operator,long-suffix,dict-view-method,dict-iter-method,
#metaclass-assignment,next-method-called,raising-string,indexing-exception,raw_input-builtin,long-builtin,file-builtin,
Expand Down
9 changes: 5 additions & 4 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ verify_ssl = true
name = "pypi"

[packages]
channels = "*"
channels-redis = "*"
daphne = "*"
mysqlclient = "*"
django-apscheduler = "*"
Expand All @@ -16,12 +14,15 @@ psutil = "*"
msgpack = "*"
django = "*"
django-hashid-field = "*"
mod-wsgi-standalone = "*"
django-bootstrap5 = "*"
django-tables2 = "*"
requests = "*"
djangorestframework = "*"
watchdog = "*"
channels = "*"
channels-redis = "*"
mod-wsgi-standalone = "*"
django-bootstrap5 = "*"
pytz = "*"

[dev-packages]
pycodestyle = "*"
Expand Down
412 changes: 233 additions & 179 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1-c58e97d5
0.1-fb9df462
6 changes: 3 additions & 3 deletions dev-tools/check_project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pylinter(){
mapfile -t PY_SCRIPTS < <(find . -type d -name migrations -prune -false -o -iname "*.py")
for PY_SCRIPT in "${PY_SCRIPTS[@]}"; do
echo -e "\\n""${GREEN}""Run pylint on ${PY_SCRIPT}:""${NC}""\\n"
mapfile -t PY_RESULT < <(pipenv run pylint --rcfile=../.pylintrc "${PY_SCRIPT}" 2> >(grep -v "Courtesy Notice\|Loading .env" >&2) )
mapfile -t PY_RESULT < <(pipenv run pylint --load-plugins pylint_django --rcfile=../.pylintrc "${PY_SCRIPT}" 2> >(grep -v "Courtesy Notice\|Loading .env" >&2) )
local RATING_10=0
if [[ "${#PY_RESULT[@]}" -gt 0 ]]; then
if ! printf '%s\n' "${PY_RESULT[@]}" | grep -q -P '^Your code has been rated at 10'; then
Expand All @@ -229,14 +229,14 @@ pylinter(){
done

echo -e "\\n""${GREEN}""Run pylint on all scripts:""${NC}""\\n"
pipenv run pylint --rcfile=../.pylintrc ./* 2> >(grep -v "Courtesy Notice\|Loading .env" >&2) | grep "Your code has been rated"
pipenv run pylint --load-plugins pylint_django --rcfile=../.pylintrc ./* 2> >(grep -v "Courtesy Notice\|Loading .env" >&2) | grep "Your code has been rated"
cd .. || exit 1
}

dockerchecker(){
if ! [[ -f .env ]]; then
ENV=1
touch .env #dummy file
touch .env # dummy file
else
ENV=0
fi
Expand Down
11 changes: 2 additions & 9 deletions dev-tools/debug-server-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# Description: Automates setup of developer environment for Debug-Server

# http-server options
PORT="8000"
PORT="8001"
IP="0.0.0.0"

export RED='\033[0;31m'
Expand Down Expand Up @@ -125,19 +125,12 @@ python3 ./embark/manage.py createsuperuser --noinput
echo -e "\n[""${BLUE} JOB""${NC}""] Starting runapscheduler"
python3 ./embark/manage.py runapscheduler | tee -a ./logs/scheduler.log &

echo -e "\n[""${BLUE} JOB""${NC}""] Starting daphne(ASGI) - log to /embark/logs/daphne.log"
echo "START DAPHNE" >./logs/daphne.log
cd ./embark || exit 1
pipenv run daphne -v 3 -p 8001 -b "${IP}" --root-path="${PWD}"/embark embark.asgi:application &>../logs/daphne.log &
cd .. || exit 1

# start embark
# systemctl start embark.service

echo -e "${ORANGE}""${BOLD}""start EMBArk server (WS/WSS not enabled -a also asgi)""${NC}"
echo -e "${ORANGE}""${BOLD}""start EMBArk server(ASGI only) on port ${PORT}""${NC}"
python3 ./embark/manage.py runserver "${IP}":"${PORT}" |& tee -a ./logs/debug-server.log

wait


echo -e "\n${ORANGE}""${BOLD}""Done. To clean-up use the clean-setup script""${NC}"
19 changes: 14 additions & 5 deletions embark/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
from django.conf import settings
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseServerError
from django.contrib.auth.decorators import login_required
from django.contrib.auth.decorators import login_required, permission_required
from django.views.decorators.http import require_http_methods
from django.contrib import messages
from django.shortcuts import redirect
from django.views.decorators.csrf import csrf_protect
from tracker.forms import AssociateForm
from uploader.boundedexecutor import BoundedExecutor
from uploader.forms import LabelForm
Expand All @@ -30,6 +29,7 @@
req_logger = logging.getLogger("requests")


@permission_required("users.dashboard_permission_minimal", login_url='/')
@require_http_methods(["GET"])
@login_required(login_url='/' + settings.LOGIN_URL)
def main_dashboard(request):
Expand All @@ -41,6 +41,7 @@ def main_dashboard(request):
return HttpResponseForbidden


@permission_required("users.dashboard_permission_advanced", login_url='/')
@login_required(login_url='/' + settings.LOGIN_URL)
@require_http_methods(["POST"])
def stop_analysis(request):
Expand Down Expand Up @@ -78,6 +79,7 @@ def stop_analysis(request):
return HttpResponseBadRequest("invalid form")


@permission_required("users.dashboard_permission_minimal", login_url='/')
@require_http_methods(["GET"])
@login_required(login_url='/' + settings.LOGIN_URL)
def service_dashboard(request):
Expand All @@ -92,6 +94,7 @@ def service_dashboard(request):
return render(request, 'dashboard/serviceDashboard.html', {'username': request.user.username, 'form': form, 'success_message': False})


@permission_required("users.dashboard_permission_minimal", login_url='/')
@require_http_methods(["GET"])
@login_required(login_url='/' + settings.LOGIN_URL)
def report_dashboard(request):
Expand All @@ -109,6 +112,7 @@ def report_dashboard(request):
return render(request, 'dashboard/reportDashboard.html', {'firmwares': firmwares, 'username': request.user.username, 'label_form': label_form, 'label_select_form': label_select_form})


@permission_required("users.dashboard_permission_minimal", login_url='/')
@login_required(login_url='/' + settings.LOGIN_URL)
def individual_report_dashboard(request, analysis_id):
"""
Expand All @@ -123,6 +127,7 @@ def individual_report_dashboard(request, analysis_id):
return render(request, 'dashboard/individualReportDashboard.html', {'username': request.user.username, 'analysis_id': analysis_id, 'form': form})


@permission_required("users.dashboard_permission_advanced", login_url='/')
@require_http_methods(["GET"])
@login_required(login_url='/' + settings.LOGIN_URL)
def show_log(request, analysis_id):
Expand All @@ -148,6 +153,7 @@ def show_log(request, analysis_id):
return HttpResponseServerError(content="File is not yet available")


@permission_required("users.dashboard_permission_advanced", login_url='/')
@require_http_methods(["GET"])
@login_required(login_url='/' + settings.LOGIN_URL)
def show_logviewer(request, analysis_id):
Expand All @@ -174,6 +180,7 @@ def show_logviewer(request, analysis_id):
return HttpResponseServerError(content="File is not yet available")


@permission_required("users.dashboard_permission_advanced", login_url='/')
@require_http_methods(["GET"])
@login_required(login_url='/' + settings.LOGIN_URL)
def delete_analysis(request, analysis_id):
Expand Down Expand Up @@ -210,6 +217,7 @@ def delete_analysis(request, analysis_id):
return redirect('..')


@permission_required("users.dashboard_permission_minimal", login_url='/')
@login_required(login_url='/' + settings.LOGIN_URL)
@require_http_methods(["GET"])
def archive_analysis(request, analysis_id):
Expand All @@ -232,6 +240,7 @@ def archive_analysis(request, analysis_id):
return redirect('..')


@permission_required("users.dashboard_permission_advanced", login_url='/')
@login_required(login_url='/' + settings.LOGIN_URL)
@require_http_methods(["GET"])
def hide_analysis(request, analysis_id):
Expand All @@ -250,7 +259,7 @@ def hide_analysis(request, analysis_id):
return redirect('..')


@csrf_protect
@permission_required("users.dashboard_permission_advanced", login_url='/')
@require_http_methods(["POST"])
@login_required(login_url='/' + settings.LOGIN_URL)
def create_label(request):
Expand All @@ -269,7 +278,7 @@ def create_label(request):
return redirect('..')


@csrf_protect
@permission_required("users.dashboard_permission_advanced", login_url='/')
@require_http_methods(["POST"])
@login_required(login_url='/' + settings.LOGIN_URL)
def add_label(request, analysis_id):
Expand All @@ -289,7 +298,7 @@ def add_label(request, analysis_id):
return redirect('..')


@csrf_protect
@permission_required("users.dashboard_permission_advanced", login_url='/')
@require_http_methods(["POST"])
@login_required(login_url='/' + settings.LOGIN_URL)
def rm_label(request, analysis_id, label_name):
Expand Down
14 changes: 6 additions & 8 deletions embark/embark/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@

import os

import django

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter
from channels.routing import URLRouter
from django.core.asgi import get_asgi_application

asgi_application = get_asgi_application()

from embark.routing import ws_urlpatterns

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'embark.settings.deploy')

django.setup()

from embark.routing import ws_urlpatterns

application = ProtocolTypeRouter({
'http': asgi_application,
'websocket': AuthMiddlewareStack(URLRouter(ws_urlpatterns))
'websocket': AuthMiddlewareStack(ws_urlpatterns)
})
31 changes: 31 additions & 0 deletions embark/embark/asgi_dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# pylint: disable=C0413
"""
ASGI config for djangoProject project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
"""
__copyright__ = 'Copyright 2021-2024 Siemens Energy AG, Copyright 2021 The AMOS Projects'
__author__ = 'Benedikt Kuehne, diegiesskanne, m-1-k-3'
__license__ = 'MIT'

import os

import django
from django.core.asgi import get_asgi_application

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'embark.settings.deploy')

django.setup()

from embark.routing import ws_urlpatterns

application = ProtocolTypeRouter({
'http': get_asgi_application(),
'websocket': AuthMiddlewareStack(ws_urlpatterns)
})
12 changes: 6 additions & 6 deletions embark/embark/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
__license__ = 'MIT'

from django.urls import path
# from django.urls import re_path
# from django.conf.urls import url
from channels.routing import URLRouter

from embark.consumers import ProgressConsumer
from embark.logviewer import LogConsumer

# url patterns for websocket communication -> equivalent to urls.py
ws_urlpatterns = [
path('ws/progress/', ProgressConsumer.as_asgi()),
path('ws/logs/<uuid:analysis_id>', LogConsumer.as_asgi())
]
ws_urlpatterns = URLRouter([
path('ws/progress', ProgressConsumer.as_asgi(), name="websocket-progress"),
path('ws/logs/<uuid:analysis_id>', LogConsumer.as_asgi(), name="websocket-logviewer")
])
2 changes: 1 addition & 1 deletion embark/embark/settings/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

# Application definition - defines what apps gets migrated
INSTALLED_APPS = [
'daphne',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
Expand All @@ -51,7 +52,6 @@
'django_bootstrap5',
'django_tables2',
'mod_wsgi.server',
'channels',
'uploader',
'users',
'reporter',
Expand Down
Loading

0 comments on commit 26b4f3a

Please sign in to comment.