api Package

api Package

pylorax.api.crossdomain(origin, methods=None, headers=None, max_age=21600, attach_to_all=True, automatic_options=True)

config Module

class pylorax.api.config.ComposerConfig(defaults=None, dict_type=<class 'collections.OrderedDict'>, allow_no_value=False)[source]

Bases: ConfigParser.SafeConfigParser

get_default(section, option, default)[source]
pylorax.api.config.configure(conf_file='/etc/lorax/composer.conf', root_dir='/', test_config=False)[source]

lorax-composer configuration

Parameters:
  • conf_file (str) – Path to the config file overriding the default settings
  • root_dir (str) – Directory to prepend to paths, defaults to /
  • test_config (bool) – Set to True to skip reading conf_file

crossdomain Module

pylorax.api.crossdomain.crossdomain(origin, methods=None, headers=None, max_age=21600, attach_to_all=True, automatic_options=True)[source]

projects Module

exception pylorax.api.projects.ProjectsError[source]

Bases: exceptions.Exception

pylorax.api.projects.api_changelog(changelog)[source]

Convert the changelog to a string

Parameters:changelog (tuple) – A list of time, author, string tuples.
Returns:The most recent changelog text or “”
Return type:str

This returns only the most recent changelog entry.

pylorax.api.projects.api_time(t)[source]

Convert time since epoch to a string

Parameters:t (int) – Seconds since epoch
Returns:Time string
Return type:str
pylorax.api.projects.dep_evra(dep)[source]

Return the epoch:version-release.arch for the dep

Parameters:dep (dict) – dependency dict
Returns:epoch:version-release.arch
Return type:str
pylorax.api.projects.modules_info(yb, module_names)[source]

Return details about a module, including dependencies

Parameters:
  • yb (YumBase) – yum base object
  • module_names (str) – Names of the modules to get info about
Returns:

List of dicts with module details and dependencies.

Return type:

list of dicts

pylorax.api.projects.modules_list(yb, module_names)[source]

Return a list of modules

Parameters:
  • yb (YumBase) – yum base object
  • offset – Number of modules to skip
  • limit (int) – Maximum number of modules to return
Returns:

List of module information and total count

Return type:

tuple of a list of dicts and an Int

Modules don’t exist in RHEL7 so this only returns projects and sets the type to “rpm”

pylorax.api.projects.projects_depsolve(yb, project_names)[source]

Return the dependencies for a list of projects

Parameters:
  • yb (YumBase) – yum base object
  • project_names (List of Strings) – The projects to find the dependencies for
Returns:

NEVRA’s of the project and its dependencies

Return type:

list of dicts

pylorax.api.projects.projects_info(yb, project_names)[source]

Return details about specific projects

Parameters:
  • yb (YumBase) – yum base object
  • project_names (str) – List of names of projects to get info about
Returns:

List of project info dicts with yaps_to_project as well as epoch, version, release, etc.

Return type:

list of dicts

pylorax.api.projects.projects_list(yb)[source]

Return a list of projects

Parameters:yb (YumBase) – yum base object
Returns:List of project info dicts with name, summary, description, homepage, upstream_vcs
Return type:list of dicts
pylorax.api.projects.tm_to_dep(tm)[source]

Extract the info from a TransactionMember object

Parameters:tm (TransactionMember) – A Yum transaction object
Returns:A dict with name, epoch, version, release, arch
Return type:dict
pylorax.api.projects.yaps_to_module(yaps)[source]

Extract the name from a YumAvailablePackageSqlite object

Parameters:yaps (YumAvailablePackageSqlite) – Yum object with package details
Returns:A dict with name, and group_type
Return type:dict

group_type is hard-coded to “rpm”

pylorax.api.projects.yaps_to_project(yaps)[source]

Extract the details from a YumAvailablePackageSqlite object

Parameters:yaps (YumAvailablePackageSqlite) – Yum object with package details
Returns:A dict with the name, summary, description, and url.
Return type:dict

upstream_vcs is hard-coded to UPSTREAM_VCS

pylorax.api.projects.yaps_to_project_info(yaps)[source]

Extract the details from a YumAvailablePackageSqlite object

Parameters:yaps (YumAvailablePackageSqlite) – Yum object with package details
Returns:A dict with the project details, as well as epoch, release, arch, build_time, changelog, ...
Return type:dict

metadata entries are hard-coded to {}

recipes Module

class pylorax.api.recipes.CommitDetails(commit, timestamp, message, revision=None)[source]

Bases: pylorax.base.DataHolder

exception pylorax.api.recipes.CommitTimeValError[source]

Bases: exceptions.Exception

class pylorax.api.recipes.Recipe(name, description, version, modules, packages)[source]

Bases: dict

A Recipe of package and modules

This is a subclass of dict that enforces the constructor arguments and adds a .filename property to return the recipe’s filename, and a .toml() function to return the recipe as a TOML string.

bump_version(old_version=None)[source]

semver recipe version number bump

Parameters:old_version (str) – An optional old version number
Returns:The new version number or None
Return type:str
Raises :ValueError

If neither have a version, 0.0.1 is returned If there is no old version the new version is checked and returned If there is no new version, but there is a old one, bump its patch level If the old and new versions are the same, bump the patch level If they are different, check and return the new version

filename[source]

Return the Recipe’s filename

Replaces spaces in the name with ‘-‘ and appends .toml

toml()[source]

Return the Recipe in TOML format

exception pylorax.api.recipes.RecipeError[source]

Bases: exceptions.Exception

exception pylorax.api.recipes.RecipeFileError[source]

Bases: exceptions.Exception

class pylorax.api.recipes.RecipeModule(name, version)[source]

Bases: dict

class pylorax.api.recipes.RecipePackage(name, version)[source]

Bases: pylorax.api.recipes.RecipeModule

pylorax.api.recipes.commit_recipe(repo, branch, recipe)[source]

Commit a recipe to a branch

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
  • recipe (Recipe) – Recipe to commit
Returns:

OId of the new commit

Return type:

Git.OId

Raises :

Can raise errors from Ggit

pylorax.api.recipes.commit_recipe_directory(repo, branch, directory)[source]

Commit all *.toml files from a directory, if they aren’t already in git.

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
  • directory (str) – The directory of *.toml recipes to commit
Returns:

None

Raises :

Can raise errors from Ggit or RecipeFileError

Files with Toml or RecipeFileErrors will be skipped, and the remainder will be tried.

pylorax.api.recipes.commit_recipe_file(repo, branch, filename)[source]

Commit a recipe file to a branch

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
  • filename (str) – Path to the recipe file to commit
Returns:

OId of the new commit

Return type:

Git.OId

Raises :

Can raise errors from Ggit or RecipeFileError

pylorax.api.recipes.delete_file(repo, branch, filename)[source]

Delete a file from a branch.

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
  • filename (str) – filename to delete
Returns:

OId of the new commit

Return type:

Git.OId

Raises :

Can raise errors from Ggit

pylorax.api.recipes.delete_recipe(repo, branch, recipe_name)[source]

Delete a recipe from a branch.

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
  • recipe_name (str) – Recipe name to delete
Returns:

OId of the new commit

Return type:

Git.OId

Raises :

Can raise errors from Ggit

pylorax.api.recipes.diff_items(title, old_items, new_items)[source]

Return the differences between two lists of dicts.

Parameters:
  • title (str) – Title of the entry
  • old_items (list(dict)) – List of item dicts with “name” field
  • new_items (list(dict)) – List of item dicts with “name” field
Returns:

List of diff dicts with old/new entries

Return type:

list(dict)

pylorax.api.recipes.find_commit_tag(repo, branch, filename, commit_id)[source]

Find the tag that matches the commit_id

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
  • filename (str) – filename to revert
  • commit_id (Git.OId) – The commit id to check
Returns:

The tag or None if there isn’t one

Return type:

str or None

There should be only 1 tag pointing to a commit, but there may not be a tag at all.

The tag will look like: ‘refs/tags/<branch>/<filename>/r<revision>’

pylorax.api.recipes.find_name(name, lst)[source]

Find the dict matching the name in a list and return it.

Parameters:
  • name (str) – Name to search for
  • lst – List of dict’s with “name” field
Returns:

First dict with matching name, or None

Return type:

dict or None

pylorax.api.recipes.get_commit_details(commit, revision=None)[source]

Return the details about a specific commit.

Parameters:
  • commit (Git.Commit) – The commit to get details from
  • revision (int) – Optional commit revision
Returns:

Details about the commit

Return type:

CommitDetails

Raises :

CommitTimeValError or Ggit exceptions

pylorax.api.recipes.get_revision_from_tag(tag)[source]

Return the revision number from a tag

Parameters:tag (str) – The tag to exract the revision from
Returns:The integer revision or None
Return type:int or None

The revision is the part after the r in ‘branch/filename/rXXX’

pylorax.api.recipes.gfile(path)[source]

Convert a string path to GFile for use with Git

pylorax.api.recipes.head_commit(repo, branch)[source]

Get the branch’s HEAD Commit Object

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
Returns:

Branch’s head commit

Return type:

Git.Commit

Raises :

Can raise errors from Ggit

pylorax.api.recipes.is_commit_tag(repo, commit_id, tag)[source]

Check to see if a tag points to a specific commit.

Parameters:
  • repo (Git.Repository) – Open repository
  • commit_id (Git.OId) – The commit id to check
  • tag (str) – The tag to check
Returns:

True if the tag points to the commit, False otherwise

Return type:

bool

pylorax.api.recipes.is_parent_diff(repo, filename, tree, parent)[source]

Check to see if the commit is different from its parents

Parameters:
  • repo (Git.Repository) – Open repository
  • filename (str) – filename to revert
  • tree (Git.Tree) – The commit’s tree
  • parent (Git.Commit) – The commit’s parent commit
Retuns :

True if filename in the commit is different from its parents

Return type:

bool

pylorax.api.recipes.list_branch_files(repo, branch)[source]

Return a sorted list of the files on the branch HEAD

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
Returns:

A sorted list of the filenames

Return type:

list(str)

Raises :

Can raise errors from Ggit

pylorax.api.recipes.list_commit_files(repo, commit)[source]

Return a sorted list of the files on a commit

Parameters:
  • repo (Git.Repository) – Open repository
  • commit (str) – The commit hash to list
Returns:

A sorted list of the filenames

Return type:

list(str)

Raises :

Can raise errors from Ggit

pylorax.api.recipes.list_commits(repo, branch, filename)[source]

List the commit history of a file on a branch.

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
  • filename (str) – filename to revert
Returns:

A list of commit details

Return type:

list(CommitDetails)

Raises :

Can raise errors from Ggit

pylorax.api.recipes.open_or_create_repo(path)[source]

Open an existing repo, or create a new one

Parameters:path (string) – path to recipe directory
Returns:A repository object
Return type:Git.Repository
Raises :Can raise errors from Ggit

A bare git repo will be created in the git directory of the specified path. If a repo already exists it will be opened and returned instead of creating a new one.

pylorax.api.recipes.prepare_commit(repo, branch, builder)[source]

Prepare for a commit

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
  • builder (TreeBuilder) – instance of TreeBuilder
Returns:

(Tree, Sig, Ref)

Return type:

tuple

Raises :

Can raise errors from Ggit

pylorax.api.recipes.read_commit(repo, branch, filename, commit=None)[source]

Return the contents of a file on a specific branch or commit.

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
  • filename (str) – filename to read
  • commit (str) – Optional commit hash
Returns:

Contents of the commit

Return type:

str

Raises :

Can raise errors from Ggit

If no commit is passed the master:filename is returned, otherwise it will be commit:filename

pylorax.api.recipes.read_commit_spec(repo, spec)[source]

Return the raw content of the blob specified by the spec

Parameters:
  • repo (Git.Repository) – Open repository
  • spec (str) – Git revparse spec
Returns:

Contents of the commit

Return type:

str

Raises :

Can raise errors from Ggit

eg. To read the README file from master the spec is “master:README”

pylorax.api.recipes.read_recipe_commit(repo, branch, recipe_name, commit=None)[source]

Read a recipe commit from git and return a Recipe object

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
  • recipe_name (str) – Recipe name to read
  • commit (str) – Optional commit hash
Returns:

A Recipe object

Return type:

Recipe

Raises :

Can raise errors from Ggit

If no commit is passed the master:filename is returned, otherwise it will be commit:filename

pylorax.api.recipes.recipe_diff(old_recipe, new_recipe)[source]

Diff two versions of a recipe

Parameters:
  • old_recipe (Recipe) – The old version of the recipe
  • new_recipe (Recipe) – The new version of the recipe
Returns:

A list of diff dict entries with old/new

Return type:

list(dict)

pylorax.api.recipes.recipe_filename(name)[source]

Return the toml filename for a recipe

Replaces spaces with ‘-‘ and appends ‘.toml’

pylorax.api.recipes.recipe_from_dict(recipe_dict)[source]

Create a Recipe object from a plain dict.

Parameters:recipe_dict (dict) – A plain dict of the recipe
Returns:A Recipe object
Return type:Recipe
Raises :RecipeError
pylorax.api.recipes.recipe_from_toml(recipe_str)[source]

Create a Recipe object from a toml string.

Parameters:recipe_str (str) – The Recipe TOML string
Returns:A Recipe object
Return type:Recipe
Raises :TomlError
pylorax.api.recipes.revert_file(repo, branch, filename, commit)[source]

Revert the contents of a file to that of a previous commit

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
  • filename (str) – filename to revert
  • commit (str) – Commit hash
Returns:

OId of the new commit

Return type:

Git.OId

Raises :

Can raise errors from Ggit

pylorax.api.recipes.revert_recipe(repo, branch, recipe_name, commit)[source]

Revert the contents of a recipe to that of a previous commit

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
  • recipe_name (str) – Recipe name to revert
  • commit (str) – Commit hash
Returns:

OId of the new commit

Return type:

Git.OId

Raises :

Can raise errors from Ggit

pylorax.api.recipes.tag_file_commit(repo, branch, filename)[source]

Tag a file’s most recent commit

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
  • filename (str) – Filename to tag
Returns:

Tag id or None if it failed.

Return type:

Git.OId

Raises :

Can raise errors from Ggit

This uses git tags, of the form refs/tags/<branch>/<filename>/r<revision> Only the most recent recipe commit can be tagged to prevent out of order tagging. Revisions start at 1 and increment for each new commit that is tagged. If the commit has already been tagged it will return false.

pylorax.api.recipes.tag_recipe_commit(repo, branch, recipe_name)[source]

Tag a file’s most recent commit

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
  • recipe_name (str) – Recipe name to tag
Returns:

Tag id or None if it failed.

Return type:

Git.OId

Raises :

Can raise errors from Ggit

Uses tag_file_commit()

pylorax.api.recipes.write_commit(repo, branch, filename, message, content)[source]

Make a new commit to a repository’s branch

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
  • filename (str) – full path of the file to add
  • message (str) – The commit message
  • content (str) – The data to write
Returns:

OId of the new commit

Return type:

Git.OId

Raises :

Can raise errors from Ggit

server Module

class pylorax.api.server.GitLock

Bases: tuple

GitLock(repo, lock, dir)

dir

Alias for field number 2

lock

Alias for field number 1

repo

Alias for field number 0

v0 Module

pylorax.api.v0.take_limits(iterable, offset, limit)[source]
pylorax.api.v0.v0_api(api)[source]

Setup v0 of the API server

workspace Module

pylorax.api.workspace.workspace_delete(repo, branch, recipe_name)[source]

Delete the recipe from the workspace

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
  • recipe_name (str) – The name of the recipe
Returns:

None

Raises :

IO related errors

pylorax.api.workspace.workspace_dir(repo, branch)[source]

Create the workspace’s path from a Repository and branch

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
Returns:

The path to the branch’s workspace directory

Return type:

str

pylorax.api.workspace.workspace_read(repo, branch, recipe_name)[source]

Read a Recipe from the branch’s workspace

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
  • recipe_name (str) – The name of the recipe
Returns:

The workspace copy of the recipe, or None if it doesn’t exist

Return type:

Recipe or None

Raises :

RecipeFileError

pylorax.api.workspace.workspace_write(repo, branch, recipe)[source]

Write a recipe to the workspace

Parameters:
  • repo (Git.Repository) – Open repository
  • branch (str) – Branch name
  • recipe (Recipe) – The recipe to write to the workspace
Returns:

None

Raises :

IO related errors

yumbase Module

pylorax.api.yumbase.get_base_object(conf)[source]

Get the Yum object with settings from the config file

Parameters:conf (ComposerParser) – configuration object
Returns:A Yum base object
Return type:YumBase

Table Of Contents

Previous topic

pylorax Package

This Page