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

[python3]: fixed import

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