Exemplo n.º 1
0
    def test_softlink_with_broken_entry(self):
        self.maxDiff = None

        # Given
        path = VTK_EGG_DEFERRED_SOFTLINK
        expected_files = [
            os.path.join('EGG-INFO', 'PKG-INFO'),
            os.path.join('EGG-INFO', 'inst', 'targets.dat'),
            os.path.join('EGG-INFO', 'inst', 'files_to_install.txt'),
            os.path.join('EGG-INFO', 'usr', 'lib', 'vtk-5.10',
                         'libvtkViews.so.5.10.1'),
            os.path.join('EGG-INFO', 'usr', 'lib', 'vtk-5.10',
                         'libvtkViews.so.5.10'),
            os.path.join('EGG-INFO', 'usr', 'lib', 'vtk-5.10',
                         'libvtkViews.so'),
            os.path.join('EGG-INFO', 'spec', 'lib-provide'),
            os.path.join('EGG-INFO', 'spec', 'depend'),
            os.path.join('EGG-INFO', 'spec', 'lib-depend'),
            os.path.join('EGG-INFO', 'spec', 'summary'),
        ]

        with mkdtemp() as d:
            existing_link = os.path.join(
                d, 'EGG-INFO/usr/lib/vtk-5.10/libvtkViews.so')
            create_broken_symlink(existing_link)

            # When
            with ZipFile(path) as zp:
                zp.extractall(d)
            files = list_files(d)

            # Then
            assertCountEqual(self, files, expected_files)
            path = os.path.join(d, "EGG-INFO/usr/lib/vtk-5.10/libvtkViews.so")
            self.assertTrue(os.path.islink(path))
Exemplo n.º 2
0
    def test_endist_metadata_simple(self):
        # Given
        source = os.path.join(self.prefix, os.path.basename(NOSE_1_2_1))
        shutil.copy(NOSE_1_2_1, source)

        target = os.path.join(self.prefix, "babar-1.2.1-2.egg")
        endist = os.path.join(self.prefix, "endist.dat")
        with open(endist, "w") as fp:
            data = textwrap.dedent("""\
            packages = ["foo"]

            name = "babar"
            """)
            fp.write(data)

        # When
        with chdir(self.prefix):
            repack(source, 2, "rh5-64")

        # Then
        self.assertTrue(os.path.exists(target))
        with ZipFile(target) as zp:
            info = info_from_z(zp)
        assertCountEqual(self, info["packages"], ["foo"])
        assertCountEqual(self, info["name"], "babar")
Exemplo n.º 3
0
    def test_endist_add_files_simple(self):
        # Given
        source = os.path.join(self.prefix, os.path.basename(NOSE_1_2_1))
        shutil.copy(NOSE_1_2_1, source)

        target = os.path.join(self.prefix, "nose-1.2.1-2.egg")
        endist = os.path.join(self.prefix, "endist.dat")
        with open(endist, "w") as fp:
            data = textwrap.dedent("""\
            packages = ["foo"]

            add_files = [(".", "foo*", "EGG-INFO")]
            """)
            fp.write(data)
        fubar = os.path.join(self.prefix, "foo.txt")
        with open(fubar, "w") as fp:
            fp.write("babar")

        # When
        with chdir(self.prefix):
            repack(source, 2, "rh5-64")

        # Then
        self.assertTrue(os.path.exists(target))
        with ZipFile(target) as zp:
            data = zp.read("EGG-INFO/foo.txt").decode("utf8")
        self.assertEqual(data, "babar")
Exemplo n.º 4
0
def _create_dummy_enstaller_egg(prefix):
    path = os.path.join(prefix, "enstaller-4.8.0-1.egg")
    with ZipFile(path, "w") as fp:
        # We write a dummy file as empty zip files are not properly handled by
        # zipfile in python 2.6
        fp.writestr("EGG-INFO/dummy", "")
    return path
Exemplo n.º 5
0
 def from_egg(cls, path):
     """
     Create an instance from an egg filename.
     """
     with ZipFile(path) as zp:
         metadata = info_from_z(zp)
     metadata["packages"] = metadata.get("packages", [])
     return cls.from_json_dict(os.path.basename(path), metadata)
Exemplo n.º 6
0
def extract_egg(path, to):
    usr = posixpath.join(EGG_INFO, "usr")

    with ZipFile(path) as zp:
        for p in zp.infolist():
            if p.filename.startswith(usr):
                target = os.path.relpath(p.filename, usr)
                zp.extract_to(p, target, to)
Exemplo n.º 7
0
def _create_inmemory_egg(archives):
    s = BytesIO()
    with ZipFile(s, "w") as z:
        for arcname, data in archives.items():
            z.writestr(arcname, data)
    s.seek(0)

    return s
Exemplo n.º 8
0
    def test_extract(self):
        # Given
        path = NOSE_1_3_0
        arcname = "EGG-INFO/PKG-INFO"

        # When
        with mkdtemp() as d:
            with ZipFile(path) as zp:
                zp.extract(arcname, d)
            self.assertTrue(os.path.exists(os.path.join(d, arcname)))
Exemplo n.º 9
0
 def from_egg(cls, path, ctime, store_location):
     """
     Create an instance from an egg filename.
     """
     with ZipFile(path) as zp:
         metadata = info_from_z(zp)
     metadata["packages"] = metadata.get("packages", [])
     metadata["ctime"] = ctime
     metadata["store_location"] = store_location
     metadata["key"] = os.path.basename(path)
     return cls.from_installed_meta_dict(metadata)
Exemplo n.º 10
0
    def test_setuptools_egg_with_ext(self):
        # Given
        source = os.path.join(self.prefix, os.path.basename(STANDARD_EGG_WITH_EXT))
        shutil.copy(STANDARD_EGG_WITH_EXT, source)

        target = os.path.join(self.prefix, "PyYAML-3.11-1.egg")

        # When
        repack(source, 1, "rh5-64")

        # Then
        self.assertTrue(os.path.exists(target))
        with ZipFile(target) as zp:
            zp.read("EGG-INFO/spec/depend")
Exemplo n.º 11
0
    def test_simple_setuptools_egg(self):
        # Given
        source = os.path.join(self.prefix, os.path.basename(STANDARD_EGG))
        shutil.copy(STANDARD_EGG, source)

        target = os.path.join(self.prefix, "Jinja2-2.6-1.egg")

        # When
        repack(source, 1, "rh5-64")

        # Then
        self.assertTrue(os.path.exists(target))
        with ZipFile(target) as zp:
            zp.read("jinja2/__init__.py")
Exemplo n.º 12
0
def _looks_like_enthought_egg(path):
    """ Returns True if the give file looks like an enthought egg.
    """
    filename = os.path.basename(path)

    if is_egg_name_valid(filename):
        with ZipFile(path) as zp:
            try:
                zp.getinfo(_SPEC_DEPEND_LOCATION)
                return True
            except KeyError:
                pass

    return False
Exemplo n.º 13
0
    def test_softlink(self):
        # Given
        path = ZIP_WITH_SOFTLINK

        # When/Then
        with mkdtemp() as d:
            with ZipFile(path) as zp:
                zp.extractall(d)
            paths = list_files(d)

            assertCountEqual(self, paths, [
                os.path.join("lib", "foo.so.1.3"),
                os.path.join("lib", "foo.so")
            ])
            self.assertTrue(os.path.islink(os.path.join(d, "lib", "foo.so")))
Exemplo n.º 14
0
    def test_extract_to(self):
        # Given
        path = NOSE_1_3_0
        arcname = "EGG-INFO/PKG-INFO"

        # When
        with mkdtemp() as d:
            with ZipFile(path) as zp:
                zp.extract_to(arcname, "FOO", d)
                extracted_data = zp.read(arcname)
            self.assertTrue(os.path.exists(os.path.join(d, "FOO")))
            self.assertEqual(compute_md5(os.path.join(d, "FOO")),
                             compute_md5(BytesIO(extracted_data)))
            self.assertFalse(
                os.path.exists(os.path.join(d, "EGG-INFO", "PKG-INFO")))
Exemplo n.º 15
0
    def test_simple(self):
        r_metadata = {
            "name": "numpy",
            "version": "1.4.0",
            "build": 3,
            "arch": "x86",
            "platform": "win32",
            "osdist": None,
            "python": "2.6",
            "packages": [],
            "type": "egg",
        }

        s = _create_inmemory_egg({"EGG-INFO/spec/depend": NUMPY_1_4_0_WIN32})
        with ZipFile(s) as z:
            metadata = info_from_z(z)
            self.assertEqual(metadata, r_metadata)
Exemplo n.º 16
0
    def test_name_casing(self):
        r_metadata = {
            "name": "pil",
            "version": "1.1.7",
            "build": 3,
            "arch": "x86",
            "platform": "win32",
            "osdist": None,
            "python": "2.7",
            "packages": [],
            "type": "egg",
        }

        s = _create_inmemory_egg({"EGG-INFO/spec/depend": PIL_1_1_7_WIN32})
        with ZipFile(s) as z:
            metadata = info_from_z(z)
            self.assertEqual(metadata, r_metadata)
Exemplo n.º 17
0
def is_custom_egg(egg):
    """
    Return True if the egg is built using Enthought build infrastructure, False
    otherwise.

    Note
    ----
    This is not 100 % reliable, as some Enthought eggs don't always have any
    specific metadata.
    """
    with ZipFile(egg) as zp:
        for dest in ("spec/depend", "inst/targets.dat"):
            try:
                zp.getinfo("EGG-INFO/{0}".format(dest))
                return True
            except KeyError:
                pass
        return False
Exemplo n.º 18
0
    def test_proxy_directory(self):
        """
        Test we handle correctly entries of the form 'path some_directory'.
        """
        with mkdtemp() as prefix:
            with mock.patch("sys.executable", os.path.join(prefix, "python.exe")):
                egginst = EggInst(DUMMY_EGG_WITH_PROXY_SCRIPTS, prefix)
                with ZipFile(egginst.path) as zp:
                    egginst.z = zp
                    egginst.arcnames = zp.namelist()
                    create_proxies(egginst)

                    proxied_files = [
                        os.path.join(prefix, "Scripts", "dummy.dll"),
                        os.path.join(prefix, "Scripts", "dummy.lib"),
                    ]
                    for proxied_file in proxied_files:
                        self.assertTrue(os.path.exists(proxied_file))
Exemplo n.º 19
0
    def test_proxy(self):
        """
        Test we handle correctly entries of the form 'path PROXY'.
        """
        r_python_proxy_data_template = """\
#!"%(executable)s"
# This proxy was created by egginst from an egg with special instructions
#
import sys
import subprocess

src = %(src)r

sys.exit(subprocess.call([src] + sys.argv[1:]))
"""

        with mkdtemp() as prefix:
            with mock.patch("sys.executable", os.path.join(prefix, "python.exe")):
                proxy_path = os.path.join(prefix, "EGG-INFO", "dummy_with_proxy", "usr", "swig.exe")
                if PY2:
                    proxy_path = proxy_path.decode("utf8")
                r_python_proxy_data = r_python_proxy_data_template % \
                    {'executable': os.path.join(prefix, "python.exe"),
                     'src': proxy_path}

                egginst = EggInst(DUMMY_EGG_WITH_PROXY, prefix)
                with ZipFile(egginst.path) as zp:
                    egginst.z = zp
                    egginst.arcnames = zp.namelist()
                    create_proxies(egginst)

                    python_proxy = os.path.join(prefix, "Scripts", "swig-script.py")
                    coff_proxy = os.path.join(prefix, "Scripts", "swig.exe")

                    self.assertTrue(os.path.exists(python_proxy))
                    self.assertTrue(os.path.exists(coff_proxy))

                    self.assertTrue(compute_md5(coff_proxy),
                                    hashlib.md5(exe_data.cli).hexdigest())

                    with open(python_proxy, "rt") as fp:
                        python_proxy_data = fp.read()
                        self.assertMultiLineEqual(python_proxy_data,
                                                  r_python_proxy_data)
Exemplo n.º 20
0
    def test_repack_default_platform(self):
        # Given
        source = os.path.join(self.prefix, "nose-1.2.1-py2.7.egg")
        shutil.copy(STANDARD_EGG, source)

        target = os.path.join(self.prefix, "nose-1.2.1-1.egg")

        # When
        mocked = "enstaller.tools.repack.LegacyEPDPlatform." \
                 "from_running_system"
        platform = LegacyEPDPlatform.from_epd_platform_string("rh5-32")
        with mock.patch(mocked, return_value=platform):
            repack(source, 1)

        # Then
        self.assertTrue(os.path.exists(target))
        with ZipFile(target) as zp:
            spec = info_from_z(zp)
        self.assertEqual(spec["arch"], "x86")
Exemplo n.º 21
0
    def test_simple(self):
        # Given
        path = NOSE_1_3_0
        r_paths = [
            os.path.join("EGG-INFO", "entry_points.txt"),
            os.path.join("EGG-INFO", "PKG-INFO"),
            os.path.join("EGG-INFO", "spec", "depend"),
            os.path.join("EGG-INFO", "spec", "summary"),
            os.path.join("EGG-INFO", "usr", "share", "man", "man1",
                         "nosetests.1"),
        ]

        # When
        with mkdtemp() as d:
            with ZipFile(path) as zp:
                zp.extractall(d)
            paths = list_files(d)

        # Then
        assertCountEqual(self, paths, r_paths)
Exemplo n.º 22
0
    def from_egg(cls, path, store_location=""):
        """
        Create an instance from an egg filename.
        """
        with ZipFile(path) as zp:
            metadata = info_from_z(zp)

        if len(store_location) == 0:
            store_location = path_to_uri(os.path.dirname(path)) + "/"

        if not store_location.endswith("/"):
            msg = "Invalid uri for store location: {0!r} (expected an uri " \
                  "ending with '/')".format(store_location)
            raise ValueError(msg)

        metadata["packages"] = metadata.get("packages", [])
        st = os.stat(path)
        metadata["size"] = st.st_size
        metadata["md5"] = compute_md5(path)
        metadata["mtime"] = st.st_mtime
        metadata["store_location"] = store_location
        return cls.from_json_dict(os.path.basename(path), metadata)
Exemplo n.º 23
0
def repack(source_egg_path, build_number=1, platform_string=None):
    legacy_spec = _get_spec(source_egg_path, build_number, platform_string)

    parent_dir = os.path.dirname(os.path.abspath(source_egg_path))
    target_egg_path = os.path.join(parent_dir, legacy_spec.egg_name)

    if os.path.exists(target_egg_path) and \
            samefile(source_egg_path, target_egg_path):
        msg = "source and repack-ed egg are the same file: {0!r}. Inplace " \
              "mode not yet implemented."
        raise EnstallerException(msg.format(source_egg_path))
    # XXX: implement endist.dat/app handling

    print(20 * '-' + '\n' + legacy_spec.to_string() + 20 * '-')
    shutil.copy2(source_egg_path, target_egg_path)

    with ZipFile(target_egg_path, "a") as target:
        target.writestr(_SPEC_DEPEND_LOCATION, legacy_spec.to_string())

        if os.path.exists(ENDIST_DAT):
            data = _parse_endist_for_egg_content(ENDIST_DAT)
            for entry in data.get("add_files", []):
                _add_files(target, entry[0], entry[1], entry[2])
Exemplo n.º 24
0
def _create_egg_with_symlink(filename, name):
    with ZipFile(filename, "w") as fp:
        fp.writestr("EGG-INFO/usr/include/foo.h", "/* header */")
        zip_write_symlink(fp, "EGG-INFO/usr/HEADERS", "include")