This file is indexed.

/usr/share/pyshared/PyMca/SpsDataSource.py is in pymca 4.5.0-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
###########################################################################
# Copyright (C) 2004-2011 European Synchrotron Radiation Facility
#
# This file is part of the PyMCA X-ray Fluorescence Toolkit developed at
# the ESRF by the Beamline Instrumentation Software Support (BLISS) group.
#
# This toolkit is free software; you can redistribute it and/or modify it 
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option) 
# any later version.
#
# PyMCA is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# PyMCA; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307, USA.
#
# PyMCA follows the dual licensing model of Trolltech's Qt and Riverbank's PyQt
# and cannot be used as a free plugin for a non-free program. 
#
# Please contact the ESRF industrial unit (industry@esrf.fr) if this license 
# is a problem for you.
#############################################################################
import DataObject
import types
import copy
import spswrap as sps
import string
DEBUG = 0

SOURCE_TYPE = 'SPS'

class SpsDataSource:
    def __init__(self, name, object=None, copy = True):
        if type(name) != types.StringType:
            raise TypeError("Constructor needs string as first argument")
        self.name = name
        self.sourceName = name
        self.sourceType=SOURCE_TYPE


    def refresh(self):
        pass

    def getSourceInfo(self):
        """
        Returns information about the Spec version in self.name
        to give application possibility to know about it before loading.
        Returns a dictionary with the key "KeyList" (list of all available keys
        in this source). Each element in "KeyList" is an shared memory
        array name.
        """
        return self.__getSourceInfo()
        
    def getKeyInfo(self,key):
        if key in self.getSourceInfo()['KeyList']:
            return self.__getArrayInfo(key)
        else:
            return {}
                
    def getDataObject(self,key_list,selection=None):
        if type(key_list) != types.ListType:
            nolist = True
            key_list=[key_list]
        else:
            output = []
            nolist = False
        if self.name in sps.getspeclist():
            sourcekeys = self.getSourceInfo()['KeyList']
            for key in key_list:
                #a key corresponds to an array name
                if key not in sourcekeys:
                    raise KeyError("Key %s not in source keys" % key)
                #array = key
                #create data object
                data = DataObject.DataObject()
                data.info=self.__getArrayInfo(key)
                data.info ['selection'] = selection
                """
                info["row"]=row
                info["col"]=col
                if info["row"]!="ALL":
                    data= sps.getdatarow(self.SourceName,array,info["row"])
                    if data is not None: data=Numeric.reshape(data,(1,data.shape[0]))
                elif info["col"]!="ALL":
                    data= sps.getdatacol(self.SourceName,array,info["col"])
                    if data is not None: data=Numeric.reshape(data,(data.shape[0],1))
                else: data=sps.getdata (self.SourceName,array)
                """
                data.data=sps.getdata (self.name,key)
                if nolist:
                    if selection is not None:
                        scantest = (data.info['flag'] & sps.TAG_SCAN) == sps.TAG_SCAN
                        if ((key in ["SCAN_D"]) or scantest) \
                            and selection.has_key('cntlist'):
                            data.x = None
                            data.y = None
                            data.m = None
                            if data.info['envdict'].has_key('nopts'):
                                nopts  = string.atoi(data.info['envdict']['nopts']) + 1
                            else:
                                nopts  =data.info['rows']
                            if not data.info.has_key('LabelNames'):
                                data.info['LabelNames'] = selection['cntlist'] * 1
                            if selection.has_key('x'):
                                for labelindex in selection['x']:
                                    label = data.info['LabelNames'][labelindex]
                                    if label not in data.info['LabelNames']:
                                        raise ValueError("Label %s not in scan labels" % label)
                                    index = data.info['LabelNames'].index(label)
                                    if data.x is None: data.x = []
                                    data.x.append(data.data[:nopts, index])
                            if selection.has_key('y'):
                                for labelindex in selection['y']:
                                    label = data.info['LabelNames'][labelindex]
                                    if label not in data.info['LabelNames']:
                                        raise ValueError("Label %s not in scan labels" % label)
                                    index = data.info['LabelNames'].index(label)
                                    if data.y is None: data.y = []
                                    data.y.append(data.data[:nopts, index])
                            if selection.has_key('m'):
                                for labelindex in selection['m']:
                                    label = data.info['LabelNames'][labelindex]
                                    if label not in data.info['LabelNames']:
                                        raise ValueError("Label %s not in scan labels" % label)
                                    index = data.info['LabelNames'].index(label)
                                    if data.m is None: data.m = []
                                    data.m.append(data.data[:nopts, index])
                            data.info['selectiontype'] = "1D"
                            data.info['scanselection'] = True
                            data.data = None 
                            return data
                        if (key in ["XIA_DATA"]) and selection.has_key("XIA"):
                            if selection["XIA"]:
                                if data.info.has_key('Detectors'):
                                    for i in range(len(selection['rows']['y'])):
                                        selection['rows']['y'][i] = \
                                            data.info['Detectors'].index(selection['rows']['y'][i]) + 1
                                    del selection['XIA']
                        return data.select(selection)
                    else:
                        if data.data is not None:
                            data.info['selectiontype'] = "%dD" % len(data.data.shape)
                            if data.info['selectiontype'] == "2D":
                                data.info["imageselection"] = True
                        return data
                else:
                    output.append(data.select(selection))
            return output
        else:
            return None

    def __getSourceInfo(self):
        arraylist= []
        sourcename = self.name
        for array in sps.getarraylist(sourcename):
            arrayinfo= sps.getarrayinfo(sourcename, array)
            arraytype= arrayinfo[2]
            arrayflag= arrayinfo[3]
            if arraytype != sps.STRING:                
                if (arrayflag & sps.TAG_ARRAY) == sps.TAG_ARRAY:
                    arraylist.append(array)
                    continue
            if DEBUG:
                print("array not added %s" % array)
        source_info={}
        source_info["Size"]=len(arraylist)
        source_info["KeyList"]=arraylist
        return source_info


    def __getArrayInfo(self,array):
        info={}
        info["SourceType"]  = SOURCE_TYPE
        info["SourceName"]  = self.name
        info["Key"]         = array
        
        arrayinfo=sps.getarrayinfo (self.name,array)
        info["rows"]=arrayinfo[0]
        info["cols"]=arrayinfo[1]
        info["type"]=arrayinfo[2]
        info["flag"]=arrayinfo[3]
        counter=sps.updatecounter (self.name,array)
        info["updatecounter"]=counter

        envdict={}
        keylist=sps.getkeylist (self.name,array+"_ENV")
        for i in keylist:
            val=sps.getenv(self.name,array+"_ENV",i)
            envdict[i]=val
        info["envdict"]=envdict
        scantest = (info['flag'] & sps.TAG_SCAN) == sps.TAG_SCAN
        if (array in ["SCAN_D"]) or scantest :
            if info["envdict"].has_key('axistitles'):
                info["LabelNames"] = self._buildLabelsList(info['envdict']['axistitles'])
            if info["envdict"].has_key('H'):
                if info["envdict"].has_key('K'):
                    if info["envdict"].has_key('L'):
                        info['hkl'] = [envdict['H'],
                                       envdict['K'],
                                       envdict['L']]
                
        calibarray= array + "_PARAM"
        if calibarray in sps.getarraylist(self.name):
            try:
                data= sps.getdata(self.name, calibarray)
                updc= sps.updatecounter(self.name, calibarray)
                info["EnvKey"]= calibarray
                info["McaCalib"]= data.tolist()[0]
                info["env_updatecounter"]= updc
            except:
                pass

        if array in ["XIA_DATA", "XIA_BASELINE"]:
            envarray= "XIA_DET"
            if envarray in sps.getarraylist(self.name):
                try:
                    data= sps.getdata(self.name, envarray)
                    updc= sps.updatecounter(self.name, envarray)
                    info["EnvKey"]= envarray
                    info["Detectors"]= data.tolist()[0]
                    info["env_updatecounter"]= updc
                except:
                    pass        
        return info

    def _buildLabelsList(self, instr):
       if DEBUG:
           print('SpsDataSource : building counter list')
       state = 0
       llist  = ['']
       for letter in instr:
          if state == 0:
             if letter == ' ':
                state = 1
             elif letter == '{':
                state = 2
             else:
                llist[-1] = llist[-1] + letter
          
          elif state == 1:
             if letter == ' ':
                 pass
             elif letter == '{':
                 state = 2
                 llist.append('')
             else:
                llist.append(letter)
                state = 0

          elif state == 2:
             if letter == '}':
                state = 0
             else:
                llist[-1] = llist[-1] + letter

       try:
            llist.remove('')
       except ValueError:
            pass

       return llist

    def isUpdated(self, sourceName, key):
        if sps.specrunning(sourceName):
            if sps.isupdated(sourceName, key):
                return True

            #return True if its environment is updated
            envkey = key+"_ENV" 
            if envkey in sps.getarraylist(sourceName):
                if sps.isupdated(sourceName, envkey):
                    return True
                
        return False

source_types = { SOURCE_TYPE: SpsDataSource}

def DataSource(name="", object=None, copy=True, source_type=SOURCE_TYPE):
  try:
     sourceClass = source_types[source_type]
  except KeyError:
     #ERROR invalid source type
     raise TypeError("Invalid Source Type, source type should be one of %s" % source_types.keys())
  
  return sourceClass(name, object, copy)

        
if __name__ == "__main__":
    import sys,time

    try:
        specname=sys.argv[1]
        arrayname=sys.argv[2]        
        obj  = DataSource(specname)
        data = obj.getData(arrayname)
        #while(1):
        #    time.sleep(1)
        #    print obj.RefreshPage(specname,arrayname)
        print("info = ",data.info)
    except:
        print("Usage: SpsDataSource <specversion> <arrayname>")
        sys.exit()