示例#1
0
def latestversion(kim):
    return database.format_kim_code(
        *database.get_latest_version(database.parse_kim_code(kim)))
示例#2
0
    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
示例#3
0
def latestversion(kim):
    return database.format_kim_code(*database.get_latest_version(database.parse_kim_code(kim)))
示例#4
0
 def latest_version(self):
     """ Return the latest version object of this thing """
     name,leader,num,version = database.get_latest_version(self.kim_code_name, self.kim_code_leader, self.kim_code_number)
     return self.__class__(database.format_kim_code(name,leader,num,version))
示例#5
0
 def get_latest_version_number(self):
     """ Figure out the latest version number """
     name,leader,num,version = database.get_latest_version(self.kim_code_name,
             self.kim_code_leader,self.kim_code_number)
     return version
示例#6
0
    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)
示例#7
0
 def latest_version(self):
     """ Return the latest version object of this thing """
     name,leader,num,version = database.get_latest_version(self.kim_code_name, self.kim_code_leader, self.kim_code_number)
     return self.__class__(database.format_kim_code(name,leader,num,version))
示例#8
0
 def get_latest_version_number(self):
     """ Figure out the latest version number """
     name,leader,num,version = database.get_latest_version(self.kim_code_name,
             self.kim_code_leader,self.kim_code_number)
     return version