make run Beremiz and PLCOpen Editor, if full path contain non-lating
characters
There was a problem in About dialog and in project properites tab and
probably in my other places, when str is automatically converted to
unicode string using ascii.
This patch converts str to unicode using proper encoding at the very beggining.
--- a/Beremiz.py Wed Apr 12 10:20:01 2017 +0000
+++ b/Beremiz.py Thu Apr 20 13:01:45 2017 +0300
@@ -27,12 +27,13 @@
+import util.paths as paths class BeremizIDELauncher:
self.updateinfo_url = None
- self.app_dir = os.path.dirname(os.path.realpath(__file__))
+ self.app_dir = paths.AbsDir(__file__) --- a/BeremizIDE.py Wed Apr 12 10:20:01 2017 +0000
+++ b/BeremizIDE.py Thu Apr 20 13:01:45 2017 +0300
@@ -30,9 +30,10 @@
+import util.paths as paths from types import ListType
-beremiz_dir = os.path.dirname(os.path.realpath(__file__))
+beremiz_dir = paths.AbsDir(__file__) return os.path.join(beremiz_dir,*args)
--- a/Beremiz_service.py Wed Apr 12 10:20:01 2017 +0000
+++ b/Beremiz_service.py Thu Apr 20 13:01:45 2017 +0300
@@ -5,6 +5,7 @@
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
+# Copyright (C) 2017: Andrey Skvortsov # See COPYING file for copyrights details.
@@ -96,7 +97,8 @@
-beremiz_dir = os.path.dirname(os.path.realpath(__file__))
+import util.paths as paths +beremiz_dir = paths.AbsDir(__file__) --- a/NativeLib.py Wed Apr 12 10:20:01 2017 +0000
+++ b/NativeLib.py Thu Apr 20 13:01:45 2017 +0300
@@ -5,6 +5,7 @@
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
+# Copyright (C) 2017: Andrey Skvortsov # See COPYING file for copyrights details.
@@ -23,9 +24,10 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+import util.paths as paths from POULibrary import POULibrary
class NativeLibrary(POULibrary):
def GetLibraryPath(self):
- return os.path.join(os.path.split(__file__)[0], "NativeLib.xml")
+ return paths.AbsNeighbourFile(__file__, "NativeLib.xml") --- a/PLCControler.py Wed Apr 12 10:20:01 2017 +0000
+++ b/PLCControler.py Thu Apr 20 13:01:45 2017 +0300
@@ -5,6 +5,7 @@
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
+# Copyright (C) 2017: Andrey Skvortsov # See COPYING file for copyrights details.
@@ -28,6 +29,7 @@
from copy import deepcopy
+import util.paths as paths from time import localtime
from collections import OrderedDict, namedtuple
@@ -88,7 +90,7 @@
LOCATION_VAR_MEMORY] = range(6)
-ScriptDirectory = os.path.split(os.path.realpath(__file__))[0]
+ScriptDirectory = paths.AbsDir(__file__) def GetUneditableNames():
--- a/PLCOpenEditor.py Wed Apr 12 10:20:01 2017 +0000
+++ b/PLCOpenEditor.py Thu Apr 20 13:01:45 2017 +0300
@@ -5,6 +5,7 @@
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
+# Copyright (C) 2017: Andrey Skvortsov # See COPYING file for copyrights details.
@@ -25,8 +26,9 @@
import os, sys, platform, time, traceback, getopt
+import util.paths as paths -beremiz_dir = os.path.dirname(os.path.realpath(__file__))
+beremiz_dir = paths.AbsDir(__file__) __version__ = "$Revision: 1.130 $"
--- a/ProjectController.py Wed Apr 12 10:20:01 2017 +0000
+++ b/ProjectController.py Thu Apr 20 13:01:45 2017 +0300
@@ -5,6 +5,7 @@
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
+# Copyright (C) 2017: Andrey Skvortsov # See COPYING file for copyrights details.
@@ -41,6 +42,7 @@
+import util.paths as paths from util.misc import CheckPathPerm, GetClassImporter
from util.MiniTextControler import MiniTextControler
from util.ProcessLogger import ProcessLogger
@@ -56,7 +58,7 @@
from targets.typemapping import UnpackDebugBuffer
from ConfigTreeNode import ConfigTreeNode, XSDSchemaErrorMessage
-base_folder = os.path.split(os.path.dirname(os.path.realpath(__file__)))[0]
+base_folder = paths.AbsParentDir(__file__) MATIEC_ERROR_MODEL = re.compile(".*\.st:(\d+)-(\d+)\.\.(\d+)-(\d+): (?:error)|(?:warning) : (.*)$")
@@ -567,7 +569,7 @@
- return os.path.split(__file__)[0]
+ return paths.AbsDir(__file__) def CTNPath(self, CTNName=None):
--- a/canfestival/canfestival.py Wed Apr 12 10:20:01 2017 +0000
+++ b/canfestival/canfestival.py Thu Apr 20 13:01:45 2017 +0300
@@ -5,6 +5,7 @@
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
+# Copyright (C) 2017: Andrey Skvortsov # See COPYING file for copyrights details.
@@ -23,8 +24,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+import util.paths as paths -base_folder = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
+base_folder = paths.AbsParentDir(__file__, 2) CanFestivalPath = os.path.join(base_folder, "CanFestival-3")
sys.path.append(os.path.join(CanFestivalPath, "objdictgen"))
@@ -579,7 +581,7 @@
format_dict["nodes_close"] += 'NODE_CLOSE(%s)\n '%(nodename)
format_dict["nodes_stop"] += 'NODE_STOP(%s)\n '%(nodename)
- filename = os.path.join(os.path.split(__file__)[0],"cf_runtime.c")
+ filename = paths.AbsNeighbourFile(__file__,"cf_runtime.c") cf_main = open(filename).read() % format_dict
cf_main_path = os.path.join(buildpath, "CF_%(locstr)s.c"%format_dict)
f = open(cf_main_path,'w')
--- a/connectors/__init__.py Wed Apr 12 10:20:01 2017 +0000
+++ b/connectors/__init__.py Thu Apr 20 13:01:45 2017 +0300
@@ -5,6 +5,7 @@
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
+# Copyright (C) 2017: Andrey Skvortsov # See COPYING file for copyrights details.
@@ -25,9 +26,9 @@
from os import listdir, path
+import util.paths as paths -_base_path = path.split(__file__)[0]
+_base_path = paths.AbsDir(__file__) def _GetLocalConnectorClassFactory(name):
--- a/plcopen/definitions.py Wed Apr 12 10:20:01 2017 +0000
+++ b/plcopen/definitions.py Thu Apr 20 13:01:45 2017 +0300
@@ -5,6 +5,7 @@
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
+# Copyright (C) 2017: Andrey Skvortsov # See COPYING file for copyrights details.
@@ -24,7 +25,8 @@
from os.path import join, split, realpath
-sd = split(realpath(__file__))[0]
+import util.paths as paths +sd = paths.AbsDir(__file__) # Override gettext _ in this module
# since we just want string to be added to dictionnary
--- a/plcopen/plcopen.py Wed Apr 12 10:20:01 2017 +0000
+++ b/plcopen/plcopen.py Thu Apr 20 13:01:45 2017 +0300
@@ -5,6 +5,7 @@
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
+# Copyright (C) 2017: Andrey Skvortsov # See COPYING file for copyrights details.
@@ -27,6 +28,7 @@
from collections import OrderedDict
+import util.paths as paths Dictionary that makes the relation between var names in plcopen and displayed values
@@ -132,7 +134,7 @@
def TextMatched(str1, str2):
return str1 and str2 and (str1.upper() == str2.upper())
-PLCOpenParser = GenerateParserFromXSD(os.path.join(os.path.split(__file__)[0], "tc6_xml_v201.xsd"))
+PLCOpenParser = GenerateParserFromXSD(paths.AbsNeighbourFile(__file__, "tc6_xml_v201.xsd")) PLCOpen_XPath = lambda xpath: etree.XPath(xpath, namespaces=PLCOpenParser.NSMAP)
LOAD_POU_PROJECT_TEMPLATE = """
@@ -167,7 +169,7 @@
-PLCOpen_v1_file = open(os.path.join(os.path.split(__file__)[0], "TC6_XML_V10_B.xsd"))
+PLCOpen_v1_file = open(paths.AbsNeighbourFile(__file__, "TC6_XML_V10_B.xsd")) PLCOpen_v1_xml = PLCOpen_v1_file.read()
PLCOpen_v1_xml = PLCOpen_v1_xml.replace(
--- a/py_ext/PythonFileCTNMixin.py Wed Apr 12 10:20:01 2017 +0000
+++ b/py_ext/PythonFileCTNMixin.py Thu Apr 20 13:01:45 2017 +0300
@@ -5,6 +5,7 @@
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
+# Copyright (C) 2017: Andrey Skvortsov # See COPYING file for copyrights details.
@@ -24,6 +25,7 @@
+import util.paths as paths from xmlclass import GenerateParserFromXSD
@@ -47,8 +49,7 @@
filepath = self.PythonFileName()
if os.path.isfile(filepath):
- PythonParser = GenerateParserFromXSD(
- os.path.join(os.path.dirname(__file__), "py_ext_xsd.xsd"))
+ PythonParser = GenerateParserFromXSD(paths.AbsNeighbourFile(__file__, "py_ext_xsd.xsd")) xmlfile = open(filepath, 'r')
pythonfile_xml = xmlfile.read()
--- a/py_ext/py_ext.py Wed Apr 12 10:20:01 2017 +0000
+++ b/py_ext/py_ext.py Thu Apr 20 13:01:45 2017 +0300
@@ -5,6 +5,7 @@
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
+# Copyright (C) 2017: Andrey Skvortsov # See COPYING file for copyrights details.
@@ -25,15 +26,15 @@
from POULibrary import POULibrary
from PythonFileCTNMixin import PythonFileCTNMixin
+import util.paths as paths class PythonLibrary(POULibrary):
def GetLibraryPath(self):
- return os.path.join(os.path.split(__file__)[0], "pous.xml")
+ return paths.AbsNeighbourFile(__file__, "pous.xml") def Generate_C(self, buildpath, varlist, IECCFLAGS):
- plc_python_filepath = os.path.join(
- os.path.split(__file__)[0], "plc_python.c")
+ plc_python_filepath = paths.AbsNeighbourFile(__file__, "plc_python.c") plc_python_file = open(plc_python_filepath, 'r')
plc_python_code = plc_python_file.read()
--- a/runtime/NevowServer.py Wed Apr 12 10:20:01 2017 +0000
+++ b/runtime/NevowServer.py Thu Apr 20 13:01:45 2017 +0300
@@ -4,6 +4,7 @@
# This file is part of Beremiz runtime.
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
+# Copyright (C) 2017: Andrey Skvortsov # See COPYING.Runtime file for copyrights details.
@@ -22,6 +23,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import util.paths as paths from nevow import rend, appserver, inevow, tags, loaders, athena
from nevow.page import renderer
from twisted.python import util
@@ -122,7 +124,7 @@
def __init__(self, plcState=False, *a, **kw):
super(WebInterface, self).__init__(*a, **kw)
- self.jsModules.mapping[u'WebInterface'] = util.sibpath(__file__, 'webinterface.js')
+ self.jsModules.mapping[u'WebInterface'] = paths.AbsNeighbourFile(__file__), 'webinterface.js') self.MainPage.setPLCState(plcState)
--- a/svgui/svgui.py Wed Apr 12 10:20:01 2017 +0000
+++ b/svgui/svgui.py Thu Apr 20 13:01:45 2017 +0300
@@ -5,6 +5,7 @@
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
+# Copyright (C) 2017: Andrey Skvortsov # See COPYING file for copyrights details.
@@ -27,13 +28,14 @@
from pyjs import translate
+import util.paths as paths from POULibrary import POULibrary
from docutil import open_svg
from py_ext import PythonFileCTNMixin
class SVGUILibrary(POULibrary):
def GetLibraryPath(self):
- return os.path.join(os.path.split(__file__)[0], "pous.xml")
+ return paths.AbsNeighbourFile(__file__, "pous.xml") class SVGUI(PythonFileCTNMixin):
@@ -49,7 +51,7 @@
- return os.path.join(os.path.dirname(__file__))
+ return paths.AbsDir(__file__) def _getSVGpath(self, project_path=None):
@@ -58,7 +60,7 @@
return os.path.join(project_path, "gui.svg")
def _getSVGUIserverpath(self):
- return os.path.join(os.path.dirname(__file__), "svgui_server.py")
+ return paths.AbsNeighbourFile(__file__, "svgui_server.py") def OnCTNSave(self, from_project_path=None):
if from_project_path is not None:
@@ -90,13 +92,14 @@
svguilibpath = os.path.join(self._getBuildPath(), "svguilib.js")
svguilibfile = open(svguilibpath, 'w')
- svguilibfile.write(translate(os.path.join(os.path.dirname(__file__), "pyjs", "lib", "sys.py"), "sys"))
- svguilibfile.write(open(os.path.join(os.path.dirname(__file__), "pyjs", "lib", "_pyjs.js"), 'r').read())
- svguilibfile.write(translate(os.path.join(os.path.dirname(__file__), "pyjs", "lib", "pyjslib.py"), "pyjslib"))
- svguilibfile.write(translate(os.path.join(os.path.dirname(__file__), "svguilib.py"), "svguilib"))
+ fpath=paths.AbsDir(__file__) + svguilibfile.write(translate(os.path.join(fpath, "pyjs", "lib", "sys.py"), "sys")) + svguilibfile.write(open(os.path.join(fpath, "pyjs", "lib", "_pyjs.js"), 'r').read()) + svguilibfile.write(translate(os.path.join(fpath, "pyjs", "lib", "pyjslib.py"), "pyjslib")) + svguilibfile.write(translate(os.path.join(fpath, "svguilib.py"), "svguilib")) svguilibfile.write("pyjslib();\nsvguilib();\n")
- svguilibfile.write(open(os.path.join(os.path.dirname(__file__), "pyjs", "lib", "json.js"), 'r').read())
- svguilibfile.write(open(os.path.join(os.path.dirname(__file__), "livesvg.js"), 'r').read())
+ svguilibfile.write(open(os.path.join(fpath, "pyjs", "lib", "json.js"), 'r').read()) + svguilibfile.write(open(os.path.join(fpath, "livesvg.js"), 'r').read()) jsmodules = {"LiveSVGPage": "svguilib.js"}
res += (("svguilib.js", file(svguilibpath,"rb")),)
--- a/targets/__init__.py Wed Apr 12 10:20:01 2017 +0000
+++ b/targets/__init__.py Thu Apr 20 13:01:45 2017 +0300
@@ -5,6 +5,7 @@
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
+# Copyright (C) 2017: Andrey Skvortsov # See COPYING file for copyrights details.
@@ -34,8 +35,9 @@
from os import listdir, path
+import util.paths as paths -_base_path = path.split(__file__)[0]
+_base_path = paths.AbsDir(__file__) def _GetLocalTargetClassFactory(name):
return lambda:getattr(__import__(name,globals(),locals()), name+"_target")
@@ -78,10 +80,10 @@
- filename = path.join(path.split(__file__)[0],"beremiz.h")
+ filename = paths.AbsNeighbourFile(__file__,"beremiz.h") return open(filename).read()
- filename = path.join(path.split(__file__)[0],name)
+ filename = paths.AbsNeighbourFile(__file__,name) return open(filename).read()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/util/paths.py Thu Apr 20 13:01:45 2017 +0300
@@ -0,0 +1,44 @@
+# This file is part of Beremiz, a Integrated Development Environment for +# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. +# Copyright (C) 2017: Andrey Skvortsov +# See COPYING file for copyrights details. +# This program 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. +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + if isinstance(file, str): + file = unicode(file,sys.getfilesystemencoding()) + return os.path.dirname(os.path.realpath(file)) +def AbsNeighbourFile(file, *args): + return os.path.join(AbsDir(file), *args) +def AbsParentDir(file, level = 1): + for i in range(0, level): + path = os.path.dirname(path) --- a/version.py Wed Apr 12 10:20:01 2017 +0000
+++ b/version.py Thu Apr 20 13:01:45 2017 +0300
@@ -24,10 +24,11 @@
+import util.paths as paths - app_dir=os.path.dirname(os.path.realpath(__file__))
+ app_dir=paths.AbsDir(__file__) @@ -88,8 +89,8 @@
- path=os.path.join(os.path.dirname(os.path.abspath(__file__)))
- license_path = os.path.join(path, u"COPYING")
+ path=paths.AbsDir(__file__) + license_path = os.path.join(path, "COPYING") if os.path.exists(license_path):
with open(license_path) as f:
--- a/wxglade_hmi/wxglade_hmi.py Wed Apr 12 10:20:01 2017 +0000
+++ b/wxglade_hmi/wxglade_hmi.py Thu Apr 20 13:01:45 2017 +0300
@@ -5,6 +5,7 @@
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
+# Copyright (C) 2017: Andrey Skvortsov # See COPYING file for copyrights details.
@@ -26,6 +27,7 @@
from xml.dom import minidom
+import util.paths as paths from py_ext import PythonFileCTNMixin
class WxGladeHMI(PythonFileCTNMixin):
@@ -41,7 +43,7 @@
- return os.path.join(os.path.dirname(__file__))
+ return paths.AbsDir(__file__) def _getWXGLADEpath(self, project_path=None):