Unfortunately, using the "bdist_rpm" target for setup.py isn't really expressive enough to generate all of the things we might need to do with the spec file for imagefactory. As one example, we might need to add additional dependencies to the spec beyond the ones that bdist_rpm detected. It would also be nice to have a package description and a changelog.
To fix all of that, maintain our own spec at the top of the repository hierarchy. That way we have full control over it.
Signed-off-by: Chris Lalancette clalance@redhat.com --- imagefactory.spec.in | 45 +++++++++++++++++++++++++++++++++++++++++++++ setup.py | 14 +++++++++++++- 2 files changed, 58 insertions(+), 1 deletions(-) create mode 100644 imagefactory.spec.in
diff --git a/imagefactory.spec.in b/imagefactory.spec.in new file mode 100644 index 0000000..f929183 --- /dev/null +++ b/imagefactory.spec.in @@ -0,0 +1,45 @@ +Summary: Image Factory system image generation tool +Name: imagefactory +Version: @VERSION@ +Release: 1%{?dist} +Source0: %{name}-%{version}.tar.gz +License: GPLv2 +Group: Development/Libraries +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot +Url: http://www.aeolusproject.org/imagefactory.html +BuildArch: noarch +Requires: oz +Requires: euca2ools +Requires: python-qmf +Requires: python-pycurl +Requires: python-libguestfs +Requires: python-zope-interface +Requires: python-boto +Requires: libxml2-python +Requires: python-httplib2 +Requires: python-argparse +BuildRequires: python + +%description +imagefactory is a daemon that listens for build requests via QMF. When +a build request is received, imagefactory will build the requested image +for the requested target. + +%prep +%setup -n %{name}-%{version} + +%build +python setup.py build + +%install +python setup.py install -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES + +%clean +rm -rf $RPM_BUILD_ROOT + +%files -f INSTALLED_FILES +%defattr(-,root,root) + +%changelog +* Mon Apr 04 2011 Chris Lalancette clalance@redhat.com - 0.1.6-1 +- Initial spec file. diff --git a/setup.py b/setup.py index 9e68f48..a6fcdb7 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ from distutils.core import setup, Extension +from distutils.command.sdist import sdist as _sdist import os import os.path import subprocess @@ -6,7 +7,7 @@ import subprocess version_file_name = "version.txt" try: if(not os.path.exists(version_file_name)): - subprocess.call('/usr/bin/git describe > %s' % (version_file_name, ), shell=True) + subprocess.call('/usr/bin/git describe | tr - _ > %s' % (version_file_name, ), shell=True) version_file = open(version_file_name, "r") VERSION = version_file.read()[0:-1] version_file.close() @@ -15,6 +16,16 @@ except Exception, e:
datafiles=[('/etc', ['imagefactory.conf']), ('/etc/pki/imagefactory', ['cert-ec2.pem']), ('/etc/rc.d/init.d', ['imagefactory/scripts/imagefactory']), ('', ['version.txt'])]
+class sdist(_sdist): + """ custom sdist command to prepare imagefactory.spec file """ + + def run(self): + cmd = (""" sed -e "s/@VERSION@/%s/g" < imagefactory.spec.in """ % + VERSION) + " > imagefactory.spec" + os.system(cmd) + + _sdist.run(self) + setup(name='imagefactory', version=VERSION, description='Image Factory system image generation tool', @@ -25,4 +36,5 @@ setup(name='imagefactory', packages=['imagefactory', 'imagefactory.builders', 'imagefactory.qmfagent'], scripts=['imgfac.py'], data_files = datafiles, + cmdclass = {'sdist': sdist} )