Commit 59d6a9d0 authored by Pavel Vainerman's avatar Pavel Vainerman Committed by Pavel Vainerman

[python3]: fixed import

parent 3bdd88fa
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
%define oname uniset2 %define oname uniset2
Name: libuniset2 Name: libuniset2
Version: 2.15.1 Version: 2.15.2
Release: alt1 Release: alt1
Summary: UniSet - library for building distributed industrial control systems Summary: UniSet - library for building distributed industrial control systems
...@@ -594,6 +594,9 @@ rm -f %buildroot%_docdir/%oname/html/*.md5 ...@@ -594,6 +594,9 @@ rm -f %buildroot%_docdir/%oname/html/*.md5
# history of current unpublished changes # history of current unpublished changes
%changelog %changelog
* Tue Oct 12 2021 Pavel Vainerman <pv@altlinux.ru> 2.15.2-alt1
- fixed python3 imports
* Mon Oct 11 2021 Pavel Vainerman <pv@altlinux.ru> 2.15.1-alt1 * Mon Oct 11 2021 Pavel Vainerman <pv@altlinux.ru> 2.15.1-alt1
- supported "hash64/hash32" for ID - supported "hash64/hash32" for ID
......
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
# See doc: http://www.gnu.org/software/hello/manual/autoconf/Generic-Programs.html # See doc: http://www.gnu.org/software/hello/manual/autoconf/Generic-Programs.html
# AC_PREREQ(2.59) # AC_PREREQ(2.59)
AC_INIT([uniset2], [2.15.1], pv@etersoft.ru) AC_INIT([uniset2], [2.15.2], pv@etersoft.ru)
AM_INIT_AUTOMAKE([subdir-objects]) AM_INIT_AUTOMAKE([subdir-objects])
LIBVER=17:1:15 LIBVER=17:2:15
AC_SUBST(LIBVER) AC_SUBST(LIBVER)
# AC_CONFIG_MACRO_DIR([m4]) # AC_CONFIG_MACRO_DIR([m4])
......
#!/bin/sh
START=uniset2-start.sh
${START} -f ./testUC.py --ulog-add-levels info,warn,crit
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from pyUConnector import *
import time
import sys import sys
from .pyUniSet.pyUConnector import *
def is_id(str_id): def is_id(str_id):
if isinstance(str_id, int) or isinstance(str_id, int): if isinstance(str_id, int) or isinstance(str_id, int):
......
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import sys from .pyUniSet.pyUniSet import *
from pyUniSet import *
from pyUExceptions import *
class UInterface(): class UInterface():
def __init__(self): def __init__(self):
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
import sys import sys
from UInterface import * from .UInterface import *
from UGlobal import * from .UGlobal import *
from pyUModbus import * from .pyUniSet.pyUModbus import *
class UInterfaceModbus(UInterface): class UInterfaceModbus(UInterface):
...@@ -14,7 +14,7 @@ class UInterfaceModbus(UInterface): ...@@ -14,7 +14,7 @@ class UInterfaceModbus(UInterface):
self.itype = "modbus" self.itype = "modbus"
self.i = UModbus() self.i = UModbus()
self.i.prepare(ip,port) self.i.prepare(ip, port)
# return [id,node,name] # return [id,node,name]
def getIDinfo(self, s_id): def getIDinfo(self, s_id):
......
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from UInterface import * from .UInterface import *
from UGlobal import * from .UGlobal import *
from pyUConnector import * from .pyUniSet.pyUConnector import *
class UInterfaceUniSet(UInterface): class UInterfaceUniSet(UInterface):
def __init__(self, xmlfile, params): def __init__(self, xmlfile, params):
......
...@@ -144,4 +144,4 @@ class SharedMemoryAPI(UniSetHTTPService): ...@@ -144,4 +144,4 @@ class SharedMemoryAPI(UniSetHTTPService):
return self.request('/lost')[self.settings['smID']] return self.request('/lost')[self.settings['smID']]
def help(self): def help(self):
return self.request('/help')[self.settings['smID']] return self.request('/help')[self.settings['smID']]
\ No newline at end of file
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import re
import sys import sys
import libxml2 import libxml2
from lxml import etree from lxml import etree
import re
import os
# ----------------------------- # -----------------------------
class EmptyNode(): class EmptyNode():
def __init__(self): def __init__(self):
self.proplist = dict() self.proplist = dict()
def prop(self,name): def prop(self, name):
if name in self.proplist: if name in self.proplist:
return self.proplist[name] return self.proplist[name]
return "" return ""
def setProp(self, name, val):
self.proplist[name] = val
def setProp(self,name,val): def reset(self):
self.proplist[name] = val self.proplist = dict()
def reset(self):
self.proplist = dict()
# ----------------------------- # -----------------------------
class UniXMLException(Exception): class UniXMLException(Exception):
def __init__(self,e=""): def __init__(self, e=""):
self.err = e self.err = e
def getError(self): def getError(self):
return self.err return self.err
# ----------------------------- # -----------------------------
class UniXML(): class UniXML():
...@@ -38,11 +43,11 @@ class UniXML(): ...@@ -38,11 +43,11 @@ class UniXML():
try: try:
self.doc = None self.doc = None
if isDoc: if isDoc:
self.fname = '' self.fname = ''
self.doc = libxml2.parseDoc(xfile) self.doc = libxml2.parseDoc(xfile)
else: else:
self.fname = xfile self.fname = xfile
self.doc = libxml2.parseFile(xfile) self.doc = libxml2.parseFile(xfile)
except libxml2.parserError: except libxml2.parserError:
raise UniXMLException("(UniXML): Can`t open file " + xfile) raise UniXMLException("(UniXML): Can`t open file " + xfile)
...@@ -83,7 +88,7 @@ class UniXML(): ...@@ -83,7 +88,7 @@ class UniXML():
while node != None: while node != None:
if node.prop(propstr) == valuestr: if node.prop(propstr) == valuestr:
return [node, node.name, node.prop(propstr)] return [node, node.name, node.prop(propstr)]
ret = self.findNode_byProp (node.children, propstr, valuestr) ret = self.findNode_byProp(node.children, propstr, valuestr)
if ret[0] != None: if ret[0] != None:
return ret return ret
node = node.__next__ node = node.__next__
...@@ -95,14 +100,14 @@ class UniXML(): ...@@ -95,14 +100,14 @@ class UniXML():
if node == None: if node == None:
return node return node
if node.name != "text" and node.name != "comment": if node.name != "text" and node.name != "comment":
return node return node
return None return None
def getNode(self, node): def getNode(self, node):
if node == None: if node == None:
return None return None
if node.name != "text" and node.name != "comment": if node.name != "text" and node.name != "comment":
return node return node
return self.nextNode(node) return self.nextNode(node)
def firstNode(self, node): def firstNode(self, node):
...@@ -117,8 +122,8 @@ class UniXML(): ...@@ -117,8 +122,8 @@ class UniXML():
def lastNode(self, node): def lastNode(self, node):
prev = node prev = node
while node != None: while node != None:
prev = node prev = node
node = self.nextNode(node) node = self.nextNode(node)
return prev return prev
...@@ -131,20 +136,20 @@ class UniXML(): ...@@ -131,20 +136,20 @@ class UniXML():
def save(self, filename=None, pretty_format=True, backup=False): def save(self, filename=None, pretty_format=True, backup=False):
if filename == None: if filename == None:
filename = self.fname filename = self.fname
if backup: if backup:
# чтобы "ссылки" не бились, делаем копирование не через rename # чтобы "ссылки" не бились, делаем копирование не через rename
#os.rename(self.fname,str(self.fname+".bak")) # os.rename(self.fname,str(self.fname+".bak"))
f_in = file(self.fname,'rb') f_in = file(self.fname, 'rb')
f_out = file(str(self.fname+".bak"),'wb') f_out = file(str(self.fname + ".bak"), 'wb')
f_in.seek(0) f_in.seek(0)
f_out.write(f_in.read()) f_out.write(f_in.read())
f_in.close() f_in.close()
f_out.close() f_out.close()
if pretty_format == True: if pretty_format == True:
return self.pretty_save(filename) return self.pretty_save(filename)
return self.doc.saveFile(filename) return self.doc.saveFile(filename)
...@@ -163,12 +168,12 @@ class UniXML(): ...@@ -163,12 +168,12 @@ class UniXML():
def pretty_save(self, filename): def pretty_save(self, filename):
context = self.doc.serialize(encoding="utf-8") context = self.doc.serialize(encoding="utf-8")
mdoc = etree.XML(context) mdoc = etree.XML(context)
s = etree.tostring(mdoc,pretty_print=True,encoding="UTF-8",method='xml',xml_declaration=True).split("\n") s = etree.tostring(mdoc, pretty_print=True, encoding="UTF-8", method='xml', xml_declaration=True).split("\n")
out = open(filename,"w") out = open(filename, "w")
p = re.compile(r'\ [^\s]{1,}=""') p = re.compile(r'\ [^\s]{1,}=""')
for l in s: for l in s:
if l.strip(): if l.strip():
# удаляем пустые свойства prop="" # удаляем пустые свойства prop=""
l = p.sub('', l) l = p.sub('', l)
out.write(l+"\n") out.write(l + "\n")
out.close() out.close()
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from UGlobal import * from .UGlobal import *
from UniXML import * from .UniXML import *
from UInterface import * from .UInterface import *
from UInterfaceUniSet import * from .UInterfaceUniSet import *
from UInterfaceModbus import * from .UInterfaceModbus import *
from pyUniSet import * from .pyUniSet.pyUniSet import *
from pyUModbus import * from .pyUniSet.pyUModbus import *
from pyUConnector import * from .pyUniSet.pyUConnector import *
from pyUExceptions import * from .pyUniSet.pyUExceptions import *
...@@ -3,7 +3,7 @@ if ENABLE_PYTHON ...@@ -3,7 +3,7 @@ if ENABLE_PYTHON
SWIG=swig SWIG=swig
#python_SCRIPTS = pyUniSet.py pyUConnector.py pyUModbus.py pyUExceptions.py #python_SCRIPTS = pyUniSet.py pyUConnector.py pyUModbus.py pyUExceptions.py
pydir=$(pkgpythondir) pydir=$(pkgpythondir)/pyUniSet
py_DATA = pyUniSet.py pyUConnector.py pyUModbus.py pyUExceptions.py py_DATA = pyUniSet.py pyUConnector.py pyUModbus.py pyUExceptions.py
BUILD_SRCDIR=$(srcdir)/../../../core BUILD_SRCDIR=$(srcdir)/../../../core
......
...@@ -36,7 +36,7 @@ if __name__ == "__main__": ...@@ -36,7 +36,7 @@ if __name__ == "__main__":
lst2.add_str(pstr2) lst2.add_str(pstr2)
p = [] p = []
print "lst: class: " + str(p.__class__.__name__) print("lst: class: " + str(p.__class__.__name__))
try: try:
uc1 = UConnector( lst, "test.xml" ) uc1 = UConnector( lst, "test.xml" )
...@@ -49,19 +49,19 @@ if __name__ == "__main__": ...@@ -49,19 +49,19 @@ if __name__ == "__main__":
uc1.activate_objects() uc1.activate_objects()
while True: while True:
print "getValue(10): %d" % obj1.getValue(10) print("getValue(10): %d" % obj1.getValue(10))
time.sleep(1) time.sleep(1)
# print "Info: %s"%uc1.getObjectInfo("TestProc1","") # print "Info: %s"%uc1.getObjectInfo("TestProc1","")
print "apiRequest: %s"%uc1.apiRequest(uc1.getObjectID("SharedMemory"),"get?10") print("apiRequest: %s"%uc1.apiRequest(uc1.getObjectID("SharedMemory"),"get?10"))
# tc = uc1.getTimeChange(2) # tc = uc1.getTimeChange(2)
# print "TimeChange: %s sup=%d"%(tc.value,tc.supplier) # print "TimeChange: %s sup=%d"%(tc.value,tc.supplier)
# print "(0)UIType: %s" % uc1.getUIType() # print "(0)UIType: %s" % uc1.getUIType()
print "(1)getShortName: id=%d name=%s" % (1, uc1.getShortName(1)) print("(1)getShortName: id=%d name=%s" % (1, uc1.getShortName(1)))
print "(2)getObjectID('TestProc'): %d" % uc1.getObjectID("TestProc") print("(2)getObjectID('TestProc'): %d" % uc1.getObjectID("TestProc"))
# print " getName: id=%d name=%s" % (1, uc1.getName(101)) # print " getName: id=%d name=%s" % (1, uc1.getName(101))
# print " getTextName: id=%d name=%s" % (1, uc1.getTextName(101)) # print " getTextName: id=%d name=%s" % (1, uc1.getTextName(101))
...@@ -71,20 +71,20 @@ if __name__ == "__main__": ...@@ -71,20 +71,20 @@ if __name__ == "__main__":
# print " getTextName: id=%d name=%s" % (2, uc1.getTextName(109)) # print " getTextName: id=%d name=%s" % (2, uc1.getTextName(109))
try: try:
print "(1)setValue: %d=%d" % (3,22) print("(1)setValue: %d=%d" % (3,22))
uc1.setValue(3,22,DefaultID) uc1.setValue(3,22,DefaultID)
except UException, e: except UException as e:
print "(1)setValue exception: " + str(e.getError()) print("(1)setValue exception: " + str(e.getError()))
try: try:
print "(2)getValue: %d=%d" % ( 3, uc1.getValue(3,DefaultID) ) print("(2)getValue: %d=%d" % ( 3, uc1.getValue(3,DefaultID) ))
except UException, e: except UException as e:
print "(2)getValue exception: " + str(e.getError()) print("(2)getValue exception: " + str(e.getError()))
try: try:
print "(3)getValue: %d=%d" % ( 100, uc1.getValue(100,DefaultID) ) print("(3)getValue: %d=%d" % ( 100, uc1.getValue(100,DefaultID) ))
except UException, e: except UException as e:
print "(3)getValue exception: " + str(e.getError()) print("(3)getValue exception: " + str(e.getError()))
except UException, e: except UException as e:
print "(testUI): catch exception: " + str(e.getError()) print("(testUI): catch exception: " + str(e.getError()))
...@@ -25,8 +25,8 @@ if __name__ == "__main__": ...@@ -25,8 +25,8 @@ if __name__ == "__main__":
# print shm.get(sensors='10,12') # print shm.get(sensors='10,12')
# print shm.lost() # print shm.lost()
# print shm.help() # print shm.help()
print shm.sensors(0,10) print(shm.sensors(0,10))
except UHTTPError, e: except UHTTPError as e:
print e.message print(e.message)
...@@ -32,29 +32,29 @@ if __name__ == "__main__": ...@@ -32,29 +32,29 @@ if __name__ == "__main__":
obj1.askSensor(10) obj1.askSensor(10)
while True: while True:
print "sleep..." print("sleep...")
print "getValue: %d=%d" % (10, obj1.getValue(10)) print("getValue: %d=%d" % (10, obj1.getValue(10)))
time.sleep(2) time.sleep(2)
print "getShortName: id=%d name=%s" % (1, getShortName(1)) print("getShortName: id=%d name=%s" % (1, getShortName(1)))
print " getName: id=%d name=%s" % (1, getName(1)) print(" getName: id=%d name=%s" % (1, getName(1)))
print " getTextName: id=%d name=%s" % (1, getTextName(1)) print(" getTextName: id=%d name=%s" % (1, getTextName(1)))
print "\n" print("\n")
print "getShortName: id=%d name=%s" % (2, getShortName(2)) print("getShortName: id=%d name=%s" % (2, getShortName(2)))
print " getName: id=%d name=%s" % (2, getName(2)) print(" getName: id=%d name=%s" % (2, getName(2)))
print " getTextName: id=%d name=%s" % (2, getTextName(2)) print(" getTextName: id=%d name=%s" % (2, getTextName(2)))
print " getObjectID: id=%d name=%s" % (getObjectID("TestProc"), "TestProc") print(" getObjectID: id=%d name=%s" % (getObjectID("TestProc"), "TestProc"))
try: try:
print "getValue: %d=%d" % (1, getValue(1)) print("getValue: %d=%d" % (1, getValue(1)))
except UException, e: except UException as e:
print "getValue exception: " + str(e.getError()) print("getValue exception: " + str(e.getError()))
try: try:
print "setValue: %d=%d" % (14, 22) print("setValue: %d=%d" % (14, 22))
setValue(14, 22) setValue(14, 22)
except UException, e: except UException as e:
print "setValue exception: " + str(e.getError()) print("setValue exception: " + str(e.getError()))
except UException, e: except UException as e:
print "(testUI): catch exception: " + str(e.getError()) print("(testUI): catch exception: " + str(e.getError()))
...@@ -14,27 +14,27 @@ if __name__ == "__main__": ...@@ -14,27 +14,27 @@ if __name__ == "__main__":
try: try:
mb = UModbus() mb = UModbus()
print "UIType: %s" % mb.getUIType() print("UIType: %s" % mb.getUIType())
mb.connect("localhost",2048) mb.connect("localhost",2048)
try: try:
print "Test READ functions..." print("Test READ functions...")
for f in range(1,5): for f in range(1,5):
print "func=%d reg=%d" % (f,22) print("func=%d reg=%d" % (f,22))
val = mb.mbread(0x01,22,f,"unsigned",-1) val = mb.mbread(0x01,22,f,"unsigned",-1)
# val = mb.mbread(0x01,22) # val = mb.mbread(0x01,22)
print "val=%d"%val print("val=%d"%val)
print "getWord: %d" % mb.getWord(0x01,22) print("getWord: %d" % mb.getWord(0x01,22))
print "getByte: %d" % mb.getByte(0x01,22) print("getByte: %d" % mb.getByte(0x01,22))
print "getBit: %d" % mb.getBit(0x01,22,3) print("getBit: %d" % mb.getBit(0x01,22,3))
# print "" # print ""
# print "Test WRITE functions..." # print "Test WRITE functions..."
# for f in range(1,6): # for f in range(1,6):
# print "func=%d reg=%d" % (f,22) # print "func=%d reg=%d" % (f,22)
# val = mb.getValue(f,0x01,22,"unsigned",-1) # val = mb.getValue(f,0x01,22,"unsigned",-1)
except UException, e: except UException as e:
print "exception: " + str(e.getError()) print("exception: " + str(e.getError()))
except UException, e: except UException as e:
print "(testUModbus): catch exception: " + str(e.getError()) print("(testUModbus): catch exception: " + str(e.getError()))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment