Beispiel #1
0
    def IsModified(self):
        '''
        to check whether object self changed
        Returns:
            -1 : the file that cacahe representing is missing
            0 : not changed
            1 : changed
        '''
        if not os.path.exists(self.pathname):
            return -1

        # check mtime
        modify_time = None
        try:
            modify_time = os.stat(self.pathname).st_mtime
        except BaseException:
            Log.Log().LevPrint('MSG',
                               'get %s modify_time failed' % self.pathname)
            self.modify_time = 0
            return 1

        if modify_time == self.modify_time:
            return 0
        else:
            self.modify_time = modify_time
            ret = 0
            # check hash
            _hash = Function.GetFileHash(self.pathname)
            if _hash != self.hash:
                self.hash = _hash
                ret = 1
            # Log.Log().LevPrint('MSG', '%s content changed' % self.pathname)
            return ret
Beispiel #2
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.modified = False
            self.build = False
            return

        self.modify_time = modify_time
        # update hash
        _hash = Function.GetFileHash(self.pathname)
        # Log.Log().LevPrint("MSG", "update %s hash id(%s) %s --> %s" % (self.pathname, id(self), self.hash, _hash))
        self.hash = _hash
        self.modified = False
        self.build = False
Beispiel #3
0
 def Initialize(self, target):
     """
     to initialize LibCache
     Args:
         target : the Target.Target object
     """
     if not self.initialized:
         try:
             self.hash = Function.GetFileHash(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
Beispiel #4
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.GetFileHash(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
     self.modified = False  # to mark whether the file has been modified since last build
Beispiel #5
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:
            #Log.Log().LevPrint('MSG', 'cache %s build mark is true' % self.pathname)
            return True
        # check mtime
        modify_time = None
        try:
            modify_time = os.stat(self.pathname).st_mtime
        except BaseException:
            Log.Log().LevPrint('MSG',
                               'get %s modify_time failed' % self.pathname)
            self.build = True
            self.modify_time = 0
            return True

        if modify_time == self.modify_time:
            return False
        else:
            self.modify_time = modify_time
            ret = False
            # check hash
            _hash = Function.GetFileHash(self.pathname)
            if _hash != self.hash:
                self.hash = _hash
                # Log.Log().LevPrint('MSG', '%s content changed' % self.pathname)
                self.build = True
                ret = True
            return ret