RASCSI/src/web
Daniel Markstedt 5befff28e6
Improve token auth and oled monitor install scripts; better venv cleanup logic (#587)
* Trigger installation of the oled monitor script after installing rascsi; break out the token auth code and clarify wordings.

* Better logic for venv cleanup
2022-01-01 11:38:10 -06:00
..
mock/bin Cleanup rascsi-web mocking for current develop (#301) 2021-10-05 20:39:26 -05:00
pwa RaSCSI logo favicons (#237) 2021-09-19 14:36:43 -07:00
service-infra Updates for running on Bullseye (#469) 2021-11-14 19:34:24 +01:00
static Display image properties inline in the image list, and remove the previous UI 2021-10-23 23:00:40 -07:00
templates Revert previous solution, and do dropzone i18n the right way. (#572) 2021-12-27 19:18:56 -06:00
translations Cvictor update german (#585) 2021-12-30 17:34:41 -08:00
.pylintrc Web UI code cleanup and refactoring (#409) 2021-11-06 19:25:02 -05:00
README.md Resolve pylint warnings for rascsi-web (#579) 2021-12-28 14:09:47 -06:00
babel.cfg Web Interface i18n (#564) 2021-12-26 15:36:12 -06:00
device_utils.py Web UI code cleanup and refactoring (#409) 2021-11-06 19:25:02 -05:00
drive_properties.json Add Apple CD Drive as pre-defined drive (#580) 2021-12-28 18:30:20 -06:00
file_cmds.py More sturdy logic for when session language is unset (#583) 2021-12-29 20:54:59 -06:00
pi_cmds.py Web Interface i18n (#564) 2021-12-26 15:36:12 -06:00
ractl_cmds.py More sturdy logic for when session language is unset (#583) 2021-12-29 20:54:59 -06:00
requirements.txt Web Interface i18n (#564) 2021-12-26 15:36:12 -06:00
settings.py Added french localization (#584) 2021-12-29 17:56:44 -08:00
socket_cmds.py Resolve pylint warnings for rascsi-web (#579) 2021-12-28 14:09:47 -06:00
start.sh Improve token auth and oled monitor install scripts; better venv cleanup logic (#587) 2022-01-01 11:38:10 -06:00
web.py Hardcoded locale fallback to English (#582) 2021-12-28 19:44:12 -06:00

README.md

RaSCSI Web

Setup local dev env

# Make a virtual env named venv
$ python3 -m venv venv
# Use that virtual env in this shell
$ source venv/bin/activate
# Install requirements
$ pip install -r requirements.txt
# Use mocks and a temp dir - start the web server
$ BASE_DIR=/tmp/images/ PATH=$PATH:`pwd`/mock/bin/ python3 web.py

Mocks for local development

You may edit the files under mock/bin to simulate Linux command responses. TODO: rascsi-web uses protobuf commands to send and receive data from rascsi. A separate mocking solution will be needed for this interface.

Static analysis with pylint

It is recommended to run pylint against new code to protect against bugs and keep the code readable and maintainable. The local pylint configuration lives in .pylintrc In order for pylint to recognize venv libraries, the pylint-venv package is required.

sudo apt install pylint3
sudo pip install pylint-venv
source venv/bin/activate
pylint3 python_source_file.py

Pushing to the Pi via git

Setup a bare repo on the rascsi

$ ssh pi@rascsi
$ mkdir /home/pi/dev.git && cd /home/pi/dev.git
$ git --bare init
Initialized empty Git repository in /home/pi/dev.git

Locally

$ cd ~/source/RASCSI
$ git remote add pi ssh://pi@rascsi/home/pi/dev.git
$ git push pi master

Localizing the Web Interface

We use the Flask-Babel library and Flask/Jinja2 extension for i18n.

It uses the 'pybabel' command line tool for extracting and compiling localizations. Activate the Python venv in src/web/ to use it:

$ cd src/web/
$ source venv/bin/activate
$ pybabel --help

To create a new localization, it needs to be added to the LANGAUGES constant in web/settings.py. To localize messages coming from the RaSCSI backend, update also code in raspberrypi/localizer.cpp in the RaSCSI C++ code.

Once this is done, follow the steps in the Flask-Babel documentation to generate the messages.po for the new language.

Updating the strings in an existing messages.po is also covered above.

When you are ready to contribute new or updated localizations, use the same Gitflow Workflow as used for any code contributions to submit PRs against the develop branch.

Working with PO files

See the GNU gettext documentation for an introduction to the PO file format.

We make heavy use of python-format for formatting, for instance:

#: file_cmds.py:353
#, python-format
msgid "%(file_name)s downloaded to %(save_dir)s"
msgstr "Laddade ner %(file_name)s till %(save_dir)s"

There are also a few instances of formatting in JavaScript:

#: templates/index.html:381
msgid "Server responded with code: {{statusCode}}"
msgstr "Servern svarade med kod: {{statusCode}}"

And with html tags:

#: templates/index.html:304
#, python-format
msgid ""
"Emulates a SCSI DaynaPORT Ethernet Adapter. <a href=\"%(url)s\">Host "
"drivers and configuration required</a>."
msgstr ""
"Emulerar en SCSI DaynaPORT ethernet-adapter. <a href=\"%(url)s\">Kräver "
"drivrutiner och inställningar</a>."

(Optional) See translation stats for a localization

Install the gettext package and use msgfmt to see the translation progress.

$ sudo apt install gettext
$ cd src/web/
$ msgfmt --statistics translations/sv/LC_MESSAGES/messages.po
215 translated messages, 1 untranslated message.