def generate(self, context=None): """ Generate the given implementation. """ #Generating content fullOutputPath = os.path.join(context.output, self.output) if self.project_data.has_key("path"): targetPath = utils.resourceref.norm(self.project_data["path"]) if targetPath and targetPath != "": fullOutputPath = os.path.join(context.output, fullOutputPath, targetPath) fs = filestorage.FileStorage(fullOutputPath, "w") newProject = api.Project(fs) for layer in self.layers: layer.generate(newProject, self.configuration.get_storage().get_path()) newProject.close() #Opening project again to validate the content and remove illegal includes. if self.project_data.has_key("validate") and self.project_data["validate"] != "false": fs = filestorage.FileStorage(fullOutputPath, "w") validateProject = api.Project(fs) for conf in validateProject.list_configurations(): validateProject.get_configuration(conf).list_all_configurations() validateProject.close() return
def test_metadata_writing(self): fs = filestorage.FileStorage("testtemp","w") fs.set_active_configuration('testing.confml') fs.close() fs = filestorage.FileStorage("testtemp","r") self.assertEquals(fs.get_active_configuration(),'testing.confml') fs.close() shutil.rmtree("testtemp")
def test_generate(self): orig_workdir = os.getcwd() os.chdir(ROOT_PATH) try: OUTPUT_DIR = os.path.join(ROOT_PATH, 'output') self.remove_if_exists(OUTPUT_DIR) self.remove_if_exists(['hello.log', 'exec_in_output_test.log',]) fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('product.confml') context = plugin.GenerationContext(configuration=config, output=OUTPUT_DIR) impls = plugin.get_impl_set(config,'file2\.commandml$') #impls.output = OUTPUT_DIR impls.generate(context) self.assert_file_content_equals('hello.log', "Hello" + os.linesep + "Cmd line args: ['-c', 'some_config.txt', '-d', 'some_dir', '-x']" + os.linesep) self.assert_file_content_equals('exec_in_output_test.log', os.path.normpath(OUTPUT_DIR) + os.linesep) # Check that the log file of the command that should not be # executed does not exist self.assertFalse(os.path.exists("should_not_be_created.log")) self.assertTrue(os.path.exists(os.path.join(OUTPUT_DIR,"helloworld.txt"))) self.assertEquals(len(context.generation_output), 1) self.assertEquals(utils.relpath(context.generation_output[0].name, OUTPUT_DIR), 'helloworld.txt') self.assertEquals(context.generation_output[0].implementation.ref, 'assets/s60/implml/file2.commandml') finally: os.chdir(orig_workdir)
def _get_impl_and_set(self, ref): fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('product.confml') impl_set = plugin.get_impl_set(config, re.escape(ref) + '$') self.assertEquals(len(impl_set), 1) return iter(impl_set).next(), impl_set
def test_flat(self): ''' Test that the configuration flattening works ''' fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('product.confml') flat = p.create_configuration('flat.confml') dview = config.get_default_view() for fea in dview.get_features('**'): newfea = copy.copy(fea._obj) flat.add_feature(newfea, fea.namespace) toview = flat.get_default_view() for fea in toview.get_features('**'): fromfea = dview.get_feature(fea.fqr) if fromfea.get_value() != None: fea.set_value(fromfea.get_value()) flat.close() config.close() config = p.get_configuration('product.confml') flat = p.get_configuration('flat.confml') fdview = flat.get_default_view() for fea in config.get_default_view().get_features('**'): self.assertEquals(fea.get_value(), fdview.get_feature(fea.fqr).get_value()) pass
def get_temp_file_storage(self, path, empty=False): """ Get a new file storage located in the temp/ directory. @param path: Path of the storage directory relative to the temp/ directory. @param empty: If False, the DATA_ZIP is extracted to the location specified by 'path' and returned as a read-only storage. If True, a new writable empty storage is returned. """ full_path = os.path.join(TEMP_DIR, path) if not empty: unzip_file(DATA_ZIP, full_path, delete_if_exists=True) return filestorage.FileStorage(full_path, 'r') else: self.recreate_dir(full_path) return filestorage.FileStorage(full_path, 'w')
def test_configuration_parse_and_filter_implementation_with_tags(self): fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('product.confml') impls = plugin.get_impl_set(config, '\.content$') impls_rofs3 = impls.filter_implementations(tags={'target': ['rofs3']}) self.assertEquals(len(list(impls_rofs3)), 3)
def test_predefined_contacts_parse_and_generate(self): fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('product.confml') impls = plugin.get_impl_set(config, '\.gcfml$') impls.output = self.output impl = impls.get_implementations_by_file( 'assets/s60/implml/predefinedcontacts.gcfml')[0] impls.generate()
def test_example_parse_and_generate_prj2(self): fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('root1.confml') impls = plugin.get_impl_set(config, '\.gcfml$') impls.output = self.output impl = impls.get_implementations_by_file( 'Layer1/implml/feature1.gcfml')[0] impls.generate()
def test_get_refs(self): fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('product.confml') impls = plugin.get_impl_set(config, '\.gcfml$') impls.output = self.output impl = impls.get_implementations_by_file( 'assets/s60/implml/commsdatcreator_01.gcfml')[0] self.assertEquals(impl.get_refs(), ['APs.AP', 'WLAN_APs.WLAN_AP']) self.assertTrue(impl.has_ref(['APs.AP']))
def test_example_parse_prj(self): output_dir = os.path.join(temp_dir, "new_project2") if os.path.exists(output_dir): shutil.rmtree(output_dir) fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('product.confml') impls = plugin.get_impl_set(config, r'file1\.convertprojectml$') self.assertEquals(1, len(impls)) impl = iter(impls).next() self.assertTrue(isinstance(impl, convertproject.ConvertProjectImpl))
def test_list_output_files(self): fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('product.confml') impls = plugin.get_impl_set(config, '\.gcfml$') impls.output = self.output impl = impls.get_implementations_by_file( 'assets/s60/implml/predefinedcontacts.gcfml')[0] normalize_slash = lambda l: map(lambda p: p.replace('\\', '/'), l) self.assertEquals(normalize_slash(impl.list_output_files()), ['private/2000BEE5/predefinedcontacts.xml'])
def test_has_ref(self): fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('product.confml') impls = plugin.get_impl_set(config, '\.gcfml$') impls.output = self.output impl = impls.get_implementations_by_file( 'assets/s60/implml/predefinedcontacts.gcfml')[0] self.assertEquals(impl.get_refs(), ['Contacts.Contact']) self.assertFalse(impl.has_ref(['ref1', 'ref2'])) self.assertTrue(impl.has_ref(['Contacts.Contact'])) self.assertTrue(impl.has_ref(['Contacts.Contact.FirstName'])) self.assertFalse(impl.has_ref(['Contacts.OtherSetting']))
def unzip_tpf(self, theme, zip_output): """ unzip the tpf file to output directory """ f_storage = filestorage.FileStorage(theme.get_temp_tdf(), 'wb') list = [] list.append(theme.get_tpf_path()) storage = self.configuration.get_storage() storage.export_resources(list, f_storage) tpf_file = os.path.join(theme.get_temp_tdf(), theme.get_tpf_path().replace("/", "\\")) unzip.unzip_file_into_dir(tpf_file, zip_output)
def test_generate(self): os.environ['ncp_version'] = 'platforms' os.environ['variants'] = 'variants' output_dir = os.path.join(temp_dir, "new_project") if os.path.exists(output_dir): shutil.rmtree(output_dir) expected_dir = os.path.join(ROOT_PATH, "expected/new_project") oldPath = os.path.join(ROOT_PATH, 'old_structure/epoc32/rom/config') fs = filestorage.FileStorage(oldPath) p = api.Project(fs) config = p.get_configuration('convert.confml') context = plugin.GenerationContext(configuration=config, output=output_dir) impls = plugin.get_impl_set(config, '\.convertprojectml$') context.filtering_disabled = True impls.generate(context) self.assert_dir_contents_equal(expected_dir, output_dir, ['.svn'])
def test_unicode_in_template_and_value(self): OUTPUT_DIR = os.path.join(ROOT_PATH, 'output', 'unicode_test') self.remove_if_exists(OUTPUT_DIR) fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('root1.confml') impls = plugin.get_impl_set(config,'unicode_template_test\.templateml$') gc = plugin.GenerationContext(output=OUTPUT_DIR, configuration=config) impls.generate(gc) self.assert_exists_and_contains_something(os.path.join(OUTPUT_DIR, "unicode_template_test.txt")) # Check that the output exists and contains expected lines f = open(os.path.join(OUTPUT_DIR, "unicode_template_test.txt"), "rb") try: data = f.read().decode('utf-8') finally: f.close() self.assertTrue(data.find(u'Value of Feature1.UnicodeValueSetting: カタカナ') != -1) self.assertTrue(data.find(u'Unicode from template: ελληνικά') != -1)
def test_flat2(self): ''' Test that the configuration flattening works ''' fs = filestorage.FileStorage(testdata, "a") p = api.Project(fs) config = p.get_configuration('product.confml') confflat = confflattener.ConfigurationFlattener() confflat.create_configuration(config, ['DNs/**'], "tempfile2.confml") config = p.get_configuration('root_cvc.confml') dview = config.get_default_view() flat = p.get_configuration('tempfile2.confml') fdview = flat.get_default_view() for fea in fdview.get_features('**'): self.assertEquals(fea.get_value(), dview.get_feature(fea.fqr).get_value()) dataconf = flat.get_configuration('tempfile2_data.confml') fearefs = fdview.list_all_features() for dataref in dataconf.list_all_datas(): self.assertTrue(dataref in fearefs, "%s not in %s" % (dataref, fearefs))
def load_config(self, config): fs = filestorage.FileStorage(testdata) p = api.Project(fs) return p.get_configuration(config)
def test_example_parse_prj(self): fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('product.confml') impls = plugin.get_impl_set(config,'\.commandml$')