Exemple #1
0
    def IsChanged(self, target=None):
        """
        to check whether cache is changed
        Args:
            target : the target that compared to 
        Returns:
            if file is modified, return True
            if file is not modified, return False
        """
        # if build flag is True, means it has changed
        if self.build:
            return True
        # check mtime
        modify_time = None
        try:
            modify_time = os.stat(self.pathname).st_mtime
        except BaseException:
            self.build = True
            self.modify_time = 0
            return True

        if modify_time == self.modify_time:
            return False

        # check hash
        _hash = Function.GetFileMd5(self.pathname)
        if _hash != self.hash:
            self.hash = _hash
            self.build = True
            return True

        return False
Exemple #2
0
 def Initialize(self, target):
     """
     to initialize LibCache
     Args:
         target : the Target.Target object
     """
     if not self.initialized:
         try:
             self.hash = Function.GetFileMd5(self.pathname)
             if self.hash:
                 self.modify_time = os.stat(self.pathname.st_mtime)
         except BaseException:
             pass
         self.build_cmd = target.GetBuildCmd()
         self.initialized = True
Exemple #3
0
 def __init__(self, pathname, initialized=True):
     """
     Args:
         pathname : the cvs path of object file
         initialized : to mark whether BrocObject need initialized, default is True,
                       if initialized is False, create a empty BrocObject object
     """
     self.pathname = pathname
     self.initialized = initialized  # initialized flag
     self.deps = set()  # dependent BrocObject
     self.reverse_deps = set()  # reversed dependent BrocObject
     self.hash = None  # hash value of content
     self.modify_time = 0  # the last modify time of BrocObject file
     self.build_cmd = ""  # the commond of BrocObject to build
     if self.initialized:
         try:
             self.hash = Function.GetFileMd5(pathname)
             if self.hash:
                 self.modify_time = os.stat(self.pathname.st_mtime)
         except BaseException:
             pass
     self.build = True  # build flag, if build is True, the BrocObject need to compiled
Exemple #4
0
    def Update(self):
        """
        Update modify time and hash value of cache object
        """
        # update modify time
        modify_time = None
        try:
            modify_time = os.stat(self.pathname).st_mtime
        except BaseException as err:
            Log.Log().LevPrint(
                "ERROR", "update cache(%s) failed: %s" % (self.pathname, err))
            return

        if self.modify_time == modify_time:
            self.build = False
            return

        self.modify_time = modify_time
        # update hash
        _hash = Function.GetFileMd5(self.pathname)
        # Log.Log().LevPrint("MSG", "update %s hash id(%s) %s --> %s" % (self.pathname, id(self), self.hash, _hash))
        self.hash = _hash
        self.build = False