On 03/23/10 11:50 AM, William Schumann wrote:
I have been experimenting with the pkg.client.api API to get the
expected disk usage for the installer, given a set of packages. There
are no examples in the documentation, which is in "pydoc
pkg.client.api", but I came up with this (some code removed):

api_inst = api.ImageInterface(img_dir, CLIENT_API_VERSION,
progresstracker, None, PKG_CLIENT_NAME)
api.image_create(PKG_CLIENT_NAME, CLIENT_API_VERSION, img_dir,
IMG_TYPE_ENTIRE, False,
repo_uri="http://ipkg.sfbay/dev";,
progtrack=progress.QuietProgressTracker(), mirrors = mirrors, force=True)

image_create() returns an ImageInterface object for the image that was created, so there's no reason for the first assignment line.

The first line you have would only be used if the image already existed, and the image_create() only if the image did not already exist.

As a general sidenote, if the arguments are keyword, always use the keyword name as the position of them is not guaranteed.

api_inst.plan_install(pkglist,refresh_catalogs=True,noexecute=False,verbose=True,
update_index=True)
ret = api_inst.info("*", True, api.PackageInfo.ALL_OPTIONS)

First, you should be passing the actual list of packages that are in the plan instead of '*' to info(). To get that, call api_inst.describe() to get a plan description object:

plan = api_inst.describe()

To get the list of FMRIs for the packages that will be installed can be retrieved using:

pkg_list = [dest.fmri for src, dest in plan.get_changes()]

Also, instead of use api.PackageInfo.ALL_OPTIONS, you should really only specify just the information you need. In this particular case, I'd guess that you only need to be able to identify the results by FMRI and size, so you'd use this for the options parameter:

info_opts = frozenset([pkg.client.api.PackageInfo.SIZE])

You actually shouldn't have to make the call to info() at all, the get_changes() call above should have given you fully populated PackageInfo objects with the size already. However, the RFEs to do that haven't been implemented yet.

pis = ret[api.ImageInterface.INFO_FOUND]
for i, pi in enumerate(pis):
print pi.pkg_stem,"size",pi.size

The bits are not actually downloaded, but the info() method returns a
list of packages with size information.

Will summing pi.size be a good estimation of disk space usage?

Yes, for a clean install case (which is your case), summing pi.size should give you a good estimation of the amount of disk usage that the installed packages will used.

Keep in mind that this won't give you an estimate of how much space the download phase will need to store all of the compressed package data that's retrieved, the package manifests (which were retrieved during the plan_install call), any space used by SMF services that will be started when the image is "booted", or any temporary files needed by the packaging system during the operation.

Cheers,
--
Shawn Walker
_______________________________________________
pkg-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss

Reply via email to