Method get_index() serves for creating index prefixes for log subfolder name. Counter for indices is only incremented for the first match of individual runs.
set_recipe() has been expanded with option prepend, which if is True it prepends recipe_path with index number in format %02d (00, 01, ...). With this implementation, every dir name is unique, and is no longer overriden when one recipe file is specified multiple times in command line arguments. This also enables alphabetical listing of folders.
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- lnst/Common/Logs.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/lnst/Common/Logs.py b/lnst/Common/Logs.py index 80bedf3..3209bfc 100644 --- a/lnst/Common/Logs.py +++ b/lnst/Common/Logs.py @@ -99,6 +99,7 @@ class LoggingCtl: recipe_log_path = "" slaves = {} transmit_handler = None + _id_seq = 0
def __init__(self, debug=False, log_dir=None, log_subdir="", colours=True): #clear any previously set handlers @@ -138,10 +139,21 @@ class LoggingCtl: logger.setLevel(logging.NOTSET) logger.addHandler(self.display_handler)
- def set_recipe(self, recipe_path, clean=True, expand=""): + def _gen_index(self, increment=True): + if increment: + self._id_seq += 1 + return "%02d" % self._id_seq + + def set_recipe(self, recipe_path, clean=True, prepend=False, expand=""): recipe_name = os.path.splitext(os.path.split(recipe_path)[1])[0] if expand != "": recipe_name += "_" + expand + if prepend: + if expand == "match_1": + recipe_name = self._gen_index() + "_" + recipe_name + else: + recipe_name = self._gen_index(increment=False) + "_" + recipe_name + self.recipe_log_path = os.path.join(self.log_folder, recipe_name) if clean: self._clean_folder(self.recipe_log_path)
Logs created by lnst-ctl will now have prefix with index number so they will no longer be overriden and lost when one recipe file is specified multiple time in command line arguments.
Fixes issue #163
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- lnst-ctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lnst-ctl b/lnst-ctl index f3c2eb2..875accd 100755 --- a/lnst-ctl +++ b/lnst-ctl @@ -98,7 +98,7 @@ def get_recipe_result(action, file_path, log_ctl, res_serializer, matches = 1 no_match = False
- log_ctl.set_recipe(file_path, expand="match_%d" % matches) + log_ctl.set_recipe(file_path, prepend=True, expand="match_%d" % matches) log_dir = log_ctl.get_recipe_log_path() recipe_head_log_entry(file_path, log_dir, matches) res_serializer.add_recipe(file_path, matches) @@ -139,7 +139,7 @@ def get_recipe_result(action, file_path, log_ctl, res_serializer, elif matches > 1: try: nettestctl.provision_machines() - log_ctl.set_recipe(file_path, expand="match_%d" % matches) + log_ctl.set_recipe(file_path, prepend=True, expand="match_%d" % matches) log_dir = log_ctl.get_recipe_log_path() recipe_head_log_entry(file_path, log_dir, matches) res_serializer.add_recipe(file_path, matches)
On Fri, May 20, 2016 at 03:43:17PM +0200, Jiri Prochazka wrote:
Method get_index() serves for creating index prefixes for log subfolder name. Counter for indices is only incremented for the first match of individual runs.
set_recipe() has been expanded with option prepend, which if is True it prepends recipe_path with index number in format %02d (00, 01, ...). With this implementation, every dir name is unique, and is no longer overriden when one recipe file is specified multiple times in command line arguments. This also enables alphabetical listing of folders.
Signed-off-by: Jiri Prochazka jprochaz@redhat.com
ack to set Acked-by: Ondrej Lichtner olichtne@redhat.com
lnst-developers@lists.fedorahosted.org