makepkginfo now inserts some user/environment metadata into generated pkginfo files. It stores the metadata under the '_metadata' key. makecatalogs now strips any key starting with _ from pkginfo before adding the pkginfo to a catalog.

This commit is contained in:
Greg Neagle
2013-11-04 10:43:06 -08:00
parent 48b1120e7d
commit 11aa83062f
2 changed files with 49 additions and 29 deletions
+34 -28
View File
@@ -51,7 +51,7 @@ except ImportError:
# munkilib is not available
def listdir(path):
"""OSX HFS+ string encoding safe listdir().
Args:
path: path to list contents of
Returns:
@@ -74,7 +74,7 @@ except ImportError:
elif type(path) is not unicode:
path = unicode(path)
return os.listdir(path)
def get_version():
'''Placeholder if munkilib is not available'''
return 'UNKNOWN'
@@ -94,27 +94,27 @@ def makecatalogs(repopath, options):
Assumes a pkgsinfo directory under repopath.
User calling this needs to be able to write to the repo/catalogs
directory.'''
# Make sure the pkgsinfo directory exists
pkgsinfopath = os.path.join(repopath, 'pkgsinfo')
# make sure pkgsinfopath is Unicode so that os.walk later gives us
# make sure pkgsinfopath is Unicode so that os.walk later gives us
# Unicode names back.
if type(pkgsinfopath) is str:
pkgsinfopath = unicode(pkgsinfopath, 'utf-8')
elif type(pkgsinfopath) is not unicode:
pkgsinfopath = unicode(pkgsinfopath)
if not os.path.exists(pkgsinfopath):
print_err_utf8("pkgsinfo path %s doesn't exist!" % pkgsinfopath)
exit(-1)
# Set a default exit code
exitCode = 0
errors = []
catalogs = {}
catalogs['all'] = []
# Walk through the pkginfo files
for dirpath, dirnames, filenames in os.walk(pkgsinfopath):
for dirname in dirnames:
@@ -126,15 +126,12 @@ def makecatalogs(repopath, options):
if filename.startswith('.'):
# skip files that start with a period as well
continue
filepath = os.path.join(dirpath, filename)
# Try to read the pkginfo file
try:
pkginfo = plistlib.readPlist(filepath)
# don't copy admin notes to catalogs.
if pkginfo.get('notes'):
del(pkginfo['notes'])
except IOError, inst:
errors.append("IO error for %s: %s" % (filepath, inst))
exitCode = -1
@@ -143,7 +140,16 @@ def makecatalogs(repopath, options):
errors.append("Unexpected error for %s: %s" % (filepath, inst))
exitCode = -1
continue
# don't copy admin notes to catalogs.
if pkginfo.get('notes'):
del(pkginfo['notes'])
# strip out any keys that start with "_"
# (example: pkginfo _metadata)
for key in pkginfo.keys():
if key.startswith('_'):
del(pkginfo[key])
#simple sanity checking
do_pkg_check = True
installer_type = pkginfo.get('installer_type')
@@ -153,18 +159,18 @@ def makecatalogs(repopath, options):
do_pkg_check = False
if pkginfo.get('PackageURL'):
do_pkg_check = False
if do_pkg_check:
if not 'installer_item_location' in pkginfo:
errors.append(
"WARNING: file %s is missing installer_item_location"
"WARNING: file %s is missing installer_item_location"
% filepath[len(pkgsinfopath)+1:])
# Skip this pkginfo unless we're running with force flag
if not options.force:
exitCode = -1
continue
# Try to form a path and fail if the
# Try to form a path and fail if the
# installer_item_location is not a valid type
try:
installeritempath = os.path.join(repopath, "pkgs",
@@ -174,7 +180,7 @@ def makecatalogs(repopath, options):
" in info file %s" % filepath[len(pkgsinfopath)+1:])
exitCode = -1
continue
# Check if the installer item actually exists
if not os.path.exists(installeritempath):
errors.append("WARNING: Info file %s refers to "
@@ -185,7 +191,7 @@ def makecatalogs(repopath, options):
if not options.force:
exitCode = -1
continue
catalogs['all'].append(pkginfo)
for catalogname in pkginfo.get("catalogs", []):
infofilename = filepath[len(pkgsinfopath)+1:]
@@ -198,13 +204,13 @@ def makecatalogs(repopath, options):
catalogs[catalogname] = []
catalogs[catalogname].append(pkginfo)
print_utf8("Adding %s to %s..." % (infofilename, catalogname))
if errors:
# group all errors at the end for better visibility
print
for error in errors:
print_err_utf8(error)
# clear out old catalogs
catalogpath = os.path.join(repopath, "catalogs")
if not os.path.exists(catalogpath):
@@ -214,7 +220,7 @@ def makecatalogs(repopath, options):
itempath = os.path.join(catalogpath, item)
if os.path.isfile(itempath):
os.remove(itempath)
# write the new catalogs
print
for key in catalogs.keys():
@@ -234,7 +240,7 @@ def makecatalogs(repopath, options):
"because it is empty "
% (key))
exitCode = -1
# Exit with "exitCode" if we got this far.
# This will be -1 if there were any errors
# that prevented the catalogs to be written.
@@ -268,11 +274,11 @@ def main():
help='Disable sanity checks.')
p.set_defaults(force=False)
options, arguments = p.parse_args()
if options.version:
print get_version()
exit(0)
# Make sure we have a path to work with
repopath = None
if len(arguments) == 0:
@@ -284,12 +290,12 @@ def main():
print_utf8("Using repo path: %s" % repopath)
else:
repopath = arguments[0].rstrip("/")
# Make sure the repo path exists
if not os.path.exists(repopath):
print_err_utf8("Repo root path %s doesn't exist!" % repopath)
exit(-1)
# Make the catalogs
makecatalogs(repopath, options)