<commit_before>#!/usr/bin/env python
#
# zip up the titanium mobile SDKs into suitable distribution formats
#
import os, types, glob, shutil, sys, platform
import zipfile, datetime, subprocess, tempfile, time

if platform.system() == 'Darwin':
	import importresolver

cur_dir = os.path.abspath(os.path.dirname(sys._getframe(0).f_code.co_filename))
top_dir = os.path.abspath(os.path.join(os.path.dirname(sys._getframe(0).f_code.co_filename),'..'))
template_dir = os.path.join(top_dir,'support')
doc_dir = os.path.abspath(os.path.join(top_dir, 'apidoc'))
all_dir = os.path.abspath(os.path.join(template_dir,'all'))
android_dir = os.path.abspath(os.path.join(template_dir,'android'))
iphone_dir = os.path.abspath(os.path.join(template_dir,'iphone'))
osx_dir = os.path.abspath(os.path.join(template_dir,'osx'))
win32_dir = os.path.abspath(os.path.join(template_dir, 'win32'))
mobileweb_dir = os.path.abspath(os.path.join(template_dir, 'mobileweb'))

buildtime = datetime.datetime.now()
ts = buildtime.strftime("%m/%d/%y %H:%M")

# get the githash for the build so we can always pull this build from a specific
# commit
gitCmd = "git"
if platform.system() == "Windows":
	gitCmd += ".cmd"

p = subprocess.Popen([gitCmd,"show","--abbrev-commit"],stderr=subprocess.PIPE, stdout=subprocess.PIPE)
githash = p.communicate()[0][7:].split('\n')[0].strip()

ignoreExtensions = ['.pbxuser','.perspectivev3','.pyc']
ignoreDirs = ['.DS_Store','.git','.gitignore','libTitanium.a','titanium.jar','build','bridge.txt', 'packaged']

def ignore(file):
	 for f in ignoreDirs:
		if file == f:
			return True
	 return False

def generate_jsca():
	 process_args = [sys.executable, os.path.join(doc_dir, 'docgen.py'), '-f', 'jsca', '--stdout']
	 print "Generating JSCA..."
	 print " ".join(process_args)
	 jsca_temp_file = tempfile.TemporaryFile()
	 try:
		 process = subprocess.Popen(process_args, stdout=jsca_temp_file, stderr=subprocess.PIPE)
		 process_return_code = process.wait()
		 if process_return_code != 0:
			 err_output = process.stderr.read()
			 print >> sys.stderr, "Failed to generate JSCA JSON.  Output:"
			 print >> sys.stderr, err_output
			 sys.exit(1)
		 jsca_temp_file.seek(0)
		 jsca_json = jsca_temp_file.read()
		 return jsca_json
	 finally:
		 jsca_temp_file.close()

def zip_dir(zf,dir,basepath,subs=None,cb=None):
	for root, dirs, files in os.walk(dir):
		for name in ignoreDirs:
			if name in dirs:
				dirs.remove(name)	# don't visit ignored directories
		for file in files:
			e = os.path.splitext(file)
			if len(e)==2 and e[1] in ignoreExtensions: continue
			from_ = os.path.join(root, file)
			to_ = from_.replace(dir, basepath, 1)
			if subs!=None:
				c = open(from_).read()
				for key in subs:
					c = c.replace(key,subs[key])
				if cb!=None:
					c = cb(file,e[1],c)
				zf.writestr(to_,c)
			else:		
				zf.write(from_, to_)

def zip2zip(src_zip, dest_zip, prepend_path=None):
	for zinfo in src_zip.infolist():
		f = src_zip.open(zinfo)
		new_name = zinfo.filename
		if prepend_path and not prepend_path.endswith("/"):
			prepend_path = "%s/" % prepend_path
		if prepend_path:
			new_name = "%s%s" % (prepend_path, new_name)
		zinfo.filename = new_name
		dest_zip.writestr(zinfo, f.read())

def zip_packaged_modules(zf, source_dir, dest_prefix):
	if not dest_prefix.endswith("/"):
		dest_prefix = dest_prefix + "/"
	for root, dirs, files in os.walk(source_dir):
		for name in ignoreDirs:
			if name in dirs:
				dirs.remove(name)
		for fname in files:
			if not fname.lower().endswith(".zip"):
				continue
			source_zip = zipfile.ZipFile(os.path.join(root, fname), "r")
			prepend = "%s%s" % (dest_prefix, root.replace(source_dir, "").replace("\\", "/"))<commit_msg>TIMOB-7806 fix double-slash in zip file<commit_after>#!/usr/bin/env python
#
# zip up the titanium mobile SDKs into suitable distribution formats
#
import os, types, glob, shutil, sys, platform
import zipfile, datetime, subprocess, tempfile, time

if platform.system() == 'Darwin':
	import importresolver

cur_dir = os.path.abspath(os.path.dirname(sys._getframe(0).f_code.co_filename))
top_dir = os.path.abspath(os.path.join(os.path.dirname(sys._getframe(0).f_code.co_filename),'..'))
template_dir = os.path.join(top_dir,'support')
doc_dir = os.path.abspath(os.path.join(top_dir, 'apidoc'))
all_dir = os.path.abspath(os.path.join(template_dir,'all'))
android_dir = os.path.abspath(os.path.join(template_dir,'android'))
iphone_dir = os.path.abspath(os.path.join(template_dir,'iphone'))
osx_dir = os.path.abspath(os.path.join(template_dir,'osx'))
win32_dir = os.path.abspath(os.path.join(template_dir, 'win32'))
mobileweb_dir = os.path.abspath(os.path.join(template_dir, 'mobileweb'))

buildtime = datetime.datetime.now()
ts = buildtime.strftime("%m/%d/%y %H:%M")

# get the githash for the build so we can always pull this build from a specific
# commit
gitCmd = "git"
if platform.system() == "Windows":
	gitCmd += ".cmd"

p = subprocess.Popen([gitCmd,"show","--abbrev-commit"],stderr=subprocess.PIPE, stdout=subprocess.PIPE)
githash = p.communicate()[0][7:].split('\n')[0].strip()

ignoreExtensions = ['.pbxuser','.perspectivev3','.pyc']
ignoreDirs = ['.DS_Store','.git','.gitignore','libTitanium.a','titanium.jar','build','bridge.txt', 'packaged']

def ignore(file):
	 for f in ignoreDirs:
		if file == f:
			return True
	 return False

def generate_jsca():
	 process_args = [sys.executable, os.path.join(doc_dir, 'docgen.py'), '-f', 'jsca', '--stdout']
	 print "Generating JSCA..."
	 print " ".join(process_args)
	 jsca_temp_file = tempfile.TemporaryFile()
	 try:
		 process = subprocess.Popen(process_args, stdout=jsca_temp_file, stderr=subprocess.PIPE)
		 process_return_code = process.wait()
		 if process_return_code != 0:
			 err_output = process.stderr.read()
			 print >> sys.stderr, "Failed to generate JSCA JSON.  Output:"
			 print >> sys.stderr, err_output
			 sys.exit(1)
		 jsca_temp_file.seek(0)
		 jsca_json = jsca_temp_file.read()
		 return jsca_json
	 finally:
		 jsca_temp_file.close()

def zip_dir(zf,dir,basepath,subs=None,cb=None):
	for root, dirs, files in os.walk(dir):
		for name in ignoreDirs:
			if name in dirs:
				dirs.remove(name)	# don't visit ignored directories
		for file in files:
			e = os.path.splitext(file)
			if len(e)==2 and e[1] in ignoreExtensions: continue
			from_ = os.path.join(root, file)
			to_ = from_.replace(dir, basepath, 1)
			if subs!=None:
				c = open(from_).read()
				for key in subs:
					c = c.replace(key,subs[key])
				if cb!=None:
					c = cb(file,e[1],c)
				zf.writestr(to_,c)
			else:		
				zf.write(from_, to_)

def zip2zip(src_zip, dest_zip, prepend_path=None):
	for zinfo in src_zip.infolist():
		f = src_zip.open(zinfo)
		new_name = zinfo.filename
		if prepend_path and not prepend_path.endswith("/"):
			prepend_path = "%s/" % prepend_path
		if prepend_path:
			new_name = "%s%s" % (prepend_path, new_name)
		zinfo.filename = new_name
		dest_zip.writestr(zinfo, f.read())

def zip_packaged_modules(zf, source_dir, dest_prefix):
	if not dest_prefix.endswith("/"):
		dest_prefix = dest_prefix + "/"
	for root, dirs, files in os.walk(source_dir):
		for name in ignoreDirs:
			if name in dirs:
				dirs.remove(name)
		for fname in files:
			if not fname.lower().endswith(".zip"):
				continue
			source_zip = zipfile.ZipFile(os.path.join(root, fname), "r")
			rel_path = root.replace(source_dir, "").replace("\\", "/")
			if rel_path.startswith("/"):
				rel_path = rel_path[1:]
			prepend = "%s%s" % (dest_prefix, rel_path)
{'fraction_non_alphanumeric': 0.15857734991309, 'fraction_numerical': 0.0054820163123412225, 'mean_word_length': 4.573770491803279, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3788801', 'n_tokens_mistral': 3075, 'n_tokens_neox': 2826, 'n_words': 575}