root/ossiedev/branches/0.8.x/tools/wavedash/src/WavedashController.py @ 10671

Revision 10671, 9.9 KB (checked in by jawil06, 2 years ago)

Merging trunk to 0.8.x branch

Line 
1#! /bin/env python
2
3## Copyright 2005, 2006, 2007, 2008 Virginia Polytechnic Institute and State University
4##
5## This file is part of the OSSIE Waveform Application Visualization Environment
6##
7## WaveDash is free software; you can redistribute it and/or modify
8## it under the terms of the GNU General Public License as published by
9## the Free Software Foundation; either version 2 of the License, or
10## (at your option) any later version.
11##
12## WaveDash is distributed in the hope that it will be useful, but WITHOUT ANY
13## WARRANTY; without even the implied warranty of
14## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15## GNU General Public License for more details.
16##
17## You should have received a copy of the GNU General Public License
18## along with OSSIE WaveDash; if not, write to the Free Software
19## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21import os
22import sys
23import xml.dom.minidom as minidom
24from WavedashModel import WavedashModel
25import WaveformModel
26import PropertyWidgets
27from PropertyWidgets import WidgetContainer
28import WavedashUtils as utils
29import time
30import shlex
31import subprocess
32import ConfigParser
33from NodeBooterUtils import NodeBooterUtils
34
35SDR_DIR = '/sdr/dom/'
36SDR_WAVEFORMS_DIR = '/waveforms'
37COMP_WAVEFORMS_DIR = '/_tmp_alf_waveforms'
38SAD_XML = '*.sad.xml'
39DAS_XML = '*_DAS.xml'
40PROPERTY_WIDGET_CONFIG_FILE = '/resources/widgetconf.xml'
41OSSIE_CONFIG_FILE = '.ossie.cfg'
42
43class Controller:
44    def __init__(self, enableGUI = True):
45        self.nodeBooterProcess = None
46        self.nbUtils = NodeBooterUtils(self)
47       
48        self.enableGUI = enableGUI
49        self.model = WavedashModel(self)
50        self.views = []
51        self.widgetContainer = None
52        self.CORBAutils = utils.WaveAppCORBA()
53       
54    def buildModel(self):
55        """ This functions walks through the system directories in /sdr/, construct a
56        list of .sad.xml files and pass them to the model to build the waveforms.
57        Waveforms in turn build their components and each component in turn build their
58        properties """     
59        try:
60            mgr = self.CORBAutils.domMgr._get_fileMgr()
61        except:
62            return
63        #Find the list of SAD and DAS files for all waveforms in standard SDR root directory (/sdr/)
64        (sdrWformsSADList, sdrWformsDASList) = (self.getFileList(SDR_WAVEFORMS_DIR, SAD_XML), self.getFileList(SDR_WAVEFORMS_DIR, DAS_XML))
65        #Find the list of SAD and DAS files for component running as waveforms. Those waveforms are installed in /sdr/_tmp_alf_waveforms
66        (tmpWformsSADList, tmpWformsDASList) = (self.getFileList(COMP_WAVEFORMS_DIR, SAD_XML, quiet=True), self.getFileList(COMP_WAVEFORMS_DIR, DAS_XML, quiet=True))
67       
68        if (sdrWformsSADList is None or sdrWformsDASList is None):
69                print "buildModel(): Error in reading SAD/DAS files for SDR waveforms in " + SDR_DIR
70                sys.exit(-1)
71       
72        if (tmpWformsSADList is None or tmpWformsDASList is None):
73            #We need not exit if no temporary waveforms are not found in /sdr/_tmp_alf_waveforms
74            tmpWformsSADList = []
75            tmpWformsDASList = []
76           
77       
78        sadFileList = sdrWformsSADList + tmpWformsSADList
79        dasFileList = sdrWformsDASList + tmpWformsDASList
80             
81        self.model.buildWaveforms(sadFileList, dasFileList)
82       
83        #update the model with currently installed waveforms in framework
84        installedWformDict = self.CORBAutils.getApplications()
85        for wform in installedWformDict.keys():
86            wformName = wform[wform.find("::") + 2 :]
87            for instance in installedWformDict[wform]:
88                instanceName = instance[instance.find("::") + 2 :]
89                self.model.addInstanceWaveform(wformName, instanceName)
90   
91    def selectNS(self):
92        isNewNS = self.CORBAutils.selectNamingService()
93        #if new namign service is selected, refresh the model and views.
94        if isNewNS:
95            self.refresh()
96   
97    def refresh(self):
98        #First, update the SDR waveforms installed
99        #model.buildWaveforms(..) will build a new object for every waveform if it is not there already
100        #in its list
101        #Find the list of SAD and DAS files for all waveforms in standard SDR root directory (/sdr/)
102        (sdrWformsSADList, sdrWformsDASList) = (self.getFileList(SDR_WAVEFORMS_DIR, SAD_XML), self.getFileList(SDR_WAVEFORMS_DIR, DAS_XML))
103        #Find the list of SAD and DAS files for component running as waveforms. Those waveforms are installed in /sdr/_tmp_alf_waveforms
104        (tmpWformsSADList, tmpWformsDASList) = (self.getFileList(COMP_WAVEFORMS_DIR, SAD_XML, quiet=True), self.getFileList(COMP_WAVEFORMS_DIR, DAS_XML, quiet = True))
105       
106        if (sdrWformsSADList is None or sdrWformsDASList is None):
107                print "buildModel(): Error in reading SAD/DAS files for SDR waveforms in " + SDR_DIR
108                sys.exit(-1)
109       
110        if (tmpWformsSADList is None or tmpWformsDASList is None):
111            #We need not exit if no temporary waveforms are not found in /sdr/_tmp_alf_waveforms
112            tmpWformsSADList = []
113            tmpWformsDASList = []
114       
115        sadFileList = sdrWformsSADList + tmpWformsSADList
116        dasFileList = sdrWformsDASList + tmpWformsDASList
117       
118        #sadFileList = self.getFileList(SDR_WAVEFORMS_DIR, SAD_XML) #list holding sad files of all the system waveforms           
119        #dasFileList = self.getFileList(SDR_WAVEFORMS_DIR, DAS_XML)
120        self.model.buildWaveforms(sadFileList, dasFileList)
121       
122        #get the new list of installed applications
123        installedWformDict = self.CORBAutils.getApplications()
124        self.model.refreshModel(installedWformDict)         
125       
126           
127    def createWidgetContainer(self):
128        root = __file__
129        if os.path.islink (root):
130            root = os.path.realpath (root)
131        root = os.path.dirname (os.path.abspath (root))
132
133        widgetsDom = minidom.parse(root + PROPERTY_WIDGET_CONFIG_FILE)#self.getDOM(PROPERTY_WIDGET_CONFIG_FILE)
134        self.widgetContainer = WidgetContainer(widgetsDom)
135       
136    def getFileList(self, dir, filetype, quiet=False):
137        fileList = []
138       
139        fileList = self.CORBAutils.getFileList(dir,filetype)
140       
141        #If no file found?
142        if fileList == None:
143            if not quiet: #Ignore the error for _tmp_alf_waveforms.
144                utils.showMessage("Could not find " + filetype + " files in this directory:\n " + dir, utils.FATAL, self.enableGUI)
145            return None
146       
147        return fileList
148   
149    def getDOM(self, xmlfile):
150        """ This method gets a file name as string and returns a DOM object built
151        using minidom
152        """
153        return self.CORBAutils.getDOM(xmlfile)
154   
155    def installWaveform(self, wformName, start):
156        wform = self.model.getWaveform(wformName, WaveformModel.SYSTEM_WAVEFORM)
157        if wform is None:
158            utils.showMessage ("Unable to install " + wformName, utils.FATAL, self.enableGUI)
159            return False
160        else:
161            instance = self.CORBAutils.installWaveform(wform.sadFile, wform.dasFile, start)
162            if instance is not None:
163                instanceName = instance[instance.find("::") + 2 :]
164                self.model.addInstanceWaveform(wformName, instanceName, start)
165                return instanceName
166            else:
167                utils.showMessage("Unable to find applications", utils.NON_FATAL, self.enableGUI)
168                return False
169    def uninstallWaveform(self, wformName):
170        status = self.CORBAutils.uninstallWaveform(wformName)
171        return status
172   
173    def startWaveform(self, wformName):
174        status = self.CORBAutils.startWaveform(wformName)
175        return status
176   
177    def stopWaveform(self, wformName):
178        status = self.CORBAutils.stopWaveform(wformName)
179        return status
180   
181    def getDefaultWidget(self, property):
182        return self.widgetContainer.getDefaultWidget(property)
183   
184    def getWidgetByType(self, type):
185        return self.widgetContainer.getWidgetByType(type)
186   
187    def getOptionalWidgets(self, propertyType):
188        return self.widgetContainer.getOptionalWidgets(propertyType)
189   
190    def getWidgetContainer(self):
191        return self.widgetContainer
192   
193    def getUtilRef(self):
194        return self.CORBAutils
195   
196    def setOSSIEProperty(self, sectionName, propertyName, propertyValue):
197        configFile = os.getenv('HOME') + '/' + OSSIE_CONFIG_FILE
198        configParser = ConfigParser.SafeConfigParser()
199        #check to see if a config file already exists
200        if os.path.exists(configFile):
201            #if so, read in its properties so they don't get lost
202            configParser.read(configFile)
203        if not configParser.has_section(sectionName):
204            configParser.add_section(sectionName)
205        configParser.set(sectionName, propertyName, propertyValue)
206        f = open(configFile, 'w')
207        configParser.write(f)
208        f.close()
209           
210    def getOSSIEProperty(self, sectionName, propertyName):
211        configFile = os.getenv('HOME') + '/' + OSSIE_CONFIG_FILE
212        if os.path.exists(configFile):
213            configParser = ConfigParser.SafeConfigParser()
214            configParser.read(configFile)
215            if configParser.has_option(sectionName, propertyName):
216                return configParser.get(sectionName, propertyName)
217        return None
218   
219    def OSSIEPropertyFileExists(self):
220        configFile = os.getenv('HOME') + '/' + OSSIE_CONFIG_FILE
221        return os.path.exists(configFile)
222   
223    def namingServiceIsRunning(self):
224        return self.nbUtils.namingServiceIsRunning()
225   
226    def startNamingService(self):
227        self.nbUtils.startNamingService()
228       
229    def nodeBooterIsRunning(self):
230        return self.nbUtils.nodeBooterIsRunning()
231   
232    def startNodeBooter(self):
233        self.nodeBooterProcess = self.nbUtils.startNodeBooter()
234   
235   
236   
237   
238       
239
240
Note: See TracBrowser for help on using the browser.