From 753dde13b080f914dda96ca9b0f419daaf49158c Mon Sep 17 00:00:00 2001
From: Nicolas Dumazet <nicolas.dumazet@nexedi.com>
Date: Wed, 17 Feb 2010 09:03:19 +0000
Subject: [PATCH] Add a way to generate a Mandriva spec given the buildout
 infos

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32667 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 buildout/profiles/mandriva2010.0.cfg          | 14 +++++
 .../createmandrivaspec/createmandrivaspec.py  | 36 +++++++++++++
 buildout/recipes/createmandrivaspec/setup.py  | 27 ++++++++++
 ...rp5-official-buildout-mandriva2010.spec.in | 52 +++++++++++++++++++
 4 files changed, 129 insertions(+)
 create mode 100644 buildout/recipes/createmandrivaspec/createmandrivaspec.py
 create mode 100644 buildout/recipes/createmandrivaspec/setup.py
 create mode 100644 buildout/templates/erp5-official-buildout-mandriva2010.spec.in

diff --git a/buildout/profiles/mandriva2010.0.cfg b/buildout/profiles/mandriva2010.0.cfg
index 812f40f379..c75cc83578 100644
--- a/buildout/profiles/mandriva2010.0.cfg
+++ b/buildout/profiles/mandriva2010.0.cfg
@@ -1,5 +1,6 @@
 [buildout]
 # temporary solution for fast system preparation to run buildout
+develop = recipes/createmandrivaspec
 parts =
 
 [dependency]
@@ -30,3 +31,16 @@ package_list =
 
 command = echo "${:package_list}" | xargs sudo urpmi --auto
 update_command = ${:command}
+
+[erp5-official-buildout]
+recipe = createmandrivaspec
+
+input = ${buildout:directory}/templates/${:base}.in
+output = ${buildout:directory}/${:base}
+name = erp5-official-buildout
+version = ${buildout:directory}/VERSION.txt
+package_list = ${dependency:package_list}
+svnpath = https://svn.erp5.org/repos/public/erp5/trunk/buildout
+
+# only a helper variable
+base = erp5-official-buildout-mandriva2010.spec
diff --git a/buildout/recipes/createmandrivaspec/createmandrivaspec.py b/buildout/recipes/createmandrivaspec/createmandrivaspec.py
new file mode 100644
index 0000000000..dd48f8511a
--- /dev/null
+++ b/buildout/recipes/createmandrivaspec/createmandrivaspec.py
@@ -0,0 +1,36 @@
+import os
+import collective.recipe.template
+
+class Recipe(collective.recipe.template.Recipe):
+  def __init__(self, buildout, name, options):
+    """
+      Create a Mandriva RPM spec file from a template
+
+      - input: path to spec template
+      - output: path where generated spec should be saved
+      - version: rpm version number, can be either the version
+          or a file path containing the version
+      - (section) name: rpm name
+      - build_requires: a list of Mandriva packages required to build the rpm
+      - svnpath: SVN path to current buildout
+
+      optional:
+        - release: rpm release number. Defaults to 1
+    """
+    package_list = options['package_list'].splitlines()
+    package_list = map(lambda x: x.strip(), package_list)
+    dependencies = ["BuildRequires: %s" % pkg for pkg in package_list if pkg]
+
+    version = options['version'].strip()
+    print '"%s"' % version
+    if os.path.exists(version):
+      version = open(version, 'r').read().strip()
+
+    release = options.get('release', str(1))
+
+    options.update(dependencies="\n".join(dependencies),
+                   version=version,
+                   release=release)
+
+    collective.recipe.template.Recipe.__init__(self, buildout, name, options)
+
diff --git a/buildout/recipes/createmandrivaspec/setup.py b/buildout/recipes/createmandrivaspec/setup.py
new file mode 100644
index 0000000000..81208b60e2
--- /dev/null
+++ b/buildout/recipes/createmandrivaspec/setup.py
@@ -0,0 +1,27 @@
+from setuptools import setup, find_packages
+
+name = "createmandrivaspec"
+version = '0.1'
+
+setup(
+    name = name,
+    version = version,
+    author = "Nicolas Dumazet",
+    author_email = "nicolas.dumazet@nexedi.com",
+    description = "ZC Buildout recipe to generate a Mandriva spec file",
+    license = "ZPL 2.1",
+    keywords = "mandriva buildout",
+    packages = find_packages(),
+    scripts = [name+".py",],
+    include_package_data = True,
+    classifiers=[
+      "License :: OSI Approved :: Zope Public License",
+      "Framework :: Buildout",
+      "Operating System :: POSIX :: Linux",
+      ],
+    install_requires = [
+      'collective.recipe.template',
+      ],
+    zip_safe=False,
+    entry_points = {'zc.buildout': ['default = %s:Recipe' % name]},
+    )
diff --git a/buildout/templates/erp5-official-buildout-mandriva2010.spec.in b/buildout/templates/erp5-official-buildout-mandriva2010.spec.in
new file mode 100644
index 0000000000..2bee10b207
--- /dev/null
+++ b/buildout/templates/erp5-official-buildout-mandriva2010.spec.in
@@ -0,0 +1,52 @@
+
+%define version ${:version}
+%define name ${:name}
+%define release ${:release}
+
+# We do not actually use /usr/local/bin/python
+%define _requires_exceptions /usr/local/bin/python
+
+%define fullname %{name}-%{version}
+%define installdir /opt/%{fullname}
+
+Name: %{name}
+Version: %{version}
+Release: %mkrel %{release}
+Summary: Open Source ERP Solution
+URL: http://www.erp5.org
+License: GPL
+Vendor: Nexedi
+Packager: Nicolas Dumazet <nicolas.dumazet@nexedi.com>
+Group: Databases
+
+${:dependencies}
+
+BuildRoot: %{_tmppath}/%{fullname}-%{release}-root
+
+%description
+%{summary}
+
+%prep
+%{__rm} -rf %{installdir}
+%{__mkdir_p} %{installdir}
+
+%build
+cd %{installdir}
+svn co ${:svnpath} .
+python bootstrap/bootstrap.py
+bin/buildout
+
+%install
+%{__rm} -rf %{buildroot}
+%{__mkdir_p} %{buildroot}
+%{__cp} -ar --parents %{installdir} %{buildroot}
+# cleanup .svn files
+find %{buildroot} -name .svn -print0 | xargs -0 %{__rm} -rf
+
+%files
+%defattr(-, root, root, 0755)
+%{installdir}
+
+%clean
+%{__rm} -rf %{buildroot} %{installdir}
+
-- 
2.30.9