def __init__(self, project_dir, type, ndk, useLogFile=False): self.top_dir = project_dir.rstrip(os.sep) self.type = type (self.variant, self.cpu) = Builder.type2variantCpu[type] self.ndk = ndk self.project_tiappxml = os.path.join(self.top_dir, 'tiapp.xml') self.tiappxml = TiAppXML(self.project_tiappxml) self.name = self.tiappxml.properties['name'] self.buildDir = os.path.join(self.top_dir, 'build', 'blackberry') self.project_deltafy = Deltafy(self.top_dir) if useLogFile: self.tiappxml = TiAppXML(self.project_tiappxml) else: # hide property output with open(os.devnull, 'w') as nul: oldStdout = sys.stdout sys.stdout = nul self.tiappxml = TiAppXML(self.project_tiappxml) sys.stdout = oldStdout self.name = self.tiappxml.properties['name'] self.buildDir = os.path.join(self.top_dir, 'build', 'blackberry')
def test_exclude_files(self): time.sleep(1) exclude_dirs = ['.ignore'] exclude_files = ['ignore.txt'] def include(path, isfile): if not isfile and os.path.basename(path) in exclude_dirs: return False elif isfile and os.path.basename(path) in exclude_files: return False return True self.d = Deltafy(tests_dir, include_callback=include) self.touch_all_files() self.deltas = self.d.scan() self.assertEquals(len(self.deltas), 3) self.assertEquals(self.deltas[0].get_path(), self.file_paths[0]) self.assertEquals(self.deltas[1].get_path(), self.file_paths[2]) self.assertEquals(self.deltas[2].get_path(), self.file_paths[5])
def __init__(self, project_dir, type, ndk, useLogFile = False): self.top_dir = project_dir.rstrip(os.sep) self.type = type (self.variant, self.cpu) = Builder.type2variantCpu[type] self.ndk = ndk self.project_tiappxml = os.path.join(self.top_dir, 'tiapp.xml') self.tiappxml = TiAppXML(self.project_tiappxml) self.name = self.tiappxml.properties['name'] self.buildDir = os.path.join(self.top_dir, 'build', 'blackberry') self.project_deltafy = Deltafy(self.top_dir) if useLogFile: self.tiappxml = TiAppXML(self.project_tiappxml) else: # hide property output with open(os.devnull, 'w') as nul: oldStdout = sys.stdout sys.stdout = nul self.tiappxml = TiAppXML(self.project_tiappxml) sys.stdout = oldStdout self.name = self.tiappxml.properties['name'] self.buildDir = os.path.join(self.top_dir, 'build', 'blackberry')
key = "%s_%s" % (relative, f) else: key = f key = key.replace('.js', '').replace( '\\', '_').replace('/', '_').replace(' ', '_').replace('.', '_') self.js_files[fullpath] = (key, js_contents) if compile_bytecode: self.compile_into_bytecode(self.js_files) if __name__ == "__main__": if len(sys.argv) != 2: print "Usage: %s <projectdir>" % sys.argv[0] sys.exit(1) project_dir = os.path.expanduser(sys.argv[1]) resources_dir = os.path.join(project_dir, 'Resources') root_dir = os.path.join(project_dir, 'build', 'android') destdir = os.path.join(root_dir, 'bin', 'classes') sys.path.append("..") from tiapp import TiAppXML tiapp = TiAppXML(os.path.join(project_dir, 'tiapp.xml')) c = Compiler(tiapp, resources_dir, 'java', destdir, root_dir) project_deltafy = Deltafy(resources_dir) project_deltas = project_deltafy.scan() c.compile()
class Builder(object): type2variantCpu = {'simulator' : ('o-g', 'x86'), 'device' : ('o.le-v7-g', 'arm'), 'deploy' : ('o.le-v7', 'arm'), 'distribute' : ('o.le-v7', 'arm')} def __init__(self, project_dir, type, ndk, useLogFile = False): self.top_dir = project_dir.rstrip(os.sep) self.type = type (self.variant, self.cpu) = Builder.type2variantCpu[type] self.ndk = ndk self.project_tiappxml = os.path.join(self.top_dir, 'tiapp.xml') self.tiappxml = TiAppXML(self.project_tiappxml) self.name = self.tiappxml.properties['name'] self.id = self.tiappxml.properties['id'] self.buildDir = os.path.join(self.top_dir, 'build', 'blackberry') self.blackberryResources = os.path.join(self.top_dir, 'Resources', 'blackberry') self.project_deltafy = Deltafy(self.top_dir) if useLogFile: self.tiappxml = TiAppXML(self.project_tiappxml) else: # hide property output with open(os.devnull, 'w') as nul: oldStdout = sys.stdout sys.stdout = nul self.tiappxml = TiAppXML(self.project_tiappxml) sys.stdout = oldStdout self.name = self.tiappxml.properties['name'] self.buildDir = os.path.join(self.top_dir, 'build', 'blackberry') def getPackage(self): return os.path.join(self.buildDir, self.cpu, self.variant, '%s.bar' % self.name) def run(self, ipAddress = None, password = None, debugToken = None, storePass = None, outputDir = None): # TODO Mac: V8 runtime should be added and possibly a lot of other stuff retCode = self.build() if retCode != 0: return retCode info('Running') templates = os.path.join(template_dir,'templates') # Check if tiapp.xml changed since last run bar_descriptor_exists = os.path.exists(os.path.join(self.buildDir, 'bar-descriptor.xml')) tiapp_delta = self.project_deltafy.scan_single_file(self.project_tiappxml) tiapp_changed = tiapp_delta is not None # Discover any splash images that follow this pattern: # splash-widthxheight.[png|jpg] resources = os.listdir(self.blackberryResources) splashScreens = [r for r in resources if re.match('splash-[0-9]*x[0-9]*.png|jpg', r)] if (tiapp_changed or not bar_descriptor_exists): # regenerate bar-descriptor.xml # TODO MAC: Add blackberry specific properties. Needs update in tiapp.py script print 'Creating bar-descriptor.xml' shutil.copy2(os.path.join(templates,'bar-descriptor.xml'), self.buildDir) newConfig = { 'id':self.tiappxml.properties['id'], 'appname':self.tiappxml.properties['name'], 'platformversion':self.ndk.version, 'description':(self.tiappxml.properties['description'] or 'not specified'), 'version':(self.tiappxml.properties['version'] or '1.0'), 'author':(self.tiappxml.properties['publisher'] or 'not specified'), 'category':'core.games', 'icon':'assets/%s' %(self.tiappxml.properties['icon'] or 'appicon.png'), 'splashScreens':splashScreens } try: Blackberry.renderTemplate(os.path.join(self.buildDir,'bar-descriptor.xml'), newConfig) except Exception, e: print >>sys.stderr, e sys.exit(1) # Change current directory to do relative operations os.chdir("%s" % self.buildDir) barPath = self.getPackage() savePath = os.path.join(self.buildDir, self.cpu, self.variant, self.name) retCode = self.ndk.package(barPath, savePath, self.name, self.type, debugToken) if retCode != 0: return retCode if self.type != 'distribute': retCode = self.ndk.deploy(ipAddress, barPath, password) retCode = self.ndk.appLog(ipAddress, barPath, password) else: retCode = self.ndk.distribute(self.name, savePath, storePass, outputDir) if retCode != 0: log.info ( 'Distribution has failed. Please check that the buildID inside your\n' + 'project/Resources/blackberry/Ti.Manifest is a higher value then the\n' + 'the last time you ran distribute.') return retCode
class Builder(object): type2variantCpu = {'simulator' : ('o-g', 'x86'), 'device' : ('o.le-v7-g', 'arm'), 'deploy' : ('o.le-v7', 'arm')} def __init__(self, project_dir, type, ndk, useLogFile = False): self.top_dir = project_dir.rstrip(os.sep) self.type = type (self.variant, self.cpu) = Builder.type2variantCpu[type] self.ndk = ndk self.project_tiappxml = os.path.join(self.top_dir, 'tiapp.xml') self.tiappxml = TiAppXML(self.project_tiappxml) self.name = self.tiappxml.properties['name'] self.buildDir = os.path.join(self.top_dir, 'build', 'blackberry') self.project_deltafy = Deltafy(self.top_dir) if useLogFile: self.tiappxml = TiAppXML(self.project_tiappxml) else: # hide property output with open(os.devnull, 'w') as nul: oldStdout = sys.stdout sys.stdout = nul self.tiappxml = TiAppXML(self.project_tiappxml) sys.stdout = oldStdout self.name = self.tiappxml.properties['name'] self.buildDir = os.path.join(self.top_dir, 'build', 'blackberry') def getPackage(self): return os.path.join(self.buildDir, self.cpu, self.variant, '%s.bar' % self.name) def run(self, ipAddress, password = None, debugToken = None): # TODO Mac: V8 runtime should be added and possibly a lot of other stuff retCode = self.build() if retCode != 0: return retCode info('Running') # Check if tiapp.xml changed since last run tiapp_delta = self.project_deltafy.scan_single_file(self.project_tiappxml) tiapp_changed = tiapp_delta is not None if (tiapp_changed): # regenerate bar-descriptor.xml # TODO MAC: Add blackberry specific properties. Needs update in tiapp.py script templates = os.path.join(template_dir,'templates') shutil.copy2(os.path.join(templates,'bar-descriptor.xml'), self.buildDir) newConfig = { 'id':self.tiappxml.properties['id'], 'appname':self.tiappxml.properties['name'], 'platformversion':self.ndk.version, 'description':(self.tiappxml.properties['description'] or 'not specified'), 'version':(self.tiappxml.properties['version'] or '1.0'), 'author':(self.tiappxml.properties['publisher'] or 'not specified'), 'category':'core.games', 'icon':'assets/%s' %(self.tiappxml.properties['icon'] or 'appicon.png'), 'splashscreen':'assets/default.png' } try: Blackberry.renderTemplate(os.path.join(self.buildDir,'bar-descriptor.xml'), newConfig) except Exception, e: print >>sys.stderr, e sys.exit(1) # Change current directory to do relative operations os.chdir("%s" % self.buildDir) barPath = self.getPackage() savePath = os.path.join(self.buildDir, self.cpu, self.variant, self.name) retCode = self.ndk.package(barPath, savePath, self.name, self.type, debugToken) if retCode != 0: return retCode retCode = self.ndk.deploy(ipAddress, barPath, password) return retCode
self.extra_source_inclusions(fullpath) if fp[1] == '.js': relative = prefix[1:] js_contents = self.make_function_from_file(fullpath, pack=False) if relative!='': key = "%s_%s" % (relative,f) else: key = f key = key.replace('.js','').replace('\\','_').replace('/','_').replace(' ','_').replace('.','_') self.js_files[fullpath] = (key, js_contents) if compile_bytecode: self.compile_into_bytecode(self.js_files) if __name__ == "__main__": if len(sys.argv) != 2: print "Usage: %s <projectdir>" % sys.argv[0] sys.exit(1) project_dir = os.path.expanduser(sys.argv[1]) resources_dir = os.path.join(project_dir, 'Resources') root_dir = os.path.join(project_dir, 'build', 'android') destdir = os.path.join(root_dir, 'bin', 'classes') sys.path.append("..") from tiapp import TiAppXML tiapp = TiAppXML(os.path.join(project_dir, 'tiapp.xml')) c = Compiler(tiapp, resources_dir, 'java', destdir, root_dir) project_deltafy = Deltafy(resources_dir) project_deltas = project_deltafy.scan() c.compile()
def setUp(self): self.d = Deltafy(tests_dir) self.deltas = self.d.scan()
class DeltafyTests(unittest.TestCase): def setUp(self): self.d = Deltafy(tests_dir) self.deltas = self.d.scan() def touch(self, file): open(file, 'w').write("#") file_paths = [ os.path.join(tests_dir, 'dir1', 'file1.txt'), os.path.join(tests_dir, 'dir1', '.ignore', 'file1.txt'), os.path.join(tests_dir, 'dir1', 'subdir1', 'file1.txt'), os.path.join(tests_dir, 'dir1', 'subdir1', 'ignore.txt'), os.path.join(tests_dir, 'dir1', 'subdir1', '.ignore', 'file1.txt'), os.path.join(tests_dir, 'dir2', 'file1.txt') ] def touch_all_files(self): for file_path in self.file_paths: self.touch(file_path) def test_initial_pass(self): self.assertEquals(len(self.deltas), len(self.file_paths)) for file_path in self.file_paths: self.assertTrue(self.deltas.has_path(file_path)) def test_second_pass(self): self.assertEquals(len(self.deltas), 0) def test_file_modified(self): file_path = os.path.join(tests_dir, 'dir1', 'subdir1', 'file1.txt') open(file_path, 'w').write("change") self.deltas = self.d.scan() self.assertEquals(len(self.deltas), 1) self.assertEquals(self.deltas[0].get_path(), file_path) self.assertEquals(self.deltas[0].get_status(), Delta.MODIFIED) def test_file_created(self): file_path = os.path.join(tests_dir, 'dir2', 'file2.txt') self.touch(file_path) self.deltas = self.d.scan() self.assertEquals(len(self.deltas), 1) self.assertEquals(self.deltas[0].get_path(), file_path) self.assertEquals(self.deltas[0].get_status(), Delta.CREATED) self.assertTrue(self.deltas.has_path(file_path)) self.assertTrue(self.deltas.is_updated(file_path)) def test_file_deleted(self): file_path = os.path.join(tests_dir, 'dir2', 'file2.txt') os.unlink(file_path) self.deltas = self.d.scan() self.assertEquals(len(self.deltas), 1) self.assertEquals(self.deltas[0].get_path(), file_path) self.assertEquals(self.deltas[0].get_status(), Delta.DELETED) def test_files_modified(self): # modified time resolution is 1 second time.sleep(1) self.touch_all_files() self.deltas = self.d.scan() self.assertEquals(len(self.deltas), len(self.file_paths)) i = 0 for file_path in self.file_paths: self.assertTrue(self.deltas.has_path(file_path)) self.assertTrue(self.deltas.is_updated(file_path)) i+=1 def test_exclude_files(self): time.sleep(1) exclude_dirs = ['.ignore'] exclude_files = ['ignore.txt'] def include(path, isfile): if not isfile and os.path.basename(path) in exclude_dirs: return False elif isfile and os.path.basename(path) in exclude_files: return False return True self.d = Deltafy(tests_dir, include_callback=include) self.touch_all_files() self.deltas = self.d.scan() self.assertEquals(len(self.deltas), 3) self.assertEquals(self.deltas[0].get_path(), self.file_paths[0]) self.assertEquals(self.deltas[1].get_path(), self.file_paths[2]) self.assertEquals(self.deltas[2].get_path(), self.file_paths[5]) def test_clear(self): self.d.clear_state() paths = self.d.get_paths() self.assertEquals(len(paths), 0) deltas = self.d.scan() self.assertEquals(len(deltas), len(self.file_paths))
#!/usr/bin/env python # deltafy unit tests # # Author: Marshall Culpepper # Licensed under the Apache Public License v2 (see LICENSE.txt) import os, sys, unittest, shutil, datetime, time top_dir = os.path.abspath("..") tests_dir = os.path.join(top_dir, "tests", "tests_dir") sys.path.append(top_dir) from deltafy import Deltafy, Delta if os.path.exists(Deltafy.get_database_path()): os.unlink(Deltafy.get_database_path()) def suite(): tests = ['test_initial_pass', 'test_second_pass', 'test_file_modified', 'test_file_created', 'test_file_deleted', 'test_files_modified', 'test_exclude_files', 'test_clear'] return unittest.TestSuite(map(DeltafyTests, tests)) class DeltafyTests(unittest.TestCase): def setUp(self): self.d = Deltafy(tests_dir) self.deltas = self.d.scan() def touch(self, file): open(file, 'w').write("#") file_paths = [ os.path.join(tests_dir, 'dir1', 'file1.txt'),
class Builder(object): type2variantCpu = { 'simulator': ('o-g', 'x86'), 'device': ('o.le-v7-g', 'arm'), 'deploy': ('o.le-v7', 'arm') } def __init__(self, project_dir, type, ndk, useLogFile=False): self.top_dir = project_dir.rstrip(os.sep) self.type = type (self.variant, self.cpu) = Builder.type2variantCpu[type] self.ndk = ndk self.project_tiappxml = os.path.join(self.top_dir, 'tiapp.xml') self.tiappxml = TiAppXML(self.project_tiappxml) self.name = self.tiappxml.properties['name'] self.buildDir = os.path.join(self.top_dir, 'build', 'blackberry') self.project_deltafy = Deltafy(self.top_dir) if useLogFile: self.tiappxml = TiAppXML(self.project_tiappxml) else: # hide property output with open(os.devnull, 'w') as nul: oldStdout = sys.stdout sys.stdout = nul self.tiappxml = TiAppXML(self.project_tiappxml) sys.stdout = oldStdout self.name = self.tiappxml.properties['name'] self.buildDir = os.path.join(self.top_dir, 'build', 'blackberry') def getPackage(self): return os.path.join(self.buildDir, self.cpu, self.variant, '%s.bar' % self.name) def run(self, ipAddress, password=None, debugToken=None): # TODO Mac: V8 runtime should be added and possibly a lot of other stuff retCode = self.build() if retCode != 0: return retCode info('Running') # Check if tiapp.xml changed since last run tiapp_delta = self.project_deltafy.scan_single_file( self.project_tiappxml) tiapp_changed = tiapp_delta is not None if (tiapp_changed): # regenerate bar-descriptor.xml # TODO MAC: Add blackberry specific properties. Needs update in tiapp.py script templates = os.path.join(template_dir, 'templates') shutil.copy2(os.path.join(templates, 'bar-descriptor.xml'), self.buildDir) newConfig = { 'id': self.tiappxml.properties['id'], 'appname': self.tiappxml.properties['name'], 'platformversion': self.ndk.version, 'description': (self.tiappxml.properties['description'] or 'not specified'), 'version': (self.tiappxml.properties['version'] or '1.0'), 'author': (self.tiappxml.properties['publisher'] or 'not specified'), 'category': 'core.games', 'icon': 'assets/%s' % (self.tiappxml.properties['icon'] or 'appicon.png'), 'splashscreen': 'assets/default.png' } try: Blackberry.renderTemplate( os.path.join(self.buildDir, 'bar-descriptor.xml'), newConfig) except Exception, e: print >> sys.stderr, e sys.exit(1) # Change current directory to do relative operations os.chdir("%s" % self.buildDir) barPath = self.getPackage() savePath = os.path.join(self.buildDir, self.cpu, self.variant, self.name) retCode = self.ndk.package(barPath, savePath, self.name, self.type, debugToken) if retCode != 0: return retCode retCode = self.ndk.deploy(ipAddress, barPath, password) return retCode
class Builder(object): type2variantCpu = {'simulator' : ('o-g', 'x86'), 'device' : ('o.le-v7-g', 'arm'), 'deploy' : ('o.le-v7', 'arm'), 'distribute' : ('o.le-v7', 'arm')} def __init__(self, project_dir, type, ndk, useLogFile = False): self.top_dir = project_dir.rstrip(os.sep) self.type = type (self.variant, self.cpu) = Builder.type2variantCpu[type] self.ndk = ndk self.project_tiappxml = os.path.join(self.top_dir, 'tiapp.xml') self.tiappxml = TiAppXML(self.project_tiappxml) self.name = self.tiappxml.properties['name'] self.id = self.tiappxml.properties['id'] self.buildDir = os.path.join(self.top_dir, 'build', 'blackberry') self.blackberryResources = os.path.join(self.top_dir, 'Resources', 'blackberry') self.project_deltafy = Deltafy(self.top_dir) if useLogFile: self.tiappxml = TiAppXML(self.project_tiappxml) else: # hide property output with open(os.devnull, 'w') as nul: oldStdout = sys.stdout sys.stdout = nul self.tiappxml = TiAppXML(self.project_tiappxml) sys.stdout = oldStdout self.name = self.tiappxml.properties['name'] self.buildDir = os.path.join(self.top_dir, 'build', 'blackberry') def getPackage(self): return os.path.join(self.buildDir, self.cpu, self.variant, '%s.bar' % self.name) def run(self, ipAddress = None, password = None, debugToken = None, storePass = None, outputDir = None): # TODO Mac: V8 runtime should be added and possibly a lot of other stuff retCode = self.build() if retCode != 0: return retCode info('Running') templates = os.path.join(template_dir,'templates') # Check if tiapp.xml changed since last run bar_descriptor_exists = os.path.exists(os.path.join(self.buildDir, 'bar-descriptor.xml')) tiapp_delta = self.project_deltafy.scan_single_file(self.project_tiappxml) tiapp_changed = tiapp_delta is not None # Discover any splash images that follow this pattern: # splash-widthxheight.[png|jpg] resources = os.listdir(self.blackberryResources) splashScreens = [r for r in resources if re.match('splash-[0-9]*x[0-9]*.png|jpg', r)] if (tiapp_changed or not bar_descriptor_exists): # regenerate bar-descriptor.xml # TODO MAC: Add blackberry specific properties. Needs update in tiapp.py script print 'Creating bar-descriptor.xml' shutil.copy2(os.path.join(templates,'bar-descriptor.xml'), self.buildDir) newConfig = { 'id':self.tiappxml.properties['id'], 'appname':self.tiappxml.properties['name'], 'platformversion':self.ndk.version, 'description':(self.tiappxml.properties['description'] or 'not specified'), 'version':(self.tiappxml.properties['version'] or '1.0'), 'author':(self.tiappxml.properties['publisher'] or 'not specified'), 'category':'core.games', 'icon':'assets/%s' %(self.tiappxml.properties['icon'] or 'appicon.png'), 'splashScreens':splashScreens, 'orientation': self.tiappxml.blackberry.get('orientation', 'default') } try: Blackberry.renderTemplate(os.path.join(self.buildDir,'bar-descriptor.xml'), newConfig) except Exception, e: print >>sys.stderr, e sys.exit(1) # Write application properties to INI file. write_app_properties( self.tiappxml.app_properties.items(), os.path.join(self.buildDir, 'app_properties.ini')) # Change current directory to do relative operations os.chdir("%s" % self.buildDir) barPath = self.getPackage() savePath = os.path.join(self.buildDir, self.cpu, self.variant, self.name) retCode = self.ndk.package(barPath, savePath, self.name, self.type, debugToken) if retCode != 0: return retCode if self.type != 'distribute': retCode = self.ndk.deploy(ipAddress, barPath, password) retCode = self.ndk.appLog(ipAddress, barPath, password) else: retCode = self.ndk.distribute(self.name, savePath, storePass, outputDir) if retCode != 0: log.info ( 'Distribution has failed. Please check that the buildID inside your\n' + 'project/Resources/blackberry/Ti.Manifest is a higher value then the\n' + 'the last time you ran distribute.') return retCode