Skip to content

WDT#479 sort variable file and remove old debug prints #497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions core/src/main/python/wlsdeploy/tool/util/variable_injector.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,10 +894,7 @@ def sort_dictionary_by_keys(dictionary):
sorted_props = dictionary.keys()
sorted_props.sort()
for prop in sorted_props:
print '******* what is the order ? ', prop
sorted_dict[prop] = dictionary[prop]
for key, value in sorted_dict.iteritems():
print key, '=', value
return sorted_dict


Expand Down
54 changes: 44 additions & 10 deletions core/src/main/python/wlsdeploy/util/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from java.io import FileInputStream
from java.io import FileOutputStream
from java.io import FileReader
from java.io import PrintWriter
from java.io import IOException
from java.util import Properties

Expand Down Expand Up @@ -70,23 +71,56 @@ def write_variables(program_name, variable_map, file_path, append=False):
"""
_method_name = 'write_variables'
_logger.entering(program_name, file_path, append, class_name=_class_name, method_name=_method_name)
props = Properties()
for key, value in variable_map.items():
props.setProperty(key, value)
if isinstance(variable_map, OrderedDict):
write_ordered_variables(program_name, variable_map, file_path, append)
else:
props = Properties()
for key, value in variable_map.items():
props.setProperty(key, value)

comment = exception_helper.get_message('WLSDPLY-01731', program_name)
output_stream = None
try:
output_stream = FileOutputStream(File(file_path), Boolean(append))
props.store(output_stream, comment)
output_stream.close()
except IOException, ioe:
_logger.fine('WLSDPLY-20007', file_path, ioe.getLocalizedMessage())
ex = exception_helper.create_variable_exception('WLSDPLY-20007', file_path,
ioe.getLocalizedMessage(), error=ioe)
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
if output_stream is not None:
output_stream.close()
raise ex
_logger.exiting(class_name=_class_name, method_name=_method_name)
return


comment = exception_helper.get_message('WLSDPLY-01731', program_name)
output_stream = None
def write_ordered_variables(program_name, variable_map, file_path, append=False):
"""
Write variables to file while preserving order of the variables.
:param program_name: name of the calling program
:param variable_map: map or variable properties to write to file
:param file_path: the file to which to write the properties
:param append: defaults to False. Append properties to the end of file
:raises VariableException if an error occurs while storing the variables in the file
"""
_method_name = 'write_ordered_variables'
_logger.entering(program_name, file_path, append, class_name=_class_name, method_name=_method_name)
pw = None
try:
output_stream = FileOutputStream(File(file_path), Boolean(append))
props.store(output_stream, comment)
output_stream.close()
pw = PrintWriter(FileOutputStream(File(file_path), Boolean(append)), Boolean('true'))
for key, value in variable_map.iteritems():
formatted = '%s=%s' % (key, value)
pw.println(formatted)
pw.close()
except IOException, ioe:
_logger.fine('WLSDPLY-20007', file_path, ioe.getLocalizedMessage())
ex = exception_helper.create_variable_exception('WLSDPLY-20007', file_path,
ioe.getLocalizedMessage(), error=ioe)
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
if output_stream is not None:
output_stream.close()
if pw is not None:
pw.close()
raise ex
_logger.exiting(class_name=_class_name, method_name=_method_name)
return
Expand Down