From f4f72174be11db9dcbd441a6f066e7d5c6b83051 Mon Sep 17 00:00:00 2001 From: Heig Gregorian Date: Thu, 3 May 2012 11:14:34 -0700 Subject: [PATCH] Added new function to read an option_value as either a plain string or path to file Since adding the '--notes' option, which can either be a simple string or the contents of a file (if a valid path is supplied), this same functionality has been extended to the '--description' option. Providing a function so that this same operation can be used in other areas seemed like the logical thing to do. --- code/client/makepkginfo | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/code/client/makepkginfo b/code/client/makepkginfo index 727906f2..f92d716a 100755 --- a/code/client/makepkginfo +++ b/code/client/makepkginfo @@ -193,6 +193,20 @@ def readfile(path): return "" +def readFileOrString(option_value): + """ + If option_value is a path to a file, + return contents of file. + + Otherwise, return the string. + """ + if os.path.exists(os.path.expanduser(option_value)): + string = readfile(option_value) + else: + string = option_value + + return string + def getiteminfo(itempath): """ Gets info for filesystem items passed to makecatalog item, to be used for @@ -311,9 +325,11 @@ def main(): String display name of the package. Note: overrides any display_name in the package itself''') p.add_option('--description', + metavar='STRING|PATH', help='''Optional flag. String description of the package. + Can be a PATH to a file (plain text or html). Note: overrides any description in the package itself''') p.add_option('--autoremove', action='store_true', help='''Optional flag. @@ -380,7 +396,7 @@ def main(): Can be specified multiple times to build an array of blocking applications.''') p.add_option('--notes', - metavar='[STRING|PATH]', + metavar='STRING|PATH', help='''Optional flag. Specifies administrator provided notes @@ -558,19 +574,20 @@ def main(): itemsize += int(os.lstat(filename).st_size) # convert to kbytes itemsize = int(itemsize/1024) - + else: print >> sys.stderr, "%s is not an installer package!" % item exit(-1) if options.description: - catinfo['description'] = options.description + catinfo['description'] = readFileOrString(options.description) + if options.displayname: catinfo['display_name'] = options.displayname - + catinfo['installer_item_size'] = int(itemsize/1024) catinfo['installer_item_hash'] = itemhash - + # try to generate the correct item location temppath = item location = "" @@ -689,11 +706,7 @@ def main(): catinfo['uninstall_script'] = scriptstring catinfo['uninstall_method'] = 'uninstall_script' if options.notes: - if os.path.exists(os.path.expanduser(options.notes)): - notesString = readfile(options.notes) - else: - notesString = options.notes - catinfo['notes'] = notesString + catinfo['notes'] = readFileOrString(options.notes) if options.autoremove: catinfo['autoremove'] = True if options.unattended_install: