~facundo/enjuewemela/trunk

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Facundo Batista
  • Date: 2011-08-16 01:48:00 UTC
  • Revision ID: facundo@taniquetil.com.ar-20110816014800-r3ha0gn8ez7n39p8
New setup.py and project refactor.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
 
3
 
"""setup -- setuptools setup file for Enjuewemela."""
 
3
# Copyright 2011 Facundo Batista
 
4
#
 
5
# This program is free software: you can redistribute it and/or modify it
 
6
# under the terms of the GNU General Public License version 3, as published
 
7
# by the Free Software Foundation.
 
8
#
 
9
# This program is distributed in the hope that it will be useful, but
 
10
# WITHOUT ANY WARRANTY; without even the implied warranties of
 
11
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
12
# PURPOSE.  See the GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License along
 
15
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
#
 
17
# For further info, check  https://launchpad.net/encuentro
4
18
 
5
 
__author__ = "Facundo Batista"
6
 
__author_email__ = "facundo en taniquetil punto com punto ar"
7
 
__version__ = "0.1"
8
 
__date__ = "2010-04-08"
 
19
"""Setup file for Enjuewemela."""
9
20
 
10
21
import glob
11
22
import os
12
23
 
 
24
from distutils.command.install import install
13
25
from distutils.core import setup
14
26
 
15
 
__description__ = """
16
 
Crazy game with a lot of gems that tend to dissappear strangely
17
 
following user actions.
18
 
"""
19
 
 
20
 
def recursive(base, dirs):
21
 
    all_files = []
22
 
    for d in dirs:
23
 
        for basedir, dirnames, filenames in os.walk(os.path.join(base, d)):
24
 
#            all_files.extend(os.path.join(basedir, x) for x in dirnames)
25
 
            all_files.extend(os.path.join(basedir, x) for x in filenames)
26
 
 
27
 
    # remove the base dir
28
 
    lenbase = len(base) + 1
29
 
    return [x[lenbase:] for x in all_files]
30
 
 
31
 
def get_sub_packages(basedir):
32
 
    all_packages = []
33
 
    for directory, dirnames, filenames in os.walk(basedir):
34
 
        if "__init__.py" in filenames:
35
 
            packpath = directory.replace("/", ".")
36
 
            all_packages.append(packpath)
37
 
    return all_packages
 
27
 
 
28
class CustomInstall(install):
 
29
    """Custom installation class on package files.
 
30
 
 
31
    It copies all the files into the "PREFIX/share/PROJECTNAME" dir.
 
32
    """
 
33
    def run(self):
 
34
        """Run parent install, and then save the install dir in the script."""
 
35
        install.run(self)
 
36
 
 
37
        for script in self.distribution.scripts:
 
38
            script_path = os.path.join(self.install_scripts,
 
39
                                       os.path.basename(script))
 
40
            with open(script_path, 'rb') as fh:
 
41
                content = fh.read()
 
42
            content = content.replace('@ INSTALLED_BASE_DIR @',
 
43
                                      self._custom_data_dir)
 
44
            with open(script_path, 'wb') as fh:
 
45
                fh.write(content)
 
46
 
 
47
 
 
48
    def finalize_options(self):
 
49
        """Alter the installation path."""
 
50
        install.finalize_options(self)
 
51
 
 
52
        # the data path is under 'prefix'
 
53
        data_dir = os.path.join(self.prefix, "share",
 
54
                                self.distribution.get_name())
 
55
 
 
56
        # if we have 'root', put the building path also under it (used normally
 
57
        # by pbuilder)
 
58
        if self.root is None:
 
59
            build_dir = data_dir
 
60
        else:
 
61
            build_dir = os.path.join(self.root, data_dir[1:])
 
62
 
 
63
        # change the lib install directory so all package files go inside here
 
64
        self.install_lib = build_dir
 
65
 
 
66
        # save this custom data dir to later change the scripts
 
67
        self._custom_data_dir = data_dir
 
68
 
 
69
 
 
70
#def recursive(base, dirs):
 
71
#    all_files = []
 
72
#    for d in dirs:
 
73
#        for basedir, dirnames, filenames in os.walk(os.path.join(base, d)):
 
74
##            all_files.extend(os.path.join(basedir, x) for x in dirnames)
 
75
#            all_files.extend(os.path.join(basedir, x) for x in filenames)
 
76
#
 
77
#    # remove the base dir
 
78
#    lenbase = len(base) + 1
 
79
#    return [x[lenbase:] for x in all_files]
 
80
#
 
81
#def get_sub_packages(basedir):
 
82
#    all_packages = []
 
83
#    for directory, dirnames, filenames in os.walk(basedir):
 
84
#        if "__init__.py" in filenames:
 
85
#            packpath = directory.replace("/", ".")
 
86
#            all_packages.append(packpath)
 
87
#    return all_packages
 
88
#
 
89
 
 
90
# first of all, remove .pyc files
 
91
for dirpath, dirname, filenames in os.walk('enjuewemela'):
 
92
    for fname in filenames:
 
93
        if fname.endswith('.pyc'):
 
94
            os.remove(os.path.join(dirpath, fname))
38
95
 
39
96
setup(
40
97
    name = 'enjuewemela',
41
 
    version = __version__,
42
 
    author = __author__,
43
 
    author_email = __author_email__,
44
 
    description = __description__,
45
 
    url = 'https://launchpad.net/enjuewemela/',
46
 
 
47
 
    packages = ['enjuewemela', 'enjuewemela.cocos'] +
48
 
                get_sub_packages("enjuewemela/cocos/cocos"),
49
 
 
50
 
    package_data = {
51
 
        'enjuewemela': recursive('enjuewemela',
52
 
                   ['audio', 'fonts', 'images', 'jewels', 'locale', 'tests']),
53
 
        'enjuewemela.cocos': ['README'] + glob.glob('LICENSE*'),
54
 
        'enjuewemela.cocos.cocos': ['resources/*'],
55
 
    },
56
 
    )
 
98
    version = '0.3',
 
99
    license = 'GPL-3',
 
100
    author = 'Facundo Batista',
 
101
    author_email = 'facundo@taniquetil.com.ar',
 
102
    description = "The crazy gems game",
 
103
    long_description = "Crazy game with a lot of gems that tend to dissappear"\
 
104
                       " strangely following user actions.",
 
105
    url = 'http://launchpad.net/enjuewemela/',
 
106
 
 
107
    packages = ['enjuewemela', 'enjuewemela.cocos'],
 
108
#    packages = ['enjuewemela'] +
 
109
#                get_sub_packages("enjuewemela/cocos/cocos"),
 
110
#
 
111
#    package_data = {
 
112
#        'enjuewemela': recursive('enjuewemela',
 
113
#                   ['audio', 'fonts', 'images', 'jewels', 'locale', 'tests']),
 
114
#        'enjuewemela.cocos': ['README'] + glob.glob('LICENSE*'),
 
115
#        'enjuewemela.cocos.cocos': ['resources/*'],
 
116
 
 
117
    scripts = ["bin/enjuewemela"],
 
118
    cmdclass = {
 
119
        'install': CustomInstall,
 
120
    }
 
121
)