示例#1
0
 def test_remote_modified_timestamp(self):
     serialize = SerializeModel()
     a = ModelFile("a", True)
     b = ModelFile("b", False)
     b.remote_modified_timestamp = datetime(2018, 11, 9, 21, 40, 18, tzinfo=timezone('UTC'))
     files = [a, b]
     out = parse_stream(serialize.model(files))
     data = json.loads(out["data"])
     self.assertEqual(2, len(data))
     self.assertEqual(None, data[0]["remote_modified_timestamp"])
     self.assertEqual(str(1541799618.0), data[1]["remote_modified_timestamp"])
示例#2
0
            def __fill_model_file(
                    _model_file: ModelFile, _remote: Optional[SystemFile],
                    _local: Optional[SystemFile],
                    _transfer_state: Optional[LftpJobStatus.TransferState]):
                # set local and remote sizes
                if _remote:
                    _model_file.remote_size = _remote.size
                if _local:
                    _model_file.local_size = _local.size

                # Note: no longer use lftp's file sizes
                #       they represent remaining size for resumed downloads

                # set the downloading speed and eta
                if _transfer_state:
                    _model_file.downloading_speed = _transfer_state.speed
                    _model_file.eta = _transfer_state.eta

                # set the transferred size (only if file or dir exists on both ends)
                if _local and _remote:
                    if _model_file.is_dir:
                        # dir transferred size is updated by child files
                        _model_file.transferred_size = 0
                    else:
                        _model_file.transferred_size = min(
                            _local.size, _remote.size)

                        # also update all parent directories
                        _parent_file = _model_file.parent
                        while _parent_file is not None:
                            _parent_file.transferred_size += _model_file.transferred_size
                            _parent_file = _parent_file.parent

                # set the is_extractable flag
                if not _model_file.is_dir and Extract.is_archive_fast(
                        _model_file.name):
                    _model_file.is_extractable = True
                    # Also set the flag for all of its parents
                    _parent_file = _model_file.parent
                    while _parent_file is not None:
                        _parent_file.is_extractable = True
                        _parent_file = _parent_file.parent

                # set the timestamps
                if _local:
                    if _local.timestamp_created:
                        _model_file.local_created_timestamp = _local.timestamp_created
                    if _local.timestamp_modified:
                        _model_file.local_modified_timestamp = _local.timestamp_modified
                if _remote:
                    if _remote.timestamp_created:
                        _model_file.remote_created_timestamp = _remote.timestamp_created
                    if _remote.timestamp_modified:
                        _model_file.remote_modified_timestamp = _remote.timestamp_modified