Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ envPaths
!*configure/ExampleRELEASE.local
O.*/
QtC-*
ui_*.py
*_rc.py
*.so
*.pyc
__pycache__/
Expand Down
5 changes: 5 additions & 0 deletions configure/CONFIG_SITE
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ USR_INCLUDES += -I $(INSTALL_LOCATION)/include
# default if not set
PYTHON ?= python

PYRCC ?= pyrcc4

PYRCCFLAGS_NO = -py2
PYRCCFLAGS_YES = -py3
PYRCCFLAGS = $(PYRCCFLAGS_$(PY_IS3)) $(CMD_PYRCCFLAGS)
5 changes: 5 additions & 0 deletions makehelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
print('TARGET_CFLAGS +=',get_config_var('BASECFLAGS'), file=out)
print('TARGET_CXXFLAGS +=',get_config_var('BASECFLAGS'), file=out)

if tuple(int(comp) for comp in get_config_var('VERSION').split('.')) >= (3,0):
print('PY_IS3 := YES', file=out)
else:
print('PY_IS3 := NO', file=out)

print('PY_VER :=',get_config_var('VERSION'), file=out)
ldver = get_config_var('LDVERSION')
if ldver is None:
Expand Down
25 changes: 25 additions & 0 deletions python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ PY += minimasar/test/__init__.py
PY += minimasar/test/test_db.py
PY += minimasar/test/test_ops.py

# generated to remove
QTCLEANS += masarclient/ui/ui_commentdetail.py
QTCLEANS += masarclient/ui/ui_commentdiag.py
QTCLEANS += masarclient/ui/ui_masar.py
QTCLEANS += masarclient/ui/masarRC_rc.py

include $(TOP)/configure/RULES
include $(TOP)/configure/RULES_PY

Expand All @@ -44,3 +50,22 @@ nose.%:
[ -d "$(P4P)/python$(PY_LD_VER)/$(T_A)/p4p" ]
PYTHONPATH="${PYTHONPATH}:$(abspath $(P4P))/python$(PY_LD_VER)/$(T_A):$(abspath $(TOP))/python$(PY_LD_VER)/$(T_A)" $(PYTHON) -m nose -P -v $* $(NOSEFLAGS)
endif

ui_%.py: ui_%.ui
$(PYTHON) -c 'import PyQt4.uic.pyuic' -o $@ --from-imports $<

# pyrcc4 is not python code...
# So there is no recipe like: python -c '...'
%_rc.py: %.qrc Makefile
$(PYRCC) $(PYRCCFLAGS) -o $@ $<

ifndef T_A
ifdef BASE_3_15
realclean: qt_clean
else
realclean:: qt_clean
endif

qt_clean:
$(RM) $(QTCLEANS)
endif
2 changes: 1 addition & 1 deletion python/masarclient/masarClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def saveSnapshot(self, params):

otherwise, False if nothing is found.
"""
print "saveSnapshot", params
print("saveSnapshot", params)
R = self._proxy.saveSnapshot(**params)
return (R.timeStamp.userTag, # actually new event #
R.channelName,
Expand Down
9 changes: 3 additions & 6 deletions python/masarclient/ui/authendlg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@

from PyQt4.QtGui import (QDialog, QVBoxLayout, QGridLayout, QLabel,
QDialogButtonBox, QLineEdit)
from PyQt4.QtCore import (QString, QObject, SIGNAL,Qt)
from PyQt4.QtCore import (QObject, SIGNAL,Qt)

try:
_fromUtf8 = QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
_fromUtf8 = lambda s: s

class AuthenDlg(QDialog):
def __init__(self, password, parent=None):
Expand Down Expand Up @@ -67,4 +64,4 @@ def result(self):
return None
else:
return (self.password)


2 changes: 1 addition & 1 deletion python/masarclient/ui/commentdetail.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from PyQt4.QtCore import (pyqtSignature)
from PyQt4.QtGui import (QApplication, QDialog, QDialogButtonBox)

import ui_commentdetail
from . import ui_commentdetail

class CommentDetail(QDialog,
ui_commentdetail.Ui_commentdetail):
Expand Down
2 changes: 1 addition & 1 deletion python/masarclient/ui/commentdlg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from PyQt4.QtCore import (pyqtSignature)
from PyQt4.QtGui import (QApplication, QDialog, QDialogButtonBox)

import ui_commentdiag
from . import ui_commentdiag

class CommentDlg(QDialog,
ui_commentdiag.Ui_commentdlg):
Expand Down
9 changes: 3 additions & 6 deletions python/masarclient/ui/finddlg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@
from __future__ import unicode_literals

from PyQt4.QtGui import (QDialog, QGridLayout, QLineEdit, QPushButton, QBrush, QLabel)
from PyQt4.QtCore import (QString, QObject, SIGNAL, Qt)
from PyQt4.QtCore import (QObject, SIGNAL, Qt)
import re, fnmatch
#from masar import masarUI #ImportError: cannot import name masarUI
try:
_fromUtf8 = QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
_fromUtf8 = lambda s: s

class FindDlg(QDialog):
#def __init__(self, info, parent=None):
Expand Down Expand Up @@ -120,4 +117,4 @@ def cleanup(self):
table.item(self.foundPVPos[i],0).setBackground(QBrush(Qt.white))

self.close()


9 changes: 6 additions & 3 deletions python/masarclient/ui/getmasarconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

import os
import platform
import ConfigParser
try:
from configparser import SafeConfigParser as ConfigParser
except ImportError:
from ConfigParser import SafeConfigParser as ConfigParser

def getmasarconfig():
'''Get configuration file for MASAR service which enables service integration for Olog and channel finder for example.
Expand All @@ -29,7 +32,7 @@ def getmasarconfig():
'''
system = platform.system()

config = ConfigParser.ConfigParser()
config = ConfigParser()
if system == 'Windows':
raise RuntimeError("Does not support Windows platform yet.")

Expand All @@ -55,4 +58,4 @@ def getmasarconfig():
return masarconfig

if __name__ == "__main__":
print getmasarconfig()
print(getmasarconfig())
9 changes: 3 additions & 6 deletions python/masarclient/ui/gradualput.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@

from PyQt4.QtGui import (QDialog, QGridLayout, QDialogButtonBox, QLineEdit, QPushButton,
QLabel, QMessageBox)
from PyQt4.QtCore import (QString, QObject, SIGNAL, Qt)
from PyQt4.QtCore import (QObject, SIGNAL, Qt)
import cothread
from cothread.catools import caget, caput
import traceback
try:
_fromUtf8 = QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
_fromUtf8 = lambda s: s


class GradualPut(QDialog):
Expand Down Expand Up @@ -136,4 +133,4 @@ def rampingPut(self):
#QMessageBox.warning(self, 'Warning', "Oops: something wrong with multiple-step gradual put")

return True


61 changes: 30 additions & 31 deletions python/masarclient/ui/masar.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@
from PyQt4.QtGui import (QApplication, QMainWindow, QMessageBox, QTableWidgetItem, QTableWidget,
QFileDialog, QColor, QBrush, QTabWidget, QShortcut, QKeySequence,
QDialog, QGridLayout, QLineEdit, QPushButton, QLabel, QDialogButtonBox)
from PyQt4.QtCore import (QDateTime, Qt, QString, QObject, SIGNAL, QThread, QEventLoop)
from PyQt4.QtCore import (QDateTime, Qt, QObject, SIGNAL, QThread, QEventLoop)
#import PyQt4.QTest as QTest

try:
_fromUtf8 = QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
_fromUtf8 = lambda s: s

if sys.version_info[:2]>=(2,7):
from collections import OrderedDict as odict
Expand All @@ -38,14 +35,14 @@
except ImportError:
pyOlogExisting = False

import ui_masar
import commentdlg
from showarrayvaluedlg import ShowArrayValueDlg
from selectrefsnapshotdlg import ShowSelectRefDlg
from finddlg import FindDlg
from verifysetpoint import VerifySetpoint
from gradualput import GradualPut
import getmasarconfig
from . import ui_masar
from . import commentdlg
from .showarrayvaluedlg import ShowArrayValueDlg
from .selectrefsnapshotdlg import ShowSelectRefDlg
from .finddlg import FindDlg
from .verifysetpoint import VerifySetpoint
from .gradualput import GradualPut
from . import getmasarconfig

import masarclient.masarClient as masarClient

Expand Down Expand Up @@ -293,33 +290,34 @@ def setTable(self, data, table):
The data has to be an ordered dictionary, and table is a QtGui.QTableWidget
Here is an example to construct an ordered dictionary.
"""
datavalues = list(data.values())
if data:
length = len(data.values()[0])
length = len(datavalues[0])
else:
print ('data is empty, exit.')
return
for i in range(1, len(data.values())):
if length != len(data.values()[i]):
for i in range(1, len(datavalues)):
if length != len(datavalues[i]):
QMessageBox.warning(self,
"Warning",
"Data length are not consistent.")

return

if isinstance(data, odict) and isinstance(table, QTableWidget):
nrows = len(data.values()[0])
nrows = len(datavalues[0])
ncols = len(data)
table.setRowCount(nrows)
table.setColumnCount(ncols)
# Removes all items in the view, and also all selections
table.clear()
table.setHorizontalHeaderLabels(data.keys())
table.setHorizontalHeaderLabels(list(data.keys()))

n = 0
for key in data:
m = 0
for item in data[key]:
if not isinstance(item, basestring):
if not isinstance(item, str):
item = str(item)
if item:
newitem = QTableWidgetItem(item)
Expand All @@ -344,7 +342,7 @@ def createNewTableWidget(self, eventID, label):
types of tables in snapshotTab: comment(Welcome page), ordinary(double-click on event table),
preview, compare, filter
"""
if self.tabWindowDict.has_key(str(eventID)):
if str(eventID) in self.tabWindowDict:
tableWidget = self.tabWindowDict[str(eventID)]
else:
tableWidget = QTableWidget()
Expand Down Expand Up @@ -427,7 +425,7 @@ def createLogEntry(self, logText, logbookName = None):
#import requests
#print("requests version: %s"%requests.__version__)
from pyOlog import OlogClient, Tag, Logbook, LogEntry
if 'https_proxy' in os.environ.keys():
if 'https_proxy' in os.environ:
#print("unset https_proxy: %s"%(os.environ['https_proxy']))
del os.environ['https_proxy']

Expand Down Expand Up @@ -496,7 +494,7 @@ def saveMachineSnapshot(self):
self.data4eid[str(eid)] = data
self.e2cDict[str(self.previewId)] = [configID, configDesc, cname]#needed for configTab

label = QString.fromUtf8((cname+': Preview: '+str(eid)))
label = ((cname+': Preview: '+str(eid)))
tabWidget = self.createNewTableWidget('preview', label)
self.setSnapshotTable(data, tabWidget, eid)
#sort the table by "Connection"
Expand Down Expand Up @@ -952,7 +950,7 @@ def setSnapshotTabWindow(self, eventNames, eventTs, eventIds):
"Can't get snapshot data for eventId:%s"%eventIds[i])

ts = eventTs[i].split('.')[0]
label = QString.fromUtf8((eventNames[i]+': ' +eventIds[i]+": "+ ts))
label = ((eventNames[i]+': ' +eventIds[i]+": "+ ts))
tableWidget = self.createNewTableWidget(eventIds[i], label)
self.setSnapshotTable(data, tableWidget, eventIds[i])

Expand Down Expand Up @@ -1011,7 +1009,7 @@ def __showArrayData(self, row, column):

def __find_key(self, dic, val):
"""return the key of dictionary dic given the value"""
return [k for k, v in dic.iteritems() if v == val][0]
return [k for k, v in dic.items() if v == val][0]

def retrieveMasarData(self, eventid=None):
"""
Expand Down Expand Up @@ -1073,14 +1071,15 @@ def setSnapshotTable(self, data, table, eventid):
called by setSnapshotTabWindow(), saveMachineSnapshot()(preview table), and searchPV()
This table is different from compareSnapshotsTable, see setCompareSnapshotsTable()
"""
datavalues = list(data.values())
if data:
length = len(data.values()[0])
length = len(datavalues[0])
else:
print ('data is empty, exit.')
return

for i in range(1, len(data.values())):
if length != len(data.values()[i]):
for i in range(1, len(datavalues)):
if length != len(datavalues[i]):
QMessageBox.warning(self,
"Warning",
"Data length are not consistent.")
Expand All @@ -1090,7 +1089,7 @@ def setSnapshotTable(self, data, table, eventid):
table.setSortingEnabled(False)
table.clear()

nrows = len(data.values()[0])
nrows = len(datavalues[0])
keys = ['PV Name', 'Saved Connection', 'Not Restore', 'Saved Value', 'Live Value', 'Diff',
'Saved Timestamp', 'Saved Status', 'Saved Severity',
'Live Connection', 'Live Timestamp', 'Live Status', 'Live Severity']
Expand Down Expand Up @@ -1440,7 +1439,7 @@ def simplePut(self, eid, eid4Log, r_pvlist, r_data, no_restorepvs, rowCount):
configFile = dirPath + '/configure/' + self.e2cDict[eid][2] + '.cfg'
if not os.path.isfile(configFile):
return
if not self.verifyWindowDict.has_key(configFile):
if configFile not in self.verifyWindowDict:
verifyWin = VerifySetpoint(configFile, rowCount, self.verifyWindowDict, self)
verifyWin.show()
self.verifyWindowDict[configFile] = verifyWin
Expand Down Expand Up @@ -1872,7 +1871,7 @@ def compareSnapshots(self):
#data[i]['keyword'] is a tuple; data[i]['keyword'][index] is the element value in the tuple

#try:
if self.tabWindowDict.has_key('compare'):
if 'compare' in self.tabWindowDict:
tableWidget = self.tabWindowDict['compare']
else:
tableWidget = QTableWidget()
Expand All @@ -1882,7 +1881,7 @@ def compareSnapshots(self):
labelText = ""
for eventId in eventIds:
labelText += '_' + eventId
label = QString.fromUtf8("Compare Snapshots: IDs" + labelText)
label = ("Compare Snapshots: IDs" + labelText)
self.snapshotTabWidget.addTab(tableWidget, label)
self.snapshotTabWidget.setTabText(self.snapshotTabWidget.count(), label)
self.snapshotTabWidget.setCurrentIndex(self.snapshotTabWidget.count())
Expand Down
Loading