API reference¶
Generated from the library's docstrings. Everything here is imported from odouche, and
nothing else is public: see Stability.
Client¶
odouche.Client
¶
Client(
session: Secret | None = None,
*,
read_only: bool = False,
)
Asks Odoo.sh on behalf of one session.
With no argument the session is the one in the environment, then the one stored by login.
A tool that keeps sessions itself passes its own, which is never stored. Raises
NoSessionError when there is none, SessionExpiredError when the stored one has passed its
max age and KeyringUnavailableError when the keyring cannot be read.
Every call raises SessionExpiredError when Odoo.sh rejects the session, after deleting it if
it is the stored one. Nothing is cached: each call asks Odoo.sh. Use the client as a context
manager, or call close.
With read_only, a call that changes state on Odoo.sh raises ReadOnlyError and sends nothing.
session
property
¶
session: SessionInfo
Where the session came from and when it passes its max age. Odoo.sh is not asked.
read_only
property
¶
Whether the client refuses the calls that change state on Odoo.sh.
identity
¶
identity() -> Identity
Return the user the session belongs to, which also tells that Odoo.sh still accepts it.
branches
¶
List the branches of a project, given as a Project or by its name.
They come in the order Odoo.sh answers them, which is not by name or by stage. Raises
NotFoundError when the project is not among those the session's user can reach, whether
or not it exists, and PermissionDeniedError when Odoo.sh lists it but refuses its
branches. Asks Odoo.sh twice, for the projects and then for the branches.
builds
¶
List the latest builds of a branch, given as a Branch or by its number, newest first.
At most limit builds are returned, in one request. Odoo.sh may answer fewer than asked
for: it has only been seen to answer up to four, and older builds are out of reach. Raises
NotFoundError when the branch is not one the session's user can reach.
build
¶
Return one build of a branch by its number.
Odoo.sh has no request for a build by its number, so the build is looked for among the
branch's latest. Raises NotFoundError when it is not there, which an older build is not.
latest_build
¶
Return the newest build of a branch, or None when it has none.
ssh_target
¶
Return the user and the host ssh reaches a build with. Odoo.sh is not asked.
Odoo.sh accepts there the keys registered on the user's account, not the session. Raises
NotFoundError when the build has no host, and UpstreamChangedError when its number or
its address is not one that can be handed to ssh as it is.
rebuild
¶
Change state on Odoo.sh: start a new build of a branch, given as a Branch or by its number.
Returns the new build, which replaces the branch's latest one. Only a development or a
staging branch is rebuilt: any other raises StageRefusedError before the request.
The request is sent once. Raises OutcomeUnknownError when it left and Odoo.sh did not
confirm it, or the new build cannot be found: look at the branch before calling again,
since a second call can start a second build. Raises ReadOnlyError on a read-only
client, and NotFoundError when the branch is not one the session's user can reach.
A branch that is not a number raises TypeError.
check_rebuild
¶
check_rebuild(branch: Branch) -> None
Raise StageRefusedError when rebuild would refuse the branch for its stage.
Odoo.sh is not asked and nothing changes, on a read-only client too.
watch_build
¶
watch_build(
project: Project | str,
build: Build,
*,
timeout: float,
pulse: float | None = None,
) -> Generator[Build]
Yield a build of a project as it is now, then at each change, and end once it has finished.
A change is one of status, result or status_info. The last build yielded is the
finished one, and a build that has already finished is yielded once. The watch stays on
this build: a newer one on the branch ends it as DROPPED. Closing the iterator closes the
connection.
With pulse, the build is also yielded unchanged, every pulse seconds at least while
nothing changes. An iterator is closed only between two builds, so a caller that may have
to stop the watch asks for one.
Raises StreamTimeoutError after timeout seconds, UpstreamUnavailableError when the
connection fails three times in a row or Odoo.sh cannot be asked for the build, and
NotFoundError when the build is not among its
branch's latest, or the project is not one the session's user can reach.
logs
¶
List the logs a build of a project has, which is none while it waits for a worker.
Raises NotFoundError when the build is not among its branch's latest, or the project is
not one the session's user can reach.
read_log
¶
read_log(
project: Project | str,
build: Build,
kind: LogKind | str,
*,
tail: int | None = None,
) -> Generator[LogLine]
Yield the lines of one log of a build, given as a LogKind or by its name.
Log content is untrusted: it is whatever a process printed, terminal escape sequences and secrets of the instance included, and it is returned unchanged.
With tail, only the last lines are yielded, out of the log's last mebibyte. A line
longer than 64 KiB is cut. Closing the iterator closes the connection. Raises
NotFoundError when the build has no such log.
follow_log
¶
follow_log(
project: Project | str,
build: Build,
kind: LogKind | str,
*,
timeout: float,
tail: int = 0,
offset: int | None = None,
) -> Generator[LogLine]
Yield the lines of one log of a build as they are written, until the iterator is closed.
Log content is untrusted, as in read_log.
It starts after the log's last tail lines, or at offset, which is the offset of a
line read before. Odoo.sh is asked every second. Raises StreamTimeoutError after
timeout seconds, which math.inf makes no limit, UpstreamUnavailableError when a
failed request is not answered after two more tries, and NotFoundError when the build
has no such log.
odouche.Secret
¶
A sensitive string, such as an Odoo.sh session, that cannot print itself.
repr(), str() and format() return a placeholder, and pickling or copying raises
TypeError. The value leaves only through expose_secret.
Logging in and out¶
odouche.login
¶
login(
*,
ask: Callable[[], Secret] | None = None,
notify: Callable[[LoginStep], None] = lambda _: None,
timeout: float = 300,
) -> None
Log in to Odoo.sh and store the session in the keyring, replacing the stored one.
The user signs in with GitHub in a browser launched for the login, with a profile that is
deleted when it ends. Where no browser can be launched, ask is called for the session_id
cookie of www.odoo.sh: prompt for it without echo and return it wrapped in a Secret.
notify is called with each LoginStep. The function itself neither prints nor prompts.
The session is stored once Odoo.sh has answered one request sent with it. Raises
LoginTimeoutError when the sign-in has been waited for timeout seconds,
LoginError when no session is obtained or Odoo.sh refuses the one pasted, and
KeyringUnavailableError, before anything is asked of the user, when there is nowhere to
store one or the keyring has not been unlocked within timeout seconds.
odouche.LoginStep
¶
Bases: Enum
What a login is waiting for, for a frontend to say in its own words.
KEYRING
class-attribute
instance-attribute
¶
The keyring is being checked, and may be showing a dialog to be unlocked.
BROWSER
class-attribute
instance-attribute
¶
A browser window is open on the Odoo.sh login, for the user to sign in with GitHub.
PASTE
class-attribute
instance-attribute
¶
No browser can be launched here: the session_id cookie is about to be asked for.
odouche.logout
¶
logout(
session: Secret | None = None,
*,
invalidate_given: bool = False,
) -> LogoutResult
Log out of Odoo.sh: end the stored session there, and delete it from the keyring.
The stored session is deleted even when Odoo.sh cannot be asked to end it. The result's
failure then says why, and a copy of the session works until Odoo.sh expires it. With no
session nothing is raised. A stored one past its max age, or that cannot be read, is deleted
and not ended.
A session passed or set in the environment is not the library's to delete: the result names
its source, and unsetting it is left to the caller. It is ended on Odoo.sh only with
invalidate_given, since others may be using it. The stored session is then left as it is.
Raises NoSessionError when the session passed or set in the environment is not a cookie
value, and KeyringUnavailableError when the keyring cannot be read or the session not
deleted. When it is not deleted, the message says whether Odoo.sh ended it.
odouche.LogoutResult
dataclass
¶
LogoutResult(
source: SessionSource | None,
deleted: bool,
invalidated: bool,
failure: OdoucheError | None,
)
What a logout did.
source
instance-attribute
¶
source: SessionSource | None
Where the session came from, or None when there was none to log out of.
deleted
instance-attribute
¶
Whether the stored session was deleted. One passed or set in the environment never is.
invalidated
instance-attribute
¶
Whether Odoo.sh has ended the session, so that a copy of it no longer works.
failure
instance-attribute
¶
failure: OdoucheError | None
Why Odoo.sh could not be asked to end the session, or None.
Session¶
odouche.Identity
dataclass
¶
Identity(
user_id: int,
name: str | None,
username: str,
email: str | None,
session: SessionInfo,
)
The user a session belongs to, as Odoo.sh reports them.
email
instance-attribute
¶
The user's email address, when Odoo.sh gives one. It is personal data, carried as given.
odouche.SessionInfo
dataclass
¶
SessionInfo(
source: SessionSource,
stored_at: datetime | None,
expires_at: datetime | None,
)
What is known of a session without asking Odoo.sh. It never holds the session.
odouche.SessionSource
¶
Bases: StrEnum
Where a session came from.
odouche.SESSION_ENV
module-attribute
¶
The environment variable a session is read from. It wins over the keyring and is never stored.
odouche.KEYRING_SERVICE
module-attribute
¶
The service the session is stored under in the OS keyring.
odouche.KEYRING_ENTRY
module-attribute
¶
The name of the keyring entry, which holds the session and the time it was stored.
Projects, branches and builds¶
odouche.Project
dataclass
¶
An Odoo.sh project the session's user can reach.
repository
instance-attribute
¶
The GitHub repository the project builds, as owner/name.
odouche.Branch
dataclass
¶
Branch(id: int, name: str, stage: Stage, stage_name: str)
A branch of an Odoo.sh project.
odouche.Stage
¶
Bases: StrEnum
The stage a branch sits in on Odoo.sh.
UNKNOWN
class-attribute
instance-attribute
¶
A stage the library does not know. The branch's stage_name holds what Odoo.sh calls it.
odouche.Build
dataclass
¶
Build(
id: int,
name: str,
branch_id: int,
branch_name: str,
commit: Commit,
status: BuildStatus,
status_name: str,
result: BuildResult | None,
result_name: str | None,
status_info: str | None,
started_at: datetime | None,
url: str | None,
)
What Odoo.sh made of a commit on a branch.
name
instance-attribute
¶
The build's name on Odoo.sh, which is not derivable from its branch.
result
instance-attribute
¶
result: BuildResult | None
How the build ended, or None when Odoo.sh gives none. finished says whether it ended.
result_name
instance-attribute
¶
What Odoo.sh calls that result, such as success.
status_info
instance-attribute
¶
What the build is doing, in Odoo.sh's own words, such as Installing: account.
started_at
instance-attribute
¶
When a worker took the build, in UTC, or None while it waits for one.
finished
property
¶
Whether the build has ended, whatever its result.
DONE and DROPPED are the ended statuses Odoo.sh has been seen to give. SKIPPED and
KILLED are counted as ended from their names alone. An unknown status is not finished.
odouche.BuildStatus
¶
Bases: StrEnum
Where a build is in its life on Odoo.sh. How it ended is its BuildResult.
odouche.BuildResult
¶
Bases: StrEnum
How a build ended.
UNKNOWN
class-attribute
instance-attribute
¶
A result the library does not know. The build's result_name holds what Odoo.sh calls it.
odouche.SshTarget
dataclass
¶
odouche.Commit
dataclass
¶
The commit a build was made from, as Odoo.sh reports it.
author
instance-attribute
¶
The author's name. It is another person's personal data, carried as Odoo.sh gives it.
Logs¶
odouche.Log
dataclass
¶
Log(
kind: LogKind,
name: str,
modified_at: datetime,
size: str,
)
One of the logs a build has.
odouche.LogKind
¶
Bases: StrEnum
The logs Odoo.sh keeps of a build. A build has only some of them.
UNKNOWN
class-attribute
instance-attribute
¶
A log the library does not know. The log's name holds what Odoo.sh calls it.
odouche.LogLine
dataclass
¶
A line of a build's log. It is untrusted: whatever a process printed, unchanged.
Errors¶
odouche.OdoucheError
¶
Bases: Exception
Base class of every error the library raises.
odouche.NoSessionError
¶
Bases: OdoucheError
Raised when there is no session: none was passed, set in the environment or stored.
One that is not a session_id cookie value is none.
The user has to log in.
odouche.SessionExpiredError
¶
Bases: OdoucheError
Raised when Odoo.sh rejects the session, or when it has passed the client-side max age.
The stored session is gone and the user has to log in again.
odouche.NotFoundError
¶
Bases: OdoucheError
Raised when the project, branch, build or log asked for is not one the session's user can reach.
odouche.PermissionDeniedError
¶
odouche.UpstreamChangedError
¶
Bases: OdoucheError
Raised when an answer from Odoo.sh no longer has the shape the library reads.
Odoo.sh has no public API, so this is the expected way for the library to break. It is not a mistake in the caller's input.
odouche.UpstreamUnavailableError
¶
odouche.ReadOnlyError
¶
Bases: OdoucheError
Raised when a read-only client is asked to change state on Odoo.sh. Nothing was sent.
odouche.StageRefusedError
¶
Bases: OdoucheError
Raised when a branch is in a stage the library does not change. Nothing was changed.
odouche.OutcomeUnknownError
¶
Bases: OdoucheError
Raised when a state-changing request was sent and what Odoo.sh did with it is not known.
Look at Odoo.sh before trying again: the request is never repeated, since it may have been carried out.
odouche.StreamTimeoutError
¶
Bases: OdoucheError
Raised when a stream is still open at its timeout. Nothing says Odoo.sh is unavailable.
odouche.KeyringUnavailableError
¶
KeyringUnavailableError(
message: str = _NO_KEYRING,
*,
operation: str | None = None,
status: int | None = None,
)
Bases: OdoucheError
Raised when no accepted keyring backend is available to store the session, or it stays locked.
Nothing was persisted, unless the message says a write did not finish. The message names the ways out.
odouche.LoginError
¶
Bases: OdoucheError
Raised when a login ends without a session: none could be captured, or Odoo.sh refused it.
Nothing was stored, and the session stored before the login is untouched.
odouche.LoginTimeoutError
¶
Bases: OdoucheError
Raised when nobody completes the browser login before its timeout.
Nothing was stored, and the session stored before the login is untouched.
Version¶
odouche.__version__
module-attribute
¶
The version of the installed odouche distribution.