Skip to content

Commit

Permalink
Add --postinst-commands option
Browse files Browse the repository at this point in the history
```
$ rm -rf debian; make-deb --no-test --python=/usr/bin/python3 --python-version=3.5 --postinst-commands='mkdir -p /var/log/sm'
'debian' directory successfully placed at the root of your repository

$ cat debian/smbot.postinst
#!/bin/sh

#DEBHELPER#

mkdir -p /var/log/sm
```
  • Loading branch information
msabramo committed Oct 31, 2016
1 parent 1159419 commit 2580914
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
6 changes: 5 additions & 1 deletion bin/make-deb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ def get_dh_virtualenv_options(python, test):
@click.option('--test/--no-test',
default=True,
help='Whether to run python setup.py test')
def main(python, python_version, test):
@click.option('--postinst-commands',
default=None,
help='Commands to put in postinst script')
def main(python, python_version, test, postinst_commands):
dh_virtualenv_options = get_dh_virtualenv_options(python, test)
try:
debconf = DebianConfiguration(
os.getcwd(),
python_version=python_version,
dh_virtualenv_options=dh_virtualenv_options,
postinst_commands=postinst_commands,
)
debconf.render()
except DebianConfigurationException as e:
Expand Down
14 changes: 13 additions & 1 deletion make_deb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class DebianConfiguration(object):
"compat": 9,
}

def __init__(self, rootdir, python_version='2.x', dh_virtualenv_options=None):
def __init__(self, rootdir,
python_version='2.x', dh_virtualenv_options=None,
postinst_commands=None):
self.rootdir = rootdir
self.context = self.DEFAULT_CONTEXT.copy()
self.context.update({"date": datetime.datetime.now()})
Expand All @@ -47,6 +49,7 @@ def __init__(self, rootdir, python_version='2.x', dh_virtualenv_options=None):
"pre_depends_python": "python2.7-minimal | python2.6-minimal"})
self.context.update({"python_version": python_version})
self.context.update({"dh_virtualenv_options": dh_virtualenv_options})
self.context.update({"postinst_commands": postinst_commands})

def _context_from_git(self):
try:
Expand Down Expand Up @@ -117,3 +120,12 @@ def render(self):
trigger_filename = "%s.triggers" % self.context['name']
with open(os.path.join(output_dir, trigger_filename), "w") as f:
f.write(trigger_content+"\n")

trigger_content = Template(
resource_string("make_deb", "resources/debian/postinst.j2").
decode('utf-8')
).render(self.context)

trigger_filename = "%s.postinst" % self.context['name']
with open(os.path.join(output_dir, trigger_filename), "w") as f:
f.write(trigger_content+"\n")
5 changes: 5 additions & 0 deletions make_deb/resources/debian/postinst.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

#DEBHELPER#

{{ postinst_commands }}

0 comments on commit 2580914

Please sign in to comment.