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.
This commit is contained in:
Heig Gregorian
2012-05-03 11:14:34 -07:00
parent a2c593be9c
commit f4f72174be

View File

@@ -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: