def update_item(self, item, status=ItemRecordStatuses.OK, parent_path=None): """ :param onedrived.api.items.OneDriveItem item: :param str status: One value of enum ItemRecordStatuses. :param str parent_path: If item does not have a parent reference, fallback to this path. """ if item.is_folder: crc32_hash = None sha1_hash = None else: file_facet = item.file_props crc32_hash = file_facet.hashes.crc32 sha1_hash = file_facet.hashes.sha1 parent_ref = item.parent_reference try: parent_path = parent_ref.path except Exception: pass created_time_str = datetime_to_str(item.created_time) modified_time_str = datetime_to_str(item.modified_time) self.lock.acquire_write() self._cursor.execute( 'INSERT OR REPLACE INTO items (item_id, type, item_name, parent_id, parent_path, etag, ' 'ctag, size, created_time, modified_time, status, crc32_hash, sha1_hash)' ' VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', (item.id, item.type, item.name, parent_ref.id, parent_path, item.e_tag, item.c_tag, item.size, created_time_str, modified_time_str, status, crc32_hash, sha1_hash)) self._conn.commit() self.lock.release_write()
def update_item(self, item, status=ItemRecordStatuses.OK, parent_path=None): """ :param onedrived.api.items.OneDriveItem item: :param str status: One value of enum ItemRecordStatuses. :param str parent_path: If item does not have a parent reference, fallback to this path. """ if item.is_folder: crc32_hash = None sha1_hash = None else: file_facet = item.file_props crc32_hash = file_facet.hashes.crc32 sha1_hash = file_facet.hashes.sha1 parent_ref = item.parent_reference try: parent_path = parent_ref.path except: pass created_time_str = datetime_to_str(item.created_time) modified_time_str = datetime_to_str(item.modified_time) self.lock.acquire_write() self._cursor.execute( 'INSERT OR REPLACE INTO items (item_id, type, item_name, parent_id, parent_path, etag, ' 'ctag, size, created_time, modified_time, status, crc32_hash, sha1_hash)' ' VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', (item.id, item.type, item.name, parent_ref.id, parent_path, item.e_tag, item.c_tag, item.size, created_time_str, modified_time_str, status, crc32_hash, sha1_hash)) self._conn.commit() self.lock.release_write()
def set_datetime(self, prop, key, value): """ Used internally to set a datetime property. :param str prop: Object property name. :param str key: Dictionary key name. :param datetime.datetime value: A UTC datetime object denoting when the file was created on a client. """ setattr(self, prop, value) self.data[key] = datetime_to_str(value)
def test_convert(self): self.assertEqual(self.d, dateparser.str_to_datetime(self.s)) self.assertEqual(self.s, dateparser.datetime_to_str(self.d)) self.assertEqual(self.t, dateparser.datetime_to_timestamp(self.d))