def test_simple(self): build_manifest = BuildManifest(self.sections, self.meta, {}) sections = build_manifest.resolve_paths(self.top_node) res = sorted([(kind, source.abspath(), target.abspath()) \ for kind, source, target in iter_files(sections)]) target_dir = build_manifest.resolve_path(os.path.join("$prefix", "target")) ref = [("pythonfiles", os.path.join(self.top_node.abspath(), "source", "scripts", "bar.py"), os.path.join(target_dir, "scripts", "bar.py")), ("pythonfiles", os.path.join(self.top_node.abspath(), "source", "scripts", "foo.py"), os.path.join(target_dir, "scripts", "foo.py"))] self.assertEqual(res, ref)
def test_simple_roundtrip(self): # FIXME: we compare the loaded json to avoid dealing with encoding # differences when comparing objects, but this is kinda stupid r_build_manifest = BuildManifest(self.sections, self.meta, {}) f = StringIO() r_build_manifest._write(f) r_s = f.getvalue() build_manifest = BuildManifest.from_string(r_s) f = StringIO() build_manifest._write(f) s = f.getvalue() self.assertEqual(json.loads(r_s), json.loads(s))
def run(self, ctx): argv = ctx.command_argv p = ctx.options_context.parser o, a = p.parse_args(argv) if o.help: p.print_help() return n = ctx.build_node.make_node(BUILD_MANIFEST_PATH) build_manifest = BuildManifest.from_file(n.abspath()) scheme = ctx.retrieve_configured_scheme() build_manifest.update_paths(scheme) node_sections = build_manifest.resolve_paths_with_destdir(ctx.build_node) if o.list_files: # XXX: this won't take into account action in post install scripts. # A better way would be to log install steps and display those, but # this will do for now. for kind, source, target in iter_files(node_sections): print(target.abspath()) return if o.transaction: trans = TransactionLog("transaction.log") try: for kind, source, target in iter_files(node_sections): trans.copy(source.abspath(), target.abspath(), kind) finally: trans.close() else: for kind, source, target in iter_files(node_sections): copy_installer(source.abspath(), target.abspath(), kind)
def extract_egg(egg, extract_dir): # Given a bento-produced egg, extract its content in the given directory, # and returned the corresponding build_manifest info instance build_manifest = BuildManifest.from_egg(egg) # egg scheme build_manifest.update_paths({ "prefix": ".", "eprefix": ".", "sitedir": "." }) zid = zipfile.ZipFile(egg) try: for type, sections in build_manifest.files.items(): for name, section in sections.items(): target_dir = build_manifest.resolve_path(section.target_dir) section.source_dir = os.path.join(extract_dir, target_dir) for source, target in section.files: g = os.path.join(target_dir, target) g = os.path.normpath(g) zid.extract(g, extract_dir) finally: zid.close() return build_manifest
def write_record(self): dist = self.distribution options_context = dist.global_context.retrieve_options_context(self.cmd_name) cmd_context_klass = dist.global_context.retrieve_command_context(self.cmd_name) context = cmd_context_klass(dist.global_context, [], options_context, dist.pkg, dist.run_node) n = context.build_node.make_node(BUILD_MANIFEST_PATH) build_manifest = BuildManifest.from_file(n.abspath()) scheme = context.retrieve_configured_scheme() build_manifest.update_paths(scheme) file_sections = build_manifest.resolve_paths_with_destdir(src_root_node=context.build_node) # copy egg info to install directory meta = build_manifest.meta src = op.join('pip-egg-info', meta['name'] + '.egg-info') dest = op.abspath(build_manifest.resolve_path(op.join('$sitedir', meta['name'] + '-' + meta['version'] + '-py$py_version_short.egg-info'))) shutil.copytree(src, dest) def writer(fid): for kind, source, target in iter_files(file_sections): fid.write("%s\n" % target.abspath()) fid.write("%s\n" % dest) bento.utils.io2.safe_write(self.record, writer, "w")
def run(self, ctx): argv = ctx.command_argv p = ctx.options_context.parser o, a = p.parse_args(argv) if o.help: p.print_help() return n = ctx.build_node.make_node(BUILD_MANIFEST_PATH) build_manifest = BuildManifest.from_file(n.abspath()) scheme = ctx.retrieve_configured_scheme() build_manifest.update_paths(scheme) node_sections = build_manifest.resolve_paths_with_destdir( ctx.build_node) if o.list_files: # XXX: this won't take into account action in post install scripts. # A better way would be to log install steps and display those, but # this will do for now. for kind, source, target in iter_files(node_sections): print(target.abspath()) return if o.transaction: trans = TransactionLog("transaction.log") try: for kind, source, target in iter_files(node_sections): trans.copy(source.abspath(), target.abspath(), kind) finally: trans.close() else: for kind, source, target in iter_files(node_sections): copy_installer(source.abspath(), target.abspath(), kind)
def test_create_exe(self): # FIXME: do a real test here meta, sections, nodes = create_simple_ipkg_args(self.top_node) ipkg = BuildManifest(sections, meta, {}) fid, arcname = tempfile.mkstemp(prefix="zip") try: create_exe(ipkg, arcname, "some-name.exe") finally: os.close(fid)
def run(self, ctx): argv = ctx.command_argv p = ctx.options_context.parser o, a = p.parse_args(argv) if o.help: p.print_help() return output_dir = o.output_dir output_file = o.output_file n = ctx.build_node.make_node(IPKG_PATH) build_manifest = BuildManifest.from_file(n.abspath()) build_egg(build_manifest, ctx.build_node, ctx.build_node, output_dir, output_file)
def run(self, ctx): argv = ctx.command_argv p = ctx.options_context.parser o, a = p.parse_args(argv) if o.help: p.print_help() return n = ctx.build_node.make_node(IPKG_PATH) ipkg = BuildManifest.from_file(n.abspath()) create_wininst(ipkg, src_root_node=ctx.build_node, build_node=ctx.build_node, wininst=o.output_file, output_dir=o.output_dir)
def test_create_exe(self): # FIXME: do a real test here meta, sections, nodes = create_simple_build_manifest_args(self.top_node) build_manifest = BuildManifest(sections, meta, {}) fid, arcname = tempfile.mkstemp(prefix="zip") try: f = tempfile.NamedTemporaryFile(suffix=".exe") try: create_exe(build_manifest, arcname, f.name) finally: f.close() finally: os.close(fid)
def test_simple(self): """This just tests whether create_wininst runs at all and produces a zip-file.""" ipackage = BuildManifest({}, {"name": "foo", "version": "1.0"}, {}) create_wininst(ipackage, self.build_node, self.build_node, wininst="foo.exe", output_dir="dist") arcname = bento.commands.build_wininst.create_exe.call_args[0][1] fp = zipfile.ZipFile(arcname) try: fp.namelist() finally: fp.close()
def run(self): self.run_command("build") dist = self.distribution n = dist.build_node.make_node(IPKG_PATH) ipkg = BuildManifest.from_file(n.abspath()) egg_info = EggInfo.from_ipkg(ipkg, dist.build_node) egg_info_dir = op.join(self.egg_base, "%s.egg-info" % dist.pkg.name) try: os.makedirs(egg_info_dir) except OSError, e: if e.errno != 17: raise
def run(self, context): o, a = context.get_parsed_arguments() if o.help: p.print_help() return output_dir = o.output_dir output_file = o.output_file n = context.build_node.find_node(IPKG_PATH) manifest = BuildManifest.from_file(n.abspath()) msi_root = context.build_node.make_node("msi") build_msi_tree(manifest, context.build_node, msi_root) create_msi_installer(context.pkg, context.run_node, msi_root, o.output_file, o.output_dir)
def write_record(self): dist = self.distribution options_context = dist.global_context.retrieve_options_context(self.cmd_name) cmd_context_klass = dist.global_context.retrieve_command_context(self.cmd_name) context = cmd_context_klass(dist.global_context, [], options_context, dist.pkg, dist.run_node) n = context.build_node.make_node(IPKG_PATH) ipkg = BuildManifest.from_file(n.abspath()) scheme = context.retrieve_configured_scheme() ipkg.update_paths(scheme) file_sections = ipkg.resolve_paths_with_destdir(src_root_node=context.build_node) def writer(fid): for kind, source, target in iter_files(file_sections): fid.write("%s\n" % target.abspath()) bento.utils.io2.safe_write(self.record, writer, "w")
def write_record(self): dist = self.distribution options_context = dist.global_context.retrieve_options_context(self.cmd_name) cmd_context_klass = dist.global_context.retrieve_command_context(self.cmd_name) context = cmd_context_klass(dist.global_context, [], options_context, dist.pkg, dist.run_node) n = context.build_node.make_node(BUILD_MANIFEST_PATH) build_manifest = BuildManifest.from_file(n.abspath()) scheme = context.retrieve_configured_scheme() build_manifest.update_paths(scheme) file_sections = build_manifest.resolve_paths_with_destdir(src_root_node=context.build_node) def writer(fid): for kind, source, target in iter_files(file_sections): fid.write("%s\n" % target.abspath()) bento.utils.io2.safe_write(self.record, writer, "w")
def extract_egg(egg, extract_dir): # Given a bento-produced egg, extract its content in the given directory, # and returned the corresponding build_manifest info instance build_manifest = BuildManifest.from_egg(egg) # egg scheme build_manifest.update_paths({"prefix": ".", "eprefix": ".", "sitedir": "."}) zid = zipfile.ZipFile(egg) try: for type, sections in build_manifest.files.items(): for name, section in sections.items(): target_dir = build_manifest.resolve_path(section.target_dir) section.source_dir = os.path.join(extract_dir, target_dir) for source, target in section.files: g = os.path.join(target_dir, target) g = os.path.normpath(g) zid.extract(g, extract_dir) finally: zid.close() return build_manifest
def run(self): self.run_command("build") dist = self.distribution n = dist.build_node.make_node(IPKG_PATH) ipkg = BuildManifest.from_file(n.abspath()) egg_info = EggInfo.from_ipkg(ipkg, dist.build_node) egg_info_dir = op.join(self.egg_base, "%s.egg-info" % dist.pkg.name) try: os.makedirs(egg_info_dir) except OSError: e = extract_exception() if e.errno != 17: raise for filename, cnt in egg_info.iter_meta(dist.build_node): filename = op.join(egg_info_dir, filename) fid = open(filename, "w") try: fid.write(cnt) finally: fid.close()
def run(self): self.run_command("build") dist = self.distribution n = dist.build_node.make_node(BUILD_MANIFEST_PATH) build_manifest = BuildManifest.from_file(n.abspath()) egg_info = EggInfo.from_build_manifest(build_manifest, dist.build_node) egg_info_dir = op.join(self.egg_base, "%s.egg-info" % dist.pkg.name) try: os.makedirs(egg_info_dir) except OSError: e = extract_exception() if e.errno != 17: raise for filename, cnt in egg_info.iter_meta(dist.build_node): filename = op.join(egg_info_dir, filename) fid = open(filename, "w") try: fid.write(cnt) finally: fid.close()
def test_get_inidata_run(self): """Simply execute get_inidata.""" # FIXME: do a real test here meta, sections, nodes = create_simple_ipkg_args(self.top_node) ipkg = BuildManifest(sections, meta, {}) get_inidata(ipkg)
def run(self, ctx): argv = ctx.command_argv p = ctx.options_context.parser o, a = p.parse_args(argv) if o.help: p.print_help() return root = ctx.top_node while root.height() > 0: root = root.parent default_scheme = get_default_scheme(ctx.pkg.name) default_prefix = default_scheme["prefix"] default_sitedir = default_scheme["sitedir"] n = ctx.build_node.make_node(BUILD_MANIFEST_PATH) build_manifest = BuildManifest.from_file(n.abspath()) name = build_manifest.meta["name"] version = build_manifest.meta["version"] py_short = ".".join([str(i) for i in sys.version_info[:2]]) if o.output_file is None: mpkg_name = "%s-%s-py%s.mpkg" % (name, version, py_short) else: mpkg_name = o.output_file categories = set() file_sections = build_manifest.resolve_paths(ctx.build_node) for kind, source, target in iter_files(file_sections): categories.add(kind) # Mpkg metadata mpkg_root = os.path.join(os.getcwd(), o.output_dir, mpkg_name) mpkg_cdir = os.path.join(mpkg_root, "Contents") if os.path.exists(mpkg_root): shutil.rmtree(mpkg_root) os.makedirs(mpkg_cdir) f = open(os.path.join(mpkg_cdir, "PkgInfo"), "w") try: f.write("pmkrpkg1") finally: f.close() mpkg_info = MetaPackageInfo.from_build_manifest(build_manifest) purelib_pkg = "%s-purelib-%s-py%s.pkg" % (name, version, py_short) scripts_pkg = "%s-scripts-%s-py%s.pkg" % (name, version, py_short) datafiles_pkg = "%s-datafiles-%s-py%s.pkg" % (name, version, py_short) mpkg_info.packages = [purelib_pkg, scripts_pkg, datafiles_pkg] make_mpkg_plist(mpkg_info, os.path.join(mpkg_cdir, "Info.plist")) mpkg_rdir = os.path.join(mpkg_root, "Contents", "Resources") os.makedirs(mpkg_rdir) make_mpkg_description(mpkg_info, os.path.join(mpkg_rdir, "Description.plist")) # Package the stuff which ends up into site-packages pkg_root = os.path.join(mpkg_root, "Contents", "Packages", purelib_pkg) build_pkg_from_temp(ctx, build_manifest, pkg_root, root, "/", ["pythonfiles"], "Pure Python modules and packages") pkg_root = os.path.join(mpkg_root, "Contents", "Packages", scripts_pkg) build_pkg_from_temp(ctx, build_manifest, pkg_root, root, "/", ["executables"], "Scripts and binaries") pkg_root = os.path.join(mpkg_root, "Contents", "Packages", datafiles_pkg) build_pkg_from_temp(ctx, build_manifest, pkg_root, root, "/", ["bentofiles", "datafiles"], "Data files")
def store(self, filename, pkg): meta = ipkg_meta_from_pkg(pkg) p = BuildManifest(self.sections, meta, pkg.executables) if not op.exists(op.dirname(filename)): os.makedirs(op.dirname(filename)) p.write(filename)
def store(self, filename, pkg): meta = build_manifest_meta_from_pkg(pkg) p = BuildManifest(self.sections, meta, pkg.executables) if not op.exists(op.dirname(filename)): os.makedirs(op.dirname(filename)) p.write(filename)
def test_simple_create(self): BuildManifest(self.sections, self.meta, {})