Skip to content

Commit

Permalink
Merge pull request #19 from jortel/part-doux
Browse files Browse the repository at this point in the history
Each unit is a branch head; Publish using pull-local.
  • Loading branch information
jortel committed Mar 2, 2015
2 parents db9b56f + d8e5349 commit b97d943
Show file tree
Hide file tree
Showing 12 changed files with 554 additions and 784 deletions.
4 changes: 1 addition & 3 deletions common/pulp_ostree/common/constants.py
Expand Up @@ -33,7 +33,5 @@
IMPORT_STEP_ADD_UNITS = 'import_add_unit'

PUBLISH_STEP_WEB_PUBLISHER = 'ostree_publish_step_web'
PUBLISH_STEP_EMPTY = 'ostree_publish_empty'
PUBLISH_STEP_CONTENT = 'ostree_publish_content'
PUBLISH_STEP_METADATA = 'ostree_publish_metadata'
PUBLISH_STEP_MAIN = 'ostree_publish_main'
PUBLISH_STEP_OVER_HTTP = 'ostree_publish_over_http'
253 changes: 58 additions & 195 deletions common/pulp_ostree/common/model.py
@@ -1,16 +1,7 @@
"""
The content model:
{ remote_id: <id>
digest: <hex-digest>
timestamp: <timestamp>
refs: {
heads [
path: <path>, commit_id: <commit>,
path: <path>, commit_id: <commit>,
]
}
}
{ remote_id: <id>, branch: <path>, commit: <commit>}
"""

import os
Expand All @@ -34,102 +25,55 @@ def generate_remote_id(url):
return h.hexdigest()


class Head(object):
class Commit(object):
"""
Branch (tree) head.
:cvar PATH: The path dictionary key.
:type PATH: str
:cvar COMMIT_ID: The commit_id dictionary key.
:type COMMIT_ID: str
Commit object.
:ivar path: The branch head file path.
:type path: str
:ivar commit_id: The unique identifier for the commit
object that is the branch head.
:ivar digest: The commit (hash) digest.
:type digest: str
:ivar metadata: The commit metadata.
:type metadata: dict
"""

PATH = 'path'
COMMIT_ID = 'commit_id'

@staticmethod
def from_dict(d):
"""
Construct using a dictionary representation.
:param d: A dictionary representation.
:type d: dict
"""
return Head(d[Head.PATH], d[Head.COMMIT_ID])

def __init__(self, path, commit_id):
"""
:param path: The branch path.
:type path: str
:param commit_id: The commit ID (digest).
:type commit_id: str
"""
self.path = path
self.commit_id = commit_id

@property
def digest(self):
"""
Get the content-based digest.
:return: The content-based digest.
:rtype: str
def __init__(self, digest, metadata):
"""
h = sha256()
h.update(self.path)
h.update(self.commit_id)
return h.hexdigest()

def to_dict(self):
"""
Get a dictionary representation.
:return: A dictionary representation.
:rtype: dict
:param digest: The commit (hash) digest.
:type digest: str
:param metadata: The commit metadata.
:type metadata: dict
"""
return {
Head.PATH: self.path,
Head.COMMIT_ID: self.commit_id
}
self.digest = digest
self.metadata = metadata


class Refs(object):
class Head(object):
"""
Repository *refs/* content. Currently this only contains
the branch heads but will likely contain tags when they are
supported by ostree.
:cvar HEADS: The heads dictionary key.
:type HEADS: str
Tree reference.
:ivar heads: The list of branch head objects.
:type heads: list
:ivar remote_id: Uniquely identifies an OSTree remote.
:type remote_id: str
:ivar branch: The branch head file path.
:type branch: str
:ivar commit: The branch head commit.
:type commit: Commit
"""

HEADS = 'heads'

@staticmethod
def from_dict(d):
"""
Construct using a dictionary representation.
:param d: A dictionary representation.
:type d: dict
"""
heads = [Head.from_dict(h) for h in d[Refs.HEADS]]
return Refs(heads)
REMOTE_ID = 'remote_id'
BRANCH = 'branch'
COMMIT = 'commit'

def __init__(self, heads=None):
def __init__(self, remote_id, branch, commit):
"""
:param heads: collection of heads.
:type heads: iterable
:param remote_id: Uniquely identifies a *remote* OSTree repository.
:type remote_id: str
:param branch: The branch path.
:type branch: str
:param commit: A commit.
:type commit: Commit
"""
self.heads = heads or []
self.remote_id = remote_id
self.branch = branch
self.commit = commit

@property
def digest(self):
Expand All @@ -140,132 +84,51 @@ def digest(self):
:rtype: str
"""
h = sha256()
for head in sorted(self.heads, key=lambda obj: obj.path):
h.update(head.digest)
h.update(self.remote_id)
h.update(self.branch)
h.update(self.commit.digest)
return h.hexdigest()

def add_head(self, head):
"""
Add the specified head.
:param head: The head to add.
:type head: Head
"""
self.heads.append(head)

def to_dict(self):
@property
def storage_path(self):
"""
Get a dictionary representation.
:return: A dictionary representation.
:rtype: dict
:return: The unit storage path.
:rtype: str
"""
return {
Refs.HEADS: [h.to_dict() for h in self.heads]
}
return os.path.join(constants.SHARED_STORAGE,
self.remote_id,
constants.LINKS_DIR,
self.digest)


class Repository(object):
class Unit(Head):
"""
An ostree repository content unit.
:cvar TYPE_ID: The content type ID.
:type TYPE_ID: str
:cvar REMOTE_ID: The remote_id dictionary key.
:type REMOTE_ID: str
:cvar TIMESTAMP: The timestamp dictionary key.
:type TIMESTAMP: str
:cvar DIGEST: The digest dictionary key.
:type DIGEST: str
:cvar REFS: The refs dictionary key.
:type REFS: str
:ivar remote_id: The unique identifier for the remote ostree repository.
This is likely to be the sha256 digest of the remote URL until
something is supported by ostree.
:type remote_id: str
:ivar timestamp: The UTC timestamp of when the repository snapshot
was taken.
:type timestamp: datetime.datetime
:ivar refs: The repository references.
:type refs: Refs
Stored content unit.
"""

TYPE_ID = constants.OSTREE_TYPE_ID

REMOTE_ID = 'remote_id'
TIMESTAMP = 'timestamp'
DIGEST = 'digest'
REFS = 'refs'

@staticmethod
def from_dict(d):
"""
Construct using a dictionary representation.
:param d: A dictionary representation.
:type d: dict
"""
return Repository(
d[Repository.REMOTE_ID],
Refs.from_dict(d[Repository.REFS]),
d[Repository.TIMESTAMP])

def __init__(self, remote_id, refs, timestamp):
"""
:param remote_id: The unique identifier for the remote.
:type remote_id: str
:param timestamp: The unit timestamp in UTC.
:type timestamp: datetime.datetime
:param refs: The repository references.
:type refs: Refs
"""
self.remote_id = remote_id
self.timestamp = timestamp
self.refs = refs
COMMIT = 'commit'

@property
def digest(self):
def key(self):
"""
Get the content-based digest.
:return: The content-based digest.
:rtype: str
"""
return self.refs.digest

@property
def unit_key(self):
"""
Get the unit key.
Unit Key.
:return: The unit key.
:rtype: dict
"""
return {
Repository.REMOTE_ID: self.remote_id,
Repository.DIGEST: self.digest
Head.REMOTE_ID: self.remote_id,
Head.BRANCH: self.branch,
Head.COMMIT: self.commit.digest
}

@property
def metadata(self):
"""
Get the unit metadata
:return: The unit metadata
:rtype dict
"""
return {
Repository.TIMESTAMP: self.timestamp,
Repository.REFS: self.refs.to_dict()
}
Unit Metadata.
@property
def storage_path(self):
"""
:return: The unit storage path.
:rtype: str
:return: The commit metadata.
:rtype: dict
"""
return os.path.join(constants.SHARED_STORAGE,
self.remote_id,
constants.LINKS_DIR,
self.digest)
return self.commit.metadata

0 comments on commit b97d943

Please sign in to comment.