Beispiel #1
0
 def __init__(self, task_base, local_parent_path, name, new_mtime):
     super().__init__(task_base)
     self.local_parent_path = local_parent_path
     self.name = name
     if isinstance(new_mtime, int):
         new_mtime = timestamp_to_datetime(new_mtime)
     self.new_mtime = new_mtime
Beispiel #2
0
 def handle(self):
     local_item_path = self.local_parent_path + '/' + self.name
     try:
         size = os.path.getsize(local_item_path)
         with open(local_item_path, 'rb') as f:
             item = self.drive.upload_file(
                 filename=self.name, data=f, size=size, parent_path=self.parent_path,
                 conflict_behavior=self.conflict_behavior)
             modified_time = timestamp_to_datetime(os.path.getmtime(local_item_path))
             fs_info = facets.FileSystemInfoFacet(modified_time=modified_time)
             item = self.drive.update_item(item_id=item.id, new_file_system_info=fs_info)
             self.items_store.update_item(item, ItemRecordStatuses.OK)
     except Exception as e:
         self.logger.error('Error occurred when uploading "%s": %s.', local_item_path, e)
Beispiel #3
0
 def check_file_hash(self, item, item_path, file_mtime):
     file_props = item.file_props
     hash_props = file_props.hashes if file_props is not None else None
     if hash_props is not None:
         if hash_props.crc32 is not None and hash_props.crc32 == hasher.crc32_value(item_path) or \
                                 hash_props.sha1 is not None and hash_props.sha1 == hasher.hash_value(item_path):
             # The remote and local files have identical content, update remote timestamps
             # and update local record. No changes on the local file.
             self.logger.debug('Item "%s" has same hash value for remote and local content.')
             self.task_pool.add_task(
                 UpdateItemInfoTask(self, self.local_relative_parent_path + '/' + self.name, item.name,
                                    timestamp_to_datetime(file_mtime)))
             return True
     return False