From d70e85a2b0892e4fd7d24a776f4b975be26a6db5 Mon Sep 17 00:00:00 2001
From: Pepping <pepping>
Date: Thu, 21 May 2015 07:58:06 +0000
Subject: [PATCH] Added two function: remove_all_but_the_dict_from_list and
 get_key_value

---
 tools/oneclick/base/common_dict_file.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/tools/oneclick/base/common_dict_file.py b/tools/oneclick/base/common_dict_file.py
index a624aeba4d..05c4c10a43 100644
--- a/tools/oneclick/base/common_dict_file.py
+++ b/tools/oneclick/base/common_dict_file.py
@@ -115,6 +115,19 @@ class CommonDictFile:
         self.filePathNames.pop(k)
         self.dicts.remove(the_dict)
         self.nof_dicts -= 1
+
+    def remove_all_but_the_dict_from_list(self, the_dict):
+        """Remove all dicts from the internal list of dicts from the available dictionary files, except the_dict."""
+        k = self.dicts.index(the_dict)
+        filePath = self.filePaths[k]
+        filePathName = self.filePathNames[k]
+        self.filePaths = []
+        self.filePaths.append(filePath)
+        self.filePathNames = []
+        self.filePathNames.append(filePathName)
+        self.dicts = []
+        self.dicts.append(the_dict)
+        self.nof_dicts = 1
     
     def find_all_dict_file_paths(self, rootDir=None):
         """Recursively search the rootDir tree to find the paths to all fileName files."""
@@ -279,6 +292,15 @@ class CommonDictFile:
                 key_values.append(None)
         return cm.unlistify(key_values)
 
+    def get_key_value(self, key, dict=None):
+        """Get the value of a key from a single dict or None in case the key does not exist."""
+        if dict==None: dict=self.dicts[0]
+        if key in dict:
+            key_value = dict[key]
+        else:
+            key_value = None
+        return key_value
+
     def get_dicts(self, key, values=None, dicts=None):
         """Get all dictionaries in dicts that contain the key with a value specified in values. If values==None then
            get all dictionaries in dicts that contain the key.
-- 
GitLab