Add custom distutils command to take care of aegis manifest when building
[pywienerlinien] / bdist_hdeb.py
1 import os
2 import stdeb.util as util
3 from shutil import copy
4 from stdeb.command.sdist_dsc import sdist_dsc
5
6 from distutils.core import Command
7
8 __all__ = ['bdist_hdeb']
9
10 class bdist_hdeb(Command):
11     description = 'distutils command to create debian harmattan binary package'
12
13     user_options = [ ("aegis-manifest=", None, 'aegis manifest to use') ]
14     boolean_options = []
15
16     def initialize_options (self):
17         self.aegis_manifest = None
18
19     def finalize_options (self):
20         pass
21
22     def run(self):
23         
24         # generate .dsc source pkg
25         self.run_command('sdist_dsc')
26
27         # execute system command and read output (execute and read output of find cmd)
28         dsc_tree = 'deb_dist'
29         target_dir = None
30         for entry in os.listdir(dsc_tree):
31             fulldir = os.path.join(dsc_tree,entry)
32             if os.path.isdir(fulldir):
33                 if target_dir is not None:
34                     raise ValueError('more than one directory in deb_dist. '
35                                      'Unsure which is source directory')
36                 else:
37                     target_dir = fulldir
38         if target_dir is None:
39             raise ValueError('could not find debian source directory')        
40         
41         # inject aegis manifest into .deb
42         if self.aegis_manifest is not None:
43           DEBNAME = self.distribution.get_name()+'_'+self.distribution.get_version()+'*_all.deb'
44           copy(self.aegis_manifest, target_dir+'/_aegis')
45           rules = open(target_dir+'/debian/rules', 'a')
46           rules.write('override_dh_builddeb:\n\tdh_builddeb\n\tar q ../'+DEBNAME+' _aegis\n\n')
47           rules.close()
48
49         # define system command to execute (gen .deb binary pkg)
50         syscmd = ['dpkg-buildpackage','-rfakeroot','-uc','-b']
51
52         util.process_command(syscmd,cwd=target_dir)   
53