File: install_data_ext.py

package info (click to toggle)
positron 1%3A1.1-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 500 kB
  • ctags: 274
  • sloc: python: 2,952; sh: 385; makefile: 51
file content (80 lines) | stat: -rw-r--r-- 3,059 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# install_data_ext.py
#
# Subclass of normal distutils install_data command to allow more
# configurable installation of data files.

import os
from distutils.command.install_data import install_data
from distutils.util import change_root, convert_path

class install_data_ext(install_data):

    def initialize_options(self):
        self.install_base = None
        self.install_platbase = None
        self.install_purelib = None
        self.install_headers = None
        self.install_lib = None
        self.install_scripts = None
        self.install_data = None

        self.outfiles = []
        self.root = None
        self.force = 0
        self.data_files = self.distribution.data_files
        self.warn_dir = 1
        

    def finalize_options(self):
        self.set_undefined_options('install',
                                   ('root', 'root'),
                                   ('force', 'force'),
                                   ('install_base', 'install_base'),
                                   ('install_platbase',
                                    'install_platbase'),
                                   ('install_purelib',
                                    'install_purelib'),
                                   ('install_headers',
                                    'install_headers'),
                                   ('install_lib', 'install_lib'),
                                   ('install_scripts',
                                    'install_scripts'),
                                   ('install_data', 'install_data'))
                                   

    def run(self):
        """
        This is where the meat is.  Basically the data_files list must
        now be a list of tuples of 3 entries.  The first
        entry is one of 'base', 'platbase', etc, which indicates which
        base to install from.  The second entry is the path to install
        too.  The third entry is a list of files to install.
        """
        for lof in self.data_files:
            if lof[0]:
                base = getattr(self, 'install_' + lof[0])
            else:
                base = getattr(self, 'install_base')
            dir = convert_path(lof[1])
            if not os.path.isabs(dir):
                dir = os.path.join(base, dir)
            elif self.root:
                dir = change_root(self.root, dir)
            self.mkpath(dir)

            files = lof[2]
            if len(files) == 0:
                # If there are no files listed, the user must be
                # trying to create an empty directory, so add the the
                # directory to the list of output files.
                self.outfiles.append(dir)
            else:
                # Copy files, adding them to the list of output files.
                for f in files:
                    f = convert_path(f)
                    (out, _) = self.copy_file(f, dir)
                    #print "DEBUG: ", out  # dbg
                    self.outfiles.append(out)
                    

        return self.outfiles