rtcprof.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- Python -*-
00003 
00004 ##
00005 # @file rtcprof.py
00006 # @brief RT-Component profile dump command
00007 # @date $Date$
00008 # @author Noriaki Ando <n-ando@aist.go.jp> and Shinji Kurihara
00009 #
00010 # Copyright (C) 2010
00011 #     Intelligent Systems Research Institute,
00012 #     National Institute of
00013 #         Advanced Industrial Science and Technology (AIST), Japan
00014 #     All rights reserved.
00015 #
00016 # $Id$
00017 
00018 import sys
00019 import os
00020 
00021 import OpenRTM_aist
00022 
00023 def main():
00024 
00025   if len(sys.argv) != 2:
00026     print "usage: "
00027     print sys.argv[0], " *.py "
00028     return
00029 
00030   # file name with full path
00031   fullname  = sys.argv[1]
00032   # directory name
00033   dirname   = os.path.dirname(sys.argv[1])
00034   tmp_path = sys.path
00035   sys.path.append(dirname)
00036 
00037   # basename
00038   basename  = os.path.basename(sys.argv[1])
00039   # classname
00040   classname  = basename.split(".")[0].lower()
00041 
00042   opts =[]
00043   opts.append("dummy")
00044   opts.append("-o")
00045   opts.append("manager.modules.load_path: " + dirname)
00046   opts.append("-o")
00047   opts.append("logger.enable:NO")
00048   opts.append("-o")
00049   opts.append("manager.corba_servant:NO")
00050 
00051   # Manager initialization
00052   OpenRTM_aist.Manager.init(opts)
00053   mgr = OpenRTM_aist.Manager.instance()
00054 
00055   # loaded profile = old profiles - new profiles
00056   # for old
00057   oldp = mgr.getFactoryProfiles()
00058 
00059   # for new
00060   comp_spec_name = classname+"_spec"
00061 
00062   try:
00063     imp_file = __import__(basename.split(".")[0])
00064   except:
00065     sys.path = tmp_path
00066     return
00067 
00068   comp_spec = getattr(imp_file,comp_spec_name,None)
00069   if not comp_spec:
00070     sys.path = tmp_path
00071     return
00072 
00073   newp = OpenRTM_aist.Properties(defaults_str=comp_spec)
00074 
00075   profs = []
00076     
00077   exists = False
00078   for i in range(len(oldp)):
00079     if    oldp[i].getProperty("implementation_id") == newp.getProperty("implementation_id") and \
00080           oldp[i].getProperty("type_name") == newp.getProperty("type_name") and \
00081           oldp[i].getProperty("description") == newp.getProperty("description") and \
00082           oldp[i].getProperty("version") == newp.getProperty("version"):
00083       exists = True
00084   if not exists:
00085     profs.append(newp)
00086 
00087         
00088   # loaded component profile have to be one
00089   if len(profs) == 0:
00090     print "Load failed. file name: ", fname
00091     sys.path = tmp_path
00092     return OpenRTM_aist.Properties()
00093 
00094   if len(profs) > 1:
00095     print "One or more modules loaded."
00096     sys.path = tmp_path
00097     return OpenRTM_aist.Properties()
00098 
00099   keys = profs[0].propertyNames()
00100   for key in keys:
00101     print "%s:%s"%(key,profs[0].getProperty(key))
00102 
00103   sys.path = tmp_path
00104   return
00105 
00106 if __name__ == "__main__":
00107   main()


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Aug 27 2015 14:17:28