def _get_phylesystem_parent_with_source(**kwargs): src = "environment" if "PHYLESYSTEM_PARENT" in os.environ: phylesystem_parent = os.environ.get("PHYLESYSTEM_PARENT") else: try: phylesystem_parent = expand_path(get_config_setting_kwargs(None, "phylesystem", "parent", **kwargs)) src = "configfile" except: raise ValueError('No [phylesystem] "parent" specified in config or environmental variables') x = phylesystem_parent.split(":") # TEMP hardcoded assumption that : does not occur in a path name return x, src
def _get_phylesystem_parent_with_source(**kwargs): src = 'environment' if 'PHYLESYSTEM_PARENT' in os.environ: phylesystem_parent = os.environ.get('PHYLESYSTEM_PARENT') else: try: phylesystem_parent = expand_path( get_config_setting_kwargs(None, 'phylesystem', 'parent', **kwargs)) src = 'configfile' except: raise ValueError( 'No [phylesystem] "parent" specified in config or environmental variables' ) x = phylesystem_parent.split( ':') #TEMP hardcoded assumption that : does not occur in a path name return x, src
def __init__(self, name, path, repo_nexml2json=None, git_ssh=None, pkey=None, git_action_class=GitAction, push_mirror_repo_path=None, new_study_prefix=None, infrastructure_commit_author='OpenTree API <*****@*****.**>', **kwargs): self._index_lock = Lock() PhylesystemShardBase.__init__(self, name) self._infrastructure_commit_author = infrastructure_commit_author self._study_counter_lock = Lock() self._master_branch_repo_lock = Lock() self._new_study_prefix = new_study_prefix self._ga_class = git_action_class self.git_ssh = git_ssh self.pkey = pkey path = os.path.abspath(path) dot_git = os.path.join(path, '.git') study_dir = os.path.join(path, 'study') if not os.path.isdir(path): raise ValueError('"{p}" is not a directory'.format(p=path)) if not os.path.isdir(dot_git): raise ValueError('"{p}" is not a directory'.format(p=dot_git)) if not os.path.isdir(study_dir): raise ValueError('"{p}" is not a directory'.format(p=study_dir)) self.path = path self._id_minting_file = os.path.join(path, 'next_study_id.json') if self._new_study_prefix is None: prefix_file = os.path.join(path, 'new_study_prefix') if os.path.exists(prefix_file): pre_content = open(prefix_file, 'r').read().strip() valid_pat = re.compile('^[a-zA-Z0-9]+_$') if len(pre_content) != 3 or not valid_pat.match(pre_content): raise ValueError('Expecting prefix in new_study_prefix file to be two '\ 'letters followed by an underscore') self._new_study_prefix = pre_content else: self._new_study_prefix = 'ot_' # ot_ is the default if there is no file d = create_id2study_info(study_dir, name) rc_dict = diagnose_repo_study_id_convention(path) self.filepath_for_study_id_fn = rc_dict['fp_fn'] self.filepath_for_global_resource_fn = lambda frag: os.path.join(path, frag) self.id_alias_list_fn = rc_dict['id2alias_list'] if rc_dict['convention'] != 'simple': a = {} for k, v in d.items(): alias_list = self.id_alias_list_fn(k) for alias in alias_list: a[alias] = v d = a self.has_aliases = True self.inferred_study_prefix = True self.infer_study_prefix() else: self.inferred_study_prefix = False self.study_dir = study_dir with self._index_lock: self._locked_refresh_study_ids() self.parent_path = os.path.split(path)[0] + '/' self.git_dir = dot_git self.push_mirror_repo_path = push_mirror_repo_path if repo_nexml2json is None: try: repo_nexml2json = get_config_setting_kwargs(None, 'phylesystem', 'repo_nexml2json', **kwargs) except: pass if repo_nexml2json == None: repo_nexml2json = self.diagnose_repo_nexml2json() self.repo_nexml2json = repo_nexml2json self._next_study_id = None self._study_counter_lock = None self._known_prefixes = None
#! /usr/bin/env python from peyotl.evaluate_tree import evaluate_tree_rooting from peyotl.ott import OTT from peyotl.utility import get_config_setting_kwargs, get_logger from peyotl.nexson_proxy import NexsonProxy from peyotl.test.support import pathmap import unittest _LOG = get_logger(__name__) do_test = False try: ott_dir = get_config_setting_kwargs(None, section='ott', param='parent', default=False) if ott_dir is False or not ott_dir.endswith('/aster'): _LOG.debug( 'ott_dir setting is "{}" this does not look like it is the Asterales system' .format(ott_dir)) else: do_test = True except: _LOG.debug('[ott]/parent setting could not be read correctly.') @unittest.skipIf(not do_test, 'the test_evaluate_tree.py is only run if you have your OTT/parent configuration set' \ ' to point to a directory called "aster" (which should hold the taxonomy of Asterales) ' \ 'See http://opentreeoflife.github.io/peyotl/configuration/ ' \ ' and open tree of life reference taxonomy documentation about the Asterales test system') class TestProxy(unittest.TestCase): def setUp(self): self.nexson = pathmap.nexson_obj('pg_329/pg_329.json') self.np = NexsonProxy(nexson=self.nexson)
def __init__(self, name, path, repo_nexml2json=None, git_ssh=None, pkey=None, git_action_class=GitAction, push_mirror_repo_path=None, new_study_prefix=None, infrastructure_commit_author='OpenTree API <*****@*****.**>', **kwargs): self._index_lock = Lock() PhylesystemShardBase.__init__(self, name) self._infrastructure_commit_author = infrastructure_commit_author self._study_counter_lock = Lock() self._master_branch_repo_lock = Lock() self._new_study_prefix = new_study_prefix self._ga_class = git_action_class self.git_ssh = git_ssh self.pkey = pkey path = os.path.abspath(path) dot_git = os.path.join(path, '.git') study_dir = os.path.join(path, 'study') if not os.path.isdir(path): raise NotAPhylesystemShardError('"{p}" is not a directory'.format(p=path)) if not os.path.isdir(dot_git): raise NotAPhylesystemShardError('"{p}" is not a directory'.format(p=dot_git)) if not os.path.isdir(study_dir): raise NotAPhylesystemShardError('"{p}" is not a directory'.format(p=study_dir)) self.path = path self._id_minting_file = os.path.join(path, 'next_study_id.json') if self._new_study_prefix is None: prefix_file = os.path.join(path, 'new_study_prefix') if os.path.exists(prefix_file): pre_content = open(prefix_file, 'r').read().strip() valid_pat = re.compile('^[a-zA-Z0-9]+_$') if len(pre_content) != 3 or not valid_pat.match(pre_content): raise NotAPhylesystemShardError('Expecting prefix in new_study_prefix file to be two '\ 'letters followed by an underscore') self._new_study_prefix = pre_content else: self._new_study_prefix = 'ot_' # ot_ is the default if there is no file d = create_id2study_info(study_dir, name) rc_dict = diagnose_repo_study_id_convention(path) self.filepath_for_study_id_fn = rc_dict['fp_fn'] self.filepath_for_global_resource_fn = lambda frag: os.path.join(path, frag) self.id_alias_list_fn = rc_dict['id2alias_list'] if rc_dict['convention'] != 'simple': a = {} for k, v in d.items(): alias_list = self.id_alias_list_fn(k) for alias in alias_list: a[alias] = v d = a self.has_aliases = True self.inferred_study_prefix = True self.infer_study_prefix() else: self.inferred_study_prefix = False self.study_dir = study_dir with self._index_lock: self._locked_refresh_study_ids() self.parent_path = os.path.split(path)[0] + '/' self.git_dir = dot_git self.push_mirror_repo_path = push_mirror_repo_path if repo_nexml2json is None: try: repo_nexml2json = get_config_setting_kwargs(None, 'phylesystem', 'repo_nexml2json', **kwargs) except: pass if repo_nexml2json == None: repo_nexml2json = self.diagnose_repo_nexml2json() max_file_size = kwargs.get('max_file_size') if max_file_size is None: max_file_size = get_config_setting_kwargs(None, 'phylesystem', 'max_file_size', default=None, **kwargs) if max_file_size is not None: try: max_file_size = int(max_file_size) except: m = 'Configuration-base value of max_file_size was "{}". Expecting and integer.' m = m.format(max_file_size) raise RuntimeError(m) self.max_file_size = max_file_size self.repo_nexml2json = repo_nexml2json self._next_study_id = None self._study_counter_lock = None self._known_prefixes = None
#! /usr/bin/env python from peyotl.evaluate_tree import evaluate_tree_rooting from peyotl.ott import OTT from peyotl.utility import get_config_setting_kwargs, get_logger from peyotl.nexson_proxy import NexsonProxy from peyotl.test.support import pathmap import unittest _LOG = get_logger(__name__) do_test = False try: ott_dir = get_config_setting_kwargs(None, section='ott', param='parent', default=False) if ott_dir is False or not ott_dir.endswith('/aster'): _LOG.debug('ott_dir setting is "{}" this does not look like it is the Asterales system'.format(ott_dir)) else: do_test = True except: _LOG.debug('[ott]/parent setting could not be read correctly.') @unittest.skipIf(not do_test, 'the test_evaluate_tree.py is only run if you have your OTT/parent configuration set' \ ' to point to a directory called "aster" (which should hold the taxonomy of Asterales) ' \ 'See http://opentreeoflife.github.io/peyotl/configuration/ ' \ ' and open tree of life reference taxonomy documentation about the Asterales test system') class TestProxy(unittest.TestCase): def setUp(self): self.nexson = pathmap.nexson_obj('pg_329/pg_329.json') self.np = NexsonProxy(nexson=self.nexson) def testTaxoRooting(self): ott = OTT() phylo = self.np.get_tree(tree_id='tree324') evaluate_tree_rooting(self.nexson, ott, phylo) if __name__ == "__main__":