Coverage for modules/org/openteacher/profileRunners/webGenerator/webGenerator : 28%
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 2013-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/>.
self._mm.mods(type="execute"), self._mm.mods(type="translationIndexBuilder"), self._mm.mods(type="translationIndexesMerger"), self._mm.mods(type="translationIndexJSONWriter"), self._mm.mods(type="metadata"), # to load translations from: self._mm.mods(type="jsInputTypingLogic"), ) "default": -1, "generate-web": 0, } #all files directly in the scr directory are web-specific and #thus ui related and thus contain translations. (In theory ;))
global pyratemp global QtGui try: import pyratemp from PyQt5 import QtGui except ImportError: return self._modules = set(self._mm.mods(type="modules")).pop() self._modules.default(type="execute").startRunning.handle(self._run)
self._metadata = self._modules.default("active", type="metadata").metadata
self.active = True
#get path to save to try: path = sys.argv[1] couchdbHost = sys.argv[2] servicesHost = sys.argv[3] bundleAction = sys.argv[4] except IndexError: print("Please specify a path to save the site to, the couchdb hostname, the services server hostname and the bundle action as last command line arguments. (e.g. -p generate-web web-debug http://localhost:5984 http://localhost:5000 watch)", 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)
#copy all static stuff shutil.copytree(self._mm.resourcePath("static"), path) os.mkdir(os.path.join(path, 'css')) os.mkdir(os.path.join(path, 'scr'))
#create the config file template = pyratemp.Template(filename=self._mm.resourcePath("config.templ.js")) with open(os.path.join(path, "scr", "config.js"), "w", encoding='UTF-8') as f: f.write(template( couchdbHost=couchdbHost, servicesHost=servicesHost, appName=self._metadata ))
#create the style file template = pyratemp.Template(filename=self._mm.resourcePath("style.templ.css")) hue = self._metadata["mainColorHue"] data = { "headerBgColor": QtGui.QColor.fromHsv(hue, 41, 250).name(), "footerBgColor": QtGui.QColor.fromHsv(hue, 30, 228).name(), } with open(os.path.join(path, "css/style.css"), "w", encoding='UTF-8') as f: f.write(template(**data))
#write the translation index 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) url = "scr/translations" writeJSONIndex(masterIndex, os.path.join(path, url), url)
#copy the logo shutil.copy(self._metadata["iconPath"], os.path.join(path, "img/logo"))
#create the bundle os.chdir(os.path.join('node_modules', 'ot-web')) bundlePath = os.path.join('..', '..', path, 'scr', 'bundle.js') subprocess.check_call(['npm', 'run', bundleAction, '--silent', '--', '-o', bundlePath]) os.chdir(os.path.join('..', '..'))
print("Writing OpenTeacher web to '%s' is now done." % path)
self.active = False
self._modules.default(type="execute").startRunning.unhandle(self._run) del self._modules del self._metadata
|