EVOLUTION-MANAGER
Edit File: layouts.py
# Copyright (c) 2015 - Red Hat Inc. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2 of the License, or (at your # option) any later version. See http://www.gnu.org/copyleft/gpl.html for # the full text of the license. """package layout implementation""" import os from .base import BaseLayout from pyrpkg.errors import LayoutError class DistGitLayout(BaseLayout): """ This class represents a dist-git package layout. """ def __init__(self, root_dir=None, sources_file_template='sources'): """ Default class constructor to create a new object instance. """ self.root_dir = root_dir self.sourcedir = root_dir self.specdir = root_dir self.builddir = root_dir self.rpmdir = root_dir self.srcrpmdir = root_dir self.sources_file_template = sources_file_template @classmethod def from_path(cls, path): """ Creates a new object instance from a valid path in the file system. Returns none if path or package structure is invalid. """ super(DistGitLayout, cls).from_path(path) if len([f for f in os.listdir(path) if f.endswith('.spec')]) == 0: raise LayoutError('spec file not found.') sources = 'sources' if os.path.exists('%s/sources' % path) else None return cls(root_dir=path, sources_file_template=sources) class SRPMLayout(BaseLayout): """ This class represents an exposed source RPM package layout. """ def __init__(self, root_dir=None, sources_file_template='.{0.repo_name}.metadata'): """ Default class constructor to create a new object instance. """ self.root_dir = root_dir self.sourcedir = os.path.join(root_dir, 'SOURCES') self.specdir = os.path.join(root_dir, 'SPECS') self.builddir = os.path.join(root_dir, 'BUILD') self.rpmdir = os.path.join(root_dir, 'RPMS') self.srcrpmdir = os.path.join(root_dir, 'SRPMS') self.sources_file_template = sources_file_template @classmethod def from_path(cls, path): """ Creates a new object instance from a valid path in the file system. Returns none if path or package structure is invalid. """ super(SRPMLayout, cls).from_path(path) if not os.path.exists(os.path.join(path, 'SPECS')): raise LayoutError('SPECS dir not found.') if len([f for f in os.listdir(os.path.join(path, 'SPECS')) if f.endswith('.spec')]) == 0: raise LayoutError('spec file not found.') if len([f for f in os.listdir(path) if f.endswith('.metadata')]) == 0: raise LayoutError('metadata file not found.') return cls(root_dir=path)