"""Update brython_modules.js with the scripts in main folder """ import os import json from tools import make_bundle folder = os.path.dirname(__file__) more_modules = make_bundle.bundle(folder) print('add modules', list(more_modules)) # read modules in /dist/brython_stdlib bm_path = os.path.join(folder, 'dist', 'brython_stdlib.js') with open(bm_path, encoding="utf-8") as fobj: src = fobj.read() # skip first line src = src[src.find('\n'):].lstrip() # skip assignment to __BRYTHON__.VFS src = src[src.find('=') + 1:].lstrip() # load all modules in brython_stdlib as a Python dict mods = json.loads(src.strip()) # update with new modules mods.update(more_modules) # save new version of brython_modules bm_path = os.path.join(folder, 'dist', 'brython_modules.js') with open(bm_path, "w", encoding="utf-8") as out: out.write('__BRYTHON__.use_VFS = true;\n') out.write('__BRYTHON__.VFS = {}\n'.format(json.dumps(mods)))
import os import shutil import json from tools import make_bundle # prepare script with standard distribution www = os.path.join(os.path.dirname(os.path.dirname(os.getcwd())), 'www') folders = [ os.path.join(www, 'src', 'Lib'), os.path.join(www, 'src', 'libs') ] res = {} for folder in folders: res.update(make_bundle.bundle(folder)) # copy stdlib in dist/brython_modules.js lib_dir = os.path.join(os.getcwd(), 'dist') if not os.path.exists(lib_dir): os.mkdir(lib_dir) bundle_path = os.path.join(lib_dir, 'brython_modules.js') with open(bundle_path, 'w', encoding='utf-8') as out: out.write('__BRYTHON__.use_VFS = true;\n') out.write('__BRYTHON__.VFS = {}\n'.format(json.dumps(res))) # copy brython.js shutil.copyfile(os.path.join(www, 'src', 'brython.js'), os.path.join(lib_dir, 'brython.js'))
import os import shutil import json from tools import make_bundle # prepare script with standard distribution www = os.path.join(os.path.dirname(os.path.dirname(os.getcwd())), 'www') folders = [os.path.join(www, 'src', 'Lib'), os.path.join(www, 'src', 'libs')] res = {} for folder in folders: res.update(make_bundle.bundle(folder)) # copy stdlib in brython_stdlib.js # and initialise brython_modules.js with the same content bundle_names = ['brython_stdlib.js', 'brython_modules.js'] for name in bundle_names: with open(name, 'w', encoding='utf-8') as out: out.write('__BRYTHON__.use_VFS = true;\n') out.write('__BRYTHON__.VFS = {}\n'.format(json.dumps(res))) # copy brython.js shutil.copyfile(os.path.join(www, 'src', 'brython.js'), 'brython.js')
"""Update brython_modules.js with the scripts in main folder """ import os import json from tools import make_bundle folder = os.path.dirname(__file__) more_modules = make_bundle.bundle(folder) print('add modules', list(more_modules)) # read modules in /dist/brython_modules bm_path = os.path.join(folder, 'dist', 'brython_modules.js') with open(bm_path, encoding="utf-8") as fobj: src = fobj.read() # skip first line src = src[src.find('\n'):].lstrip() # skip assignment to __BRYTHON__.VFS src = src[src.find('=')+1:].lstrip() # load all modules in brython_modules as a Python dict mods = json.loads(src.strip()) # update with new modules mods.update(more_modules) # save new version of brython_modules with open(bm_path, "w", encoding="utf-8") as out: out.write('__BRYTHON__.use_VFS = true;\n') out.write('__BRYTHON__.VFS = {}\n'.format(json.dumps(mods)))