From 8f5a872f9535d2204a6c29c2f2b24e5bab472fd7 Mon Sep 17 00:00:00 2001
From: System User <operateur@rcm1.rcm>
Date: Tue, 27 Jul 2021 13:18:55 +0200
Subject: [PATCH] Initial commit env

---
 env_tango.py | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 112 insertions(+)
 create mode 100644 env_tango.py

diff --git a/env_tango.py b/env_tango.py
new file mode 100644
index 0000000..abbf7de
--- /dev/null
+++ b/env_tango.py
@@ -0,0 +1,112 @@
+import PyTango as tango
+import re
+
+# =============================================================================
+# The following attributes will be populated when first needed.
+# =============================================================================
+# List of attributes tangopath in TDB
+TDBLIST = []
+
+# List of attributes tangopath in TDB
+HDBLIST = []
+
+# List of tango devices
+DEVLIST = []
+
+###############################################################################
+## USEFULL FUNCTION
+###############################################################################
+def searchattr(prx, attr, ignorecase=True):
+    """
+    Search in a tango device proxy for an attribute name.
+
+    PARAMETERS
+    ----------
+    prx: tango.DeviceProxy
+        Proxy to the device.
+
+    attr: string
+        String to search for.
+
+    ignorecase: bool
+        Case insensitive.
+    """
+    if ignorecase:
+        return [a for a in prx.get_attribute_list() if attr.lower() in a.lower()]
+    else:
+        return [a for a in prx.get_attribute_list() if attr in a]
+
+def searcharch(attr, db, ignorecase=True):
+    """
+    Search for an attribute in the archiver list.
+
+    PARAMETERS
+    ----------
+    attr: string
+        String to search for.
+
+    db: string
+        Which database, "H", "T"
+
+    ignorecase: bool
+        Case insensitive.
+
+    RETURNS
+    -------
+
+    """
+    global ARCHLIST
+    if ARCHLIST is None:
+        # Populate archlist
+        ARCHLIST=dict()
+        for db in "HT":
+            ARCHLIST[db] = tango.DeviceProxy("archiving/{}dbextractor/1".format(db)).getcurrentarchivedatt()
+
+    if ignorecase:
+        return [a for a in ARCHLIST[db] if attr.lower() in a.lower()]
+    else:
+        return [a for a in prx.get_attribute_list() if attr in a]
+
+
+###############################################################################
+## POPULATE ATTRIBUTE FUNCTIONS
+###############################################################################
+
+# =============================================================================
+def populate_tdblist():
+    """
+    Fill the global list of TDB archived attributes.
+    """
+    global TDBLIST
+    TDBLIST= tango.DeviceProxy("archiving/tdbextractor/1").getcurrentarchivedatt()
+
+# =============================================================================
+def populate_hdblist():
+    """
+    Fill the global list of HDB archived attributes.
+    """
+    global HDBLIST
+    HDBLIST= tango.DeviceProxy("archiving/hdbextractor/1").getcurrentarchivedatt()
+
+# =============================================================================
+def populate_devlist():
+    """
+    Fill the global list of devices.
+    """
+
+    DB = tango.Database()
+
+    for domain in DB.get_device_domain("*"):
+        for family in DB.get_device_family(domain+"/*"):
+            for member in DB.get_device_member(domain+"/"+family+"/*"):
+                DEVLIST.append(domain+"/"+family+"/"+member)
+
+# =============================================================================
+def populate_devlist2():
+    """
+    Fill the global list of devices.
+    """
+
+    DB = tango.Database()
+
+    DEVLIST = [dev for dev in DB.get_device_exported("*")]
-- 
GitLab