Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev-0.9' into dev-0.10
Browse files Browse the repository at this point in the history
# Conflicts:
#	frontend/templates/help.html
#	urpc/builder/bindings/python.py
#	version.py
  • Loading branch information
mikheev committed Feb 18, 2022
2 parents c3ec487 + b9b1900 commit 44e5209
Show file tree
Hide file tree
Showing 12 changed files with 714 additions and 670 deletions.
19 changes: 12 additions & 7 deletions frontend/handler/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from tornado.web import HTTPError

from frontend.handler.base import BaseRequestHandler
from frontend.util.validator import check_if_empty, check_if_number
from frontend.util.validator import check_if_empty, check_if_number, check_if_version, check_project_name
from urpc import ast
from urpc.util.accessor import split_by_type
from urpc.util.cconv import cstr_to_type
Expand Down Expand Up @@ -706,12 +706,17 @@ def _protocol_post(self, action, handle):
project_name = self.get_body_argument("project_name", None)
version = self.get_body_argument("version")
extra_options = self.get_body_argument("extra_options", "")
self._editor.update_protocol(
handle=handle,
project_name=project_name,
version=version,
extra_options=extra_options
)
try:
check_project_name(project_name)
check_if_version(version)
self._editor.update_protocol(
handle=handle,
project_name=project_name,
version=version,
extra_options=extra_options
)
except ValueError as e:
EditorHandler.messages["project-message"] = str(e)
self.redirect(url_concat(self.reverse_url("editor")[1:], {"action": "view", "handle": handle}))
elif action == "create_command":
cid, name = self.get_body_argument("cid"), self.get_body_argument("command_name")
Expand Down
7 changes: 6 additions & 1 deletion frontend/handler/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from tornado.web import HTTPError

from frontend.handler.base import BaseRequestHandler
from frontend.handler.editor import EditorHandler
from urpc.builder import bindings
from urpc.builder import firmware
from urpc.builder.adapters import tango
Expand Down Expand Up @@ -154,7 +155,8 @@ def get(self, action):

def post(self, action):
if action == "load":
if not self.request.files or len(self.request.files) == 0: # if user hasn"t recently loaded project file
if not self.request.files:
EditorHandler.messages["load-message"] = "No input file"
self.redirect(".." + self.reverse_url("main"))
file_info = self.request.files["project"][0]
ext = os.path.splitext(file_info["filename"])[1]
Expand All @@ -171,6 +173,9 @@ def post(self, action):

output_buffer, file_name, mime = BytesIO(), "", ""

if not self.request.files:
EditorHandler.messages["assembly-profiles-message"] = "No input file"
self.redirect(".." + self.reverse_url("main"))
files_info = self.request.files["profiles"]

profiles_list = []
Expand Down
Binary file added frontend/static/favicon.ico
Binary file not shown.
Binary file added frontend/static/img/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions frontend/static/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-Agent: *
Allow: /
2 changes: 2 additions & 0 deletions frontend/templates/editor/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<fieldset>
<input type="file" name="project">
<button type="submit" class="pure-button pure-button-primary">Load</button>
<span class="error-message">{{ messages.get("load-message", "") }}</span>
</fieldset>
</form>
<form class="pure-form pure-form-stacked" action="{{ reverse_url("project", "save")[1:] }}" method="get">
Expand Down Expand Up @@ -120,6 +121,7 @@
<fieldset>
<input type="file" name="profiles" multiple="True">
<button type="submit" class="pure-button pure-button-primary">Assemble</button>
<span class="error-message">{{ messages.get("assembly-profiles-message", "") }}</span>
</fieldset>
</form>

Expand Down
1 change: 1 addition & 0 deletions frontend/templates/editor/protocol.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ <h2>General:</h2>
<textarea name="extra_options" value="" placeholder="Extra options in format: Opt1=Value1, Opt2=Value, ...">{{ protocol.extra_options }}</textarea>
<p></p>
<button type="submit" class="pure-button pure-button-primary">Update</button>
<span class="error-message">{{ messages.get("project-message", "") }}</span>
</fieldset>
</form>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/util/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __getitem__(self, uid):
with open(path, "rb") as f:
item.project = self._storage.load(f)
else:
item.project = Protocol(name="Default project", version="0")
item.project = Protocol(name="default_project", version="0.0.1")

item.timeout = self._loop.call_later(self._dump_timeout, self._dump_cached, uid)
return item.project
Expand Down
24 changes: 24 additions & 0 deletions frontend/util/validator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import re


version_pattern = re.compile(r"^((?:[1-9][0-9]*?)|0)(?:\.((?:[1-9][0-9]*?)|0))?(?:\.((?:[1-9][0-9]*?)|0))?$")
project_name_pattern = re.compile(r"^[a-zA-Z_][a-zA-Z0-9_]*?$")


def check_if_empty(val, par_name="Value"):
if not val.strip():
raise ValueError("%s should not be empty string" % par_name)
Expand All @@ -8,3 +15,20 @@ def check_if_number(val, par_name="Value"):
if not val.isdigit() and val.strip():
raise ValueError("%s should be a number" % par_name)
return val


def check_if_version(val, par_name="Version"):
match = version_pattern.match(val)
if not match:
raise ValueError("{} should match pattern x.y.z, x.y or just x (e.g. '1.1.1', '1.1' or just '1')".format(
par_name
))
return val


def check_project_name(val, par_name="Project name"):
match = project_name_pattern.match(val)
if not match:
raise ValueError("{} may contain only: letters [a-Z], digits [0-9], underscores; "
"but not starts with digits".format(par_name))
return val
6 changes: 4 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging

from tornado.platform.asyncio import AsyncIOMainLoop
from tornado.web import Application
from tornado.web import Application, StaticFileHandler

from frontend.handler import editor, generic, project
from frontend.util.session import SessionManager
Expand Down Expand Up @@ -40,7 +40,9 @@ def make_app():
(Settings.url_prefix + r"/editor$", editor.EditorHandler, {"sessions": sessions}, "editor"),
(Settings.url_prefix + r"/project/(?P<action>[a-z_]+)?$",
project.ProjectHandler, {"sessions": sessions}, "project"),
(Settings.url_prefix + r"/(?P<action>[a-z_]+)?$", generic.MainHandler, {"sessions": sessions}, "upload")
(Settings.url_prefix + r"/(?P<action>[a-z_]+)?$", generic.MainHandler, {"sessions": sessions}, "upload"),
(Settings.url_prefix + r"/(favicon\.ico)", StaticFileHandler),
(Settings.url_prefix + r"/(robots\.txt)", StaticFileHandler),
), **settings)


Expand Down
Loading

0 comments on commit 44e5209

Please sign in to comment.