Пример #1
0
 def _process_namespace(self, src_zip):
     if self.options.get('namespace_tokenize'):
         src_zip = zip_tokenize_namespace(
             src_zip, self.options['namespace_tokenize'])
     if self.options.get('namespace_inject'):
         if self.options.get('unmanaged'):
             src_zip = zip_inject_namespace(
                 src_zip, self.options['namespace_inject'])
         else:
             src_zip = zip_inject_namespace(
                 src_zip, self.options['namespace_inject'], True)
     if self.options.get('namespace_strip'):
         src_zip = zip_strip_namespace(src_zip,
                                       self.options['namespace_strip'])
     return src_zip
Пример #2
0
 def _process_namespace(self, zipf):
     if self.options.get('namespace_tokenize'):
         self.logger.info(
             'Tokenizing namespace prefix {}__'.format(
                 self.options['namespace_tokenize'],
             )
         )
         zipf = zip_tokenize_namespace(zipf, self.options['namespace_tokenize'], logger=self.logger)
     if self.options.get('namespace_inject'):
         kwargs = {}
         kwargs['managed'] = not process_bool_arg(self.options.get('unmanaged', True))
         kwargs['namespaced_org'] = process_bool_arg(self.options.get('namespaced_org', False))
         kwargs['logger'] = self.logger
         if kwargs['managed']:
             self.logger.info(
                 'Replacing namespace tokens from metadata with namespace prefix {}__'.format(
                     self.options['namespace_inject'],
                 )
             )
         else:
             self.logger.info(
                 'Stripping namespace tokens from metadata for unmanaged deployment'
             )
         zipf = zip_inject_namespace(zipf, self.options['namespace_inject'], **kwargs)
     if self.options.get('namespace_strip'):
         zipf = zip_strip_namespace(zipf, self.options['namespace_strip'], logger=self.logger)
     return zipf
Пример #3
0
 def _process_namespace(self, zipf):
     if self.options.get("namespace_tokenize"):
         self.logger.info("Tokenizing namespace prefix {}__".format(
             self.options["namespace_tokenize"]))
         zipf = zip_tokenize_namespace(zipf,
                                       self.options["namespace_tokenize"],
                                       logger=self.logger)
     if self.options.get("namespace_inject"):
         kwargs = {}
         kwargs["managed"] = not process_bool_arg(
             self.options.get("unmanaged", True))
         kwargs["namespaced_org"] = process_bool_arg(
             self.options.get("namespaced_org", False))
         kwargs["logger"] = self.logger
         if kwargs["managed"]:
             self.logger.info(
                 "Replacing namespace tokens from metadata with namespace prefix {}__"
                 .format(self.options["namespace_inject"]))
         else:
             self.logger.info(
                 "Stripping namespace tokens from metadata for unmanaged deployment"
             )
         zipf = zip_inject_namespace(zipf, self.options["namespace_inject"],
                                     **kwargs)
     if self.options.get("namespace_strip"):
         zipf = zip_strip_namespace(zipf,
                                    self.options["namespace_strip"],
                                    logger=self.logger)
     return zipf
Пример #4
0
    def test_zip_inject_namespace_skips_binary(self):
        contents = b'\xe2\x98\x83%%%NAMESPACE%%%'
        zf = zipfile.ZipFile(io.BytesIO(), 'w')
        zf.writestr('test', contents)

        zf = utils.zip_inject_namespace(zf, namespace='ns', managed=True, namespaced_org=True)
        result = zf.read('test')
        self.assertEqual(contents, result)
Пример #5
0
    def test_zip_inject_namespace_unmanaged(self):
        zf = zipfile.ZipFile(io.BytesIO(), 'w')
        zf.writestr(
            '___NAMESPACE___test',
            '%%%NAMESPACE%%%|%%%NAMESPACED_ORG%%%|%%%NAMESPACE_OR_C%%%|%%%NAMESPACED_ORG_OR_C%%%')

        zf = utils.zip_inject_namespace(zf, namespace='ns')
        result = zf.read('test')
        self.assertEqual('||c|c', result)
Пример #6
0
    def test_zip_inject_namespace_namespaced_org(self):
        zf = zipfile.ZipFile(io.BytesIO(), 'w')
        zf.writestr(
            '___NAMESPACE___test',
            '%%%NAMESPACE%%%|%%%NAMESPACED_ORG%%%|%%%NAMESPACE_OR_C%%%|%%%NAMESPACED_ORG_OR_C%%%')

        zf = utils.zip_inject_namespace(zf, namespace='ns', managed=True, namespaced_org=True)
        result = zf.read('ns__test')
        self.assertEqual('ns__|ns__|ns|ns', result)
Пример #7
0
    def _install_dependency(self, dependency):
        if 'zip_url' in dependency:
            self.logger.info(
                'Deploying unmanaged metadata from /{} of {}'.format(
                    dependency['subfolder'],
                    dependency['zip_url'],
                ))
            package_zip = download_extract_zip(
                dependency['zip_url'],
                subfolder=dependency.get('subfolder'),
                headers=dependency.get('headers', {}),
            )
            if dependency.get('namespace_tokenize'):
                self.logger.info(
                    'Replacing namespace prefix {}__ in files and filenames with namespace token strings'
                    .format('{}__'.format(dependency['namespace_tokenize']), ))
                package_zip = zip_tokenize_namespace(
                    package_zip,
                    namespace=dependency['namespace_tokenize'],
                    logger=self.logger,
                )

            if dependency.get('namespace_inject'):
                self.logger.info('Replacing namespace tokens with {}'.format(
                    '{}__'.format(dependency['namespace_inject']), ))
                package_zip = zip_inject_namespace(
                    package_zip,
                    namespace=dependency['namespace_inject'],
                    managed=not dependency.get('unmanaged'),
                    namespaced_org=self.options['namespaced_org'],
                    logger=self.logger,
                )

            if dependency.get('namespace_strip'):
                self.logger.info(
                    'Removing namespace prefix {}__ from all files and filenames'
                    .format('{}__'.format(dependency['namespace_strip']), ))
                package_zip = zip_strip_namespace(
                    package_zip,
                    namespace=dependency['namespace_strip'],
                    logger=self.logger,
                )

            package_zip = ZipfilePackageZipBuilder(package_zip)()

        elif 'namespace' in dependency:
            self.logger.info('Installing {} version {}'.format(
                dependency['namespace'],
                dependency['version'],
            ))
            package_zip = InstallPackageZipBuilder(dependency['namespace'],
                                                   dependency['version'])()

        api = self.api_class(self,
                             package_zip,
                             purge_on_delete=self.options['purge_on_delete'])
        return api()
Пример #8
0
    def test_zip_inject_namespace__skips_binary(self):
        contents = b"\x9c%%%NAMESPACE%%%"
        zf = zipfile.ZipFile(io.BytesIO(), "w")
        zf.writestr("test", contents)

        zf = utils.zip_inject_namespace(
            zf, namespace="ns", managed=True, namespaced_org=True
        )
        result = zf.read("test")
        self.assertEqual(contents, result)
Пример #9
0
    def test_zip_inject_namespace__skips_binary(self):
        contents = b"\x9c%%%NAMESPACE%%%"
        zf = zipfile.ZipFile(io.BytesIO(), "w")
        zf.writestr("test", contents)

        zf = utils.zip_inject_namespace(
            zf, namespace="ns", managed=True, namespaced_org=True
        )
        result = zf.read("test")
        self.assertEqual(contents, result)
Пример #10
0
    def test_zip_inject_namespace_unmanaged(self):
        zf = zipfile.ZipFile(io.BytesIO(), "w")
        zf.writestr(
            "___NAMESPACE___test",
            "%%%NAMESPACE%%%|%%%NAMESPACED_ORG%%%|%%%NAMESPACE_OR_C%%%|%%%NAMESPACED_ORG_OR_C%%%",
        )

        zf = utils.zip_inject_namespace(zf, namespace="ns")
        result = zf.read("test")
        self.assertEqual(b"||c|c", result)
Пример #11
0
    def test_zip_inject_namespace_unmanaged(self):
        zf = zipfile.ZipFile(io.BytesIO(), "w")
        zf.writestr(
            "___NAMESPACE___test",
            "%%%NAMESPACE%%%|%%%NAMESPACED_ORG%%%|%%%NAMESPACE_OR_C%%%|%%%NAMESPACED_ORG_OR_C%%%",
        )

        zf = utils.zip_inject_namespace(zf, namespace="ns")
        result = zf.read("test")
        self.assertEqual(b"||c|c", result)
Пример #12
0
    def test_zip_inject_namespace_managed(self):
        logger = mock.Mock()
        zf = zipfile.ZipFile(io.BytesIO(), "w")
        zf.writestr(
            "___NAMESPACE___test",
            "%%%NAMESPACE%%%|%%%NAMESPACED_ORG%%%|%%%NAMESPACE_OR_C%%%|%%%NAMESPACED_ORG_OR_C%%%",
        )

        zf = utils.zip_inject_namespace(zf, namespace="ns", managed=True, logger=logger)
        result = zf.read("ns__test")
        self.assertEqual(b"ns__||ns|c", result)
Пример #13
0
    def test_zip_inject_namespace_managed(self):
        logger = mock.Mock()
        zf = zipfile.ZipFile(io.BytesIO(), 'w')
        zf.writestr(
            '___NAMESPACE___test',
            '%%%NAMESPACE%%%|%%%NAMESPACED_ORG%%%|%%%NAMESPACE_OR_C%%%|%%%NAMESPACED_ORG_OR_C%%%')

        zf = utils.zip_inject_namespace(
            zf, namespace='ns', managed=True, logger=logger)
        result = zf.read('ns__test')
        self.assertEqual('ns__||ns|c', result)
Пример #14
0
    def test_zip_inject_namespace_managed(self):
        logger = mock.Mock()
        zf = zipfile.ZipFile(io.BytesIO(), "w")
        zf.writestr(
            "___NAMESPACE___test",
            "%%%NAMESPACE%%%|%%%NAMESPACED_ORG%%%|%%%NAMESPACE_OR_C%%%|%%%NAMESPACED_ORG_OR_C%%%",
        )

        zf = utils.zip_inject_namespace(zf, namespace="ns", managed=True, logger=logger)
        result = zf.read("ns__test")
        self.assertEqual(b"ns__||ns|c", result)
Пример #15
0
    def test_zip_inject_namespace_namespaced_org(self):
        zf = zipfile.ZipFile(io.BytesIO(), "w")
        zf.writestr(
            "___NAMESPACE___test",
            "%%%NAMESPACE%%%|%%%NAMESPACED_ORG%%%|%%%NAMESPACE_OR_C%%%|%%%NAMESPACED_ORG_OR_C%%%",
        )

        zf = utils.zip_inject_namespace(
            zf, namespace="ns", managed=True, namespaced_org=True
        )
        result = zf.read("ns__test")
        self.assertEqual(b"ns__|ns__|ns|ns", result)
Пример #16
0
    def test_zip_inject_namespace_namespaced_org(self):
        zf = zipfile.ZipFile(io.BytesIO(), "w")
        zf.writestr(
            "___NAMESPACE___test",
            "%%%NAMESPACE%%%|%%%NAMESPACED_ORG%%%|%%%NAMESPACE_OR_C%%%|%%%NAMESPACED_ORG_OR_C%%%",
        )

        zf = utils.zip_inject_namespace(
            zf, namespace="ns", managed=True, namespaced_org=True
        )
        result = zf.read("ns__test")
        self.assertEqual(b"ns__|ns__|ns|ns", result)
Пример #17
0
    def _install_dependency(self, dependency):
        if "zip_url" in dependency:
            self.logger.info(
                "Deploying unmanaged metadata from /{} of {}".format(
                    dependency["subfolder"], dependency["zip_url"]))
            package_zip = download_extract_zip(
                dependency["zip_url"],
                subfolder=dependency.get("subfolder"),
                headers=dependency.get("headers", {}),
            )
            if dependency.get("namespace_tokenize"):
                self.logger.info(
                    "Replacing namespace prefix {}__ in files and filenames with namespace token strings"
                    .format("{}__".format(dependency["namespace_tokenize"])))
                package_zip = zip_tokenize_namespace(
                    package_zip,
                    namespace=dependency["namespace_tokenize"],
                    logger=self.logger,
                )

            if dependency.get("namespace_inject"):
                self.logger.info("Replacing namespace tokens with {}".format(
                    "{}__".format(dependency["namespace_inject"])))
                package_zip = zip_inject_namespace(
                    package_zip,
                    namespace=dependency["namespace_inject"],
                    managed=not dependency.get("unmanaged"),
                    namespaced_org=self.options["namespaced_org"],
                    logger=self.logger,
                )

            if dependency.get("namespace_strip"):
                self.logger.info(
                    "Removing namespace prefix {}__ from all files and filenames"
                    .format("{}__".format(dependency["namespace_strip"])))
                package_zip = zip_strip_namespace(
                    package_zip,
                    namespace=dependency["namespace_strip"],
                    logger=self.logger,
                )

            package_zip = ZipfilePackageZipBuilder(package_zip)()

        elif "namespace" in dependency:
            self.logger.info("Installing {} version {}".format(
                dependency["namespace"], dependency["version"]))
            package_zip = InstallPackageZipBuilder(dependency["namespace"],
                                                   dependency["version"])()

        api = self.api_class(self,
                             package_zip,
                             purge_on_delete=self.options["purge_on_delete"])
        return api()
Пример #18
0
 def _process_namespace(self, zipf):
     if self.options.get('namespace_tokenize'):
         self.logger.info('Tokenizing namespace prefix {}__'.format(
             self.options['namespace_tokenize'], ))
         zipf = zip_tokenize_namespace(zipf,
                                       self.options['namespace_tokenize'])
     if self.options.get('namespace_inject'):
         if self.options.get('unmanaged'):
             self.logger.info(
                 'Stripping namespace tokens from metadata for unmanaged deployment'
             )
             zipf = zip_inject_namespace(zipf,
                                         self.options['namespace_inject'])
         else:
             self.logger.info(
                 'Replacing namespace tokens from metadata with namespace prefix {}__'
                 .format(self.options['namespace_inject'], ))
             zipf = zip_inject_namespace(zipf,
                                         self.options['namespace_inject'],
                                         True)
     if self.options.get('namespace_strip'):
         zipf = zip_strip_namespace(zipf, self.options['namespace_strip'])
     return zipf
Пример #19
0
 def _process_namespace(self, src_zip):
     if self.options.get("namespace_tokenize"):
         src_zip = zip_tokenize_namespace(
             src_zip,
             self.options["namespace_tokenize"],
             logger=self.logger)
     if self.options.get("namespace_inject"):
         kwargs = {}
         kwargs["managed"] = not process_bool_arg(
             self.options.get("unmanaged", True))
         kwargs["namespaced_org"] = process_bool_arg(
             self.options.get("namespaced_org", False))
         kwargs["logger"] = self.logger
         src_zip = zip_inject_namespace(src_zip,
                                        self.options["namespace_inject"],
                                        **kwargs)
     if self.options.get("namespace_strip"):
         src_zip = zip_strip_namespace(src_zip,
                                       self.options["namespace_strip"],
                                       logger=self.logger)
     return src_zip
Пример #20
0
 def _process_namespace(self, src_zip):
     if self.options.get('namespace_tokenize'):
         src_zip = zip_tokenize_namespace(
             src_zip,
             self.options['namespace_tokenize'],
             logger=self.logger)
     if self.options.get('namespace_inject'):
         kwargs = {}
         kwargs['unmanaged'] = process_bool_arg(
             self.options.get('unmanaged', True))
         kwargs['namespaced_org'] = process_bool_arg(
             self.options.get('namespaced_org', False))
         kwargs['logger'] = self.logger
         src_zip = zip_inject_namespace(src_zip,
                                        self.options['namespace_inject'],
                                        **kwargs)
     if self.options.get('namespace_strip'):
         src_zip = zip_strip_namespace(src_zip,
                                       self.options['namespace_strip'],
                                       logger=self.logger)
     return src_zip
 def _process_namespace(self, src_zip):
     if self.options.get("namespace_tokenize"):
         src_zip = zip_tokenize_namespace(
             src_zip, self.options["namespace_tokenize"], logger=self.logger
         )
     if self.options.get("namespace_inject"):
         kwargs = {}
         kwargs["managed"] = not process_bool_arg(
             self.options.get("unmanaged", True)
         )
         kwargs["namespaced_org"] = process_bool_arg(
             self.options.get("namespaced_org", False)
         )
         kwargs["logger"] = self.logger
         src_zip = zip_inject_namespace(
             src_zip, self.options["namespace_inject"], **kwargs
         )
     if self.options.get("namespace_strip"):
         src_zip = zip_strip_namespace(
             src_zip, self.options["namespace_strip"], logger=self.logger
         )
     return src_zip
Пример #22
0
 def _process_namespace(self, zipf):
     if self.options.get("namespace_tokenize"):
         self.logger.info(
             "Tokenizing namespace prefix {}__".format(
                 self.options["namespace_tokenize"]
             )
         )
         zipf = zip_tokenize_namespace(
             zipf, self.options["namespace_tokenize"], logger=self.logger
         )
     if self.options.get("namespace_inject"):
         kwargs = {}
         kwargs["managed"] = not process_bool_arg(
             self.options.get("unmanaged", True)
         )
         kwargs["namespaced_org"] = process_bool_arg(
             self.options.get("namespaced_org", False)
         )
         kwargs["logger"] = self.logger
         if kwargs["managed"]:
             self.logger.info(
                 "Replacing namespace tokens from metadata with namespace prefix {}__".format(
                     self.options["namespace_inject"]
                 )
             )
         else:
             self.logger.info(
                 "Stripping namespace tokens from metadata for unmanaged deployment"
             )
         zipf = zip_inject_namespace(
             zipf, self.options["namespace_inject"], **kwargs
         )
     if self.options.get("namespace_strip"):
         zipf = zip_strip_namespace(
             zipf, self.options["namespace_strip"], logger=self.logger
         )
     return zipf
    def _install_dependency(self, dependency):
        if "zip_url" or "repo_name" in dependency:
            package_zip = None
            if "zip_url" in dependency:
                self.logger.info(
                    "Deploying unmanaged metadata from /{} of {}".format(
                        dependency["subfolder"], dependency["zip_url"]
                    )
                )
                package_zip = self._download_extract_zip(
                    dependency["zip_url"], subfolder=dependency.get("subfolder")
                )
            elif "repo_name" in dependency:
                self.logger.info(
                    "Deploying unmanaged metadata from /{} of {}/{}".format(
                        dependency["subfolder"],
                        dependency["repo_owner"],
                        dependency["repo_name"],
                    )
                )
                package_zip = self._download_extract_github(
                    self.project_config.get_github_api(),
                    dependency["repo_owner"],
                    dependency["repo_name"],
                    dependency["subfolder"],
                    ref=dependency.get("ref"),
                )

            if package_zip:
                if dependency.get("namespace_tokenize"):
                    self.logger.info(
                        "Replacing namespace prefix {}__ in files and filenames with namespace token strings".format(
                            "{}__".format(dependency["namespace_tokenize"])
                        )
                    )
                    package_zip = zip_tokenize_namespace(
                        package_zip,
                        namespace=dependency["namespace_tokenize"],
                        logger=self.logger,
                    )

                if dependency.get("namespace_inject"):
                    self.logger.info(
                        "Replacing namespace tokens with {}".format(
                            "{}__".format(dependency["namespace_inject"])
                        )
                    )
                    package_zip = zip_inject_namespace(
                        package_zip,
                        namespace=dependency["namespace_inject"],
                        managed=not dependency.get("unmanaged"),
                        namespaced_org=self.options["namespaced_org"],
                        logger=self.logger,
                    )

                if dependency.get("namespace_strip"):
                    self.logger.info(
                        "Removing namespace prefix {}__ from all files and filenames".format(
                            "{}__".format(dependency["namespace_strip"])
                        )
                    )
                    package_zip = zip_strip_namespace(
                        package_zip,
                        namespace=dependency["namespace_strip"],
                        logger=self.logger,
                    )

                package_zip = ZipfilePackageZipBuilder(package_zip)()

            elif "namespace" in dependency:
                self.logger.info(
                    "Installing {} version {}".format(
                        dependency["namespace"], dependency["version"]
                    )
                )
                package_zip = InstallPackageZipBuilder(
                    dependency["namespace"], dependency["version"]
                )()

        api = self.api_class(
            self, package_zip, purge_on_delete=self.options["purge_on_delete"]
        )
        return api()