1 #!/usr/bin/env python |
1 #!/usr/bin/env python |
2 # -*- coding: utf-8 -*- |
2 # -*- coding: utf-8 -*- |
3 |
3 |
4 # This file is part of Beremiz runtime. |
4 from __future__ import absolute_import |
5 # |
5 import traceback |
6 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
7 # |
|
8 # See COPYING.Runtime file for copyrights details. |
|
9 # |
|
10 # This library is free software; you can redistribute it and/or |
|
11 # modify it under the terms of the GNU Lesser General Public |
|
12 # License as published by the Free Software Foundation; either |
|
13 # version 2.1 of the License, or (at your option) any later version. |
|
14 |
6 |
15 # This library is distributed in the hope that it will be useful, |
7 from runtime.Worker import worker |
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
8 MainWorker = worker() |
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
18 # Lesser General Public License for more details. |
|
19 |
9 |
20 # You should have received a copy of the GNU Lesser General Public |
10 from runtime.PLCObject import PLCObject |
21 # License along with this library; if not, write to the Free Software |
|
22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
23 |
11 |
24 from __future__ import absolute_import |
12 _PLCObjectSingleton = None |
25 import os |
|
26 |
13 |
27 from runtime.PLCObject import PLCObject, PLCprint, MainWorker |
14 def GetPLCObjectSingleton(): |
28 import runtime.ServicePublisher |
15 global _PLCObjectSingleton |
|
16 assert(_PLCObjectSingleton is not None) |
|
17 return _PLCObjectSingleton |
|
18 |
|
19 |
|
20 def LogMessageAndException(msg, exp=None): |
|
21 global _PLCObjectSingleton |
|
22 if exp is None: |
|
23 exp = sys.exc_info() |
|
24 if _PLCObjectSingleton is not None: |
|
25 _PLCObjectSingleton.LogMessage(0, msg + '\n'.join(traceback.format_exception(*exp))) |
|
26 else: |
|
27 print(msg) |
|
28 traceback.print_exception(*exp) |
|
29 |
|
30 def CreatePLCObjectSingleton(*args): |
|
31 global _PLCObjectSingleton |
|
32 _PLCObjectSingleton = PLCObject(*args) |