From 1dc5ee00b6526b800967ce925edfcab115a56606 Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Mon, 27 Jan 2014 20:26:11 +0100 Subject: [PATCH] sysctl: parse bool value as 0/1 and refactor a little bit --- system/sysctl | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/system/sysctl b/system/sysctl index 2b09d06a6f6..2e3ce767e22 100644 --- a/system/sysctl +++ b/system/sysctl @@ -120,10 +120,7 @@ class SysctlModule(object): # Whitespace is bad self.args['name'] = self.args['name'].strip() - if self.args['value'] is not None: - self.args['value'] = self.args['value'].strip() - else: - self.args['value'] = "" + self.args['value'] = self._parse_value(self.args['value']) thisname = self.args['name'] @@ -176,6 +173,16 @@ class SysctlModule(object): return len([i for i, j in zip(a, b) if i == j]) == len(a) + def _parse_value(self, value): + if value is None: + return '' + elif value.lower() in BOOLEANS_TRUE: + return '1' + elif value.lower() in BOOLEANS_FALSE: + return '0' + else: + return value.strip() + # ============================================================== # SYSCTL COMMAND MANAGEMENT # ==============================================================