buildgrid.utils module

class buildgrid.utils.BrowserURL(base_url, instance_name=None)

Bases: object

for_message(message_type, message_digest)

Completes browser URL initialization for a protobuf message.

generate()

Generates a browser URL string.

buildgrid.utils.get_hostname()

Returns the hostname of the machine executing that function.

Returns

Hostname for the current machine.

Return type

str

buildgrid.utils.get_hash_type()

Returns the hash type.

buildgrid.utils.create_digest(bytes_to_digest)

Computes the Digest of a piece of data.

The Digest of a data is a function of its hash and size.

Parameters

bytes_to_digest (bytes) – byte data to digest.

Returns

The Digest for the given byte data.

Return type

Digest

buildgrid.utils.parse_digest(digest_string)

Creates a Digest from a digest string.

A digest string should alway be: {hash}/{size_bytes}.

Parameters

digest_string (str) – the digest string.

Returns

The Digest read from the string or None if

digest_string is not a valid digest string.

Return type

Digest

buildgrid.utils.read_file(file_path)

Loads raw file content in memory.

Parameters

file_path (str) – path to the target file.

Returns

Raw file’s content until EOF.

Return type

bytes

Raises

OSError – If file_path does not exist or is not readable.

buildgrid.utils.write_file(file_path, content)

Dumps raw memory content to a file.

Parameters
  • file_path (str) – path to the target file.

  • content (bytes) – raw file’s content.

Raises

OSError – If file_path does not exist or is not writable.

buildgrid.utils.merkle_tree_maker(directory_path)

Walks a local folder tree, generating FileNode and DirectoryNode.

Parameters

directory_path (str) – absolute or relative path to a local directory.

Yields

Message, bytes, str – a tutple of either a FileNode or DirectoryNode message, the corresponding blob and the corresponding node path.

buildgrid.utils.output_file_maker(file_path, input_path, file_digest)

Creates an OutputFile from a local file and possibly upload it.

Note

file_path must point inside or be relative to input_path.

Parameters
  • file_path (str) – absolute or relative path to a local file.

  • input_path (str) – absolute or relative path to the input root directory.

  • file_digest (Digest) – the underlying file’s digest.

Returns

a new OutputFile object for the file pointed by file_path.

Return type

OutputFile

buildgrid.utils.output_directory_maker(directory_path, working_path, tree_digest)

Creates an OutputDirectory from a local directory.

Note

directory_path must point inside or be relative to input_path.

Parameters
  • directory_path (str) – absolute or relative path to a local directory.

  • working_path (str) – absolute or relative path to the working directory.

  • tree_digest (Digest) – the underlying folder tree’s digest.

Returns

a new OutputDirectory for the directory pointed by directory_path.

Return type

OutputDirectory