10 from os
.path
import join
13 def xp_filename(basename
):
14 return re
.sub('["<>*?|\\\\]', "_",
15 basename
.replace("/", "-").replace(":", "."))
18 def versionify(version
):
19 return ".".join(filter(lambda x
: x
.isdigit(),
20 re
.split("[-+.]", version
))[:3])
23 def main(nwdir
, nwpackage
):
24 if not os
.path
.isdir(nwdir
):
25 raise StandardError("input (%r) is not a directory" % nwdir
)
26 nwzip
= zipfile
.ZipFile(nwpackage
)
27 icnss
= filter(lambda f
: f
.lower().endswith(".icns"),
29 package
= json
.load(nwzip
.open("package.json"))
30 app
= join(nwdir
, "nwjs.app")
31 title
= package
["window"]["title"]
32 exe
= package
["name"].split(".")[-1]
34 CFBundleDisplayName
=title
,
35 CFBundleExecutable
=exe
,
36 CFBundleIdentifier
=package
["name"],
37 CFBundleInfoDictionaryVersion
="6.0",
39 CFBundlePackageType
="APPL",
40 CFBundleShortVersionString
=package
["version"],
41 CFBundleIconFile
="nw.icns",
42 CFBundleVersion
=versionify(package
["version"]),
43 LSMinimumSystemVersion
="10.6.0",
44 NSPrincipalClass
="NSApplication",
45 NSSupportsAutomaticGraphicsSwitching
=True,
49 os
.remove(join(app
, "Contents", "Resources", "nw.icns"))
50 nwzip
.extract(icnss
[0], join(app
, "Contents", "Resources"))
51 plist
["CFBundleIconFile"] = icnss
[0]
52 plistlib
.writePlist(plist
, join(app
, "Contents/Info.plist"))
53 exedir
= join(app
, "Contents", "MacOS")
54 shutil
.move(join(exedir
, "nwjs"), join(exedir
, exe
))
55 shutil
.copy(nwpackage
, join(app
, "Contents", "Resources", "app.nw"))
56 shutil
.move(app
, join(app
, "..", xp_filename(title
) + ".app"))
58 if __name__
== "__main__":