#!/usr/bin/env python # Generate a node-webkit package.json file for a website. # # https://github.com/rogerwang/node-webkit/wiki/Manifest-format import os import re import shutil import time import json def is_html(filename): return filename.lower().endswith(".html") def attr(name): return "data-" + name + """=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?""" def main(appdir, version=None): if not os.path.isdir(appdir): raise StandardError("input (%r) is not a directory" % appdir) indexes = [] icons = [] for root, dirnames, filenames in os.walk(appdir): root = os.path.relpath(root, appdir) for filename in filenames: if filename.lower() == "index.html": indexes.append(os.path.join(root, filename)) if ("icon" in filename.lower() and filename.lower().endswith((".ico", ".png"))): icons.append(os.path.join(root, filename)) indexes.sort(key=lambda fn: (fn.count("/"), fn)) icons.sort(key=lambda fn: (fn.count("/"), fn)) name = os.path.basename(appdir).split(".")[0] package = { "main": indexes[0], "name": name, "version": version or "0.0.0", "chromium-args": "--enable-webgl --ignore-gpu-blacklist", "window": { "show": False, "toolbar": False, "title": name, "min_width": 300, "min_height": 200, } } if icons: package["window"]["icon"] = icons[0] with open(os.path.join(appdir, indexes[0]), "r") as fobj: header = fobj.read(4096) try: title = re.search("