collaboration.databasesync module

assign_snapshot_map(local_snapshot: Snapshot, remote_snapshot: CollabSnapshot)[source]

Add a snapshot to the id map in a database

Parameters:
  • local_snapshot (Snapshot) – Local snapshot, will use this snapshot’s database

  • remote_snapshot (CollabSnapshot) – Remote snapshot

Raises:

RuntimeError – If there was an error

default_file_path(file_: RemoteFile) str[source]

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.

Parameters:
Returns:

Default file path

Raises:

RuntimeError – If there was an error

Return type:

str

default_project_path(project_: RemoteProject) str[source]

Get the default directory path for a remote Project. This is based off the Setting for collaboration.directory, the project’s id, and the project’s remote’s id.

Parameters:
Returns:

Default project path

Raises:

RuntimeError – If there was an error

Return type:

str

download_file(file_: ~binaryninja.collaboration.file.RemoteFile, db_path: str, progress: ~typing.Callable[[int, int], bool] = <function nop>) FileMetadata[source]

Download a file from its remote, saving all snapshots to a database in the specified location. Returns a FileContext for opening the file later.

Parameters:
  • file – Remote File to download and open

  • db_path (str) – File path for saved database

  • progress (Callable[[int, int], bool]) – Function to call for progress updates

  • file_ (RemoteFile) –

Returns:

FileContext for opening

Raises:

RuntimeError – If there was an error

Return type:

FileMetadata

dump_database(database: Database)[source]

Print debug information about a database to stdout

Parameters:

database (Database) – Database to dump

Raises:

RuntimeError – If there was an error

get_local_snapshot_for_remote(snapshot: CollabSnapshot, database: Database) Snapshot | None[source]

Get the local snapshot associated with a remote snapshot (if it exists)

Parameters:
Returns:

Snapshot reference if it exists, or None reference if not

Raises:

RuntimeError – If there was an error

Return type:

Snapshot | None

get_remote_file_for_local_database(database: Database) RemoteFile | None[source]

Get the Remote File for a Database

Parameters:

database (Database) – BN database, potentially with collaboration metadata

Returns:

Remote file from one of the connected remotes, or None if not found or if files are not pulled

Raises:

RuntimeError – If there was an error

Return type:

RemoteFile | None

get_remote_for_local_database(database: Database) Remote | None[source]

Get the Remote for a Database

Parameters:

database (Database) – BN database, potentially with collaboration metadata

Returns:

Remote from one of the connected remotes, or None if not found

Raises:

RuntimeError – If there was an error

Return type:

Remote | None

get_remote_project_for_local_database(database: Database) RemoteProject | None[source]

Get the Remote Project for a Database

Parameters:

database (Database) – BN database, potentially with collaboration metadata

Returns:

Remote project from one of the connected remotes, or None if not found or if projects are not pulled

Raises:

RuntimeError – If there was an error

Return type:

RemoteProject | None

get_remote_snapshot_for_local(snap: Snapshot) CollabSnapshot | None[source]

Get the remote snapshot associated with a local snapshot (if it exists)

Parameters:

snap (Snapshot) – Local snapshot

Returns:

Remote snapshot if it exists, or None if not

Raises:

RuntimeError – If there was an error

Return type:

CollabSnapshot | None

get_snapshot_author(database: Database, snapshot: Snapshot) str | None[source]

Get the remote author of a local snapshot

Parameters:
  • database (Database) – Parent database

  • snapshot (Snapshot) – Snapshot to query

Returns:

Remote author, or None if one could not be determined

Raises:

RuntimeError – If there was an error

Return type:

str | None

ignore_snapshot(database: Database, snapshot: Snapshot)[source]

Ignore a snapshot from database syncing operations

Parameters:
  • database (Database) – Parent database

  • snapshot (Snapshot) – Snapshot to ignore

Raises:

RuntimeError – If there was an error

is_collaboration_database(database: Database) bool[source]

Test if a database is valid for use in collaboration

Parameters:

database (Database) – Database to test

Returns:

True if valid

Return type:

bool

is_snapshot_ignored(database: Database, snapshot: Snapshot) bool[source]

Test if a snapshot is ignored from the database

Parameters:
  • database (Database) – Parent database

  • snapshot (Snapshot) – Snapshot to test

Returns:

True if snapshot should be ignored

Raises:

RuntimeError – If there was an error

Return type:

bool

merge_database(database: ~binaryninja.database.Database, conflict_handler: ~binaryninja.collaboration.merge.ConflictHandler | ~typing.Callable[[~typing.Dict[str, ~binaryninja.collaboration.merge.MergeConflict]], bool], progress: ~typing.Callable[[int, int], bool] = <function nop>)[source]

Merge all leaf snapshots in a database down to a single leaf snapshot.

Parameters:
Raises:

RuntimeError – If there was an error (or the operation was cancelled)

pull_database(database: ~binaryninja.database.Database, file_: file.RemoteFile, 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:
  • database (Database) – Database to pull

  • file – Remote File to pull to

  • conflict_handler (util.ConflictHandlerType) – Function to call to resolve snapshot conflicts

  • progress (util.ProgressFuncType) – Function to call for progress updates

  • name_changeset (util.NameChangesetFuncType) – Function to call for naming a pushed changeset, if necessary

  • file_ (RemoteFile) –

Raises:

RuntimeError – If there was an error (or the operation was cancelled)

push_database(database: ~binaryninja.database.Database, file_: ~binaryninja.collaboration.file.RemoteFile, 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)

set_snapshot_author(database: Database, snapshot: Snapshot, author: str)[source]

Set the remote author of a local snapshot (does not upload)

Parameters:
  • database (Database) – Parent database

  • snapshot (Snapshot) – Snapshot to edit

  • author (str) – Target author

Raises:

RuntimeError – If there was an error

sync_database(database: ~binaryninja.database.Database, file_: file.RemoteFile, conflict_handler: util.ConflictHandlerType, progress: util.ProgressFuncType = <function nop>, name_changeset: util.NameChangesetFuncType = <function nop>)[source]

Completely sync a database, pushing/pulling/merging/applying changes

Parameters:
  • database (Database) – Database to sync

  • file – File to sync with

  • conflict_handler (util.ConflictHandlerType) – Function to call to resolve snapshot conflicts

  • progress (util.ProgressFuncType) – Function to call for progress updates

  • name_changeset (util.NameChangesetFuncType) – Function to call for naming a pushed changeset, if necessary

  • file_ (RemoteFile) –

Raises:

RuntimeError – If there was an error (or the operation was cancelled)

upload_database(metadata: FileMetadata, project: project.RemoteProject, parent_folder: folder.RemoteFolder | None = None, progress: util.ProgressFuncType = <function nop>, name_changeset: util.NameChangesetFuncType = <function nop>) RemoteFile[source]

Upload a file, with database, to the remote under the given project

Parameters:
  • metadata (FileMetadata) – Local file with database

  • project (RemoteProject) – Remote project under which to place the new file

  • progress (util.ProgressFuncType) – Function to call for progress updates

  • name_changeset (util.NameChangesetFuncType) – Function to call for naming a pushed changeset, if necessary

  • parent_folder (RemoteFolder | None) – Optional parent folder in which to place this file

Returns:

Remote File created

Raises:

RuntimeError – If there was an error

Return type:

RemoteFile