[Distutils] Fwd: Re: distutils bdist_rpm and %postun section of spec file

David Malcolm dmalcolm at redhat.com
Fri Sep 18 23:43:08 CEST 2009


On Fri, 2009-09-18 at 22:22 +0200, Michał Klich wrote:
> Dnia piątek 18 września 2009 o 22:00:17 David Malcolm napisał(a):
> > On Fri, 2009-09-18 at 21:55 +0200, Michał Klich wrote:
> > > Dnia czwartek 17 września 2009 o 23:07:17 A. Cavallo napisał(a):
> > > > Hi,
> > > > as rule of thumb (followed now by all major distros) you should not put
> > > > any script in %postun, %postinst etc sections.
> > > >
> > > > Regards,
> > > > Antonio
> > > >
> > > > > Hello,
> > > > > I am looking for some advise in creating rpm package using bdist_rpm.
> > > > > I have managed to create post_install part using information
> > > > > http://stackoverflow.com/questions/1321270/how-to-extend-distutils-wi
> > > > >th-a -s imple-post-install-script Now i would like to add some code to
> > > > > %postun part of spec file to revert changes done by my post_install
> > > > > command. Is there a way to add it in setup.py or do i have to
> > > > > manually edit spec file?
> > > >
> > > > _______________________________________________
> > > > Distutils-SIG maillist  -  Distutils-SIG at python.org
> > > > http://mail.python.org/mailman/listinfo/distutils-sig
> > >
> > > It is not mentioned in Fedora guidelines
> > > http://fedoraproject.org/wiki/Packaging/Guidelines#Packaging_Guidelines
> > >
> > > Ok, how would you handle creating symlink in setup.py? and removing it of
> > > course when uninstalling rpm. That is my goal.
> > > I managed to create symlink with setup.py but can not find any option for
> > > removing, which is i think correct as there is no uninstall option for
> > > setup.py.
> > 
> > Why is the symlink not simply a part of the rpm payload?  That way it
> > would be created on installation and removed on removal.
> > 
> > 
> > Dave
> > 
> 
> Symlink is pointing to x86_64 arch file, i would like to have noarch rpm.
> It is pointing to /usr/bin/consolehelper as application needs to be run with 
> root rights.
> I might be doing something wrong here but this is my first package.

Although the target (/usr/bin/consolehelper) of the symlink is a
compiled binary and thus architecture-specific, the symlink's path and
thus the symlink itself is architecture-independent, so it ought to be
possible to create a noarch rpm.

I can think of a couple of approaches:
(i) You can write a generic setup.py script and invoke the "bdist_rpm"
command, as you're doing, and have this generate a specfile for your RPM
and build it.  The specfile is autogenerated.

If I'm reading the distutils code correctly this will internally call
the "install" command, and scrape the installed payload into a file
named "INSTALLED_FILES", which will get referenced in the autogenerated
specfile.

I believe one can create a symlink from your script to consolehelper
using:
  # caution; untested code!
  # not sure if I got src/dst the right way around
  distutils.file_util.copy_file('/usr/bin/consolehelper',
                                '/usr/bin/your_script',
                                link='sym')

However, reading the consolehelper manpage, it looks like you may also
need to set up files under /etc/pam.d/ (not my area of expertise)

(ii) You can write a generic setup.py script, and also write a .spec
file.  You then create the symlink in the specfile, and add it to the %
files section.  In Fedora we have a script "rpmdev-newspec" that makes
it easy to create new boilerplate .spec files for a setup.py file.  The
downside to this approach is that you now have a .spec file separate
from your setup.py, and have to maintain both.  It makes sense in our
world where Python is only one of many technologies, and rpm is the
native packaging format (for good or ill).

Hope this is helpful
Dave



More information about the Distutils-SIG mailing list