Skip to content

Commit

Permalink
compose: New module for easy access to compose metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Mach committed Dec 11, 2015
1 parent d533611 commit f235216
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
15 changes: 15 additions & 0 deletions doc/compose.rst
@@ -0,0 +1,15 @@
==========================================
compose -- Easy access to compose metadata
==========================================

.. automodule:: productmd.compose




Classes
=======

.. autoclass:: productmd.compose.Compose
:members:
:inherited-members:
2 changes: 2 additions & 0 deletions doc/conf.py
Expand Up @@ -217,6 +217,8 @@
[u'Daniel Mach <dmach@redhat.com>'], 7),

# modules
('compose', 'compose', u'productmd Documentation',
[u'Daniel Mach <dmach@redhat.com>'], 1),
('composeinfo', 'composeinfo', u'productmd Documentation',
[u'Daniel Mach <dmach@redhat.com>'], 1),
('discinfo', 'discinfo', u'productmd Documentation',
Expand Down
1 change: 1 addition & 0 deletions doc/index.rst
Expand Up @@ -18,6 +18,7 @@ Python modules:
:maxdepth: 2

common
compose
composeinfo
discinfo
images
Expand Down
116 changes: 116 additions & 0 deletions productmd/compose.py
@@ -0,0 +1,116 @@
# -*- coding: utf-8 -*-


# Copyright (C) 2015 Red Hat, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA


"""
This module provides Compose class that provides easy access
to ComposeInfo, Rpms and Images in compose metadata.
Example::
import productmd.compose
compose = productmd.compose.Compose("/path/to/compose")
# then you can access compose metadata via following properties:
compose.info
compose.images
compose.rpms
"""


import os

import productmd.composeinfo
import productmd.images
import productmd.rpms


__all__ = (
"Compose",
)


class Compose(object):
"""
This class provides easy access to compose metadata.
"""

def __init__(self, compose_path):
self.compose_path = compose_path
compose_path = os.path.join(compose_path, "compose")
if os.path.isdir(compose_path):
self.compose_path = compose_path

self._composeinfo = None
self._images = None
self._rpms = None

def _find_metadata_file(self, paths):
for i in paths:
path = os.path.join(self.compose_path, i)
if os.path.exists(path):
return path
return None

@property
def info(self):
"""(:class:`productmd.composeinfo.ComposeInfo`) -- Compose metadata"""
if self._composeinfo is not None:
return self._composeinfo

composeinfo = productmd.composeinfo.ComposeInfo()
paths = [
"metadata/composeinfo.json",
]
path = self._find_metadata_file(paths)
composeinfo.load(path)
self._composeinfo = composeinfo
return self._composeinfo

@property
def images(self):
"""(:class:`productmd.images.Images`) -- Compose images metadata"""
if self._images is not None:
return self._images

images = productmd.images.Images()
paths = [
"metadata/images.json",
"metadata/image-manifest.json",
]
path = self._find_metadata_file(paths)
images.load(path)
self._images = images
return self._images

@property
def rpms(self):
"""(:class:`productmd.rpms.Rpms`) -- Compose RPMs metadata"""
if self._rpms is not None:
return self._rpms

rpms = productmd.rpms.Rpms()
paths = [
"metadata/rpms.json",
"metadata/rpm-manifest.json",
]
path = self._find_metadata_file(paths)
rpms.load(path)
self._rpms = rpms
return self._rpms

0 comments on commit f235216

Please sign in to comment.