collaboration.file module¶
Class representing a remote project file. |
- class RemoteFile(handle: LP_BNRemoteFile)[source]¶
Bases:
object
Class representing a remote project file. It controls the various snapshots and raw file contents associated with the analysis.
- Parameters:
handle (LP_BNRemoteFile) –
- create_snapshot(name: str, contents: bytes, analysis_cache_contents: bytes, file: bytes, parent_ids: ~typing.List[str], progress: ~typing.Callable[[int, int], bool] = <function nop>) CollabSnapshot [source]¶
Create a new snapshot on the remote (and pull it)
- Parameters:
name (str) – Snapshot name
contents (bytes) – Snapshot contents
analysis_cache_contents (bytes) – Contents of analysis cache of snapshot
file (bytes) – New file contents (if contents changed)
parent_ids (List[str]) – List of ids of parent snapshots (or empty if this is a root snapshot)
progress (Callable[[int, int], bool]) – Function to call on progress updates
- Returns:
Reference to the created snapshot
- Raises:
RuntimeError if there was an error
- Return type:
- delete_snapshot(snapshot: CollabSnapshot)[source]¶
Delete a snapshot from the remote
- Parameters:
snapshot (CollabSnapshot) – Snapshot to delete
- Raises:
RuntimeError if there was an error
- download(progress: ~typing.Callable[[int, int], bool] = <function nop>) bytes [source]¶
Download the contents of a remote file
- download_to_bndb(path: str | None = None, progress: ~typing.Callable[[int, int], bool] = <function nop>) FileMetadata [source]¶
Download a remote file and save it to a bndb at the given path. This calls databasesync.download_file and self.sync to fully prepare the bndb.
- static get_for_bv(bv: BinaryView) RemoteFile | None [source]¶
Look up the remote File for a local BinaryView, or None if there is no matching remote File found.
- Parameters:
bv (BinaryView) – Local BinaryView
- Returns:
Remote File object
- Return type:
File or None
- static get_for_local_database(database: Database) RemoteFile | None [source]¶
Look up the remote File for a local database, or None if there is no matching remote File found. See
get_for_bv
to load from a BinaryView.- Parameters:
database (Database) – Local database
- Returns:
Remote File object
- Return type:
File or None
- get_snapshot_by_id(id: str) CollabSnapshot | None [source]¶
Get a specific Snapshot in the File by its id
Note
If snapshots have not been pulled, they will be pulled upon calling this.
- Parameters:
id (str) – Id of Snapshot
- Returns:
Snapshot object, if one with that id exists. Else, None
- Raises:
RuntimeError if there was an error pulling snapshots
- Return type:
CollabSnapshot | None
- pull(bv_or_db: BinaryView | Database, conflict_handler: util.ConflictHandlerType, progress: util.ProgressFuncType = <function nop>, name_changeset: util.NameChangesetFuncType = <function nop>)[source]¶
Pull updated snapshots from the remote. Merge local changes with remote changes and potentially create a new snapshot for unsaved changes, named via name_changeset.
- Parameters:
bv_or_db (BinaryView | Database) – Binary view or database to sync with
conflict_handler (util.ConflictHandlerType) – Function to call to resolve snapshot conflicts
name_changeset (util.NameChangesetFuncType) – Function to call for naming a pushed changeset, if necessary
progress (util.ProgressFuncType) – Function to call for progress updates
- Raises:
RuntimeError – If there was an error (or the operation was cancelled)
- pull_snapshots(progress: ~typing.Callable[[int, int], bool] = <function nop>)[source]¶
Pull the list of Snapshots from the Remote.
- push(bv_or_db: ~binaryninja.binaryview.BinaryView | ~binaryninja.database.Database, progress: ~typing.Callable[[int, int], bool] = <function nop>)[source]¶
Push locally added snapshots to the remote
- Parameters:
- Raises:
RuntimeError – If there was an error (or the operation was cancelled)
- sync(bv_or_db: BinaryView | Database, conflict_handler: util.ConflictHandlerType, progress: util.ProgressFuncType = <function nop>, name_changeset: util.NameChangesetFuncType = <function nop>)[source]¶
Completely sync a file, pushing/pulling/merging/applying changes
- Parameters:
bv_or_db (BinaryView | Database) – Binary view or database to sync with
conflict_handler (util.ConflictHandlerType) – Function to call to resolve snapshot conflicts
name_changeset (util.NameChangesetFuncType) – Function to call for naming a pushed changeset, if necessary
progress (util.ProgressFuncType) – Function to call for progress updates
- Raises:
RuntimeError – If there was an error (or the operation was cancelled)
- property core_file: ProjectFile¶
- property default_path: str¶
Get the default filepath for a remote File. This is based off the Setting for collaboration.directory, the file’s id, the file’s project’s id, and the file’s remote’s id.
- Returns:
Default file path
- Return type:
- property folder: RemoteFolder | None¶
Parent folder, if one exists. None if this is in the root of the project.
- Returns:
Folder object or None
- property has_pulled_snapshots: bool¶
If the file has pulled the snapshots yet
- Returns:
True if they have been pulled
- property last_snapshot_by: str¶
Username of user who pushed the last snapshot in the file
- Returns:
Username string
- property project: RemoteProject¶
Owning Project
- Returns:
Project object
- property snapshots: List[CollabSnapshot]¶
Get the list of snapshots in this file.
Note
If snapshots have not been pulled, they will be pulled upon calling this.
- Returns:
List of Snapshot objects
- Raises:
RuntimeError if there was an error pulling snapshots
- property type: RemoteFileType¶
File Type All files share the same properties, but files with different types may make different uses of those properties, or not use some of them at all.
- Returns:
Type of file on server (enum)