objdictgen/nodelist.py
author etisserant
Tue, 17 Jul 2007 18:20:50 +0200
changeset 241 4ecc2f3690f4
parent 239 f45fd4cd3832
child 242 4864f7f01e1d
permissions -rw-r--r--
Fixed mutex typo in win32
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     1
#!/usr/bin/env python
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     3
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     4
#This file is part of CanFestival, a library implementing CanOpen Stack. 
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     5
#
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     6
#Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     7
#
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     8
#See COPYING file for copyrights details.
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     9
#
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    10
#This library is free software; you can redistribute it and/or
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    11
#modify it under the terms of the GNU Lesser General Public
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    12
#License as published by the Free Software Foundation; either
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    13
#version 2.1 of the License, or (at your option) any later version.
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    14
#
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    15
#This library is distributed in the hope that it will be useful,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    16
#but WITHOUT ANY WARRANTY; without even the implied warranty of
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    17
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    18
#Lesser General Public License for more details.
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    19
#
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    20
#You should have received a copy of the GNU Lesser General Public
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    21
#License along with this library; if not, write to the Free Software
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    22
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    23
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    24
from gnosis.xml.pickle import *
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    25
from gnosis.xml.pickle.util import setParanoia
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    26
setParanoia(0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    27
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    28
from node import *
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    29
import eds_utils
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    30
import os, shutil
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    31
239
f45fd4cd3832 add auto-mapping tool (config_utils)
greg
parents: 205
diff changeset
    32
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    33
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    34
#                          Definition of NodeList Object
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    35
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    36
239
f45fd4cd3832 add auto-mapping tool (config_utils)
greg
parents: 205
diff changeset
    37
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    38
"""
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    39
Class recording a node list for a CANOpen network.
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    40
"""
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    41
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    42
class NodeList:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    43
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    44
    def __init__(self, manager):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    45
        self.Root = ""
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    46
        self.Manager = manager
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    47
        self.NetworkName = ""
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    48
        self.SlaveNodes = {}
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    49
        self.EDSNodes = {}
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    50
        self.CurrentSelected = None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    51
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    52
    def GetNetworkName(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    53
        return self.NetworkName
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    54
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    55
    def SetNetworkName(self, name):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    56
        self.NetworkName = name
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    57
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    58
    def GetManager(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    59
        return self.Manager
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    60
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    61
    def GetRoot(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    62
        return self.Root
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    63
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    64
    def GetSlaveNumber(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    65
        return len(self.SlaveNodes)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    66
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    67
    def GetSlaveNames(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    68
        nodes = self.SlaveNodes.keys()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    69
        nodes.sort()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    70
        return ["0x%2.2X %s"%(idx, self.SlaveNodes[idx]["Name"]) for idx in nodes]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    71
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    72
    def GetSlaveIDs(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    73
        nodes = self.SlaveNodes.keys()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    74
        nodes.sort()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    75
        return nodes
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    76
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    77
    def SetCurrentSelected(self, selected):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    78
        self.CurrentSelected = selected
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    79
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    80
    def GetCurrentSelected(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    81
        return self.CurrentSelected
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    82
            
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    83
    def LoadProject(self, root):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    84
        self.SlaveNodes = {}
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    85
        self.EDSNodes = {}
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    86
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    87
        self.Root = root
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    88
        if not os.path.exists(self.Root):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    89
            return "\"%s\" folder doesn't exist"%self.Root
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    90
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    91
        self.EDSFolder = os.path.join(self.Root, "eds")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    92
        if not os.path.exists(self.EDSFolder):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    93
            return "\"%s\" folder doesn't contain a \"eds\" folder"%self.Root
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    94
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    95
        files = os.listdir(self.EDSFolder)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    96
        for file in files:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    97
            result = self.LoadEDS(file)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    98
            if result != None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    99
                return result
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   100
                
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   101
        result = self.LoadMasterNode()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   102
        if result != None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   103
            return result
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   104
            
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   105
        result = self.LoadSlaveNodes()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   106
        if result != None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   107
            return result
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   108
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   109
    def SaveProject(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   110
        result = self.SaveMasterNode()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   111
        if result != None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   112
            return result
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   113
            
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   114
        result = self.SaveNodeList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   115
        if result != None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   116
            return result
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   117
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   118
    def ImportEDSFile(self, edspath):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   119
        dir, file = os.path.split(edspath)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   120
        eds = os.path.join(self.EDSFolder, file)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   121
        if os.path.isfile(eds):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   122
            return "EDS file already imported"
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   123
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   124
            shutil.copy(edspath, self.EDSFolder)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   125
            return self.LoadEDS(file)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   126
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   127
    def LoadEDS(self, eds):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   128
        edspath = os.path.join(self.EDSFolder, eds)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   129
        node = eds_utils.GenerateNode(edspath, self.Manager.ScriptDirectory)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   130
        if isinstance(node, Node):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   131
            self.EDSNodes[eds] = node
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   132
            return None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   133
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   134
            return node
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   135
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   136
    def AddSlaveNode(self, nodeName, nodeID, eds):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   137
        if eds in self.EDSNodes.keys():
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   138
            slave = {"Name" : nodeName, "EDS" : eds, "Node" : self.EDSNodes[eds]}
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   139
            self.SlaveNodes[nodeID] = slave
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   140
            return None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   141
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   142
            return "\"%s\" EDS file is not available"%eds
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   143
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   144
    def RemoveSlaveNode(self, index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   145
        if index in self.SlaveNodes.keys():
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   146
            self.SlaveNodes.pop(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   147
            return None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   148
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   149
            return "Node with \"0x%2.2X\" ID doesn't exist"
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   150
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   151
    def LoadMasterNode(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   152
        masterpath = os.path.join(self.Root, "master.od")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   153
        if os.path.isfile(masterpath):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   154
            self.Manager.OpenFileInCurrent(masterpath)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   155
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   156
            self.Manager.CreateNewNode("MasterNode", 0x00, "master", "", "None", "", "heartbeat", ["DS302"])
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   157
        return None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   158
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   159
    def SaveMasterNode(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   160
        masterpath = os.path.join(self.Root, "master.od")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   161
        if self.Manager.SaveCurrentInFile(masterpath):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   162
            return None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   163
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   164
            return "Fail to save Master Node"
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   165
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   166
    def LoadSlaveNodes(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   167
        cpjpath = os.path.join(self.Root, "nodelist.cpj")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   168
        if os.path.isfile(cpjpath):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   169
            try:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   170
                networks = eds_utils.ParseCPJFile(cpjpath)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   171
                if len(networks) > 0:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   172
                    self.NetworkName = networks[0]["Name"]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   173
                    for nodeid, node in networks[0]["Nodes"].items():
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   174
                        if node["Present"] == 1:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   175
                            result = self.AddSlaveNode(node["Name"], nodeid, node["DCFName"])
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   176
                            if result != None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   177
                                return result
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   178
            except SyntaxError, message:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   179
                return "Unable to load CPJ file\n%s"%message
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   180
        return None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   181
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   182
    def SaveNodeList(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   183
        cpjpath = os.path.join(self.Root, "nodelist.cpj")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   184
        content = eds_utils.GenerateCPJContent(self)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   185
        file = open(cpjpath, "w")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   186
        file.write(content)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   187
        file.close()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   188
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   189
    def GetSlaveNodeEntry(self, nodeid, index, subindex = None):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   190
        if nodeid in self.SlaveNodes.keys():
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   191
            self.SlaveNodes[nodeid]["Node"].SetNodeID(nodeid)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   192
            return self.SlaveNodes[nodeid]["Node"].GetEntry(index, subindex)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   193
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   194
            return "Node 0x%2.2X doesn't exist"%nodeid
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   195
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   196
    def GetMasterNodeEntry(self, index, subindex = None):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   197
        return self.Manager.GetCurrentEntry(index, subindex)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   198
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   199
    def SetMasterNodeEntry(self, index, subindex = None, value = None):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   200
        self.Manager.SetCurrentEntry(index, subindex, value)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   201
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   202
    def GetOrderNumber(self, nodeid):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   203
        nodeindexes = self.SlaveNodes.keys()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   204
        nodeindexes.sort()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   205
        return nodeindexes.index(nodeid) + 1
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   206
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   207
    def GetNodeByOrder(self, order):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   208
        if order > 0:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   209
            nodeindexes = self.SlaveNodes.keys()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   210
            nodeindexes.sort()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   211
            print nodeindexes
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   212
            if order <= len(nodeindexes):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   213
                return self.SlaveNodes[nodeindexes[order - 1]]["Node"]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   214
        return None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   215
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   216
    def IsCurrentEntry(self, index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   217
        if self.CurrentSelected != None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   218
            if self.CurrentSelected == 0:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   219
                return self.Manager.IsCurrentEntry(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   220
            else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   221
                node = self.SlaveNodes[self.CurrentSelected]["Node"]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   222
                if node:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   223
                    return node.IsEntry(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   224
        return False
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   225
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   226
    def GetEntryInfos(self, index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   227
        if self.CurrentSelected != None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   228
            if self.CurrentSelected == 0:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   229
                return self.Manager.GetEntryInfos(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   230
            else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   231
                node = self.SlaveNodes[self.CurrentSelected]["Node"]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   232
                if node:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   233
                    return node.GetEntryInfos(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   234
        return None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   235
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   236
    def GetCurrentValidIndexes(self, min, max):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   237
        if self.CurrentSelected != None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   238
            if self.CurrentSelected == 0:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   239
                return self.Manager.GetCurrentValidIndexes(min, max)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   240
            else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   241
                node = self.SlaveNodes[self.CurrentSelected]["Node"]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   242
                if node:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   243
                    validindexes = []
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   244
                    for index in node.GetIndexes():
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   245
                        if min <= index <= max:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   246
                            validindexes.append((node.GetEntryName(index), index))
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   247
                    return validindexes
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   248
                else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   249
                    print "Can't find node"
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   250
        return []
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   251
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   252
    def GetCurrentEntryValues(self, index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   253
        if self.CurrentSelected != None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   254
            node = self.SlaveNodes[self.CurrentSelected]["Node"]
239
f45fd4cd3832 add auto-mapping tool (config_utils)
greg
parents: 205
diff changeset
   255
            node.SetNodeID(self.CurrentSelected)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   256
            if node:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   257
                return self.Manager.GetNodeEntryValues(node, index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   258
            else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   259
                print "Can't find node"
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   260
        return [], []
239
f45fd4cd3832 add auto-mapping tool (config_utils)
greg
parents: 205
diff changeset
   261
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   262
if __name__ == "__main__":
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   263
    from nodemanager import *
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   264
    import os, sys, shutil
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   265
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   266
    manager = NodeManager(sys.path[0])
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   267
    nodelist = NodeList(manager)
239
f45fd4cd3832 add auto-mapping tool (config_utils)
greg
parents: 205
diff changeset
   268
    #result = nodelist.LoadProject("/home/deobox/beremiz/test_nodelist")
f45fd4cd3832 add auto-mapping tool (config_utils)
greg
parents: 205
diff changeset
   269
    result = nodelist.LoadProject("/home/deobox/Desktop/TestMapping")
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   270
    if result != None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   271
        print result
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   272
    else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   273
        print "MasterNode :"
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   274
        manager.CurrentNode.Print()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   275
        for nodeid, node in nodelist.SlaveNodes.items():
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   276
            print "SlaveNode name=%s id=0x%2.2X :"%(node["Name"], nodeid)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   277
            node["Node"].Print()
239
f45fd4cd3832 add auto-mapping tool (config_utils)
greg
parents: 205
diff changeset
   278