Yedidyah Bar David has uploaded a new change for review.

Change subject: core: sort or randomize events
......................................................................

core: sort or randomize events

Before this change, the order of events was semi-random, except for
specific conditions (before, after, priority, stage).

This change either sorts the list of events (default) or randomizes
this list (if directed to do so by the environment).

Change-Id: I3a81095dc4f90e523028b3f5b30c6045829f8ca1
Signed-off-by: Yedidyah Bar David <[email protected]>
---
M src/otopi/constants.py
M src/otopi/context.py
2 files changed, 10 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/otopi refs/changes/78/18478/1

diff --git a/src/otopi/constants.py b/src/otopi/constants.py
index 7bc90ad..5f1fe54 100644
--- a/src/otopi/constants.py
+++ b/src/otopi/constants.py
@@ -103,6 +103,7 @@
     EXECUTION_DIRECTORY = 'BASE/executionDirectory'
     SUPPRESS_ENVIRONMENT_KEYS = 'BASE/suppressEnvironmentKeys'
     COMMAND_PREFIX = 'COMMAND/'
+    RANDOMIZE_EVENTS = 'CORE/randomizeEvents'
 
 
 @util.export
diff --git a/src/otopi/context.py b/src/otopi/context.py
index 80e027d..ee41628 100644
--- a/src/otopi/context.py
+++ b/src/otopi/context.py
@@ -25,6 +25,7 @@
 import os
 import traceback
 import operator
+import random
 import gettext
 _ = lambda m: gettext.dgettext(message=m, domain='otopi')
 
@@ -199,6 +200,7 @@
                     '0'
                 )
             ),
+            constants.BaseEnv.RANDOMIZE_EVENTS: False,
         }
         self.registerDialog(dialog.DialogBase())
         self.registerServices(services.ServicesBase())
@@ -271,6 +273,13 @@
                 metadata['condition'] = metadata['condition'].__get__(p)
                 tmplist.append(metadata)
 
+        # Randomize?
+        if self.environment[constants.BaseEnv.RANDOMIZE_EVENTS]:
+            random.shuffle(tmplist)
+        else:
+            # Set some stable order
+            tmplist.sort(key=lambda x: x['name'])
+
         #
         # sort based on priority
         #


-- 
To view, visit http://gerrit.ovirt.org/18478
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3a81095dc4f90e523028b3f5b30c6045829f8ca1
Gerrit-PatchSet: 1
Gerrit-Project: otopi
Gerrit-Branch: master
Gerrit-Owner: Yedidyah Bar David <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to