~ellisonbg/ipython/bugfixes0411409

« back to all changes in this revision

Viewing changes to setupext/install_data_ext.py

  • Committer: ville
  • Date: 2008-02-16 09:50:47 UTC
  • mto: (0.12.1 ipython_main)
  • mto: This revision was merged to the branch mainline in revision 990.
  • Revision ID: ville@ville-pc-20080216095047-500x6dluki1iz40o
initialization (no svn history)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# install_data_ext.py
 
2
#
 
3
# Subclass of normal distutils install_data command to allow more
 
4
# configurable installation of data files.
 
5
 
 
6
import os
 
7
from distutils.command.install_data import install_data
 
8
from distutils.util import change_root, convert_path
 
9
 
 
10
class install_data_ext(install_data):
 
11
 
 
12
    def initialize_options(self):
 
13
        self.install_base = None
 
14
        self.install_platbase = None
 
15
        self.install_purelib = None
 
16
        self.install_headers = None
 
17
        self.install_lib = None
 
18
        self.install_scripts = None
 
19
        self.install_data = None
 
20
 
 
21
        self.outfiles = []
 
22
        self.root = None
 
23
        self.force = 0
 
24
        self.data_files = self.distribution.data_files
 
25
        self.warn_dir = 1
 
26
        
 
27
 
 
28
    def finalize_options(self):
 
29
        self.set_undefined_options('install',
 
30
                                   ('root', 'root'),
 
31
                                   ('force', 'force'),
 
32
                                   ('install_base', 'install_base'),
 
33
                                   ('install_platbase',
 
34
                                    'install_platbase'),
 
35
                                   ('install_purelib',
 
36
                                    'install_purelib'),
 
37
                                   ('install_headers',
 
38
                                    'install_headers'),
 
39
                                   ('install_lib', 'install_lib'),
 
40
                                   ('install_scripts',
 
41
                                    'install_scripts'),
 
42
                                   ('install_data', 'install_data'))
 
43
                                   
 
44
 
 
45
    def run(self):
 
46
        """
 
47
        This is where the meat is.  Basically the data_files list must
 
48
        now be a list of tuples of 3 entries.  The first
 
49
        entry is one of 'base', 'platbase', etc, which indicates which
 
50
        base to install from.  The second entry is the path to install
 
51
        too.  The third entry is a list of files to install.
 
52
        """
 
53
        for lof in self.data_files:
 
54
            if lof[0]:
 
55
                base = getattr(self, 'install_' + lof[0])
 
56
            else:
 
57
                base = getattr(self, 'install_base')
 
58
            dir = convert_path(lof[1])
 
59
            if not os.path.isabs(dir):
 
60
                dir = os.path.join(base, dir)
 
61
            elif self.root:
 
62
                dir = change_root(self.root, dir)
 
63
            self.mkpath(dir)
 
64
 
 
65
            files = lof[2]
 
66
            if len(files) == 0:
 
67
                # If there are no files listed, the user must be
 
68
                # trying to create an empty directory, so add the the
 
69
                # directory to the list of output files.
 
70
                self.outfiles.append(dir)
 
71
            else:
 
72
                # Copy files, adding them to the list of output files.
 
73
                for f in files:
 
74
                    f = convert_path(f)
 
75
                    (out, _) = self.copy_file(f, dir)
 
76
                    #print "DEBUG: ", out  # dbg
 
77
                    self.outfiles.append(out)
 
78
                    
 
79
 
 
80
        return self.outfiles