How to use manifest method in dbt-osmosis

Best Python code snippet using dbt-osmosis_python

manifest_fixer_test.py

Source:manifest_fixer_test.py Github

copy

Full Screen

1#!/usr/bin/env python2#3# Copyright (C) 2018 The Android Open Source Project4#5# Licensed under the Apache License, Version 2.0 (the "License");6# you may not use this file except in compliance with the License.7# You may obtain a copy of the License at8#9# http://www.apache.org/licenses/LICENSE-2.010#11# Unless required by applicable law or agreed to in writing, software12# distributed under the License is distributed on an "AS IS" BASIS,13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14# See the License for the specific language governing permissions and15# limitations under the License.16#17"""Unit tests for manifest_fixer.py."""18import StringIO19import sys20import unittest21from xml.dom import minidom22import manifest_fixer23sys.dont_write_bytecode = True24class CompareVersionGtTest(unittest.TestCase):25 """Unit tests for compare_version_gt function."""26 def test_sdk(self):27 """Test comparing sdk versions."""28 self.assertTrue(manifest_fixer.compare_version_gt('28', '27'))29 self.assertFalse(manifest_fixer.compare_version_gt('27', '28'))30 self.assertFalse(manifest_fixer.compare_version_gt('28', '28'))31 def test_codename(self):32 """Test comparing codenames."""33 self.assertTrue(manifest_fixer.compare_version_gt('Q', 'P'))34 self.assertFalse(manifest_fixer.compare_version_gt('P', 'Q'))35 self.assertFalse(manifest_fixer.compare_version_gt('Q', 'Q'))36 def test_sdk_codename(self):37 """Test comparing sdk versions with codenames."""38 self.assertTrue(manifest_fixer.compare_version_gt('Q', '28'))39 self.assertFalse(manifest_fixer.compare_version_gt('28', 'Q'))40 def test_compare_numeric(self):41 """Test that numbers are compared in numeric and not lexicographic order."""42 self.assertTrue(manifest_fixer.compare_version_gt('18', '8'))43class RaiseMinSdkVersionTest(unittest.TestCase):44 """Unit tests for raise_min_sdk_version function."""45 def raise_min_sdk_version_test(self, input_manifest, min_sdk_version,46 target_sdk_version, library):47 doc = minidom.parseString(input_manifest)48 manifest_fixer.raise_min_sdk_version(doc, min_sdk_version,49 target_sdk_version, library)50 output = StringIO.StringIO()51 manifest_fixer.write_xml(output, doc)52 return output.getvalue()53 manifest_tmpl = (54 '<?xml version="1.0" encoding="utf-8"?>\n'55 '<manifest xmlns:android="http://schemas.android.com/apk/res/android">\n'56 '%s'57 '</manifest>\n')58 # pylint: disable=redefined-builtin59 def uses_sdk(self, min=None, target=None, extra=''):60 attrs = ''61 if min:62 attrs += ' android:minSdkVersion="%s"' % (min)63 if target:64 attrs += ' android:targetSdkVersion="%s"' % (target)65 if extra:66 attrs += ' ' + extra67 return ' <uses-sdk%s/>\n' % (attrs)68 def test_no_uses_sdk(self):69 """Tests inserting a uses-sdk element into a manifest."""70 manifest_input = self.manifest_tmpl % ''71 expected = self.manifest_tmpl % self.uses_sdk(min='28', target='28')72 output = self.raise_min_sdk_version_test(manifest_input, '28', '28', False)73 self.assertEqual(output, expected)74 def test_no_min(self):75 """Tests inserting a minSdkVersion attribute into a uses-sdk element."""76 manifest_input = self.manifest_tmpl % ' <uses-sdk extra="foo"/>\n'77 expected = self.manifest_tmpl % self.uses_sdk(min='28', target='28',78 extra='extra="foo"')79 output = self.raise_min_sdk_version_test(manifest_input, '28', '28', False)80 self.assertEqual(output, expected)81 def test_raise_min(self):82 """Tests inserting a minSdkVersion attribute into a uses-sdk element."""83 manifest_input = self.manifest_tmpl % self.uses_sdk(min='27')84 expected = self.manifest_tmpl % self.uses_sdk(min='28', target='28')85 output = self.raise_min_sdk_version_test(manifest_input, '28', '28', False)86 self.assertEqual(output, expected)87 def test_raise(self):88 """Tests raising a minSdkVersion attribute."""89 manifest_input = self.manifest_tmpl % self.uses_sdk(min='27')90 expected = self.manifest_tmpl % self.uses_sdk(min='28', target='28')91 output = self.raise_min_sdk_version_test(manifest_input, '28', '28', False)92 self.assertEqual(output, expected)93 def test_no_raise_min(self):94 """Tests a minSdkVersion that doesn't need raising."""95 manifest_input = self.manifest_tmpl % self.uses_sdk(min='28')96 expected = self.manifest_tmpl % self.uses_sdk(min='28', target='27')97 output = self.raise_min_sdk_version_test(manifest_input, '27', '27', False)98 self.assertEqual(output, expected)99 def test_raise_codename(self):100 """Tests raising a minSdkVersion attribute to a codename."""101 manifest_input = self.manifest_tmpl % self.uses_sdk(min='28')102 expected = self.manifest_tmpl % self.uses_sdk(min='P', target='P')103 output = self.raise_min_sdk_version_test(manifest_input, 'P', 'P', False)104 self.assertEqual(output, expected)105 def test_no_raise_codename(self):106 """Tests a minSdkVersion codename that doesn't need raising."""107 manifest_input = self.manifest_tmpl % self.uses_sdk(min='P')108 expected = self.manifest_tmpl % self.uses_sdk(min='P', target='28')109 output = self.raise_min_sdk_version_test(manifest_input, '28', '28', False)110 self.assertEqual(output, expected)111 def test_target(self):112 """Tests an existing targetSdkVersion is preserved."""113 manifest_input = self.manifest_tmpl % self.uses_sdk(min='26', target='27')114 expected = self.manifest_tmpl % self.uses_sdk(min='28', target='27')115 output = self.raise_min_sdk_version_test(manifest_input, '28', '29', False)116 self.assertEqual(output, expected)117 def test_no_target(self):118 """Tests inserting targetSdkVersion when minSdkVersion exists."""119 manifest_input = self.manifest_tmpl % self.uses_sdk(min='27')120 expected = self.manifest_tmpl % self.uses_sdk(min='28', target='29')121 output = self.raise_min_sdk_version_test(manifest_input, '28', '29', False)122 self.assertEqual(output, expected)123 def test_target_no_min(self):124 """"Tests inserting targetSdkVersion when minSdkVersion exists."""125 manifest_input = self.manifest_tmpl % self.uses_sdk(target='27')126 expected = self.manifest_tmpl % self.uses_sdk(min='28', target='27')127 output = self.raise_min_sdk_version_test(manifest_input, '28', '29', False)128 self.assertEqual(output, expected)129 def test_no_target_no_min(self):130 """Tests inserting targetSdkVersion when minSdkVersion does not exist."""131 manifest_input = self.manifest_tmpl % ''132 expected = self.manifest_tmpl % self.uses_sdk(min='28', target='29')133 output = self.raise_min_sdk_version_test(manifest_input, '28', '29', False)134 self.assertEqual(output, expected)135 def test_library_no_target(self):136 """Tests inserting targetSdkVersion when minSdkVersion exists."""137 manifest_input = self.manifest_tmpl % self.uses_sdk(min='27')138 expected = self.manifest_tmpl % self.uses_sdk(min='28', target='16')139 output = self.raise_min_sdk_version_test(manifest_input, '28', '29', True)140 self.assertEqual(output, expected)141 def test_library_target_no_min(self):142 """Tests inserting targetSdkVersion when minSdkVersion exists."""143 manifest_input = self.manifest_tmpl % self.uses_sdk(target='27')144 expected = self.manifest_tmpl % self.uses_sdk(min='28', target='27')145 output = self.raise_min_sdk_version_test(manifest_input, '28', '29', True)146 self.assertEqual(output, expected)147 def test_library_no_target_no_min(self):148 """Tests inserting targetSdkVersion when minSdkVersion does not exist."""149 manifest_input = self.manifest_tmpl % ''150 expected = self.manifest_tmpl % self.uses_sdk(min='28', target='16')151 output = self.raise_min_sdk_version_test(manifest_input, '28', '29', True)152 self.assertEqual(output, expected)153 def test_extra(self):154 """Tests that extra attributes and elements are maintained."""155 manifest_input = self.manifest_tmpl % (156 ' <!-- comment -->\n'157 ' <uses-sdk android:minSdkVersion="27" extra="foo"/>\n'158 ' <application/>\n')159 # pylint: disable=line-too-long160 expected = self.manifest_tmpl % (161 ' <!-- comment -->\n'162 ' <uses-sdk android:minSdkVersion="28" android:targetSdkVersion="29" extra="foo"/>\n'163 ' <application/>\n')164 output = self.raise_min_sdk_version_test(manifest_input, '28', '29', False)165 self.assertEqual(output, expected)166 def test_indent(self):167 """Tests that an inserted element copies the existing indentation."""168 manifest_input = self.manifest_tmpl % ' <!-- comment -->\n'169 # pylint: disable=line-too-long170 expected = self.manifest_tmpl % (171 ' <uses-sdk android:minSdkVersion="28" android:targetSdkVersion="29"/>\n'172 ' <!-- comment -->\n')173 output = self.raise_min_sdk_version_test(manifest_input, '28', '29', False)174 self.assertEqual(output, expected)175class AddLoggingParentTest(unittest.TestCase):176 """Unit tests for add_logging_parent function."""177 def add_logging_parent_test(self, input_manifest, logging_parent=None):178 doc = minidom.parseString(input_manifest)179 if logging_parent:180 manifest_fixer.add_logging_parent(doc, logging_parent)181 output = StringIO.StringIO()182 manifest_fixer.write_xml(output, doc)183 return output.getvalue()184 manifest_tmpl = (185 '<?xml version="1.0" encoding="utf-8"?>\n'186 '<manifest xmlns:android="http://schemas.android.com/apk/res/android">\n'187 '%s'188 '</manifest>\n')189 def uses_logging_parent(self, logging_parent=None):190 attrs = ''191 if logging_parent:192 meta_text = ('<meta-data android:name="android.content.pm.LOGGING_PARENT" '193 'android:value="%s"/>\n') % (logging_parent)194 attrs += ' <application>\n %s </application>\n' % (meta_text)195 return attrs196 def test_no_logging_parent(self):197 """Tests manifest_fixer with no logging_parent."""198 manifest_input = self.manifest_tmpl % ''199 expected = self.manifest_tmpl % self.uses_logging_parent()200 output = self.add_logging_parent_test(manifest_input)201 self.assertEqual(output, expected)202 def test_logging_parent(self):203 """Tests manifest_fixer with no logging_parent."""204 manifest_input = self.manifest_tmpl % ''205 expected = self.manifest_tmpl % self.uses_logging_parent('FOO')206 output = self.add_logging_parent_test(manifest_input, 'FOO')207 self.assertEqual(output, expected)208class AddUsesLibrariesTest(unittest.TestCase):209 """Unit tests for add_uses_libraries function."""210 def run_test(self, input_manifest, new_uses_libraries):211 doc = minidom.parseString(input_manifest)212 manifest_fixer.add_uses_libraries(doc, new_uses_libraries, True)213 output = StringIO.StringIO()214 manifest_fixer.write_xml(output, doc)215 return output.getvalue()216 manifest_tmpl = (217 '<?xml version="1.0" encoding="utf-8"?>\n'218 '<manifest xmlns:android="http://schemas.android.com/apk/res/android">\n'219 ' <application>\n'220 '%s'221 ' </application>\n'222 '</manifest>\n')223 def uses_libraries(self, name_required_pairs):224 ret = ''225 for name, required in name_required_pairs:226 ret += (227 ' <uses-library android:name="%s" android:required="%s"/>\n'228 ) % (name, required)229 return ret230 def test_empty(self):231 """Empty new_uses_libraries must not touch the manifest."""232 manifest_input = self.manifest_tmpl % self.uses_libraries([233 ('foo', 'true'),234 ('bar', 'false')])235 expected = manifest_input236 output = self.run_test(manifest_input, [])237 self.assertEqual(output, expected)238 def test_not_overwrite(self):239 """new_uses_libraries must not overwrite existing tags."""240 manifest_input = self.manifest_tmpl % self.uses_libraries([241 ('foo', 'true'),242 ('bar', 'false')])243 expected = manifest_input244 output = self.run_test(manifest_input, ['foo', 'bar'])245 self.assertEqual(output, expected)246 def test_add(self):247 """New names are added with 'required:true'."""248 manifest_input = self.manifest_tmpl % self.uses_libraries([249 ('foo', 'true'),250 ('bar', 'false')])251 expected = self.manifest_tmpl % self.uses_libraries([252 ('foo', 'true'),253 ('bar', 'false'),254 ('baz', 'true'),255 ('qux', 'true')])256 output = self.run_test(manifest_input, ['bar', 'baz', 'qux'])257 self.assertEqual(output, expected)258 def test_no_application(self):259 """When there is no <application> tag, the tag is added."""260 manifest_input = (261 '<?xml version="1.0" encoding="utf-8"?>\n'262 '<manifest xmlns:android='263 '"http://schemas.android.com/apk/res/android">\n'264 '</manifest>\n')265 expected = self.manifest_tmpl % self.uses_libraries([266 ('foo', 'true'),267 ('bar', 'true')])268 output = self.run_test(manifest_input, ['foo', 'bar'])269 self.assertEqual(output, expected)270 def test_empty_application(self):271 """Even when here is an empty <application/> tag, the libs are added."""272 manifest_input = (273 '<?xml version="1.0" encoding="utf-8"?>\n'274 '<manifest xmlns:android='275 '"http://schemas.android.com/apk/res/android">\n'276 ' <application/>\n'277 '</manifest>\n')278 expected = self.manifest_tmpl % self.uses_libraries([279 ('foo', 'true'),280 ('bar', 'true')])281 output = self.run_test(manifest_input, ['foo', 'bar'])282 self.assertEqual(output, expected)283class AddUsesNonSdkApiTest(unittest.TestCase):284 """Unit tests for add_uses_libraries function."""285 def run_test(self, input_manifest):286 doc = minidom.parseString(input_manifest)287 manifest_fixer.add_uses_non_sdk_api(doc)288 output = StringIO.StringIO()289 manifest_fixer.write_xml(output, doc)290 return output.getvalue()291 manifest_tmpl = (292 '<?xml version="1.0" encoding="utf-8"?>\n'293 '<manifest xmlns:android="http://schemas.android.com/apk/res/android">\n'294 ' <application%s/>\n'295 '</manifest>\n')296 def uses_non_sdk_api(self, value):297 return ' android:usesNonSdkApi="true"' if value else ''298 def test_set_true(self):299 """Empty new_uses_libraries must not touch the manifest."""300 manifest_input = self.manifest_tmpl % self.uses_non_sdk_api(False)301 expected = self.manifest_tmpl % self.uses_non_sdk_api(True)302 output = self.run_test(manifest_input)303 self.assertEqual(output, expected)304 def test_already_set(self):305 """new_uses_libraries must not overwrite existing tags."""306 manifest_input = self.manifest_tmpl % self.uses_non_sdk_api(True)307 expected = manifest_input308 output = self.run_test(manifest_input)309 self.assertEqual(output, expected)310class UseEmbeddedDexTest(unittest.TestCase):311 """Unit tests for add_use_embedded_dex function."""312 def run_test(self, input_manifest):313 doc = minidom.parseString(input_manifest)314 manifest_fixer.add_use_embedded_dex(doc)315 output = StringIO.StringIO()316 manifest_fixer.write_xml(output, doc)317 return output.getvalue()318 manifest_tmpl = (319 '<?xml version="1.0" encoding="utf-8"?>\n'320 '<manifest xmlns:android="http://schemas.android.com/apk/res/android">\n'321 ' <application%s/>\n'322 '</manifest>\n')323 def use_embedded_dex(self, value):324 return ' android:useEmbeddedDex="%s"' % value325 def test_manifest_with_undeclared_preference(self):326 manifest_input = self.manifest_tmpl % ''327 expected = self.manifest_tmpl % self.use_embedded_dex('true')328 output = self.run_test(manifest_input)329 self.assertEqual(output, expected)330 def test_manifest_with_use_embedded_dex(self):331 manifest_input = self.manifest_tmpl % self.use_embedded_dex('true')332 expected = manifest_input333 output = self.run_test(manifest_input)334 self.assertEqual(output, expected)335 def test_manifest_with_not_use_embedded_dex(self):336 manifest_input = self.manifest_tmpl % self.use_embedded_dex('false')337 self.assertRaises(RuntimeError, self.run_test, manifest_input)338class AddExtractNativeLibsTest(unittest.TestCase):339 """Unit tests for add_extract_native_libs function."""340 def run_test(self, input_manifest, value):341 doc = minidom.parseString(input_manifest)342 manifest_fixer.add_extract_native_libs(doc, value)343 output = StringIO.StringIO()344 manifest_fixer.write_xml(output, doc)345 return output.getvalue()346 manifest_tmpl = (347 '<?xml version="1.0" encoding="utf-8"?>\n'348 '<manifest xmlns:android="http://schemas.android.com/apk/res/android">\n'349 ' <application%s/>\n'350 '</manifest>\n')351 def extract_native_libs(self, value):352 return ' android:extractNativeLibs="%s"' % value353 def test_set_true(self):354 manifest_input = self.manifest_tmpl % ''355 expected = self.manifest_tmpl % self.extract_native_libs('true')356 output = self.run_test(manifest_input, True)357 self.assertEqual(output, expected)358 def test_set_false(self):359 manifest_input = self.manifest_tmpl % ''360 expected = self.manifest_tmpl % self.extract_native_libs('false')361 output = self.run_test(manifest_input, False)362 self.assertEqual(output, expected)363 def test_match(self):364 manifest_input = self.manifest_tmpl % self.extract_native_libs('true')365 expected = manifest_input366 output = self.run_test(manifest_input, True)367 self.assertEqual(output, expected)368 def test_conflict(self):369 manifest_input = self.manifest_tmpl % self.extract_native_libs('true')370 self.assertRaises(RuntimeError, self.run_test, manifest_input, False)371class AddNoCodeApplicationTest(unittest.TestCase):372 """Unit tests for set_has_code_to_false function."""373 def run_test(self, input_manifest):374 doc = minidom.parseString(input_manifest)375 manifest_fixer.set_has_code_to_false(doc)376 output = StringIO.StringIO()377 manifest_fixer.write_xml(output, doc)378 return output.getvalue()379 manifest_tmpl = (380 '<?xml version="1.0" encoding="utf-8"?>\n'381 '<manifest xmlns:android="http://schemas.android.com/apk/res/android">\n'382 '%s'383 '</manifest>\n')384 def test_no_application(self):385 manifest_input = self.manifest_tmpl % ''386 expected = self.manifest_tmpl % ' <application android:hasCode="false"/>\n'387 output = self.run_test(manifest_input)388 self.assertEqual(output, expected)389 def test_has_application_no_has_code(self):390 manifest_input = self.manifest_tmpl % ' <application/>\n'391 expected = self.manifest_tmpl % ' <application android:hasCode="false"/>\n'392 output = self.run_test(manifest_input)393 self.assertEqual(output, expected)394 def test_has_application_has_code_false(self):395 """ Do nothing if there's already an application elemeent. """396 manifest_input = self.manifest_tmpl % ' <application android:hasCode="false"/>\n'397 output = self.run_test(manifest_input)398 self.assertEqual(output, manifest_input)399 def test_has_application_has_code_true(self):400 """ Do nothing if there's already an application elemeent even if its401 hasCode attribute is true. """402 manifest_input = self.manifest_tmpl % ' <application android:hasCode="true"/>\n'403 output = self.run_test(manifest_input)404 self.assertEqual(output, manifest_input)405if __name__ == '__main__':...

Full Screen

Full Screen

index.ts

Source:index.ts Github

copy

Full Screen

1/*2 * Copyright ©️ 2018-2020 Galt•Project Society Construction and Terraforming Company3 * (Founded by [Nikolai Popeka](https://github.com/npopeka)4 *5 * Copyright ©️ 2018-2020 Galt•Core Blockchain Company6 * (Founded by [Nikolai Popeka](https://github.com/npopeka) by7 * [Basic Agreement](ipfs/QmaCiXUmSrP16Gz8Jdzq6AJESY1EAANmmwha15uR3c1bsS)).8 */9import {IGeesomeApp} from "../../interface";10import IGeesomeEntityJsonManifestModule from "./interface";11import {GroupType, IGroup, IPost, PostStatus} from "../group/interface";12import {IContent, IUser} from "../database/interface";13import {IGroupCategory} from "../groupCategory/interface";14const pIteration = require('p-iteration');15const treeLib = require('geesome-libs/src/base36Trie');16const ipfsHelper = require('geesome-libs/src/ipfsHelper');17const log = require('debug')('geesome:app');18module.exports = async (app: IGeesomeApp) => {19 return getModule(app);20};21function getModule(app: IGeesomeApp) {22 app.checkModules(['database', 'group', 'accountStorage', 'staticId', 'storage']);23 class EntityJsonManifest implements IGeesomeEntityJsonManifestModule {24 constructor() {25 }26 async generateManifest(name, data, options?) {27 if (name === 'group') {28 //TODO: size => postsSize29 const group: IGroup = data;30 const groupManifest = ipfsHelper.pickObjectFields(group, ['name', 'homePage', 'title', 'type', 'view', 'theme', 'isPublic', 'description', 'size', 'createdAt', 'updatedAt']);31 if(data.isEncrypted) {32 groupManifest.isEncrypted = true;33 }34 groupManifest.postsCount = group.publishedPostsCount;35 //TODO: add previous ID36 groupManifest.staticId = group.manifestStaticStorageId;37 groupManifest.publicKey = await app.ms.accountStorage.getStaticIdPublicKeyByOr(groupManifest.staticId);38 if (group.avatarImage) {39 groupManifest.avatarImage = this.getStorageRef(group.avatarImage.manifestStorageId);40 }41 if (group.coverImage) {42 groupManifest.coverImage = this.getStorageRef(group.coverImage.manifestStorageId);43 }44 // TODO: is this need for protocol?45 // currently used for getting companion info in chats list46 if(group.type === GroupType.PersonalChat) {47 const creator = await app.ms.database.getUser(group.creatorId);48 groupManifest.members = [group.staticStorageId, creator.manifestStaticStorageId];49 }50 groupManifest.posts = {};51 // TODO: write all posts52 const groupPosts = await app.ms.group.getGroupPosts(group.id, {status: PostStatus.Published}, {limit: 1000, offset: 0}).then(r => r.list);53 // console.log('groupPosts', group.id, groupPosts);54 groupPosts.forEach((post: IPost) => {55 if(post.isEncrypted) {56 treeLib.setNode(groupManifest.posts, post.localId, post.encryptedManifestStorageId);57 } else if (post.manifestStorageId) {58 treeLib.setNode(groupManifest.posts, post.localId, this.getStorageRef(post.manifestStorageId));59 }60 });61 this.setManifestMeta(groupManifest, name);62 return groupManifest;63 } else if (name === 'category') {64 const category: IGroupCategory = data;65 const categoryManifest = ipfsHelper.pickObjectFields(category, ['name', 'title', 'type', 'view', 'theme', 'isGlobal', 'description', 'createdAt', 'updatedAt']);66 this.setManifestMeta(categoryManifest, name);67 return categoryManifest;68 } else if (name === 'post') {69 const post: IPost = data;70 //TODO: fix size, view and type71 //TODO: add groupNumber72 const postManifest = ipfsHelper.pickObjectFields(post, ['status', 'publishedAt', 'view', 'type', 'size', 'source', 'sourceChannelId', 'sourcePostId', 'sourceDate']);73 if(post.propertiesJson) {74 postManifest.properties = JSON.parse(post.propertiesJson);75 }76 postManifest.groupId = post.groupStorageId;77 postManifest.groupStaticId = post.groupStaticStorageId;78 postManifest.authorId = post.authorStorageId;79 postManifest.authorStaticId = post.authorStaticStorageId;80 postManifest.contents = post.contents.map((content: IContent) => {81 return {82 view: content.view,83 storageId: content.manifestStorageId //this.getStorageRef(content.manifestStorageId)84 };85 });86 this.setManifestMeta(postManifest, name);87 return postManifest;88 } else if (name === 'user') {89 const user: IUser = data;90 const userManifest = ipfsHelper.pickObjectFields(user, ['name', 'title', 'email', 'description', 'updatedAt', 'createdAt']);91 userManifest.staticId = user.manifestStaticStorageId;92 userManifest.publicKey = await app.ms.accountStorage.getStaticIdPublicKeyByOr(userManifest.staticId);93 if (user.avatarImage) {94 userManifest.avatarImage = this.getStorageRef(user.avatarImage.manifestStorageId);95 }96 this.setManifestMeta(userManifest, name);97 await app.callHook('entityJsonManifest', 'beforeEntityManifestStore', [user.id, 'user', user, userManifest]);98 return userManifest;99 } else if (name === 'content') {100 const content: IContent = data;101 const contentManifest = ipfsHelper.pickObjectFields(content, ['name', 'description', 'mimeType', 'storageType', 'size', 'extension']);102 if(content.propertiesJson) {103 contentManifest.properties = JSON.parse(content.propertiesJson);104 }105 contentManifest.storageId = content.storageId;106 contentManifest.preview = {107 medium: {108 storageId: content.mediumPreviewStorageId || null,109 mimeType: content.previewMimeType || null,110 extension: content.previewExtension || null,111 size: content.mediumPreviewSize || null112 }113 };114 if (content.smallPreviewStorageId) {115 contentManifest.preview.small = {116 storageId: content.smallPreviewStorageId || null,117 mimeType: content.previewMimeType || null,118 extension: content.previewExtension || null,119 size: content.smallPreviewSize || null120 };121 }122 if (content.largePreviewStorageId) {123 contentManifest.preview.large = {124 storageId: content.largePreviewStorageId || null,125 mimeType: content.previewMimeType || null,126 extension: content.previewExtension || null,127 size: content.largePreviewSize || null128 };129 }130 this.setManifestMeta(contentManifest, name);131 return contentManifest;132 }133 return '';134 }135 async manifestIdToDbObject(manifestId, type = null, options: any = {}) {136 manifestId = ipfsHelper.getStorageIdHash(manifestId);137 let manifest: any = {};138 if (!options.isEncrypted) {139 log('manifestIdToDbObject:getObject', type, manifestId);140 manifest = await app.ms.storage.getObject(manifestId);141 log('manifestIdToDbObject:manifest', manifest);142 if (!type) {143 type = manifest._entityName;144 }145 }146 if (type === 'group') {147 const group: IGroup = ipfsHelper.pickObjectFields(manifest, ['name', 'homePage', 'title', 'type', 'view', 'isPublic', 'description', 'size']);148 group.manifestStorageId = manifestId;149 if (manifest.avatarImage) {150 group.avatarImage = (await this.manifestIdToDbObject(manifest.avatarImage, 'content')) as any;151 }152 if (manifest.coverImage) {153 group.coverImage = (await this.manifestIdToDbObject(manifest.coverImage, 'content')) as any;154 }155 group.publishedPostsCount = manifest.postsCount;156 group.manifestStaticStorageId = manifest.staticId;157 //TODO: check ipns for valid bound to ipld158 await app.ms.accountStorage.createRemoteAccount(manifest.staticId, manifest.publicKey, manifest.name).catch(() => {});159 await app.ms.staticId.addStaticIdHistoryItem({160 staticId: manifest.staticId,161 dynamicId: manifestId,162 isActive: true,163 boundAt: new Date()164 }).catch(() => {});165 //TODO: import posts too166 return group;167 } else if (type === 'user') {168 const user: IUser = ipfsHelper.pickObjectFields(manifest, ['name', 'title', 'email', 'description']);169 user.manifestStorageId = manifestId;170 if (manifest.avatarImage) {171 user.avatarImage = (await this.manifestIdToDbObject(manifest.avatarImage, 'content')) as any;172 }173 user.manifestStaticStorageId = manifest.staticId;174 log('manifestIdToDbObject:user', user);175 //TODO: check ipns for valid bound to ipld176 await app.ms.accountStorage.createRemoteAccount(manifest.staticId, manifest.publicKey, manifest.name).catch(() => {});177 await app.ms.staticId.addStaticIdHistoryItem({178 staticId: manifest.staticId,179 dynamicId: manifestId,180 isActive: true,181 boundAt: new Date()182 }).catch(() => {});183 return user;184 } else if (type === 'post') {185 let post: IPost;186 if (options.isEncrypted) {187 post = { ...options, isEncrypted: true, encryptedManifestStorageId: manifestId };188 } else {189 post = ipfsHelper.pickObjectFields(manifest, ['status', 'publishedAt', 'view', 'type', 'size']);190 post.manifestStorageId = manifestId;191 post.authorStorageId = manifest.authorId;192 post.authorStaticStorageId = manifest.authorStaticId;193 post.groupStorageId = manifest.groupId;194 post.groupStaticStorageId = manifest.groupStaticId;195 // const group = await app.createGroupByRemoteStorageId(manifest.group)196 const contentsIds = manifest.contents.map(content => {197 return content.storageId;198 });199 post.contents = await pIteration.map(contentsIds, (contentId) => {200 return app.ms.content.createContentByRemoteStorageId(null, contentId);201 });202 }203 return post;204 } else if (type === 'content') {205 const content: IContent = ipfsHelper.pickObjectFields(manifest, ['name', 'mimeType', 'storageType', 'view', 'size', 'extension']);206 if(manifest.isEncrypted) {207 content.encryptedManifestStorageId = manifestId;208 } else {209 content.storageId = manifest.storageId;210 if(manifest.preview) {211 if(manifest.preview.medium) {212 const mediumPreview = manifest.preview.medium;213 content.mediumPreviewStorageId = mediumPreview.storageId;214 content.mediumPreviewSize = mediumPreview.size;215 content.previewExtension = mediumPreview.extension;216 content.previewMimeType = mediumPreview.mimeType;217 }218 if(manifest.preview.small) {219 const smallPreview = manifest.preview.small;220 content.smallPreviewStorageId = smallPreview.storageId;221 content.smallPreviewSize = smallPreview.size;222 content.previewExtension = content.previewExtension || smallPreview.extension;223 content.previewMimeType = content.previewMimeType || smallPreview.mimeType;224 }225 if(manifest.preview.large) {226 const largePreview = manifest.preview.large;227 content.smallPreviewStorageId = largePreview.storageId;228 content.smallPreviewSize = largePreview.size;229 content.previewExtension = content.previewExtension || largePreview.extension;230 content.previewMimeType = content.previewMimeType || largePreview.mimeType;231 }232 }233 content.manifestStorageId = manifestId;234 }235 return content;236 }237 }238 getStorageRef(storageId) {239 if (!storageId) {240 return null;241 }242 return storageId;243 }244 setManifestMeta(manifest, entityName) {245 manifest._version = "0.1";246 manifest._source = "geesome-node";247 manifest._protocol = "geesome-ipsp";248 manifest._type = 'manifest';249 manifest._entityName = entityName;250 }251 }252 return new EntityJsonManifest();...

Full Screen

Full Screen

manifest.py

Source:manifest.py Github

copy

Full Screen

...124 """125 The following function parses an initial manifest and returns a dictionary126 object with the must install, attempt only, multilib and language packages.127 """128 def parse_initial_manifest(self):129 pkgs = dict()130 with open(self.initial_manifest) as manifest:131 for line in manifest.read().split('\n'):132 comment = re.match("^#.*", line)133 pattern = "^(%s|%s|%s|%s),(.*)$" % \134 (self.PKG_TYPE_MUST_INSTALL,135 self.PKG_TYPE_ATTEMPT_ONLY,136 self.PKG_TYPE_MULTILIB,137 self.PKG_TYPE_LANGUAGE)138 pkg = re.match(pattern, line)139 if comment is not None:140 continue141 if pkg is not None:142 pkg_type = pkg.group(1)143 pkg_name = pkg.group(2)144 if not pkg_type in pkgs:145 pkgs[pkg_type] = [pkg_name]146 else:147 pkgs[pkg_type].append(pkg_name)148 return pkgs149 '''150 This following function parses a full manifest and return a list151 object with packages.152 '''153 def parse_full_manifest(self):154 installed_pkgs = list()155 if not os.path.exists(self.full_manifest):156 bb.note('full manifest not exist')157 return installed_pkgs158 with open(self.full_manifest, 'r') as manifest:159 for pkg in manifest.read().split('\n'):160 installed_pkgs.append(pkg.strip())161 return installed_pkgs162class RpmManifest(Manifest):163 """164 Returns a dictionary object with mip and mlp packages.165 """166 def _split_multilib(self, pkg_list):167 pkgs = dict()168 for pkg in pkg_list.split():169 pkg_type = self.PKG_TYPE_MUST_INSTALL170 ml_variants = self.d.getVar('MULTILIB_VARIANTS').split()171 for ml_variant in ml_variants:172 if pkg.startswith(ml_variant + '-'):173 pkg_type = self.PKG_TYPE_MULTILIB174 if not pkg_type in pkgs:175 pkgs[pkg_type] = pkg176 else:177 pkgs[pkg_type] += " " + pkg178 return pkgs179 def create_initial(self):180 pkgs = dict()181 with open(self.initial_manifest, "w+") as manifest:182 manifest.write(self.initial_manifest_file_header)183 for var in self.var_maps[self.manifest_type]:184 if var in self.vars_to_split:185 split_pkgs = self._split_multilib(self.d.getVar(var))186 if split_pkgs is not None:187 pkgs = dict(list(pkgs.items()) + list(split_pkgs.items()))188 else:189 pkg_list = self.d.getVar(var)190 if pkg_list is not None:191 pkgs[self.var_maps[self.manifest_type][var]] = self.d.getVar(var)192 for pkg_type in pkgs:193 for pkg in pkgs[pkg_type].split():194 manifest.write("%s,%s\n" % (pkg_type, pkg))195 def create_final(self):196 pass197 def create_full(self, pm):198 pass199class OpkgManifest(Manifest):200 """201 Returns a dictionary object with mip and mlp packages.202 """203 def _split_multilib(self, pkg_list):204 pkgs = dict()205 for pkg in pkg_list.split():206 pkg_type = self.PKG_TYPE_MUST_INSTALL207 ml_variants = self.d.getVar('MULTILIB_VARIANTS').split()208 for ml_variant in ml_variants:209 if pkg.startswith(ml_variant + '-'):210 pkg_type = self.PKG_TYPE_MULTILIB211 if not pkg_type in pkgs:212 pkgs[pkg_type] = pkg213 else:214 pkgs[pkg_type] += " " + pkg215 return pkgs216 def create_initial(self):217 pkgs = dict()218 with open(self.initial_manifest, "w+") as manifest:219 manifest.write(self.initial_manifest_file_header)220 for var in self.var_maps[self.manifest_type]:221 if var in self.vars_to_split:222 split_pkgs = self._split_multilib(self.d.getVar(var))223 if split_pkgs is not None:224 pkgs = dict(list(pkgs.items()) + list(split_pkgs.items()))225 else:226 pkg_list = self.d.getVar(var)227 if pkg_list is not None:228 pkgs[self.var_maps[self.manifest_type][var]] = self.d.getVar(var)229 for pkg_type in sorted(pkgs):230 for pkg in sorted(pkgs[pkg_type].split()):231 manifest.write("%s,%s\n" % (pkg_type, pkg))232 def create_final(self):233 pass234 def create_full(self, pm):235 if not os.path.exists(self.initial_manifest):236 self.create_initial()237 initial_manifest = self.parse_initial_manifest()238 pkgs_to_install = list()239 for pkg_type in initial_manifest:240 pkgs_to_install += initial_manifest[pkg_type]241 if len(pkgs_to_install) == 0:242 return243 output = pm.dummy_install(pkgs_to_install)244 with open(self.full_manifest, 'w+') as manifest:245 pkg_re = re.compile('^Installing ([^ ]+) [^ ].*')246 for line in set(output.split('\n')):247 m = pkg_re.match(line)248 if m:249 manifest.write(m.group(1) + '\n')250 return251class DpkgManifest(Manifest):252 def create_initial(self):253 with open(self.initial_manifest, "w+") as manifest:254 manifest.write(self.initial_manifest_file_header)255 for var in self.var_maps[self.manifest_type]:256 pkg_list = self.d.getVar(var)257 if pkg_list is None:258 continue259 for pkg in pkg_list.split():260 manifest.write("%s,%s\n" %261 (self.var_maps[self.manifest_type][var], pkg))262 def create_final(self):263 pass264 def create_full(self, pm):265 pass266def create_manifest(d, final_manifest=False, manifest_dir=None,267 manifest_type=Manifest.MANIFEST_TYPE_IMAGE):268 manifest_map = {'rpm': RpmManifest,269 'ipk': OpkgManifest,270 'deb': DpkgManifest}271 manifest = manifest_map[d.getVar('IMAGE_PKGTYPE')](d, manifest_dir, manifest_type)272 if final_manifest:273 manifest.create_final()274 else:275 manifest.create_initial()276if __name__ == "__main__":...

Full Screen

Full Screen

app-validator.js

Source:app-validator.js Github

copy

Full Screen

1/* This Source Code Form is subject to the terms of the Mozilla Public2 * License, v. 2.0. If a copy of the MPL was not distributed with this3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */4"use strict";5var {Ci, Cu} = require("chrome");6const {FileUtils} = require("resource://gre/modules/FileUtils.jsm");7const Services = require("Services");8const {Task} = require("devtools/shared/task");9var strings = Services.strings.createBundle("chrome://devtools/locale/app-manager.properties");10function AppValidator({ type, location }) {11 this.type = type;12 this.location = location;13 this.errors = [];14 this.warnings = [];15}16AppValidator.prototype.error = function (message) {17 this.errors.push(message);18};19AppValidator.prototype.warning = function (message) {20 this.warnings.push(message);21};22AppValidator.prototype._getPackagedManifestFile = function () {23 let manifestFile = FileUtils.File(this.location);24 if (!manifestFile.exists()) {25 this.error(strings.GetStringFromName("validator.nonExistingFolder"));26 return null;27 }28 if (!manifestFile.isDirectory()) {29 this.error(strings.GetStringFromName("validator.expectProjectFolder"));30 return null;31 }32 let appManifestFile = manifestFile.clone();33 appManifestFile.append("manifest.webapp");34 let jsonManifestFile = manifestFile.clone();35 jsonManifestFile.append("manifest.json");36 let hasAppManifest = appManifestFile.exists() && appManifestFile.isFile();37 let hasJsonManifest = jsonManifestFile.exists() && jsonManifestFile.isFile();38 if (!hasAppManifest && !hasJsonManifest) {39 this.error(strings.GetStringFromName("validator.noManifestFile"));40 return null;41 }42 return hasAppManifest ? appManifestFile : jsonManifestFile;43};44AppValidator.prototype._getPackagedManifestURL = function () {45 let manifestFile = this._getPackagedManifestFile();46 if (!manifestFile) {47 return null;48 }49 return Services.io.newFileURI(manifestFile).spec;50};51AppValidator.checkManifest = function (manifestURL) {52 return new Promise((resolve, reject) => {53 let error;54 let req = new XMLHttpRequest();55 req.overrideMimeType("text/plain");56 try {57 req.open("GET", manifestURL, true);58 req.channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE | Ci.nsIRequest.INHIBIT_CACHING;59 } catch (e) {60 error = strings.formatStringFromName("validator.invalidManifestURL", [manifestURL], 1);61 return reject(error);62 }63 req.onload = function () {64 let manifest = null;65 try {66 manifest = JSON.parse(req.responseText);67 } catch (e) {68 error = strings.formatStringFromName("validator.invalidManifestJSON", [e, manifestURL], 2);69 reject(error);70 }71 resolve({manifest, manifestURL});72 };73 req.onerror = function () {74 error = strings.formatStringFromName("validator.noAccessManifestURL", [req.statusText, manifestURL], 2);75 reject(error);76 };77 try {78 req.send(null);79 } catch (e) {80 error = strings.formatStringFromName("validator.noAccessManifestURL", [e, manifestURL], 2);81 reject(error);82 }83 });84};85AppValidator.findManifestAtOrigin = function (manifestURL) {86 let fixedManifest = Services.io.newURI(manifestURL).prePath + "/manifest.webapp";87 return AppValidator.checkManifest(fixedManifest);88};89AppValidator.findManifestPath = function (manifestURL) {90 return new Promise((resolve, reject) => {91 if (manifestURL.endsWith("manifest.webapp")) {92 reject();93 } else {94 let fixedManifest = manifestURL + "/manifest.webapp";95 resolve(AppValidator.checkManifest(fixedManifest));96 }97 });98};99AppValidator.checkAlternateManifest = function (manifestURL) {100 return Task.spawn(function* () {101 let result;102 try {103 result = yield AppValidator.findManifestPath(manifestURL);104 } catch (e) {105 result = yield AppValidator.findManifestAtOrigin(manifestURL);106 }107 return result;108 });109};110AppValidator.prototype._fetchManifest = function (manifestURL) {111 return new Promise(resolve => {112 this.manifestURL = manifestURL;113 AppValidator.checkManifest(manifestURL)114 .then(({manifest, manifestURL}) => {115 resolve(manifest);116 }, error => {117 AppValidator.checkAlternateManifest(manifestURL)118 .then(({manifest, manifestURL}) => {119 this.manifestURL = manifestURL;120 resolve(manifest);121 }, () => {122 this.error(error);123 resolve(null);124 });125 });126 });127};128AppValidator.prototype._getManifest = function () {129 let manifestURL;130 if (this.type == "packaged") {131 manifestURL = this._getPackagedManifestURL();132 if (!manifestURL)133 return Promise.resolve(null);134 } else if (this.type == "hosted") {135 manifestURL = this.location;136 try {137 Services.io.newURI(manifestURL);138 } catch (e) {139 this.error(strings.formatStringFromName("validator.invalidHostedManifestURL", [manifestURL, e.message], 2));140 return Promise.resolve(null);141 }142 } else {143 this.error(strings.formatStringFromName("validator.invalidProjectType", [this.type], 1));144 return Promise.resolve(null);145 }146 return this._fetchManifest(manifestURL);147};148AppValidator.prototype.validateManifest = function (manifest) {149 if (!manifest.name) {150 this.error(strings.GetStringFromName("validator.missNameManifestProperty"));151 }152 if (!manifest.icons || Object.keys(manifest.icons).length === 0) {153 this.warning(strings.GetStringFromName("validator.missIconsManifestProperty"));154 } else if (!manifest.icons["128"]) {155 this.warning(strings.GetStringFromName("validator.missIconMarketplace2"));156 }157};158AppValidator.prototype._getOriginURL = function () {159 if (this.type == "packaged") {160 let manifestURL = Services.io.newURI(this.manifestURL);161 return Services.io.newURI(".", null, manifestURL).spec;162 } else if (this.type == "hosted") {163 return Services.io.newURI(this.location).prePath;164 }165};166AppValidator.prototype.validateLaunchPath = function (manifest) {167 return new Promise(resolve => {168 // The launch_path field has to start with a `/`169 if (manifest.launch_path && manifest.launch_path[0] !== "/") {170 this.error(strings.formatStringFromName("validator.nonAbsoluteLaunchPath", [manifest.launch_path], 1));171 resolve();172 }173 let origin = this._getOriginURL();174 let path;175 if (this.type == "packaged") {176 path = "." + (manifest.launch_path || "/index.html");177 } else if (this.type == "hosted") {178 path = manifest.launch_path || "/";179 }180 let indexURL;181 try {182 indexURL = Services.io.newURI(path, null, Services.io.newURI(origin)).spec;183 } catch (e) {184 this.error(strings.formatStringFromName("validator.accessFailedLaunchPath", [origin + path], 1));185 return resolve();186 }187 let req = new XMLHttpRequest();188 req.overrideMimeType("text/plain");189 try {190 req.open("HEAD", indexURL, true);191 req.channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE | Ci.nsIRequest.INHIBIT_CACHING;192 } catch (e) {193 this.error(strings.formatStringFromName("validator.accessFailedLaunchPath", [indexURL], 1));194 return resolve();195 }196 req.onload = () => {197 if (req.status >= 400)198 this.error(strings.formatStringFromName("validator.accessFailedLaunchPathBadHttpCode", [indexURL, req.status], 2));199 resolve();200 };201 req.onerror = () => {202 this.error(strings.formatStringFromName("validator.accessFailedLaunchPath", [indexURL], 1));203 resolve();204 };205 try {206 req.send(null);207 } catch (e) {208 this.error(strings.formatStringFromName("validator.accessFailedLaunchPath", [indexURL], 1));209 resolve();210 }211 });212};213AppValidator.prototype.validateType = function (manifest) {214 let appType = manifest.type || "web";215 if (!["web", "privileged", "certified"].includes(appType)) {216 this.error(strings.formatStringFromName("validator.invalidAppType", [appType], 1));217 } else if (this.type == "hosted" &&218 ["certified", "privileged"].includes(appType)) {219 this.error(strings.formatStringFromName("validator.invalidHostedPriviledges", [appType], 1));220 }221 // certified app are not fully supported on the simulator222 if (appType === "certified") {223 this.warning(strings.GetStringFromName("validator.noCertifiedSupport"));224 }225};226AppValidator.prototype.validate = function () {227 this.errors = [];228 this.warnings = [];229 return this._getManifest().230 then((manifest) => {231 if (manifest) {232 this.manifest = manifest;233 // Skip validations for add-ons234 if (manifest.role === "addon" || manifest.manifest_version) {235 return Promise.resolve();236 }237 this.validateManifest(manifest);238 this.validateType(manifest);239 return this.validateLaunchPath(manifest);240 }241 });242};...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run dbt-osmosis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful