Add custom distutils command to take care of aegis manifest when building
authorChristian Ratzenhofer <christian_ratzenhofer@yahoo.de>
Thu, 12 Jan 2012 04:01:41 +0000 (05:01 +0100)
committerChristian Ratzenhofer <christian_ratzenhofer@yahoo.de>
Thu, 12 Jan 2012 14:25:25 +0000 (15:25 +0100)
README
bdist_hdeb.py [new file with mode: 0644]
setup.py

diff --git a/README b/README
index 09d22d2..a661154 100644 (file)
--- a/README
+++ b/README
@@ -10,12 +10,14 @@ Running unit tests:
 $ python -m gotovienna.tests.runner
 
 
-To build the package with aegis tokens (install python-stdeb first):
+To build the package with aegis tokens (install python-stdeb and ar first):
+
+ python setup.py --command-packages=stdeb.command bdist_hdeb --aegis-manifest=gotovienna.aegis
+
+To build the package with aegis token and upload to OBS / use scratchbox:
 
  python setup.py --command-packages=stdeb.command sdist_dsc
  cp gotovienna.aegis deb_dist/gotovienna-*/debian/
  cd deb_dist/gotovienna-*/
  dpkg-buildpackage -rfakeroot -S
 
-Upload the resulting source package to the OBS or build in Scratchbox.
-
diff --git a/bdist_hdeb.py b/bdist_hdeb.py
new file mode 100644 (file)
index 0000000..66c2ae0
--- /dev/null
@@ -0,0 +1,53 @@
+import os
+import stdeb.util as util
+from shutil import copy
+from stdeb.command.sdist_dsc import sdist_dsc
+
+from distutils.core import Command
+
+__all__ = ['bdist_hdeb']
+
+class bdist_hdeb(Command):
+    description = 'distutils command to create debian harmattan binary package'
+
+    user_options = [ ("aegis-manifest=", None, 'aegis manifest to use') ]
+    boolean_options = []
+
+    def initialize_options (self):
+        self.aegis_manifest = None
+
+    def finalize_options (self):
+        pass
+
+    def run(self):
+        
+        # generate .dsc source pkg
+        self.run_command('sdist_dsc')
+
+        # execute system command and read output (execute and read output of find cmd)
+        dsc_tree = 'deb_dist'
+        target_dir = None
+        for entry in os.listdir(dsc_tree):
+            fulldir = os.path.join(dsc_tree,entry)
+            if os.path.isdir(fulldir):
+                if target_dir is not None:
+                    raise ValueError('more than one directory in deb_dist. '
+                                     'Unsure which is source directory')
+                else:
+                    target_dir = fulldir
+        if target_dir is None:
+            raise ValueError('could not find debian source directory')        
+        
+        # inject aegis manifest into .deb
+        if self.aegis_manifest is not None:
+         DEBNAME = self.distribution.get_name()+'_'+self.distribution.get_version()+'*_all.deb'
+         copy(self.aegis_manifest, target_dir+'/_aegis')
+         rules = open(target_dir+'/debian/rules', 'a')
+         rules.write('override_dh_builddeb:\n\tdh_builddeb\n\tar q ../'+DEBNAME+' _aegis\n\n')
+         rules.close()
+
+        # define system command to execute (gen .deb binary pkg)
+        syscmd = ['dpkg-buildpackage','-rfakeroot','-uc','-b']
+
+        util.process_command(syscmd,cwd=target_dir)   
+
index 4af4ed6..4435f72 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1,5 +1,6 @@
 #!/usr/bin/env python
 
+from bdist_hdeb import bdist_hdeb
 from distutils.core import setup
 
 import re
@@ -36,7 +37,8 @@ DATA_FILES = [
         ('share/gotovienna/qml', glob.glob('qml/*')),
 ]
 
-setup(name=PACKAGE,
+setup(cmdclass={'bdist_hdeb': bdist_hdeb},
+      name=PACKAGE,
       version=VERSION,
       description=DESCRIPTION,
       long_description=LONG_DESCRIPTION,