Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot freeze on Windows #517

Open
hroncok opened this issue Jan 29, 2019 · 0 comments
Open

Cannot freeze on Windows #517

hroncok opened this issue Jan 29, 2019 · 0 comments

Comments

@hroncok
Copy link
Member

hroncok commented Jan 29, 2019

Got:

...
Rendering page intro/micropython (index)
ERROR:flask.app:Exception on /static/css/body.css [GET]
Traceback (most recent call last):
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
flask\app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
flask\app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
flask\app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
flask\_compat.py", line 35, in reraise
    raise value
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
flask\app.py", line 1811, in full_dispatch_request
    rv = self.preprocess_request()
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
flask\app.py", line 2087, in preprocess_request
    rv = func()
  File "C:\Users\Linux\naucse.python.cz\naucse\views.py", line 51, in _get_model

    g.model.freeze()
  File "C:\Users\Linux\naucse.python.cz\naucse\models.py", line 1029, in freeze
    course.freeze()
  File "C:\Users\Linux\naucse.python.cz\naucse\models.py", line 816, in freeze
    self.load_all_lessons()
  File "C:\Users\Linux\naucse.python.cz\naucse\models.py", line 799, in load_all
_lessons
    self.load_lessons(self._requested_lessons)
  File "C:\Users\Linux\naucse.python.cz\naucse\models.py", line 780, in load_les
sons
    parent=self,
  File "C:\Users\Linux\naucse.python.cz\naucse\converters.py", line 603, in load

    return converter.load(data[slug], **kwargs)
  File "C:\Users\Linux\naucse.python.cz\naucse\converters.py", line 215, in load

    result[k] = self.item_converter.load(v, **kwargs)
  File "C:\Users\Linux\naucse.python.cz\naucse\converters.py", line 468, in load

    field.load_into(result, data, parent=result)
  File "C:\Users\Linux\naucse.python.cz\naucse\converters.py", line 360, in load
_into
    value = self.converter.load(item_data, **kwargs)
  File "C:\Users\Linux\naucse.python.cz\naucse\converters.py", line 215, in load

    result[k] = self.item_converter.load(v, **kwargs)
  File "C:\Users\Linux\naucse.python.cz\naucse\converters.py", line 468, in load

    field.load_into(result, data, parent=result)
  File "C:\Users\Linux\naucse.python.cz\naucse\converters.py", line 360, in load
_into
    value = self.converter.load(item_data, **kwargs)
  File "C:\Users\Linux\naucse.python.cz\naucse\models.py", line 162, in load
    return self.sanitizer(parent, value)
  File "C:\Users\Linux\naucse.python.cz\naucse\models.py", line 147, in _sanitiz
e_page_content
    'static': static_url,
  File "C:\Users\Linux\naucse.python.cz\naucse\sanitize.py", line 198, in saniti
ze_html
    for fragment in lxml.html.fragments_fromstring(text)
  File "C:\Users\Linux\naucse.python.cz\naucse\sanitize.py", line 198, in <listc
omp>
    for fragment in lxml.html.fragments_fromstring(text)
  File "C:\Users\Linux\naucse.python.cz\naucse\sanitize.py", line 186, in saniti
ze_fragment
    sanitize_element(fragment, naucse_urls=naucse_urls)
  File "C:\Users\Linux\naucse.python.cz\naucse\sanitize.py", line 179, in saniti
ze_element
    sanitize_element(child, naucse_urls=naucse_urls)
  File "C:\Users\Linux\naucse.python.cz\naucse\sanitize.py", line 179, in saniti
ze_element
    sanitize_element(child, naucse_urls=naucse_urls)
  File "C:\Users\Linux\naucse.python.cz\naucse\sanitize.py", line 169, in saniti
ze_element
    attr_name, value, naucse_urls=naucse_urls)
  File "C:\Users\Linux\naucse.python.cz\naucse\sanitize.py", line 103, in conver
t_link
    new_url = naucse_urls[url.path](**query)
  File "C:\Users\Linux\naucse.python.cz\naucse\models.py", line 140, in static_u
rl
    return parent_page.lesson.static_files[filename].get_url(**kw)
KeyError: 'pics/grass.svg'
Traceback (most recent call last):
  File "C:\Users\Linux\AppData\Local\Programs\Python\Python36-32\Lib\runpy.py",
line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\Linux\AppData\Local\Programs\Python\Python36-32\Lib\runpy.py",
line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Linux\naucse.python.cz\naucse\__main__.py", line 3, in <module>

    main()
  File "C:\Users\Linux\naucse.python.cz\naucse\cli.py", line 8, in main
    elsa.cli(app, base_url='https://naucse.python.cz')
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
elsa\_cli.py", line 158, in cli
    return command()
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
click\core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
click\core.py", line 717, in main
    rv = self.invoke(ctx)
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
elsa\_cli.py", line 113, in freeze
    freeze_app(app, freezer, path, base_url, verbose=verbose)
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
elsa\_cli.py", line 50, in freeze_app
    for page in freezer.freeze_yield():
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
flask_frozen\__init__.py", line 183, in freeze_yield
    new_filename = self._build_one(url)
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
flask_frozen\__init__.py", line 322, in _build_one
    % (response.status, url))
ValueError: Unexpected status '500 INTERNAL SERVER ERROR' on URL /static/css/bod
y.css

C:\Users\Linux\naucse.python.cz>

Hacking on:

diff --git a/naucse/models.py b/naucse/models.py
index 6cbb0169..e5072320 100644
--- a/naucse/models.py
+++ b/naucse/models.py
@@ -137,7 +137,9 @@ def _sanitize_page_content(parent, content):
         return parent_page.solutions[int(solution)].get_url(**kw)

     def static_url(*, filename, **kw):
-        return parent_page.lesson.static_files[filename].get_url(**kw)
+        filename_ = filename.replace('/', '\\')
+        print('XXX', filename, filename_)
+        return parent_page.lesson.static_files[filename_].get_url(**kw)

     return sanitize.sanitize_html(
         content,
diff --git a/naucse/sanitize.py b/naucse/sanitize.py
index 4595bfb7..edee94de 100644
--- a/naucse/sanitize.py
+++ b/naucse/sanitize.py
@@ -81,7 +81,7 @@ def convert_link(attr_name, value, *, naucse_urls=None):
     elif url.scheme == '':
         if url.netloc == '':
             # Relative URL
-            if url.path.startswith('static/'):
+            if url.path.startswith(('static/', 'static\\')):
                 return url.path
             elif url.path != '':
                 # Documents should not assume that naucse has any particular
diff --git a/naucse/views.py b/naucse/views.py
index f72bfdbd..f59a7612 100644
--- a/naucse/views.py
+++ b/naucse/views.py
@@ -2,6 +2,7 @@ import datetime
 from pathlib import Path
 import functools
 import calendar
+import mimetypes
 import os

 from flask import Flask, render_template, jsonify, url_for, Response, abort, g,
 redirect
@@ -103,6 +104,9 @@ def init_model():
 register_url_converters(app)
 setup_jinja_env(app.jinja_env)

+# Old Windows might serve this as application/octet-stream
+mimetypes.add_type('application/json', '.json')
+

 @app.route('/')
 def index():

So far I have:

...
XXX pics/wall.svg pics\wall.svg
XXX naucse_fork.png naucse_fork.png
XXX naucse_fork.png naucse_fork.png
sending C:\Users\Linux\naucse.python.cz info.yml
Traceback (most recent call last):
  File "C:\Users\Linux\AppData\Local\Programs\Python\Python36-32\Lib\runpy.py",
line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\Linux\AppData\Local\Programs\Python\Python36-32\Lib\runpy.py",
line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Linux\naucse.python.cz\naucse\__main__.py", line 3, in <module>

    main()
  File "C:\Users\Linux\naucse.python.cz\naucse\cli.py", line 8, in main
    elsa.cli(app, base_url='https://naucse.python.cz')
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
elsa\_cli.py", line 158, in cli
    return command()
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
click\core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
click\core.py", line 717, in main
    rv = self.invoke(ctx)
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
elsa\_cli.py", line 113, in freeze
    freeze_app(app, freezer, path, base_url, verbose=verbose)
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
elsa\_cli.py", line 50, in freeze_app
    for page in freezer.freeze_yield():
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
flask_frozen\__init__.py", line 183, in freeze_yield
    new_filename = self._build_one(url)
  File "C:\Users\Linux\.virtualenvs\naucse.python.cz-Ap5RjXMi\lib\site-packages\
flask_frozen\__init__.py", line 322, in _build_one
    % (response.status, url))
ValueError: Unexpected status '404 NOT FOUND' on URL /course/meta/meta/local-run
/static/info.yml

C:\Users\Linux\naucse.python.cz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant