Пример #1
0
    def _upload_application_directory(self, app: Entity,
                                      application_path: str):
        _logger.debug("Uploading application from directory %s",
                      application_path)
        _, temp_file = tempfile.mkstemp()
        try:
            resource_descriptions_by_path = PushOperation._load_all_resources(
                application_path)

            def generate_key(item: dict):
                return "%s-%d" % (item["sha1"], item["size"])

            already_uploaded_entries = [
                generate_key(item) for item in self.client.v2.resources.match([
                    dict(sha1=item["sha1"], size=item["size"])
                    for item in resource_descriptions_by_path.values()
                ])
            ]
            _logger.debug("Already uploaded %d / %d items",
                          len(already_uploaded_entries),
                          len(resource_descriptions_by_path))

            FileHelper.zip(
                temp_file,
                application_path,
                lambda item: item in resource_descriptions_by_path and
                generate_key(resource_descriptions_by_path[item]
                             ) not in already_uploaded_entries,
            )
            _logger.debug("Diff zip file built: %s", temp_file)
            resources = [
                dict(
                    fn=resource_path,
                    sha1=resource_description["sha1"],
                    size=resource_description["size"],
                    mode=resource_description["mode"],
                ) for resource_path, resource_description in
                resource_descriptions_by_path.items() if generate_key(
                    resource_description) in already_uploaded_entries
            ]
            _logger.debug("Uploading bits of application")
            job = self.client.v2.apps.upload(app["metadata"]["guid"],
                                             resources, temp_file, True)
            self._poll_job(job)
        finally:
            _logger.debug("Skipping remove of zip file")
Пример #2
0
    def _upload_application_directory(self, app, path):
        _logger.debug('Uploading application from directory %s', path)
        _, temp_file = tempfile.mkstemp()
        try:
            resource_descriptions_by_path = PushOperation._load_all_resources(
                path)

            def generate_key(item):
                return '%s-%d' % (item["sha1"], item["size"])

            already_uploaded_entries = [
                generate_key(item) for item in self.client.v2.resources.match([
                    dict(sha1=item["sha1"], size=item["size"])
                    for item in resource_descriptions_by_path.values()
                ])
            ]
            _logger.debug('Already uploaded %d / %d items',
                          len(already_uploaded_entries),
                          len(resource_descriptions_by_path))

            FileHelper.zip(
                temp_file, path,
                lambda item: generate_key(resource_descriptions_by_path[item]
                                          ) not in already_uploaded_entries)
            _logger.debug('Diff zip file built: %s', temp_file)
            resources = [
                dict(fn=resource_path,
                     sha1=resource_description["sha1"],
                     size=resource_description["size"],
                     mode=resource_description["mode"]) for resource_path,
                resource_description in resource_descriptions_by_path.items()
                if generate_key(
                    resource_description) in already_uploaded_entries
            ]
            _logger.debug('Uploading bits of application')
            job = self.client.v2.apps.upload(app['metadata']['guid'],
                                             resources, temp_file, True)
            self._poll_job(job)
        finally:
            _logger.debug('Skipping remove of zip file')