Skip to content

Commit

Permalink
Merge branch 'bugs/modulemanagerlang' into feature/confreplaceenv
Browse files Browse the repository at this point in the history
  • Loading branch information
Nobu19800 committed Mar 23, 2022
2 parents cc99e25 + 591a3d6 commit c786078
Show file tree
Hide file tree
Showing 43 changed files with 302 additions and 156 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/static_code_analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Workflow for openrtm-aist-python static code analysis
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu_2004_pycodestyle, ubuntu_2004_pyflakes, ubuntu_2004_flake8, ubuntu_2004_bandit]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: run static code analysis
run: |
export OPENRTMPYTHON_IMAGE=openrtm-aist-python:${{matrix.os}}-$(date +%s)
docker build .. --file scripts/${{matrix.os}}/Dockerfile --tag $OPENRTMPYTHON_IMAGE
docker run $OPENRTMPYTHON_IMAGE
3 changes: 3 additions & 0 deletions OpenRTM_aist/CORBA_IORUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
# @author Noriaki Ando
#

import sys
from omniORB import CORBA
from omniORB import *
from omniORB import any
from omniORB import cdrMarshal
from omniORB import cdrUnmarshal
from IORProfile_idl import *
from IORProfile_idl import _0__GlobalIDL
endian = True
Expand Down
2 changes: 1 addition & 1 deletion OpenRTM_aist/CSPInPort.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def getDataBufferMode(self, con, retry):
if not self._syncmode:
guard_ctrl = OpenRTM_aist.ScopedLock(self._ctrl._cond)
if not self._thebuffer.empty():
_, value = self._thebuffer.read(value)
_, value = self._thebuffer.read()
if guard_ctrl is not None:
del guard_ctrl
self.notify()
Expand Down
2 changes: 1 addition & 1 deletion OpenRTM_aist/ConfigAdmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,7 @@ def __init__(self, name):
return

def __call__(self, conf):
if conf is None:
if conf is None or conf == 0:
return False

return self._name == conf.name
2 changes: 1 addition & 1 deletion OpenRTM_aist/ConnectorListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ def notify(self, info, cdrdata):

endian = info.properties.getProperty(
"serializer.cdr.endian", "little")
if endian is not "little" and endian is not None:
if endian != "little" and endian is not None:
# Maybe endian is ["little","big"]
endian = OpenRTM_aist.split(endian, ",")
# Maybe self._endian is "little" or "big"
Expand Down
31 changes: 8 additions & 23 deletions OpenRTM_aist/CorbaNaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,11 @@ def __init__(self, orb, name_server=None):

if name_server:
self._nameServer = "corbaloc::" + name_server + "/NameService"
try:
obj = orb.string_to_object(self._nameServer)
self._rootContext = obj._narrow(CosNaming.NamingContext)
if CORBA.is_nil(self._rootContext):
print("CorbaNaming: Failed to narrow the root naming context.")

except CORBA.ORB.InvalidName:
self.__print_exception()
print("Service required is invalid [does not exist].")
obj = orb.string_to_object(self._nameServer)
self._rootContext = obj._narrow(CosNaming.NamingContext)
if CORBA.is_nil(self._rootContext):
print("CorbaNaming: Failed to narrow the root naming context.")
raise MemoryError

return

Expand Down Expand Up @@ -346,14 +342,12 @@ def rebind(self, name_list, obj, force=True):
if force:
self.rebindRecursive(self._rootContext, name_list, obj)
else:
self.__print_exception()
raise

except CosNaming.NamingContext.CannotProceed as err:
if force:
self.rebindRecursive(err.cxt, err.rest_of_name, obj)
else:
self.__print_exception()
raise

##
Expand Down Expand Up @@ -570,12 +564,8 @@ def resolve(self, name):
else:
name_ = name

try:
obj = self._rootContext.resolve(name_)
return obj
except CosNaming.NamingContext.NotFound:
self.__print_exception()
return None
obj = self._rootContext.resolve(name_)
return obj

##
# @if jp
Expand Down Expand Up @@ -611,10 +601,7 @@ def unbind(self, name):
else:
name_ = name

try:
self._rootContext.unbind(name_)
except BaseException:
self.__print_exception()
self._rootContext.unbind(name_)

return

Expand Down Expand Up @@ -679,14 +666,12 @@ def bindNewContext(self, name, force=True):
if force:
self.bindRecursive(self._rootContext, name_, self.newContext())
else:
self.__print_exception()
raise
except CosNaming.NamingContext.CannotProceed as err:
if force:
self.bindRecursive(
err.cxt, err.rest_of_name, self.newContext())
else:
self.__print_exception()
raise
return None

Expand Down
2 changes: 1 addition & 1 deletion OpenRTM_aist/EventPort_pyfsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __call__(self, info, cdrdata):
return OpenRTM_aist.ConnectorListenerStatus.NO_CHANGE, cdrdata

def run(self, data):
self._fsm.dispatch(pyfsm.Event(self._handler, data_))
self._fsm.dispatch(pyfsm.Event(self._handler, data))


class EventConnListener(OpenRTM_aist.ConnectorListener):
Expand Down
5 changes: 2 additions & 3 deletions OpenRTM_aist/ExecutionContextWorker.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,11 @@ def addComponent(self, comp):
id_, comp))
del guard
except BaseException:
del guard
self._rtcout.RTC_ERROR("addComponent() failed.")
return RTC.RTC_ERROR

self._rtcout.RTC_DEBUG("addComponent() succeeded.")
if self._running == False:
if self._running is False:
self.updateComponentList()
return RTC.RTC_OK

Expand Down Expand Up @@ -635,7 +634,7 @@ def removeComponent(self, comp):
guard = OpenRTM_aist.ScopedLock(self._removedMutex)
self._removedComps.append(rtobj_)
del guard
if self._running == False:
if self._running is False:
self.updateComponentList()
return RTC.RTC_OK

Expand Down
4 changes: 2 additions & 2 deletions OpenRTM_aist/ExtTrigExecutionContext.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,13 @@ def onStopping(self):

def onAddedComponent(self, rtobj):
guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
if self._workerthread._ticked == False:
if self._workerthread._ticked is False:
self._worker.updateComponentList()
return RTC.RTC_OK

def onRemovedComponent(self, rtobj):
guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
if self._workerthread._ticked == False:
if self._workerthread._ticked is False:
self._worker.updateComponentList()
return RTC.RTC_OK

Expand Down
2 changes: 1 addition & 1 deletion OpenRTM_aist/FiniteStateMachineComponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# Advanced Industrial Science and Technology (AIST), Japan
# All rights reserved.


import OpenRTM_aist
import RTC
import OpenRTM
import OpenRTM__POA

Expand Down
32 changes: 0 additions & 32 deletions OpenRTM_aist/FiniteStateMachineComponentBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,38 +282,6 @@ def get_owned_contexts(self):
# @endif
# virtual ExecutionContext_ptr get_context(UniqueId exec_handle)

def get_owned_contexts(self):
return OpenRTM_aist.RTObject_impl.get_owned_contexts(self)

##
# @if jp
# @brief [CORBA interface] ExecutionContextを取得する
#
# 指定したハンドルの ExecutionContext を取得する。
# ハンドルから ExecutionContext へのマッピングは、特定の RTC インスタンスに
# 固有である。ハンドルはこの RTC を attach_context した際に取得できる。
#
# @param self
# @param ec_id 取得対象 ExecutionContext ハンドル
#
# @return ExecutionContext
#
# @else
# @brief [CORBA interface] Get ExecutionContext.
#
# Obtain a reference to the execution context represented by the given
# handle.
# The mapping from handle to context is specific to a particular RTC
# instance. The given handle must have been obtained by a previous call to
# attach_context on this RTC.
#
# @param ec_id ExecutionContext handle
#
# @return ExecutionContext
#
# @endif
# virtual ExecutionContext_ptr get_context(UniqueId exec_handle)

def get_context(self, ec_id):
return OpenRTM_aist.RTObject_impl.get_context(self, ec_id)

Expand Down
6 changes: 3 additions & 3 deletions OpenRTM_aist/GlobalFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self):
# bool hasFactory(const Identifier& id)

def hasFactory(self, id):
if not id in self._creators:
if id not in self._creators:
return False
return True

Expand Down Expand Up @@ -64,7 +64,7 @@ def addFactory(self, id, creator):
# ReturnCode removeFactory(const Identifier& id)

def removeFactory(self, id):
if not id in self._creators:
if id not in self._creators:
return self.NOT_FOUND

del self._creators[id]
Expand All @@ -73,7 +73,7 @@ def removeFactory(self, id):
# AbstractClass* createObject(const Identifier& id)

def createObject(self, id):
if not id in self._creators:
if id not in self._creators:
print("Factory.createObject return None id: ", id)
return None
obj_ = self._creators[id]()
Expand Down
6 changes: 3 additions & 3 deletions OpenRTM_aist/InPort.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def isNew(self, names=None):
self._rtcout.RTC_TRACE("isNew()")

guard = OpenRTM_aist.ScopedLock(self._valueMutex)
if self._directNewData == True:
if self._directNewData is True:
self._rtcout.RTC_TRACE(
"isNew() returns true because of direct write.")
return True
Expand Down Expand Up @@ -226,7 +226,7 @@ def isNew(self, names=None):

def isEmpty(self, names=None):
self._rtcout.RTC_TRACE("isEmpty()")
if self._directNewData == True:
if self._directNewData is True:
return False
if not self._connectors:
self._rtcout.RTC_DEBUG("no connectors")
Expand Down Expand Up @@ -347,7 +347,7 @@ def read(self, name=None):
self._rtcout.RTC_TRACE("OnRead called")

guard = OpenRTM_aist.ScopedLock(self._valueMutex)
if self._directNewData == True:
if self._directNewData is True:

self._rtcout.RTC_TRACE("Direct data transfer")
if self._OnReadConvert is not None:
Expand Down
4 changes: 2 additions & 2 deletions OpenRTM_aist/InPortBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ def publishInterfaces(self, cprof):
# marge ConnectorProfile for buffer property.
prop.mergeProperties(conn_prop.getNode("dataport.inport"))

if not self.isExistingMarshalingType(prop):
if self._value is not None and not self.isExistingMarshalingType(prop):
return RTC.RTC_ERROR

#
Expand Down Expand Up @@ -1008,7 +1008,7 @@ def subscribeInterfaces(self, cprof):
# marge ConnectorProfile for buffer property.
prop.mergeProperties(conn_prop.getNode("dataport.inport"))

if not self.isExistingMarshalingType(prop):
if self._value is not None and not self.isExistingMarshalingType(prop):
return RTC.RTC_ERROR

#
Expand Down
2 changes: 1 addition & 1 deletion OpenRTM_aist/InPortPushConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def disconnect(self):
self._provider = None

# delete buffer
if self._buffer and self._deleteBuffer == True:
if self._buffer and self._deleteBuffer is True:
bfactory = OpenRTM_aist.CdrBufferFactory.instance()

self._buffer = None
Expand Down
6 changes: 3 additions & 3 deletions OpenRTM_aist/Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ def createContext(self, ec_args):

avail_ec_ = OpenRTM_aist.ExecutionContextFactory.instance().getIdentifiers()

if not ec_id in avail_ec_:
if ec_id not in avail_ec_:
self._rtcout.RTC_ERROR("Factory not found: %s", ec_id)
return None

Expand Down Expand Up @@ -1446,7 +1446,7 @@ def initManager(self, argv):
try:
self._module.load(mpm_, basename_)
except BaseException:
self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
print(OpenRTM_aist.Logger.print_exception())

self._config.setProperty("manager.instance_name", self.formatString(self._config.getProperty("manager.instance_name"),
self._config))
Expand Down Expand Up @@ -2098,7 +2098,7 @@ def initCpuAffinity(self):

ret = OpenRTM_aist.setProcessAffinity(cpu_num)

if ret == False:
if ret is False:
self._rtcout.RTC_ERROR("CPU affinity mask setting failed")

##
Expand Down
25 changes: 17 additions & 8 deletions OpenRTM_aist/ModuleManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,14 @@ def __init__(self, prop):
self._rtcout = self._mgr.getLogbuf("ModuleManager")
self._modprofs = []
self._loadfailmods = {}
langs = self._properties.getProperty(
"manager.supported_languages").split(",")
for lang in langs:
if OpenRTM_aist.toBool(prop.getProperty("manager.is_master"),
"YES", "NO", False):
self._supported_languages = self._properties.getProperty(
"manager.supported_languages").split(",")
else:
self._supported_languages = ["Python", "Python3"]

for lang in self._supported_languages:
lang = lang.strip()
self._loadfailmods[lang] = []

Expand Down Expand Up @@ -272,10 +277,15 @@ def load(self, file_name, init_func=None):
file_path = name

else:
paths_lang = self._properties.getProperty(
"manager.modules.Python.load_paths").split(",")
paths_lang.extend(self._properties.getProperty(
"manager.modules.Python3.load_paths").split(","))
paths_lang.extend(self._loadPath)
paths = []
for path in self._loadPath:
for path in paths_lang:
paths.append(OpenRTM_aist.replaceEnv(path))
file_path = self.findFile(name, paths)
file_path = self.findFile(file_name, paths)

if not file_path:
raise ModuleManager.FileNotFound(file_name)
Expand Down Expand Up @@ -737,13 +747,12 @@ def deleteSamePath(self, paths):
def getLoadableModules(self):
self._rtcout.RTC_TRACE("getLoadableModules()")
# getting loadable module file path list.
langs = self._properties.getProperty(
"manager.supported_languages").split(",")

self._rtcout.RTC_DEBUG(
"langs: %s",
self._properties.getProperty("manager.supported_languages"))

for lang in langs:
for lang in self._supported_languages:
lang = lang.strip()

modules_ = []
Expand Down
Loading

0 comments on commit c786078

Please sign in to comment.