[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

question about cdbs, setup.py and a python package



hi, this is my first python packge (without me speaking
substantial python) and i wanted to do it with cdbs to smoothen
the learning curve.

i attache the setup.py of the package and wonder about the
section about the install, where it seems to have some option for
installing in special places (which i need to install stuff into
my packages install-dir, i assume).

how can i pass this --root= option to cdbs? 

This is the error i get:

[... everything works fine ...]
copying build/lib/Cerebrum/client/ServerConnection.py -> /home/andreas/src/deb/cerebrum-0.0.20040131/debian/tmp/usr/lib/python2.3/site-packages/Cerebrum/client
copying build/lib/Cerebrum/client/__init__.py -> /home/andreas/src/deb/cerebrum-0.0.20040131/debian/tmp/usr/lib/python2.3/site-packages/Cerebrum/client
running install_data
error: /usr/lib/python2.3/site-packages/cerebrum_path.py: Permission denied
make: *** [common-install-impl] Error 1
/usr/bin/fakeroot: line 1: wait: pid 26664 is not a child of this shell


the package also comes with a binary file (__init__.pyc in cvs,
eventhough the uncompiled package is also there). i can delete
that, i guess?



#!/usr/bin/env python2.2
# -*- coding: iso-8859-1 -*-
#
# Placement of files when installing Cerebrum
# -------------------------------------------
#
# NOTE: At least while developing, I recommend using "--prefix
# /cerebrum".  Otherwise all these paths are relative to / unless
# otherwise noted.
#
# /
#   README:       usr/share/cerebrum/doc/
#   COPYING:      usr/share/cerebrum/doc/
#
# Cerebrum/
#   */*.py:       under site-packages of the running python interpreter
#   cereconf.py:  etc/cerebrum/
#   */tests/*:    Not installed
#
#   Note that the entire Cerebrum/modules catalog is installed.
#   Site-specific components should assert that they do not use names
#   that clashes with the files distributed with Cerebrum, otherwise
#   they may be overwritten by a later installation.  The naming
#   syntax should be that of a reversed dns name with '.' replaced with
#   '/'.  E.g., for uio.no, the directory modules/no/uio is used.
#
# design/
#   *.sql:        usr/share/cerebrum/doc/design/
#   *.html,*.dia: usr/share/cerebrum/doc/
#
# doc/
#   *:            usr/share/cerebrum/doc/
#   *cron*:       usr/share/cerebrum/doc/samples
#
# testsuite/
#   *:            Not installed
#
# server/
#   bofhd.py:     usr/sbin/
#   config.dat:   etc/cerebrum/bofhd.config
#   *.py:         usr/share/cerebrum/bofhd (site-packages/modules/bofhd better?)
#
# client/
#   bofh.py:      usr/bin
#   config-files: etc/cerebrum/client
#   template.ps:  usr/share/cerebrum/client
#   passweb.py:   usr/share/cerebrum/client ?
#
#   As the client will be installed stand-alone on numerous machines,
#   the files for it resides in a separate directory to make
#   distribution easier.  All clients should share at least one config
#   file
#
# java/jbofh/
#   jbofh.jar:    usr/share/cerebrum/client
#   libJavaReadline.so:
#                 usr/share/cerebrum/client/linux
#   jbofh.sh:     usr/bin
#
# contrib/
#   generate_nismaps.py:  usr/sbin
#
# contrib/no
#   *.py:         usr/sbin
# contrib/no/uio
#   *.py:         usr/sbin
#
# contrib/no/uio/studit
#   *:            usr/share/cerebrum/studit
#
#
# Other directories/files:
#
#   var/log/cerebrum/:
#        All log-files for cerebrum, unless the number of files is
#        above 4, when a seperate directory should be created.
#
#   usr/share/cerebrum/data:
#        A number of subdirectories for various backends

# To install python modules in standard locations, and cerebrum files
# under /cerebrum, run like:
#  python2.2 setup.py install install_data --install-dir=/cerebrum
#
# To get the files in /etc under /cerebrum/etc, add:
#  --root=/cerebrum
#
# To build dist file:
#  python2.2 setup.py sdist

import os
import sys
import pwd
from glob import glob
from types import StringType

from distutils import sysconfig
from distutils.command import install_data, install_lib
from distutils.command.build import build
from distutils.command.sdist import sdist
from distutils.core import setup, Command
from distutils.util import change_root, convert_path
import Cerebrum

#
# Which user should own the installed files
#
cerebrum_user = "cerebrum"

class my_install_data (install_data.install_data, object):
    def finalize_options (self):
        """Add wildcard support for filenames.  Generate cerebrum_path.py"""
        super(my_install_data, self).finalize_options()
        for f in self.data_files:
            if type(f) != StringType:
                files = f[1]
                i = 0
                while i < len(files):
                    if files[i][0].find('*') > -1:
                        for e in glob(files[i][0]):
                            files.append((e, files[i][1]))
                        files.pop(i)
                        i -= 1
                    i += 1
        if(os.geteuid() != 0):
            print "Warning, uid!=0, not writing cerebrum_path.py"
            return
        f_in = open("cerebrum_path.py.in", "r")
        f_out = open("%s/cerebrum_path.py" % sysconfig.get_python_lib(), "w")
        etc_dir = "%s/etc/cerebrum" % self.install_dir
        python_dir = sysconfig.get_python_lib(prefix=self.install_dir)
        for line in f_in.readlines():
            line = line.replace("@CONFDIR@", etc_dir)
            line = line.replace("@PYTHONDIR@", python_dir)
            f_out.write(line)
        f_in.close()
        f_out.close()

    def run (self):
        self.mkpath(self.install_dir)
        for f in self.data_files:
            # it's a tuple with dict to install to and a list of files
            tdict = f[0]
            dir = convert_path(tdict['path'])
            if not os.path.isabs(dir):
                dir = os.path.join(self.install_dir, dir)
            elif self.root:
                dir = change_root(self.root, dir)
            self.mkpath(dir)
            os.chmod(dir, tdict['mode'])
            if(os.geteuid() == 0):
                try:
                    uinfo = pwd.getpwnam(tdict['owner'])
                except KeyError:
                    print "Error: Unkown user %s" % tdict['owner']
                    sys.exit(1)
                uid, gid = uinfo[2], uinfo[3]
                os.chown(dir, uid, gid)
            if f[1] == []:
                # If there are no files listed, the user must be
                # trying to create an empty directory, so add the
                # directory to the list of output files.
                self.outfiles.append(dir)
            else:
                # Copy files, adding them to the list of output files.
                for data, mode in f[1]:
                    data = convert_path(data)
                    (out, _) = self.copy_file(data, dir)
                    self.outfiles.append(out)
                    os.chmod(out, mode)
                    if(os.geteuid() == 0):
                        os.chown(out, uid, gid)

class test(Command):
    user_options = [('check', None, 'Run check'),
                    ('dbcheck', None, 'Run db-check')]
    def initialize_options (self):
        self.check = None
        self.dbcheck = None

    def finalize_options (self):
        if self.check is None and self.dbcheck is None:
            raise RuntimeError, "Must specify test option"
    
    def run (self):
        if self.dbcheck is not None:
            os.system('%s testsuite/Run.py -v Cerebrum.tests.SQLDriverTestCase.suite' % sys.executable)
        if self.check is not None:
            os.system('%s testsuite/Run.py -v' % sys.executable)

class my_sdist(sdist, object):
    def finalize_options (self):
        super(my_sdist, self).finalize_options()
        if os.system('cd java/jbofh && ant dist') != 0:
            raise RuntimeError, "Error running ant"

prefix="."  # Should preferably be initialized from the command-line argument
sharedir="%s/share" % prefix
sbindir="%s/sbin" % prefix
bindir="%s/bin" % prefix
sysconfdir = "%s/etc/cerebrum" % prefix # Should be /etc/cerebrum/
logdir = "%s/var/log/cerebrum" % prefix # Should be /var/log/cerebrum/

setup (name = "Cerebrum", version = Cerebrum.__version__,
       url = "http://cerebrum.sourceforge.net";,
       maintainer = "Cerebrum Developers",
       maintainer_email = "do.we@want.this.here",
       description = "Cerebrum is a user-administration system",
       license = "GPL",
       long_description = ("System for user semi-automatic user "+
                           "administration in a heterogenous "+
                           "environment"),
       platforms = "UNIX",
       # NOTE: all scripts ends up in the same dir!
       # scripts = ['contrib/no/uio/import_FS.py', 'contrib/generate_nismaps.py'],
       packages = ['Cerebrum',
                   'Cerebrum/extlib',
                   'Cerebrum/extlib/Plex',
                   'Cerebrum/modules',
                   'Cerebrum/modules/bofhd',
                   'Cerebrum/modules/no',
                   'Cerebrum/modules/no/uio',
                   'Cerebrum/modules/no/uio/AutoStud',
                   'Cerebrum/modules/no/feidegvs',
                   'Cerebrum/modules/templates',
                   'Cerebrum/client',
                   ],

       # options override --prefix
       #options = {'install_data': {'root' : '/foo/bar',  # prefix on slash
       #                            'install_dir': '/dddddddd' # prefix on no-slash
       #                            }},
       # data_files doesn't seem to handle wildcards
       data_files = [({'path': "%s/doc/cerebrum/design" % sharedir,
                       'owner': cerebrum_user,
                       'mode': 0755},
                      [('design/*.sql', 0644),
                       ]),
                     ({'path': "%s/doc/cerebrum" % sharedir,
                       'owner': cerebrum_user,
                       'mode': 0755},
                      [('design/cerebrum-core.dia', 0644),
                       ('design/cerebrum-core.html', 0644),
                       ('design/adminprotocol.html', 0644),
                       ('README', 0644),
                       ('COPYING', 0644)
                       # 'doc/*'
                       ]),
                     ## ("%s/samples" % sharedir,
                     ##  ['doc/*.cron']),
                     ({'path': sbindir,
                       'owner': cerebrum_user,
                       'mode': 0755},
                      [('server/bofhd.py', 0755),
                       ('server/job_runner.py', 0755),
                       ('makedb.py', 0755)]),
                     ({'path': "%s/cerebrum/contrib" % sharedir,
                       'owner': cerebrum_user,
                       'mode': 0755},
                      [('contrib/*.py', 0755)]),
                     ({'path': "%s/cerebrum/contrib/no" % sharedir,
                       'owner': cerebrum_user,
                       'mode': 0755},
                      [('contrib/no/*.py', 0755)]),
                     ({'path': "%s/cerebrum/contrib/no/uio" % sharedir,
                       'owner': cerebrum_user,
                       'mode': 0755},
                      [('contrib/no/uio/*.py', 0755)]),
                     ({'path': bindir,
                       'owner': cerebrum_user,
                       'mode': 0755},
                      [('client/bofh.py', 0755),
                       ('java/jbofh/fix_jbofh_jar.py', 0755)]),
                     ({'path': "%s/cerebrum/client" % sharedir,
                       'owner': cerebrum_user,
                       'mode': 0755},
                       [('client/passweb.py', 0755),
                        ('client/passweb_form.html', 0644),
                        ('client/passweb_receipt.html', 0644),
                        ('java/jbofh/dist/lib/JBofh.jar', 0644)]),
                     ({'path': sysconfdir,
                       'owner': cerebrum_user,
                       'mode': 0755},
                      [('design/cereconf.py', 0644),
                       ('server/config.dat', 0644),
                       ('server/scheduled_jobs.py', 0644),
                       ('design/logging.ini', 0644)
                       ]),
                     ({'path': logdir,
                       'owner': cerebrum_user,
                       'mode': 0750},
                      []),
                     ({'path': "%s/cerebrum/data" % sharedir,
                       'owner': cerebrum_user,
                       'mode': 0755},
                      []),
                     ],
       # Overridden command classes
       cmdclass = {'install_data': my_install_data,
                   'sdist': my_sdist,
                   'test': test}
      )



Reply to: