def test_overwrite_linkspec(self): import os content = """ links: - source: '{{__dir__}}/aaa' target: '{{__target__}}/aaa' external_links: - source: '{{resources_package}}' target: '{{__dir__}}/aaa/resources' default_content: ['{{__dir__}}/_resources/*'] """ package_linkspec = yaml.load(content) if os.path.exists('../test_data/empty_resources/default-data.txt'): os.remove('../test_data/empty_resources/default-data.txt') if os.path.exists('../test_data/empty_resources/a'): utils.rmdir('../test_data/empty_resources/a') output = '../temp/output/lib-a' utils.rmdir(output) linker = PackageLinker() linker.link( source='../test_data/lib-a.1.0.8/content', target=output, forced=True, params=dict(resources_package='../test_data/empty_resources'), **package_linkspec) self.assertTrue(os.path.isfile('%s/aaa/data.txt' % output)) self.assertTrue( os.path.isfile('%s/aaa/resources/default-data.txt' % output)) self.assertTrue(os.path.isfile('%s/aaa/resources/a/data.txt' % output))
def run(self, args): try: if os.path.exists(args.location): if os.path.isfile(args.location) or os.listdir(args.location): raise RuntimeError('"%s" must be an empty folder.' % args.location) else: os.mkdir(args.location) os.mkdir(os.path.join(args.location, 'assets')) os.mkdir(os.path.join(args.location, 'plugins')) os.mkdir(os.path.join(args.location, 'settings')) os.mkdir(os.path.join(args.location, 'packages')) os.mkdir(os.path.join(args.location, 'project')) # package_config_template_file = os.path.join(self.data_folder, 'create-package', 'package-config.yaml') if True: template = self.env.get_template('upkit.yaml.j2') file_path = os.path.join(args.location, 'upkit.yaml') with open(file_path, 'w') as writer: data = template.render() writer.write(data.encode('utf-8')) if True: template = self.env.get_template('linkspec.yaml.j2') file_path = os.path.join(args.location, 'linkspec.yaml') with open(file_path, 'w') as writer: data = template.render() writer.write(data.encode('utf-8')) if True: template = self.env.get_template('git-ignore.j2') file_path = os.path.join(args.location, '.gitignore') with open(file_path, 'w') as writer: data = template.render() writer.write(data.encode('utf-8')) if True: template = self.env.get_template('package.nuspec.j2') file_path = os.path.join(args.location, 'package.nuspec') with open(file_path, 'w') as writer: data = template.render() writer.write(data.encode('utf-8')) print('Package created.') if hasattr(args, 'link') and args.link: from upkit.package_linker import PackageLinker linker = PackageLinker(config_file=os.path.abspath( os.path.join(args.location, 'upkit.yaml'))) linker.run() print('Package link completed.') except: print('Creating package failed with errors.') print(traceback.format_exc()) sys.exit(1)
def test_link_with_empty_child_links_in_linkspec(self): output = '../temp/output/lib-a' utils.rmdir(output) linker = PackageLinker() linker.link(source='../test_data/lib-a.1.0.3/content', target=output, forced=True) self.assertTrue(os.path.isfile('%s/data.txt' % output))
def test_run_from_config_with_no_link_targets(self): output = '../temp/output/run-config-no-link-targets' utils.rmdir(output) linker = PackageLinker( config_file='../test_data/config-no-link-targets.yaml', params={'output': output}) linker.run() self.assertTrue(os.path.isfile('%s/child/data.txt' % output))
def test_link_with_no_target_if_linkspec_has_links(self): output = '../temp/output/lib-a' utils.rmdir(output) linker = PackageLinker() linker.link(source='../test_data/lib-a.1.0.9/content', forced=True, params={'output': output}) self.assertTrue(os.path.isfile('%s/child/data.txt' % output))
def test_link_with_external_links_in_linkspec(self): output = '../temp/output/lib-a' utils.rmdir(output) linker = PackageLinker() linker.link(source='../test_data/lib-a.1.0.7/content', target=output, forced=True, params=dict(resources_package='../test_data/resources')) self.assertTrue(os.path.isfile('%s/data.txt' % output)) self.assertTrue(os.path.isfile('%s/resources/data.txt' % output))
def test_link_with_content_selection_in_linkspec(self): output = '../temp/output/lib-a' utils.rmdir(output) linker = PackageLinker() linker.link(source='../test_data/lib-a.1.0.5/content', target=output, forced=True) self.assertTrue(os.path.isfile('%s/data0.txt' % output)) self.assertTrue(os.path.isfile('%s/data1.txt' % output)) self.assertTrue(os.path.isfile('%s/data2.txt' % output)) self.assertFalse(os.path.isfile('%s/data.txt' % output))
def test_run_from_config_and_overwrite_params(self): output = '../temp/output/run-config-params-overwrite' utils.rmdir(output) linker = PackageLinker( config_file='../test_data/config-params-overwrite.yaml', params={'output': output}) linker.run() self.assertTrue( os.path.isfile('%s/project-ios/assets/images/fake-image.txt' % output)) self.assertTrue( os.path.isfile('%s/project-ios/assets/plugins/lib-c/c-data.txt' % output)) linker = PackageLinker( config_file='../test_data/config-params-overwrite.yaml', params={ 'output': output, 'platform': 'android' }) linker.run() self.assertTrue( os.path.isfile('%s/project-android/assets/images/fake-image.txt' % output)) self.assertTrue( os.path.isfile( '%s/project-android/assets/plugins/lib-c/c-data.txt' % output))
def test_support_git_source_with_branch_and_path(self): output = '../temp/output/lib-a' package_folder = '../temp/output/packages' utils.rmdir(output) utils.rmdir(package_folder) linker = PackageLinker(package_folder=package_folder) linker.link( source= 'git:https://bitbucket.org/tuongvu/upkit-test-package.git@feature/ccc#ccc', target=output, forced=True) self.assertTrue(os.path.isfile(os.path.join(output, '333.txt')))
def test_support_git_source_using_ssh(self): output = '../temp/output/lib-a' package_folder = '../temp/output/packages' utils.rmdir(output) utils.rmdir(package_folder) linker = PackageLinker(package_folder=package_folder) linker.link( source='git:[email protected]:tuongvu/upkit-test-package.git', target=output, forced=True) # linker.link(source='git:http://[email protected]', target=output, forced=True) # self.assertTrue(os.path.isfile(os.path.join(package_folder, 'README.md'))) self.assertTrue(os.path.isfile(os.path.join(output, 'README.md')))
def test_support_nuget_source_with_deep_path(self): output = '../temp/output/lib-a' package_folder = '../temp/output/packages' utils.rmdir(output) utils.rmdir(package_folder) linker = PackageLinker(package_folder=package_folder) linker.link(source='nuget:[email protected]#lib/net40-Client', target=output, forced=True) # linker.link(source='git:http://[email protected]', target=output, forced=True) self.assertTrue( os.path.isdir(os.path.join(package_folder, 'Nuget.Core.2.14.0'))) self.assertTrue(os.path.isfile(os.path.join(output, 'NuGet.Core.Dll')))
def test_run_from_config_and_overwrite_linkspec(self): output = '../temp/output/run-config-overwrite' utils.rmdir(output) linker = PackageLinker( config_file='../test_data/config-overwrite.yaml', params={'output': output}) linker.run() self.assertTrue(os.path.isfile('%s/lib-a/aaa/data.txt' % output)) self.assertTrue( os.path.isfile('%s/lib-a/aaa/resources/default-data.txt' % output)) self.assertTrue( os.path.isfile('%s/lib-a/aaa/resources/a/data.txt' % output)) self.assertTrue(os.path.isfile('%s/lib-c/c-data.txt' % output))
def test_support_git_source_with_branch_via_ssh(self): output = '../temp/output/lib-a' package_folder = '../temp/output/packages' utils.rmdir(output) utils.rmdir(package_folder) linker = PackageLinker(package_folder=package_folder) linker.link( source= 'git:[email protected]:tuongvu/upkit-test-package.git@feature/ccc', target=output, forced=True) self.assertTrue(os.path.isdir(os.path.join(output, 'ccc'))) self.assertTrue(os.path.isfile(os.path.join(output, 'README.md')))
def test_support_git_source_with_tag(self): output = '../temp/output/lib-a' package_folder = '../temp/output/packages' utils.rmdir(output) utils.rmdir(package_folder) linker = PackageLinker(package_folder=package_folder) linker.link( source= 'git:https://bitbucket.org/tuongvu/upkit-test-package.git@tag-1', target=output, forced=True) # linker.link(source='git:http://[email protected]', target=output, forced=True) self.assertTrue(os.path.isdir(os.path.join(output, 'ccc'))) self.assertFalse(os.path.isdir(os.path.join(output, 'eee'))) self.assertTrue(os.path.isfile(os.path.join(output, 'README.md')))
def test_link_with_external_links_default_content_in_linkspec(self): if os.path.exists('../test_data/empty_resources/default-data.txt'): os.remove('../test_data/empty_resources/default-data.txt') if os.path.exists('../test_data/empty_resources/a'): utils.rmdir('../test_data/empty_resources/a') output = '../temp/output/lib-a' utils.rmdir(output) linker = PackageLinker() linker.link( source='../test_data/lib-a.1.0.8/content', target=output, forced=True, params=dict(resources_package='../test_data/empty_resources')) self.assertTrue(os.path.isfile('%s/child/data.txt' % output)) self.assertTrue( os.path.isfile('%s/child/resources/default-data.txt' % output)) self.assertTrue( os.path.isfile('%s/child/resources/a/data.txt' % output))
def run(self, args): from upkit.package_linker import PackageLinker, UnityProjectLinkTemplate try: params = dict( (k, v) for (k, v) in [i.split('=') for i in utils.guaranteed_list(args.params)]) if not args.package_folder: args.package_folder = os.path.join( os.path.dirname(args.config), '.packages') link_template = UnityProjectLinkTemplate() linker = PackageLinker(config_file=args.config, package_folder=args.package_folder, link_template=link_template, params=params) linker.run() print('Package link completed.') except: print('Package link failed with errors.') print(traceback.format_exc()) sys.exit(1)
def test_support_git_source_if_already_cloned(self): output = '../temp/output/lib-a' package_folder = '../temp/output/packages' utils.rmdir(output) utils.rmdir(package_folder) linker = PackageLinker(package_folder=package_folder) linker.link( source='git:https://bitbucket.org/tuongvu/upkit-test-package.git', target=output, forced=True) # link again, with existing package folder utils.rmdir(output) linker.link( source='git:https://bitbucket.org/tuongvu/upkit-test-package.git', target=output, forced=True) self.assertTrue(os.path.isfile(os.path.join(output, 'README.md')))