def get_components(self): """Retrieve all components declared in module catalogs of the resource""" appliPath = self.get_appliPath() userName = self.get_user() hostname = self.get_host() resource_dir = os.path.join(cata_dir, self.get_name()) catalogs_list = glob.glob(os.path.join(resource_dir, "*Catalog.xml")) if hostname == "localhost" or hostname == get_hostname( ) and userName == getUserName(): #user local resource if appliPath[0] != '/': appliPath = os.path.join(os.getenv("HOME"), appliPath) if appliPath == appli_local: #main local resource: get catalogs in share/salome/resources catalogs_list = glob.glob( os.path.join(appliPath, "share", "salome", "resources", "*", "*Catalog.xml")) catalogs_list = catalogs_list + glob.glob( os.path.join(appliPath, "share", "salome", "resources", "*Catalog.xml")) for cata in catalogs_list: moduleName = os.path.basename(cata)[:-11] #Parse module catalog doc = etree_.parse(cata) rootNode = doc.getroot() for componentName in rootNode.findall( "component-list/component/component-name"): self.components.append( Component(componentName.text, moduleName))
def _writeConfigFile(port, host): path = os.environ['OMNIORB_USER_PATH'] kwargs = {'with_username' : getUserName()} from ORBConfigFile import writeORBConfigFile [ filename, msgSize ] = writeORBConfigFile(path, host, port, kwargs) os.environ['OMNIORB_CONFIG'] = filename
def run(tree, args): CatalogFileName=getParamValue("catalog", "CatalogModulePersonnel.xml", args) if re.compile(".*?.xml$").match(CatalogFileName, 1) is None: CatalogFileName = CatalogFileName + '.xml' #========= Read parameters ====================== common_data["ICON"] = getParamValue("icon", "", args) common_data["AUTHOR"] = getParamValue("author", getUserName(), args) common_data["VERSION"] = getParamValue("version", "1", args) common_data["COMP_NAME"] = getParamValue("name", "", args) common_data["COMP_UNAME"] = getParamValue("username", "", args) common_data["COMP_TYPE"] = getParamValue("type", "OTHER", args) common_data["COMP_MULT"] = getParamValue("multistudy", "1", args) common_data["COMP_IMPL"] = getParamValue("impltype", "1", args) print common_data remove_comp = getParamValue("remove", "", args) #================================================== if (os.path.exists(CatalogFileName)): print "Importing", CatalogFileName C = Catalog(CatalogFileName) else: print "Creating ",CatalogFileName C = Catalog() print "Reading idl file" visitor = ModuleCatalogVisitor(C) tree.accept(visitor) ## C.Dump() if remove_comp : C.removeComponent(remove_comp) if (os.path.exists(CatalogFileName)): print "Updating", CatalogFileName CatalogFileName_old = CatalogFileName + '_old' os.rename(CatalogFileName, CatalogFileName_old) else: CatalogFileName_old = "" print "Writing", CatalogFileName CatalogFileName_new = CatalogFileName + '_new' f=open(CatalogFileName_new, 'w') f.write("<?xml version='1.0' encoding='us-ascii' ?>\n\n") C.output_xml(f) f.close() os.rename(CatalogFileName_new, CatalogFileName) if ((CatalogFileName_old != "") & os.path.exists(CatalogFileName_old)): os.unlink(CatalogFileName_old) print
def registerEnv(args, modules_list, modules_root_dir): """ Register args, modules_list, modules_root_dir in a file for further use, when SALOME is launched embedded in an other application. """ from salome_utils import getTmpDir fileEnv = getTmpDir() from salome_utils import getUserName fileEnv += getUserName() + "_" + str(args['port']) \ + '_' + args['appname'].upper() + '_env' fenv = open(fileEnv, 'w') pickle.dump((args, modules_list, modules_root_dir), fenv) fenv.close() os.environ["SALOME_LAUNCH_CONFIG"] = fileEnv
def registerEnv(args, modules_list, modules_root_dir): """ Register args, modules_list, modules_root_dir in a file for further use, when SALOME is launched embedded in an other application. """ from salome_utils import getTmpDir fileEnv = getTmpDir() from salome_utils import getUserName fileEnv += getUserName() + "_" + str(args['port']) \ + '_' + args['appname'].upper() + '_env' fenv=open(fileEnv,'w') pickle.dump((args, modules_list, modules_root_dir),fenv) fenv.close() os.environ["SALOME_LAUNCH_CONFIG"] = fileEnv
def get_catalogs(self): """Get module catalogs file from the resource and copy them locally in remote_catalogs/<resource name>""" hostname = self.get_host() appliPath = self.get_appliPath() userName = self.get_user() rcopy = self.get_rcp() resource_dir = os.path.join(cata_dir, self.get_name()) if hostname == "localhost" or hostname == get_hostname( ) and userName == getUserName(): #local machine, use cp if appliPath[0] != '/': #relative path appliPath = os.path.join(os.getenv("HOME"), appliPath) if appliPath == appli_local: return os.mkdir(resource_dir) cata_path = os.path.join(appliPath, "share", "salome", "resources", "*Catalog.xml") cmd = "cp %s %s" % (cata_path, resource_dir) print cmd os.system(cmd) cata_path = os.path.join(appliPath, "share", "salome", "resources", "*", "*Catalog.xml") cmd = "cp %s %s" % (cata_path, resource_dir) print cmd os.system(cmd) else: #remote machine, use rcopy os.mkdir(resource_dir) cata_path = os.path.join(appliPath, "share", "salome", "resources", "*Catalog.xml") cmd = "%s %s@%s:%s %s" cmd = cmd % (rcopy, userName, hostname, cata_path, resource_dir) print cmd os.system(cmd) cata_path = os.path.join(appliPath, "share", "salome", "resources", "*", "*Catalog.xml") cmd = "%s %s@%s:%s %s" cmd = cmd % (rcopy, userName, hostname, cata_path, resource_dir) print cmd os.system(cmd) schema_cata = os.path.join(resource_dir, "*SchemaCatalog.xml") os.system("rm %s" % schema_cata) self.resource_dir = os.path.abspath(resource_dir)
def __get_running_session(requested_port=None, lastInstanceByDefault=False): import glob import salome_utils from ORBConfigFile import readORBConfigFile omniorbUserPath = os.getenv("OMNIORB_USER_PATH") files = glob.glob( os.path.join( omniorbUserPath, ".omniORB_" + salome_utils.getUserName() + "_*[!last].cfg")) available_connexions = [] for filename in files: host, port = readORBConfigFile(filename) available_connexions.append((host, port, filename)) host, port, filename = None, None, None if requested_port: print "Search for running instance on port %s..." % requested_port found = [(h, p, f) for h, p, f in available_connexions if int(p) == int(requested_port)] if not found: print " ...no running instance found" elif len(found) == 1: host, port, filename = found[0] print " ...found unique instance: %s:%s" % (host, port) else: print " ...multiple instances found ; please choose one in the following:" host, port, filename = __choose_in(found) else: # no requested port if not available_connexions: print "No running instance found" elif len(available_connexions) == 1: host, port, filename = available_connexions[0] print "Found unique instance: %s:%s" % (host, port) else: print "Multiple instances found ; please choose one in the following:" host, port, filename = __choose_in(available_connexions) pass if port: print "Selected instance: %s:%s" % (host, port) else: print "Cancel." return host, port, filename
def get_catalogs(self): """Get module catalogs file from the resource and copy them locally in remote_catalogs/<resource name>""" hostname=self.get_host() appliPath= self.get_appliPath() userName = self.get_user() rcopy=self.get_rcp() resource_dir=os.path.join(cata_dir,self.get_name()) if hostname == "localhost" or hostname == get_hostname() and userName == getUserName(): #local machine, use cp if appliPath[0]!='/': #relative path appliPath=os.path.join(os.getenv("HOME"),appliPath) if appliPath == appli_local: return os.mkdir(resource_dir) cata_path=os.path.join(appliPath,"share","salome","resources","*Catalog.xml") cmd="cp %s %s" % (cata_path,resource_dir) print cmd os.system(cmd) cata_path=os.path.join(appliPath,"share","salome","resources","*","*Catalog.xml") cmd="cp %s %s" % (cata_path,resource_dir) print cmd os.system(cmd) else: #remote machine, use rcopy os.mkdir(resource_dir) cata_path=os.path.join(appliPath,"share","salome","resources","*Catalog.xml") cmd="%s %s@%s:%s %s" cmd= cmd%(rcopy,userName,hostname,cata_path,resource_dir) print cmd os.system(cmd) cata_path=os.path.join(appliPath,"share","salome","resources","*","*Catalog.xml") cmd="%s %s@%s:%s %s" cmd= cmd%(rcopy,userName,hostname,cata_path,resource_dir) print cmd os.system(cmd) schema_cata=os.path.join(resource_dir,"*SchemaCatalog.xml") os.system("rm %s"% schema_cata) self.resource_dir=os.path.abspath(resource_dir)
def __get_running_session(requested_port=None, lastInstanceByDefault=False): import glob import salome_utils from ORBConfigFile import readORBConfigFile omniorbUserPath = os.getenv("OMNIORB_USER_PATH") files = glob.glob(os.path.join(omniorbUserPath,".omniORB_"+salome_utils.getUserName()+"_*[!last].cfg")) available_connexions = [] for filename in files: host, port = readORBConfigFile(filename) available_connexions.append((host, port, filename)) host, port, filename = None, None, None if requested_port: print "Search for running instance on port %s..."%requested_port found = [(h,p,f) for h,p,f in available_connexions if int(p) == int(requested_port)] if not found: print " ...no running instance found" elif len(found) == 1: host, port, filename = found[0] print " ...found unique instance: %s:%s"%(host,port) else: print " ...multiple instances found ; please choose one in the following:" host, port, filename = __choose_in(found) else: # no requested port if not available_connexions: print "No running instance found" elif len(available_connexions) == 1: host, port, filename = available_connexions[0] print "Found unique instance: %s:%s"%(host,port) else: print "Multiple instances found ; please choose one in the following:" host, port, filename = __choose_in(available_connexions) pass if port: print "Selected instance: %s:%s"%(host, port) else: print "Cancel." return host, port, filename
def get_components(self): """Retrieve all components declared in module catalogs of the resource""" appliPath= self.get_appliPath() userName = self.get_user() hostname=self.get_host() resource_dir=os.path.join(cata_dir,self.get_name()) catalogs_list=glob.glob(os.path.join(resource_dir,"*Catalog.xml")) if hostname == "localhost" or hostname == get_hostname() and userName == getUserName(): #user local resource if appliPath[0]!='/': appliPath=os.path.join(os.getenv("HOME"),appliPath) if appliPath == appli_local: #main local resource: get catalogs in share/salome/resources catalogs_list=glob.glob(os.path.join(appliPath,"share","salome","resources","*","*Catalog.xml")) catalogs_list=catalogs_list + glob.glob(os.path.join(appliPath,"share","salome","resources","*Catalog.xml")) for cata in catalogs_list: moduleName= os.path.basename(cata)[:-11] #Parse module catalog doc = etree_.parse(cata) rootNode = doc.getroot() for componentName in rootNode.findall("component-list/component/component-name"): self.components.append(Component(componentName.text,moduleName))
def killAllPorts(): """ Kill all SALOME sessions belonging to the user. """ user = getUserName() #hostname = getHostName() #shostname = getShortHostName() # new-style dot-prefixed pidict file #fpidict = getPiDict('(\d*)',hidden=True) #problem with WIN32 path slashes fpidict = getPiDict('#####',hidden=True) dirpidict = os.path.dirname(fpidict) fpidict = os.path.basename(fpidict) #if hostname in fpidict: # fpidict = fpidict.replace(hostname, shostname+".*") fpidict = fpidict.replace('#####', '(\d*)') fnamere = re.compile("^%s" % fpidict) try: for f in os.listdir(dirpidict): mo = fnamere.match(f) try: killMyPort(mo.group(1)) except: pass pass pass except: pass # provide compatibility with old-style pidict file (not dot-prefixed) #fpidict = getPiDict('(\d*)',hidden=False) fpidict = getPiDict('#####',hidden=False) dirpidict = os.path.dirname(fpidict) fpidict = os.path.basename(fpidict) #if hostname in fpidict: # fpidict = fpidict.replace(hostname, shostname+".*") fpidict = fpidict.replace('#####', '(\d*)') fnamere = re.compile("^%s$" % fpidict) try: for f in os.listdir(dirpidict): mo = fnamere.match(f) try: killMyPort(mo.group(1)) except: pass pass pass except: pass # kill other processes if sys.platform != 'win32': import commands cmd = "ps -fea | grep '%s' | grep 'ghs3d' | grep 'f /tmp/GHS3D_' | grep -v 'grep' | awk '{print $2}'" % user prc = commands.getoutput(cmd) for field in prc.split(): try: os.kill(int(field), signal.SIGKILL) except: pass pass pass # kill ompi-server needed for MPI containers coupling cmd = "ps -fea | grep '%s' | grep 'ompi-server' | grep -v 'grep' | awk '{print $2}'" % user prc = commands.getoutput(cmd) for field in prc.split(): try: os.kill(int(field), signal.SIGKILL) except: pass pass pass # delete uri files needed by ompi-server cmd = "rm -f " + os.environ['HOME'] + "/.urifile_*" os.system(cmd) pass
def appliCleanOmniOrbConfig(port): """ Remove omniorb config files related to the port in SALOME application: - ${OMNIORB_USER_PATH}/.omniORB_${USER}_${HOSTNAME}_${NSPORT}.cfg - ${OMNIORB_USER_PATH}/.omniORB_${USER}_last.cfg the last is removed only if the link points to the first file. """ if verbose(): print "clean OmniOrb config for port %s" % port from salome_utils import generateFileName, getUserName omniorbUserPath = os.getenv("OMNIORB_USER_PATH") if omniorbUserPath is None: #Run outside application context pass else: omniorb_config = generateFileName(omniorbUserPath, prefix="omniORB", extension="cfg", hidden=True, with_username=True, with_hostname=True, with_port=port) last_running_config = generateFileName(omniorbUserPath, prefix="omniORB", with_username=True, suffix="last", extension="cfg", hidden=True) if os.access(last_running_config, os.F_OK): if not sys.platform == 'win32': pointedPath = os.readlink(last_running_config) if pointedPath[0] != '/': pointedPath = os.path.join( os.path.dirname(last_running_config), pointedPath) pass if pointedPath == omniorb_config: os.unlink(last_running_config) pass pass else: os.remove(last_running_config) pass pass if os.access(omniorb_config, os.F_OK): os.remove(omniorb_config) pass if os.path.lexists(last_running_config): return #try to relink last.cfg to an existing config file if any files = glob.glob( os.path.join(omniorbUserPath, ".omniORB_" + getUserName() + "_*.cfg")) current_config = None current = 0 for f in files: stat = os.stat(f) if stat.st_atime > current: current = stat.st_atime current_config = f if current_config: if sys.platform == "win32": import shutil shutil.copyfile(os.path.normpath(current_config), last_running_config) pass else: os.symlink(os.path.normpath(current_config), last_running_config) pass pass pass pass
(options, args) = parser.parse_args(short_args) except Exception, e: print e return port = options.port host = options.host # :GLITCH: this code defines specific environment variables (OMNIORB_CONFIG, NSPORT, # NSHOST) which are later used by other modules. Working, but not really "safe"... if not port: if not host: # neither MACHINE nor PORT are given # --- set omniORB configuration to current session if any omniorbUserPath = os.environ['OMNIORB_USER_PATH'] fileOmniConfig = omniorbUserPath + '/.omniORB_' + getUserName() + '_last.cfg' if os.path.isfile(fileOmniConfig): os.environ['OMNIORB_CONFIG'] = fileOmniConfig # --- set environment variables for port and hostname of NamingService host, port = getNSparams() else: # No running session host = "no_host" port = "no_port" else: # only MACHINE is given port = '2810' _writeConfigFile(port, host) # else: if not host:
def killAllPorts(): """ Kill all SALOME sessions belonging to the user. """ user = getUserName() #hostname = getHostName() #shostname = getShortHostName() # new-style dot-prefixed pidict file #fpidict = getPiDict('(\d*)',hidden=True) #problem with WIN32 path slashes fpidict = getPiDict('#####', hidden=True) dirpidict = os.path.dirname(fpidict) fpidict = os.path.basename(fpidict) #if hostname in fpidict: # fpidict = fpidict.replace(hostname, shostname+".*") fpidict = fpidict.replace('#####', '(\d*)') fnamere = re.compile("^%s" % fpidict) try: for f in os.listdir(dirpidict): mo = fnamere.match(f) try: killMyPort(mo.group(1)) except: pass pass pass except: pass # provide compatibility with old-style pidict file (not dot-prefixed) #fpidict = getPiDict('(\d*)',hidden=False) fpidict = getPiDict('#####', hidden=False) dirpidict = os.path.dirname(fpidict) fpidict = os.path.basename(fpidict) #if hostname in fpidict: # fpidict = fpidict.replace(hostname, shostname+".*") fpidict = fpidict.replace('#####', '(\d*)') fnamere = re.compile("^%s$" % fpidict) try: for f in os.listdir(dirpidict): mo = fnamere.match(f) try: killMyPort(mo.group(1)) except: pass pass pass except: pass # kill other processes if sys.platform != 'win32': import commands cmd = "ps -fea | grep '%s' | grep 'ghs3d' | grep 'f /tmp/GHS3D_' | grep -v 'grep' | awk '{print $2}'" % user prc = commands.getoutput(cmd) for field in prc.split(): try: os.kill(int(field), signal.SIGKILL) except: pass pass pass # kill ompi-server needed for MPI containers coupling cmd = "ps -fea | grep '%s' | grep 'ompi-server' | grep -v 'grep' | awk '{print $2}'" % user prc = commands.getoutput(cmd) for field in prc.split(): try: os.kill(int(field), signal.SIGKILL) except: pass pass pass # delete uri files needed by ompi-server cmd = "rm -f " + os.environ['HOME'] + "/.urifile_*" os.system(cmd) pass
def get_user(self): userName= self.node.get("userName") if not userName: userName=getUserName() return userName
def get_user(self): userName = self.node.get("userName") if not userName: userName = getUserName() return userName
def appliCleanOmniOrbConfig(port): """ Remove omniorb config files related to the port in SALOME application: - ${OMNIORB_USER_PATH}/.omniORB_${USER}_${HOSTNAME}_${NSPORT}.cfg - ${OMNIORB_USER_PATH}/.omniORB_${USER}_last.cfg the last is removed only if the link points to the first file. """ if verbose(): print "clean OmniOrb config for port %s"%port from salome_utils import generateFileName, getUserName omniorbUserPath = os.getenv("OMNIORB_USER_PATH") if omniorbUserPath is None: #Run outside application context pass else: omniorb_config = generateFileName(omniorbUserPath, prefix="omniORB", extension="cfg", hidden=True, with_username=True, with_hostname=True, with_port=port) last_running_config = generateFileName(omniorbUserPath, prefix="omniORB", with_username=True, suffix="last", extension="cfg", hidden=True) if os.access(last_running_config,os.F_OK): if not sys.platform == 'win32': pointedPath = os.readlink(last_running_config) if pointedPath[0] != '/': pointedPath=os.path.join(os.path.dirname(last_running_config), pointedPath) pass if pointedPath == omniorb_config: os.unlink(last_running_config) pass pass else: os.remove(last_running_config) pass pass if os.access(omniorb_config,os.F_OK): os.remove(omniorb_config) pass if os.path.lexists(last_running_config):return #try to relink last.cfg to an existing config file if any files = glob.glob(os.path.join(omniorbUserPath,".omniORB_"+getUserName()+"_*.cfg")) current_config=None current=0 for f in files: stat=os.stat(f) if stat.st_atime > current: current=stat.st_atime current_config=f if current_config: if sys.platform == "win32": import shutil shutil.copyfile(os.path.normpath(current_config), last_running_config) pass else: os.symlink(os.path.normpath(current_config), last_running_config) pass pass pass pass