def kimcode_to_dict(kimcode): name, leader, num, version = parse_kim_code(kimcode) if not name: name = database.look_for_name(leader, num, version) kimcode = database.format_kim_code(name, leader, num, version) leader = leader.lower() foo = { "name": name, "type": leader.lower(), "kimnum": num, "version": int(version), "shortcode": "_".join((leader.upper(), num)), "kimcode": kimcode, "path": os.path.join(leader.lower(), kimcode), "approved": True, '_id': kimcode, "inserted_on": str(datetime.datetime.utcnow()), "latest": True, } if foo['type'] in ('te', 'mo', 'md', 'tv', 'mv'): foo['makeable'] = True if foo['type'] in ('te', 'tv', 'mv'): foo['runner'] = True if foo['type'] in ('te', 'mo'): foo['subject'] = True if foo['type'] in ('md', 'td'): foo['driver'] = True else: foo['driver'] = False specpath = os.path.join(PATH_APPROVED, leader, kimcode, cf.CONFIG_FILE) spec = config_edn(specpath) if foo['type'] == 'te': try: testresult = spec.get('test-driver') if testresult: foo['driver'] = rmbadkeys(kimcode_to_dict(testresult)) except: pass if foo['type'] == 'mo': try: modeldriver = spec.get('model-driver') if modeldriver: foo['driver'] = rmbadkeys(kimcode_to_dict(modeldriver)) except: pass foo.update(spec) return foo
def kimcode_to_dict(kimcode): name,leader,num,version = parse_kim_code(kimcode) if not name: name = database.look_for_name(leader, num, version) kimcode = database.format_kim_code(name, leader, num, version) leader = leader.lower() extended_id = None short_id = None m = re.search('(.+)__([A-Z]{2}_\d{12}_\d{3})$', kimcode) if m: extended_id = kimcode short_id = m.group(2) else: short_id = kimcode foo = {} if extended_id: foo['extended-id'] = extended_id foo['short-id'] = short_id if extended_id: foo['kimid-prefix'] = name foo['kimid-typecode'] = leader.lower() foo['kimid-number'] = num foo['kimid-version'] = version foo['kimid-version-as-integer'] = int( version ) foo['name'] = name foo['type'] = leader.lower() foo['kimnum'] = num foo['version'] = int(version) foo['shortcode'] = "_".join((leader.upper(),num)) foo['kimcode'] = kimcode foo['path'] = os.path.join(leader.lower(),kimcode) foo['approved'] = True foo['_id'] = kimcode foo['inserted_on'] = str(datetime.datetime.utcnow()) foo['latest'] = True if foo['type'] in ('te','mo','md','tv','mv'): foo['makeable'] = True if foo['type'] in ('te','tv','mv'): foo['runner'] = True if foo['type'] in ('te','mo'): foo['subject'] = True if foo['type'] in ('md','td'): foo['driver'] = True else: foo['driver'] = False specpath = os.path.join(PATH_APPROVED,leader,kimcode,cf.CONFIG_FILE) spec = config_edn(specpath) if foo['type'] == 'te': try: testresult = spec.get('test-driver') if testresult: foo['driver'] = rmbadkeys(kimcode_to_dict(testresult)) except: pass if foo['type'] == 'mo': try: modeldriver = spec.get('model-driver') if modeldriver: foo['driver'] = rmbadkeys(kimcode_to_dict(modeldriver)) except: pass foo.update(spec) return foo
def __init__(self,kim_code,search=True,subdir=None,abspath=None,precheck=False): """ Initialize a KIMObject given the kim_code, where partial kim codes are promoted if possible, if search is False, then don't look for existing ones Args: kim_code (str) A full or partial kim_code, i.e. one like: * "Full_Name_of_thing__TE_000000000000_000" * "TE_000000000000_000" * "TE_000000000000" * "Full_Name_of_thing__TE_000000000000" search (bool) Whether or not to search the directory structure for the fullest match, false is useful when creating new KIMObjects to avoid hitting a PipelineSearchError subdir (str) In order to point to a directory that does not follow that pattern /home/openkim/openkim-repository/{mo,md,te...}/KIM_CODE/KIM_CODE can provide the folder of /home/openkim/openkim-repository/{mo,md,te...}/SUBDIR/KIM_CODE """ logger.debug("Initializing a new KIMObject: %r", kim_code) name, leader, num, version = database.parse_kim_code(kim_code) # test to see if we have the right leader if self.required_leader: assert leader==self.required_leader,"{} not a valid KIM code for {}".format(kim_code, self.__class__.__name__) #grab the attributes self.kim_code_name = name self.kim_code_leader = leader self.kim_code_number = num self.kim_code_version = version if not search: self.kim_code = kim_code #if we were given everything, we are good to go elif name and leader and num and version: self.kim_code = database.format_kim_code(name,leader,num,version) #if we weren't given a name, see if one exists elif name is None and leader and num and version: name = database.look_for_name(leader,num,version) self.kim_code_name = name self.kim_code = database.format_kim_code(name,leader,num,version) #if we weren't given a version elif name and leader and num and version is None: name,leader,num,version = database.get_latest_version(name,leader,num) self.kim_code_version = version self.kim_code = database.format_kim_code(name,leader,num,version) #if we weren't given a name or version elif name is None and leader and num and version is None: name,leader,num,version = database.get_latest_version(name,leader,num) self.kim_code_name = name self.kim_code_version = version self.kim_code = database.format_kim_code(name,leader,num,version) self.kim_code_id = database.strip_name(self.kim_code) self.kim_code_short = database.strip_version(self.kim_code) # Determine where this KIMObject sits in the local repository if precheck: self.parent_dir = os.path.join(os.path.join(cf.LOCAL_REPOSITORY_PATH,'precheck'), self.kim_code_leader.lower()) else: self.parent_dir = os.path.join(cf.LOCAL_REPOSITORY_PATH, self.kim_code_leader.lower()) if subdir is not None: self.path = os.path.join(self.parent_dir, subdir) else: self.path = os.path.join(self.parent_dir, self.kim_code) if abspath is not None: self.path = abspath # assume the object is not built by default self.built = False
def __init__(self,kim_code,search=True,subdir=None): """ Initialize a KIMObject given the kim_code, where partial kim codes are promoted if possible, if search is False, then don't look for existing ones Args: kim_code (str) A full or partial kim_code, i.e. one like: * "Full_Name_of_thing__TE_000000000000_000" * "TE_000000000000_000" * "TE_000000000000" * "Full_Name_of_thing__TE_000000000000" search (bool) Whether or not to search the directory structure for the fullest match, false is useful when creating new KIMObjects to avoid hitting a PipelineSearchError subdir (str) In order to point to a directory that does not follow that pattern /home/openkim/openkim-repository/{mo,md,te...}/KIM_CODE/KIM_CODE can provide the folder of /home/openkim/openkim-repository/{mo,md,te...}/SUBDIR/KIM_CODE """ logger.debug("Initializing a new KIMObject: %r", kim_code) name, leader, num, version = database.parse_kim_code(kim_code) # test to see if we have the right leader if self.required_leader: assert leader==self.required_leader,"{} not a valid KIM code for {}".format(kim_code, self.__class__.__name__) #grab the attributes self.kim_code_name = name self.kim_code_leader = leader self.kim_code_number = num self.kim_code_version = version if not search: self.kim_code = kim_code #if we were given everything, we are good to go elif name and leader and num and version: self.kim_code = database.format_kim_code(name,leader,num,version) #if we weren't given a name, see if one exists elif name is None and leader and num and version: name = database.look_for_name(leader,num,version) self.kim_code_name = name self.kim_code = database.format_kim_code(name,leader,num,version) #if we weren't given a version elif name and leader and num and version is None: name,leader,num,version = database.get_latest_version(name,leader,num) self.kim_code_version = version self.kim_code = database.format_kim_code(name,leader,num,version) #if we weren't given a name or version elif name is None and leader and num and version is None: name,leader,num,version = database.get_latest_version(name,leader,num) self.kim_code_name = name self.kim_code_version = version self.kim_code = database.format_kim_code(name,leader,num,version) self.kim_code_id = database.strip_name(self.kim_code) self.kim_code_short = database.strip_version(self.kim_code) self.parent_dir = os.path.join(cf.KIM_REPOSITORY_DIR, self.kim_code_leader.lower()) if subdir is not None: self.path = os.path.join(self.parent_dir, subdir) else: self.path = os.path.join(self.parent_dir, self.kim_code)