Пример #1
0
    def set_utime(self, last_modified: str = None):
        """Sets the last modified and last activated time of a downloaded file

        Args:
            last_modified (str, optional): The last_modified header from the Webpage. Defaults to None.
        """

        try:
            if last_modified is not None:
                filetime = timeconvert(last_modified)
                if filetime is not None and filetime > 0:
                    os.utime(self.file.saved_to, (time.time(), filetime))
                    return

            if self.file.content_timemodified is not None and self.file.content_timemodified > 0:
                os.utime(self.file.saved_to,
                         (time.time(), self.file.content_timemodified))

        except Exception:
            logging.debug('T%s - Could not change utime', self.thread_id)
Пример #2
0
 def try_utime(self, filename, last_modified_hdr):
     """Try to set the last-modified time of the given file."""
     if last_modified_hdr is None:
         return
     if not os.path.isfile(encodeFilename(filename)):
         return
     timestr = last_modified_hdr
     if timestr is None:
         return
     filetime = timeconvert(timestr)
     if filetime is None:
         return filetime
     # Ignore obviously invalid dates
     if filetime == 0:
         return
     try:
         os.utime(filename, (time.time(), filetime))
     except:
         pass
     return filetime
Пример #3
0
 def test_timeconvert(self):
     self.assertTrue(timeconvert('') is None)
     self.assertTrue(timeconvert('bougrg') is None)
Пример #4
0
 def test_timeconvert(self):
     self.assertTrue(timeconvert('') is None)
     self.assertTrue(timeconvert('bougrg') is None)
Пример #5
0
 def test_timeconvert(self):
     self.assertTrue(timeconvert("") is None)
     self.assertTrue(timeconvert("bougrg") is None)