summaryrefslogtreecommitdiffstats
path: root/pyanaconda/flags.py
diff options
context:
space:
mode:
authorVratislav Podzimek <vpodzime@redhat.com>2012-09-20 14:06:33 +0200
committerVratislav Podzimek <vpodzime@redhat.com>2012-09-28 11:29:50 +0200
commit4800aad84a4d51eb63e41d01773cd9bf687181da (patch)
tree71bc34aeba0fc7a08b7d5d33612a81b008b47851 /pyanaconda/flags.py
parent720712000d0b8e0abd1deecd142524160bdb894d (diff)
downloadanaconda-4800aad84a4d51eb63e41d01773cd9bf687181da.tar.gz
anaconda-4800aad84a4d51eb63e41d01773cd9bf687181da.tar.xz
anaconda-4800aad84a4d51eb63e41d01773cd9bf687181da.zip
Add a guard for testing if we can modify runtime system
Using "if flags.liveCDinstall or flags.imageInstall or flags.testing" over and over is incovinient, one may forget to involve some of the conditions and there is no logging of the skipped actions. This patch adds flags.can_touch_runtime_system function, that can be used as a guard and that logs skipped actions. It can also be easily mocked or masked for the needs of testing.
Diffstat (limited to 'pyanaconda/flags.py')
-rw-r--r--pyanaconda/flags.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/pyanaconda/flags.py b/pyanaconda/flags.py
index 2d828dd27..fdbd504f1 100644
--- a/pyanaconda/flags.py
+++ b/pyanaconda/flags.py
@@ -24,9 +24,13 @@ import glob
from constants import *
from collections import OrderedDict
+import logging
+log = logging.getLogger("anaconda")
+
# A lot of effort, but it only allows a limited set of flags to be referenced
class Flags(object):
def __setattr__(self, attr, val):
+ # pylint: disable-msg=E1101
if attr not in self.__dict__ and not self._in_init:
raise AttributeError, attr
else:
@@ -169,6 +173,29 @@ class BootArgs(OrderedDict):
result = False # XXX: should noarg=off -> True?
return result
+def can_touch_runtime_system(msg):
+ """
+ Guard that should be used before doing actions that modify runtime system.
+
+ @param msg: message to be logged in case that runtime system cannot be touched
+ @rtype: bool
+
+ """
+
+ if flags.livecdInstall:
+ log.info("Not doing '%s' in live installation" % msg)
+ return False
+
+ if flags.imageInstall:
+ log.info("Not doing '%s' in image installation" % msg)
+ return False
+
+ if flags.testing:
+ log.info("Not doing '%s', because we are just testing" % msg)
+ return False
+
+ return True
+
global flags
flags = Flags()