9

I'm interested in what pitfalls can be (except Python is not installed in target system) when using Python for deb package flow control scripts (preinst, postinst, etc.). Will it be practical to implement those scripts in Python, not in sh?

As I understand it's at least possible.

the paul
  • 8,972
  • 1
  • 36
  • 53
Rostyslav Dzinko
  • 39,424
  • 5
  • 49
  • 62
  • You can use any language as long as preinst or whatever is an executable. It can be a `chmod +x`ed script with proper hashbang or a compiled C program. – C0deH4cker Jul 05 '12 at 15:33
  • tcc for compiling c as a scripting langauge ;) – Jakob Bowyer Jul 05 '12 at 15:35
  • You can, but why would you? `sh` is pretty good as what it does, which is a glue language for calling various programs. There's not much logic in the flow control scripts, not even calculations - it's mostly moving files, changing permissions, creating symlinks... – cha0site Jul 05 '12 at 15:57
  • 1
    +1 to counter IMHO unfounded close votes. – tripleee Jul 05 '12 at 18:12

1 Answers1

8

The only reason this isn't commonly done, afaik, is that it's not convention, and Python isn't usually more useful or straightforward than plain shell script for the sorts of things that maintainer scripts do. When it is more useful, you can often break out the Python-needing functionality into a separate Python script which is called by the maintainer scripts.

It can help to follow convention in this sort of situation, since there are a lot of helpful tools and scripts (e.g., Lintian, Debhelper) which generally assume that maintainer scripts use bash. If they don't, it's ok, but those tools may not be as useful as they would be otherwise. The only other issue I think you need to be aware of is that if your preinst or postrm scripts need Python, then Python needs to be a pre-dependency (Pre-Depends) of your package instead of just a Depends.

That said, I've found it useful to use Python in a maintainer script before.

the paul
  • 8,972
  • 1
  • 36
  • 53
  • Oh, I've also thought of separate Python script to be called from main sh one as there can still be some logic to be better implemented in Python. I thing python as a dependency is not quite a problem as it's usually preinstalled with possibly almost all popular debian-based OSs. I see the biggest problem in such scripts support. Basically you need to be careful about Python version as it's not as hardly stable as sh. Thanks for your answer. – Rostyslav Dzinko Jul 05 '12 at 18:57
  • 5
    That does bring up another valid issue; if you target a specific Python version, you won't be able to support all current popular Debian-based OSes. For example, the oldest Ubuntu LTS release (8.04) only supports Python 2.5, while Ubuntu 10.04 only supports Python 2.6, and Ubuntu 12.04 only supports Python 2.7. But if you can write compatible Python (not really that hard), you should be fine. – the paul Jul 05 '12 at 20:13