def _run(self, dir): spec = self.get_spec() if spec.is_dir(): pdir = os.path.abspath(spec.dirname) elif spec.is_file(): pdir = archive.from_file(spec.filename).unpack(dir) elif not spec.is_local(): self.opts.target = dir fn = Download(self.opts).run() pdir = archive.from_file(fn).unpack(dir) else: assert False self.maybe_run_configure(pdir) self._inun(pdir)
def get_meta(self, spec): """ Return the content of the ``META.json`` file for *spec*. Return the object obtained parsing the JSON. """ if spec.is_name(): # Get the metadata from the API try: data = self.api.dist(spec.name) except NotFound: # Distro not found: maybe it's an extension? ext = self.api.ext(spec.name) name, ver = self.get_best_version_from_ext(ext, spec) return self.api.meta(name, ver) else: ver = self.get_best_version(data, spec) return self.api.meta(spec.name, ver) elif spec.is_dir(): # Get the metadata from a directory fn = os.path.join(spec.dirname, 'META.json') logger.debug("reading %s", fn) if not os.path.exists(fn): raise PgxnClientException( _("file 'META.json' not found in '%s'") % spec.dirname ) with open(fn) as f: return load_json(f) elif spec.is_file(): arc = archive.from_spec(spec) return arc.get_meta() elif spec.is_url(): with network.get_file(spec.url) as fin: with temp_dir() as dir: fn = network.download(fin, dir) arc = archive.from_file(fn) return arc.get_meta() else: assert False
def get_meta(self, spec): """ Return the content of the ``META.json`` file for *spec*. Return the object obtained parsing the JSON. """ if spec.is_name(): # Get the metadata from the API try: data = self.api.dist(spec.name) except NotFound: # Distro not found: maybe it's an extension? ext = self.api.ext(spec.name) name, ver = self.get_best_version_from_ext(ext, spec) return self.api.meta(name, ver) else: ver = self.get_best_version(data, spec) return self.api.meta(spec.name, ver) elif spec.is_dir(): # Get the metadata from a directory fn = os.path.join(spec.dirname, 'META.json') logger.debug("reading %s", fn) if not os.path.exists(fn): raise PgxnClientException( _("file 'META.json' not found in '%s'") % spec.dirname) with open(fn) as f: return load_json(f) elif spec.is_file(): arc = archive.from_spec(spec) return arc.get_meta() elif spec.is_url(): with network.get_file(spec.url) as fin: with temp_dir() as dir: fn = network.download(fin, dir) arc = archive.from_file(fn) return arc.get_meta() else: assert False
def test_from_file_tar(self): fn = get_test_filename('foobar-0.42.1.tar.gz') a = archive.from_file(fn) self.assert_(isinstance(a, tar.TarArchive)) self.assertEqual(a.filename, fn)
def test_from_file_zip(self): fn = get_test_filename('foobar-0.42.1.zip') a = archive.from_file(fn) self.assert_(isinstance(a, zip.ZipArchive)) self.assertEqual(a.filename, fn)