collaboration.databasesync module

assign_snapshot_map(local_snapshot: Snapshot, remote_snapshot: Snapshot)[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 (Snapshot) – Remote snapshot

Raises:

RuntimeError – If there was an error

default_file_path(file_: File) 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:
  • file – Remote File

  • file_ (File) –

Returns:

Default file path

Raises:

RuntimeError – If there was an error

Return type:

str

default_project_path(project_: Project) 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:
  • project – Remote Project

  • project_ (Project) –

Returns:

Default project path

Raises:

RuntimeError – If there was an error

Return type:

str

download_file(file_: ~binaryninja.collaboration.file.File, 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_ (File) –

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: Snapshot, database: Database) Optional[Snapshot][source]

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

Parameters:
  • snapshot (Snapshot) – Remote snapshot

  • database (Database) – Local database to search

Returns:

Snapshot reference if it exists, or None reference if not

Raises:

RuntimeError – If there was an error

Return type:

Optional[Snapshot]

get_remote_file_for_local_database(database: Database) Optional[File][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:

Optional[File]

get_remote_for_local_database(database: Database) Optional[Remote][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:

Optional[Remote]

get_remote_project_for_local_database(database: Database) Optional[Project][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:

Optional[Project]

get_remote_snapshot_for_local(snap: Snapshot) Optional[Snapshot][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:

Optional[Snapshot]

get_snapshot_author(database: Database, snapshot: Snapshot) Optional[str][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:

Optional[str]

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: ~typing.Union[merge.ConflictHandler, ~typing.Callable[[~typing.Dict[str, 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)

nop(*args, **kwargs)[source]
pull_database(database: ~binaryninja.database.Database, file_: ~binaryninja.collaboration.file.File, conflict_handler: ~typing.Union[merge.ConflictHandler, ~typing.Callable[[~typing.Dict[str, merge.MergeConflict]], bool]], progress: ~typing.Callable[[int, int], bool] = <function nop>, name_changeset: ~typing.Callable[[changeset.Changeset], bool] = <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:
Raises:

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

push_database(database: ~binaryninja.database.Database, file_: ~binaryninja.collaboration.file.File, progress: ~typing.Callable[[int, int], bool] = <function nop>)[source]

Push locally added snapshots to the remote

Parameters:
  • database (Database) – Database to push

  • file – Remote File to push to

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

  • file_ (File) –

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_: ~binaryninja.collaboration.file.File, conflict_handler: ~typing.Union[merge.ConflictHandler, ~typing.Callable[[~typing.Dict[str, merge.MergeConflict]], bool]], progress: ~typing.Callable[[int, int], bool] = <function nop>, name_changeset: ~typing.Callable[[changeset.Changeset], bool] = <function nop>)[source]

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

Parameters:
Raises:

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

upload_database(metadata: ~binaryninja.filemetadata.FileMetadata, project: ~binaryninja.collaboration.project.Project, parent_folder: ~typing.Optional[~binaryninja.collaboration.folder.Folder] = None, progress: ~typing.Callable[[int, int], bool] = <function nop>, name_changeset: ~typing.Callable[[changeset.Changeset], bool] = <function nop>) File[source]

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

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

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

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

  • name_changeset (Callable[[Changeset], bool]) – Function to call for naming a pushed changeset, if necessary

  • parent_folder (Optional[Folder]) – Optional parent folder in which to place this file

Returns:

Remote File created

Raises:

RuntimeError – If there was an error

Return type:

File