''' NOT WORKING (any more) Script used to create a new cipres_registry.xml file from hard-coded description of services and environmental settings. Can be used in the fresh installation of CIPRES on a new machine.''' from PIPRes.util.rich_cipres_registry import * from PIPRes.util.io import expandPath, prependNumberToRename import os _dcmRegEntry = SimpleRegistryEntry( 'dcm3', 'TreeDecompose', cipresC = True, description = 'Roshan DCM3', command = os.path.join('$DCM3_BIN_ROOT', 'cipres_dcm3'), xtermWindowTitle = 'dcm3LeafSetDecompose') _pyTreeImproveRegEntry = SimpleRegistryEntry( 'paupWrap', 'TreeImprove', cipresPython = True, description = "Python wrapper around PAUP's HSearch command (using parsimony). file-based io.", args = [expandPath('$PIPRES_ROOT/PIPRes/service_impl/tree_improve_server.py'), expandPath(os.path.join('$PAUP_BIN_ROOT', 'paup')), '-debug'], python = PythonRegistryInfo(module = 'PIPRes.service_impl.tree_improve_server', factory = "createPaupWrap", needsRegistry = True), xtermWindowTitle = 'pyTreeImprove') _readNexusRegEntry = SimpleRegistryEntry( 'read_nexus_server', 'ReadNexus', cipresC = True, description = 'Phycas/NCL NEXUS parser - support for mulitple characters blocks has been disabled', command = os.path.join('$PHYCAS_READ_NEXUS_BIN_ROOT', 'phycas_read_nexus'), xtermWindowTitle = 'phycasReadNexus') _validatingTreeMergeRegEntry = SimpleRegistryEntry( 'validatingTreeMerge', 'TreeMerge', cipresPython = True, description = "Debugging tool which tests the scm merger performed by an implementation against the pipres merger", args = [expandPath('$PIPRES_ROOT/PIPRes/service_impl/validating_tree_merge.py'), '-applicationName', 'phycas'], python = PythonRegistryInfo(module = 'PIPRes.service_impl.validating_tree_merge', factory = "createValidatingTreeMerge", needsRegistry = True), xtermWindowTitle = 'pyTreeImprove') _pipresTreeMergeRegEntry = SimpleRegistryEntry( 'PIPRes TreeMerge', 'TreeMerge', cipresPython = True, description = "Python implementation of the Strict Consensus Merger super tree construction algorithm", args = [expandPath('$PIPRES_ROOT/PIPRes/service_impl/tree_merge_server.py')], python = PythonRegistryInfo(module = 'PIPRes.service_impl.tree_merge_server', factory = "SCMTreeMerge"), xtermWindowTitle = 'pyTreeImprove') _phycasTreeMeregeRegEntry = SimpleRegistryEntry( 'phycas', 'TreeMerge', cipresC = True, description = 'Phycas (C++) implementation of the Strict Consensus Merger super tree construction algorithm', command = os.path.join('$PHYCAS_TREE_MERGE_BIN_ROOT', 'phycas_tree_merge'), xtermWindowTitle = 'phycas_tree_merge') _pipresTreeRefineRegEntry = SimpleRegistryEntry( 'PIPRes random refine', 'TreeRefine', cipresPython = True, description = "Python implementation of a random refinement of polytomies (Random seed hard-coded for debugging purposes)", args = [expandPath('$PIPRES_ROOT/PIPRes/service_impl/tree_refine_server.py')], python = PythonRegistryInfo(module = 'PIPRes.service_impl.tree_refine_server', factory = "RandomRefineImpl"), xtermWindowTitle = 'pyTreeRefine') def checkEnvironParPath(varName, defaultLoc, fileToVerify, prompt = False): '''Checks for "fileToVerify" in the directory specified by the environmental setting "varName" If the variable is not set correctly, it is set to "defaultLoc" and the path is checked. If this is still not valid and "bool(prompt) == True", the user is prompted to provide a value. Returns the environmental setting or None if no appropriate setting is found.''' environ = os.environ added = False pathName = os.path.join('$' + varName, fileToVerify) query = False if varName in environ: if os.path.exists(expandPath(pathName)): return if prompt: print "The %s was not found in the path described by the environmental variable %s." % (fileToVerify, varName) query = True environ[varName] = str(defaultLoc) if not query and defaultLoc is not None: if prompt: print "The environmental variable, %s, is not set. Checking the default value (%s)...\n" % (varName, expandPath(defaultLoc)) environ[varName] = defaultLoc while not os.path.exists(expandPath(pathName)): c = '' if prompt: defLocPrompt = defaultLoc and ( 'Usually the correct setting will be %s\n' % expandPath(defaultLoc)) or '' c = raw_input('The environmental variable %s is not set correctly (%s was not found in the path specified by $%s).\n\n%sEnter a path (or an empty line to leave the variable set to %s).\n>>' % (varName, fileToVerify, varName, defLocPrompt, environ[varName])) if c == '': return None environ[varName] = expandPath(c) if prompt: print fileToVerify, 'found.\n' return environ[varName] if __name__ == '__main__': import sys interactive = not '-n' in sys.argv[1:] cipresBinDir = os.path.join('$CIPRES_CONFIG_DIR', 'bin') checkEnvironParPath('DCM3_BIN_ROOT', cipresBinDir, 'cipres_dcm3', interactive) checkEnvironParPath('PIPRES_ROOT', os.path.join('$CIPRES_APP_ROOT', 'lib'), 'PIPRes', interactive) checkEnvironParPath('PAUP_BIN_ROOT', cipresBinDir, 'paup', interactive) checkEnvironParPath('PHYCAS_TREE_MERGE_BIN_ROOT', cipresBinDir, 'phycas_tree_merge', interactive) checkEnvironParPath('PHYCAS_READ_NEXUS_BIN_ROOT', cipresBinDir, 'phycas_read_nexus', interactive) hostName = '' if not hostName: defName = os.environ.get('HOST', '') if not defName: user = os.environ.get('USER', '') if user: defName = "%s's machine" % user if interactive: guessStr = defName is not None and '(or enter an empty line to accept the default name of %s)' % defName or '' for i in range(10): c = raw_input('Enter a name for this cipres registry%s.\n>>' % guessStr) hostName = c or defName if hostName: break else: hostName = defName if not hostName: hostName = 'registry of person who refuse his/her machine' registry = RichCipresRegistry() entries = [_dcmRegEntry, _pyTreeImproveRegEntry, _readNexusRegEntry, _validatingTreeMergeRegEntry, _pipresTreeMergeRegEntry, _phycasTreeMeregeRegEntry, _pipresTreeRefineRegEntry] registry.addEntries(entries) regFileName = getCipresProperty('registryFile') if os.path.exists(regFileName): moved = prependNumberToRename(regFileName) print 'Registry file (%s) already found!\nThis file was moved to %s' % (regFileName, moved) out = open(regFileName, 'w') registry.writeXML(out) print regFileName, 'written.'