transaction module
Manage a single transaction.
- class pdbstore.store.transaction.Transaction(store: Store, transaction_id: str | None = None, transaction_type: TransactionType = TransactionType.ADD, ref: str = 'file', timestamp: datetime | None = None, product: str | None = None, version: str | None = None, comment: str | None = None, deleted_id: str | None = None)
Bases:
objectA SymbolStore transaction representation
- add_entry(entry: TransactionEntry) None
Add a new TransactionEntry object
- Parameters:
entry – The TransactionEntry object to be added
- commit(transaction_id: str, timestamp: datetime, force: bool | None = False, store: Store | None = None) Summary
Save the transaction on the disk.
If
storeis None, this function will consider as a standard transaction, else this function will promote the files referenced bythis transaction objectobject and stored instoreas a new transaction from its associatedStoreobject.- Parameters:
transaction_id – The transaction ID
timestamp – The transaction date/time
store – Optional
Storeobjectforce – If True and a file is already present in the store, the existing file will be overwritten and the file will be associated to
transaction, else this function will only make the associated between the file andtransaction.
- Returns:
True if successful, else False
- Raise:
- WriteFileError:
Failed to update history file
- compute_disk_usage() int
Compute the disk space usage related to all files associated to this transaction
- Returns:
The disk space usage in bytes.
- property count: int
Retrieve the total number of entries
- Returns:
The total number of registered entries
- property entries: List[TransactionEntry]
Retrieve the list of associated entries
- Returns:
List of associated
TransactionEntryobjects
- find_entry(file_name: str, file_hash: str) TransactionEntry | None
Search a transaction entry given by file name and hash value.
- Parameters:
file_name – The file name to be found
file_hash – The required file hash associated to file_name
- Returns:
The requested
TransactionEntryobject if successful, else None
- property id: str
Retrieve transaction id
- Returns:
The transcaction id as a string formated using
%010dformat
- is_committed() bool
Determine whether the transaction is committed or not
- Returns:
True if committed (as part of symbol store), else False
- is_delete_operation() bool
Determine whether the transaction is associated to a del operation.
- Returns:
True if it is a deleted transaction, else False.
- is_deleted() bool
Determine whether the transaction is deleted or not
- Returns:
True if it is a deleted transaction, else False.
- is_promoted() bool
Determine whether the transaction is promoted or not
- Returns:
True if it is a promoted transaction, else False.
- mark_deleted() None
Tag this transaction as deleted
This function will rename existing transaction file by appending
.delete.- Raise:
- RenameFileError:
Failed to rename the transaction file
- mark_promoted() None
Tag this transaction as promoted
This function will copy existing transaction file by appending
.promotedto the new file name.- Raise:
- RenameFileError:
Failed to rename the transaction file
- static parse_line(store: Store, line: str) Transaction | None
Parse a transaction entry from disk.
Examine
lineto extract all information related to an entry and create the associatedTransactionobject.- Parameters:
store – The associated
Storeobjectline – the line to be parsed
- Returns:
The corresponding Transaction object if successful, else None
- register_entry(pathname: str | Path, compress: bool = False) bool
Register a new transaction entry
This function will ceate a new TransactionEntry before to call add_entry.
- Parameters:
pathname – Path to the file
compress – True to compress it, else False
- Returns:
True if successful, else False
- Raise:
- FileNotExistsError:
The specified file doesn’t exists