mirror of
https://github.com/munki/munki.git
synced 2026-04-24 05:49:42 -05:00
Added support for installer_item_size to makecatalogitem for all package types.
Added support for installed_size to makecatalogitem for some package types: simple bundle packages and some flat packages. Need to do mpkgs and test dist and other flat styles. New version of getmanifest.py that properly generates HTTP headers. git-svn-id: http://munki.googlecode.com/svn/trunk@28 a4e17f2e-e282-11dd-95e1-755cbddbdd66
This commit is contained in:
@@ -84,11 +84,15 @@ def nameAndVersion(s):
|
||||
|
||||
|
||||
def getCatalogInfo(pkgitem):
|
||||
installedsize = 0
|
||||
info = managedinstalls.getPkgInfo(pkgitem)
|
||||
highestpkgversion = "0.0"
|
||||
for infoitem in info:
|
||||
if version.LooseVersion(infoitem['version']) > version.LooseVersion(highestpkgversion):
|
||||
highestpkgversion = infoitem['version']
|
||||
if "installed_size" in infoitem:
|
||||
# note this is in KBytes
|
||||
installedsize += infoitem['installed_size']
|
||||
|
||||
name = os.path.split(pkgitem)[1]
|
||||
shortname = os.path.splitext(name)[0]
|
||||
@@ -101,6 +105,8 @@ def getCatalogInfo(pkgitem):
|
||||
cataloginfo['version'] = metaversion
|
||||
cataloginfo['description'] = ""
|
||||
cataloginfo['receipts'] = []
|
||||
if installedsize > 0:
|
||||
cataloginfo['installed_size'] = installedsize
|
||||
for infoitem in info:
|
||||
pkginfo = {}
|
||||
pkginfo['packageid'] = infoitem['id']
|
||||
@@ -218,6 +224,18 @@ def main():
|
||||
|
||||
item = arguments[0].rstrip("/")
|
||||
if os.path.exists(item):
|
||||
# get size of installer item
|
||||
itemsize = 0
|
||||
if os.path.isfile(item):
|
||||
itemsize = int(os.path.getsize(item))
|
||||
if os.path.isdir(item):
|
||||
# need to walk the dir and add it all up
|
||||
for (path, dirs, files) in os.walk(item):
|
||||
for f in files:
|
||||
filename = os.path.join(path, f)
|
||||
# use os.lstat so we don't follow symlinks
|
||||
itemsize += int(os.lstat(filename).st_size)
|
||||
|
||||
if item.endswith('.dmg'):
|
||||
catinfo = getCatalogInfoFromDmg(item)
|
||||
elif item.endswith('.pkg') or item.endswith('.mpkg'):
|
||||
@@ -227,6 +245,7 @@ def main():
|
||||
exit(-1)
|
||||
|
||||
if catinfo:
|
||||
catinfo['installer_item_size'] = itemsize
|
||||
minosversion = ""
|
||||
if options.file:
|
||||
installs = []
|
||||
|
||||
@@ -113,6 +113,8 @@ def parsePkgRefs(filename):
|
||||
pkginfo = {}
|
||||
pkginfo['id'] = ref.attributes['id'].value.encode('UTF-8')
|
||||
pkginfo['version'] = normalizeVersion(ref.attributes['version'].value.encode('UTF-8'))
|
||||
if 'installKBytes' in keys:
|
||||
pkginfo['installed_size'] = int(ref.attributes['installKBytes'].value.encode('UTF-8'))
|
||||
if not pkginfo in info:
|
||||
info.append(pkginfo)
|
||||
else:
|
||||
@@ -170,16 +172,22 @@ def getBundlePackageInfo(pkgpath):
|
||||
if debug:
|
||||
for key in pl:
|
||||
print key, "=>", pl[key]
|
||||
|
||||
if "CFBundleIdentifier" in pl:
|
||||
pkginfo['id'] = pl["CFBundleIdentifier"];
|
||||
if "CFBundleShortVersionString" in pl:
|
||||
majorVersion = pl["CFBundleShortVersionString"]
|
||||
minorVersion = "0"
|
||||
if "IFMinorVersion" in pl:
|
||||
minorVersion = str(pl["IFMinorVersion"])
|
||||
pkginfo['version'] = normalizeVersion(majorVersion, minorVersion)
|
||||
infoarray.append(pkginfo)
|
||||
return infoarray
|
||||
pkginfo['id'] = pl["CFBundleIdentifier"]
|
||||
|
||||
if "CFBundleShortVersionString" in pl:
|
||||
majorVersion = pl["CFBundleShortVersionString"]
|
||||
minorVersion = "0"
|
||||
if "IFMinorVersion" in pl:
|
||||
minorVersion = str(pl["IFMinorVersion"])
|
||||
pkginfo['version'] = normalizeVersion(majorVersion, minorVersion)
|
||||
|
||||
if "IFPkgFlagInstalledSize" in pl:
|
||||
pkginfo['installed_size'] = pl["IFPkgFlagInstalledSize"]
|
||||
|
||||
infoarray.append(pkginfo)
|
||||
return infoarray
|
||||
|
||||
bundlecontents = os.path.join(pkgpath, "Contents")
|
||||
if os.path.exists(bundlecontents):
|
||||
|
||||
+22
-10
@@ -11,7 +11,6 @@ http://webserver/cgi-bin/getmanifest.py?arbitrarystring
|
||||
|
||||
arbitrarystring could be the hostname, a UUID, a username...
|
||||
|
||||
You can call this from the client with getcatalog.py
|
||||
This could be extended to do wildcard matching, or to
|
||||
read another file that mapped hostnames/strings to catalog
|
||||
files
|
||||
@@ -21,10 +20,8 @@ import os
|
||||
import socket
|
||||
import sys
|
||||
import cgi
|
||||
|
||||
print "Content-type: text/plain"
|
||||
print
|
||||
|
||||
import time
|
||||
|
||||
hostname = ""
|
||||
if 'QUERY_STRING' in os.environ:
|
||||
hostname = os.environ['QUERY_STRING']
|
||||
@@ -38,15 +35,30 @@ if hostname == "":
|
||||
hostname = lookup[0]
|
||||
except:
|
||||
hostname = ip
|
||||
|
||||
# path to manifests: this is the local file path, not the web-relative
|
||||
# path. Must be readable by whatever process is running the CGI
|
||||
manifestdir = "/Library/WebServer/Documents/swrepo/catalogs"
|
||||
|
||||
# the manifestdir is a local path to wherever you keep the master catalogs;
|
||||
# must be readable by the webserver process
|
||||
manifestdir = "/Library/WebServer/Documents/repo/catalogs"
|
||||
|
||||
manifest = os.path.join(manifestdir, hostname)
|
||||
if os.path.exists(manifest):
|
||||
statinfo = os.stat(manifest)
|
||||
modtime = statinfo.st_mtime
|
||||
inode = statinfo.st_ino
|
||||
size = statinfo.st_size
|
||||
print "Content-type: text/plain"
|
||||
print "Content-length: %s" % size
|
||||
print "Last-modified:", time.strftime("%a, %d %b %Y %H:%M:%S GMT",time.gmtime(modtime))
|
||||
# Generate ETag the same way Apache does on OS X...
|
||||
print "ETag:", '"%s-%s-%s"' % (hex(int(inode))[2:], hex(int(size))[2:], hex(int(modtime))[2:])
|
||||
print
|
||||
|
||||
f = open(manifest, mode='r', buffering=1)
|
||||
if f:
|
||||
for line in f.readlines():
|
||||
print line
|
||||
print line.rstrip('\n')
|
||||
f.close()
|
||||
else:
|
||||
print "Content-type: text/plain"
|
||||
print "Content-length: 0"
|
||||
print
|
||||
|
||||
Reference in New Issue
Block a user