Coverage for modules/org/openteacher/profileRunners/mobileGenerator/mobileGenerator : 39%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#! /usr/bin/env python3 # -*- coding: utf-8 -*-
# Copyright 2012-2014, 2017, Marten de Vries # # This file is part of OpenTeacher. # # OpenTeacher is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # OpenTeacher is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with OpenTeacher. If not, see <http://www.gnu.org/licenses/>.
"""Generates the HTML of OpenTeacher Mobile as a command line profile.
"""
self._mm.mods(type="execute"), self._mm.mods(type="metadata"), self._mm.mods(type="translationIndexBuilder"), self._mm.mods(type="translationIndexesMerger"), self._mm.mods(type="translationIndexJSONWriter"), # to load translations from: self._mm.mods(type="jsInputTypingLogic"), )
"default": -1, "generate-mobile": 0, }
global QtCore, QtGui global pyratemp global polib except ImportError: sys.stderr.write("For this developer profile to work, you need pyratemp, polib and PyQt5 (QtCore & QtGui) to be installed.\n") return #remain disabled
#build splash.png image = QtGui.QImage(width, height, QtGui.QImage.Format_ARGB32) painter = QtGui.QPainter(image)
#it currently is 128x128, but this way a new future icon render/ #new icon won't mess up this code. icon = QtGui.QImage(iconPath).scaled(128, 128) painter.setBrush(QtGui.QColor(209, 233, 250)) painter.drawRect(0, 0, image.width(), image.height())
#horizontally centered, vertically at 1/4 painter.drawImage(QtCore.QPointF( (image.width() - icon.width()) / 2.0, image.height() / 4.0, ), icon)
#text, at 2/3 painter.setFont(QtGui.QFont("Ubuntu", 32)) painter.drawText(QtCore.QRectF( 0, image.height() / 3.0 * 2.0, image.width(), image.height() / 3.0 ), QtCore.Qt.AlignHCenter, self._metadata["name"])
painter.end() return image
#get path to save to try: path = sys.argv[1] bundleAction = sys.argv[2] except IndexError: print("Please specify a path to save the mobile site to and a bundle action as last command line arguments. (e.g. -p generate-mobile mobile-debug build)", file=sys.stderr) return #ask if overwrite if os.path.isdir(path): confirm = input("There is already a directory at '%s'. Do you want to remove it and continue (y/n). " % path) if confirm != "y": return shutil.rmtree(path) return path, bundleAction
#copy css shutil.copytree(self._mm.resourcePath("css"), os.path.join(path, "css"))
buildIndex = self._modules.default("active", type="translationIndexBuilder").buildTranslationIndex mergeIndexes = self._modules.default("active", type="translationIndexesMerger").mergeIndexes writeJSONIndex = self._modules.default("active", type="translationIndexJSONWriter").writeJSONIndex
index = buildIndex(self._mm.resourcePath("translations")) masterIndex = mergeIndexes(index, self._modules.default('active', type='jsInputTypingLogic').translationIndex) writeJSONIndex(masterIndex, os.path.join(path, "translations"), "translations")
destination = os.path.join(path, "scr") os.mkdir(destination)
# generate bundle os.chdir(os.path.join('node_modules', 'ot-mobile')) bundlePath = os.path.join('..', '..', destination, 'bundle.js') subprocess.check_call(['npm', 'run', bundleAction, '--silent', '--', '-o', bundlePath]) os.chdir(os.path.join('..', '..'))
#generate html headerTemplate = pyratemp.Template(filename=self._mm.resourcePath("header.html.templ"))
template = pyratemp.Template(filename=self._mm.resourcePath("index.html.templ")) result = template(**{ "enterTabHeader": headerTemplate(titleHeader="<h1 id='enter-list-header'></h1>", tab="enter"), "teachTabHeader": headerTemplate(titleHeader="<h1 id='teach-me-header'></h1>", tab="teach"), }) #write html to index.html with open(os.path.join(path, "index.html"), "w", encoding='UTF-8') as f: f.write(result)
#copy config.xml (phonegap config) shutil.copy( self._mm.resourcePath("config.xml"), os.path.join(path, "config.xml") )
#copy COPYING shutil.copy( self._mm.resourcePath("COPYING.txt"), os.path.join(path, "COPYING.txt") )
#copy icon.png shutil.copy( iconPath, os.path.join(path, "icon.png") )
#splash screen self._buildSplash(320, 480, iconPath).save( os.path.join(path, "splash.png") )
path, bundleAction = self._getInfo() if not path: return
self._copyCss(path) self._generateTranslationFiles(path) self._writeHtml(path)
self._copyPhonegapConfig(path) self._copyCopying(path)
#graphics iconPath = self._metadata["iconPath"] self._copyIcon(iconPath, path) self._writeSplash(iconPath, path)
# last, because this might block when in watching mode. self._writeBundle(path, bundleAction)
print("Writing %s mobile to '%s' is now done." % (self._metadata["name"], path))
|