Esempio n. 1
0
    def scan_manifest(self, manifest):
        """Return a dict of StoredResources based on an input manifest.

        Returns:
            A dict of store_filename to StoredResource
        """

        # Extend the list of import roots to include workspace roots
        top_roots = set()
        for stored_path in manifest.keys():
            if '/' in stored_path:  # Zip file paths use / on all platforms
                top_dir = stored_path.split('/', 1)[0]
                if top_dir not in top_roots:
                    top_roots.add(top_dir)
        import_roots = list(self.import_roots) + sorted(top_roots)

        # Include some files that every .par file needs at runtime
        stored_resources = {}
        for support_file in _runtime_support_files:
            resource = fetch_support_file(support_file, self.timestamp_tuple)
            stored_filename = resource.zipinfo.filename
            stored_resources[stored_filename] = resource

        # Scan manifest
        for stored_path, local_path in manifest.items():
            if local_path is None:
                stored_resources[stored_path] = stored_resource.EmptyFile(
                    stored_path, self.timestamp_tuple)
            else:
                stored_resources[stored_path] = stored_resource.StoredFile(
                    stored_path, self.timestamp_tuple, local_path)

        # Copy main entry point to well-known name
        if '__main__.py' in stored_resources:
            raise error.Error(
                ('Configuration error for [%s]: Manifest file included a '
                 'file named __main__.py, which is not allowed') %
                self.manifest_filename)
        stored_resources['__main__.py'] = self.generate_main(
            self.main_filename, self.generate_boilerplate(import_roots))

        # Add an __init__.py for each parent package of the support files
        for stored_filename in _runtime_init_files:
            if stored_filename in stored_resources:
                logging.debug('Skipping __init__.py already present [%s]',
                              stored_filename)
                continue
            stored_resources[stored_filename] = stored_resource.EmptyFile(
                stored_filename, self.timestamp_tuple)

        return stored_resources
Esempio n. 2
0
 def test_EmptyFile(self):
     name = 'foo/bar'
     resource = stored_resource.EmptyFile(name)
     self._write_and_check(resource, name, b'')