Skip to content

Commit

Permalink
Template fix, now a build_zip in zip.py, does package the application…
Browse files Browse the repository at this point in the history
… in the output zip file. We also fix the relative path to become full path, in the harness.js. So it's works now with a full path passsed from chromeless script, or also with a relative path passed from chromeless using browser_embeded_path.
  • Loading branch information
taboca committed Nov 29, 2010
1 parent a2ac8a8 commit 2e0e97c
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 26 deletions.
27 changes: 4 additions & 23 deletions chromeless
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ except:
pass

executionMode = "run"
browserArgument ="browser"

try:
if sys.argv[2] == "package":
executionMode = "xpi"
browserArgument ="browser_embeded_path"
print "Packaging your application for distribution or installation..."
print "Note: expect a chromeless.zip application generated in this directory; "
print "Note: use xulrunner --install-app full_path_to-chromeless.zip to install; "
Expand All @@ -75,33 +77,12 @@ print "Using Browser HTML at '%s'" % browserToLaunch
import cuddlefish
import simplejson as json

# now let's run the cfx thingy and specify the app-kit main module
# as our starting point
def copy_package_file(file_src, file_dst):
for file in os.listdir(file_src):
print "Copying file: %s" % file
shutil.copy(os.path.join(file_src, file), os.path.join(file_dst, file))

if executionMode == "run":
cuddlefish.run([
executionMode,
"-a", "xulrunner",
"-b", f.xulrunner_path(),
"-t", "./template",
"--static-args", json.dumps({"browser": browserToLaunch}),
"-p", "packages/chromeless"
])
else:
splitfilename = browserToLaunch.split("/");
stripdir = browserToLaunch.split("/"+splitfilename[len(splitfilename)-1])[0]
os.makedirs("./template/"+stripdir);
copy_package_file(stripdir,"./template/"+stripdir);
cuddlefish.run([
cuddlefish.run([
executionMode,
"-a", "xulrunner",
"-b", f.xulrunner_path(),
"-t", "./template",
"--static-args", json.dumps({"browserRelative": browserToLaunch}),
"--static-args", json.dumps({browserArgument: browserToLaunch}),
"-p", "packages/chromeless"
])

Expand Down
3 changes: 2 additions & 1 deletion impl/cuddlefish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ def run(arguments=sys.argv[1:], target_cfg=None, pkg_cfg=None,

if command == 'xpi':
from cuddlefish.xpi import build_xpi
from cuddlefish.zip import build_zip
from cuddlefish.rdf import gen_manifest, RDFUpdate

manifest = gen_manifest(template_root_dir=app_extension_dir,
Expand All @@ -592,7 +593,7 @@ def run(arguments=sys.argv[1:], target_cfg=None, pkg_cfg=None,

xpi_name = XPI_FILENAME % target_cfg.name
print "Exporting extension to %s." % xpi_name
build_xpi(template_root_dir=app_extension_dir,
build_zip(template_root_dir=app_extension_dir,
manifest=manifest,
xpi_name=xpi_name,
harness_options=harness_options,
Expand Down
79 changes: 79 additions & 0 deletions impl/cuddlefish/zip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import os
import zipfile

import simplejson as json

def build_zip(template_root_dir, manifest, xpi_name,
harness_options, xpts):
zf = zipfile.ZipFile(xpi_name, "w", zipfile.ZIP_DEFLATED)

open('.install.rdf', 'w').write(str(manifest))
zf.write('.install.rdf', 'install.rdf')
os.remove('.install.rdf')

staticArgs = json.loads(harness_options['staticArgs'])
dir_src = staticArgs['browser_embeded_path'];
splitfilename = dir_src.split("/");
stripdir = dir_src.split("/"+splitfilename[len(splitfilename)-1])[0]
for file in os.listdir(os.getcwd() + "/"+ stripdir):
print "Inserting file: %s" % os.getcwd() + "/"+ stripdir+"/"+file
zf.write(os.getcwd() + "/"+ stripdir+"/"+file, stripdir +"/"+ file);
#shutil.copy(os.path.join(file_src, file), os.path.join(file_dst, fil e))


#zf.write(os.getcwd()+'/'+harness_options.

IGNORED_FILES = [".hgignore", "install.rdf", xpi_name]
IGNORED_FILE_SUFFIXES = ["~"]
IGNORED_DIRS = [".svn", ".hg", "defaults"]

def filter_filenames(filenames):
for filename in filenames:
if filename in IGNORED_FILES:
continue
if any([filename.endswith(suffix)
for suffix in IGNORED_FILE_SUFFIXES]):
continue
yield filename

for dirpath, dirnames, filenames in os.walk(template_root_dir):
filenames = list(filter_filenames(filenames))
dirnames[:] = [dirname for dirname in dirnames
if dirname not in IGNORED_DIRS]
for filename in filenames:
abspath = os.path.join(dirpath, filename)
arcpath = abspath[len(template_root_dir)+1:]
zf.write(abspath, arcpath)

for abspath in xpts:
zf.write(str(abspath),
str(os.path.join('components',
os.path.basename(abspath))))

new_resources = {}
for resource in harness_options['resources']:
base_arcpath = os.path.join('resources', resource)
new_resources[resource] = ['resources', resource]
abs_dirname = harness_options['resources'][resource]
# Always write the directory, even if it contains no files,
# since the harness will try to access it.
dirinfo = zipfile.ZipInfo(base_arcpath + "/")
dirinfo.external_attr = 0755 << 16L
zf.writestr(dirinfo, "")
for dirpath, dirnames, filenames in os.walk(abs_dirname):
goodfiles = list(filter_filenames(filenames))
for filename in goodfiles:
abspath = os.path.join(dirpath, filename)
arcpath = abspath[len(abs_dirname)+1:]
arcpath = os.path.join(base_arcpath, arcpath)
zf.write(str(abspath), str(arcpath))
dirnames[:] = [dirname for dirname in dirnames
if dirname not in IGNORED_DIRS]
harness_options['resources'] = new_resources

open('.options.json', 'w').write(json.dumps(harness_options, indent=1,
sort_keys=True))
zf.write('.options.json', 'harness-options.json')
os.remove('.options.json')

zf.close()
1 change: 1 addition & 0 deletions packages/chromeless/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ exports.main = function main(options) {

var protocol = require("custom-protocol").register("chromeless");
protocol.setHost("main", require('url').fromFilename(directory), "system");
console.log("Launching browser from:"+require('url').fromFilename(directory));

var contentWindow = require("chromeless-sandbox-window");

Expand Down
4 changes: 2 additions & 2 deletions template/components/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,9 @@ function getDefaults(rootFileSpec) {
options = JSON.parse(jsonData);
if ("staticArgs" in options) {
options.staticArgs = JSON.parse(options.staticArgs);
if(options.staticArgs.browserRelative) {
if(options.staticArgs.browser_embeded_path) {
dirbase = rootFileSpec.clone();
options.staticArgs.browser=dirbase.path+"/"+options.staticArgs.browserRelative;
options.staticArgs.browser=dirbase.path+"/"+options.staticArgs.browser_embeded_path;
}
}
} catch (e) {
Expand Down

0 comments on commit 2e0e97c

Please sign in to comment.