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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
#!/usr/bin/env python
# Copyright 2011 Facundo Batista
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# For further info, check https://launchpad.net/enjuewemela
"""Setup file for Enjuewemela."""
import glob
import os
from distutils.command.install import install
from distutils.core import setup
class CustomInstall(install):
"""Custom installation class on package files.
It copies all the files into the "PREFIX/share/PROJECTNAME" dir.
"""
def run(self):
"""Run parent install, and then save the install dir in the script."""
# make the distutils infrastructure run
install.run(self)
# fix installation path in the script(s)
for script in self.distribution.scripts:
script_path = os.path.join(self.install_scripts,
os.path.basename(script))
with open(script_path, 'rb') as fh:
content = fh.read()
content = content.replace('@ INSTALLED_BASE_DIR @',
self._custom_data_dir)
with open(script_path, 'wb') as fh:
fh.write(content)
# fix the icon path, and save the .desktop file where it should be
src_desktop = self.distribution.get_name() + '.desktop'
if not os.path.exists(self._custom_apps_dir):
os.makedirs(self._custom_apps_dir)
dst_desktop = os.path.join(self._custom_apps_dir, src_desktop)
with open(src_desktop, 'rb') as fh:
content = fh.read()
icon = os.path.join(self._custom_data_dir,
'enjuewemela', 'images', 'icon-32x32.png')
content = content.replace('@ INSTALLED_ICON @', icon)
with open(dst_desktop, 'wb') as fh:
fh.write(content)
def finalize_options(self):
"""Alter the installation path."""
install.finalize_options(self)
# the data path is under 'prefix'
data_dir = os.path.join(self.prefix, "share",
self.distribution.get_name())
apps_dir = os.path.join(self.prefix, "share", "applications")
# if we have 'root', put the building path also under it (used normally
# by pbuilder)
if self.root is None:
build_dir = data_dir
else:
build_dir = os.path.join(self.root, data_dir[1:])
apps_dir = os.path.join(self.root, apps_dir[1:])
# change the lib install directory so all package files go inside here
self.install_lib = build_dir
# save this custom data dir to later change the scripts
self._custom_data_dir = data_dir
self._custom_apps_dir = apps_dir
def recursive(base, dirs):
"""Recursively get all dirs."""
all_files = []
for d in dirs:
for basedir, dirnames, filenames in os.walk(os.path.join(base, d)):
all_files.extend(os.path.join(basedir, x) for x in filenames)
# remove the base dir
lenbase = len(base) + 1
return [x[lenbase:] for x in all_files]
def get_sub_packages(basedir):
"""Get sub packages for a package."""
all_packages = []
for directory, dirnames, filenames in os.walk(basedir):
if "__init__.py" in filenames:
packpath = directory.replace("/", ".")
all_packages.append(packpath)
return all_packages
# first of all, remove .pyc files
for dirpath, dirname, filenames in os.walk('enjuewemela'):
for fname in filenames:
if fname.endswith('.pyc'):
os.remove(os.path.join(dirpath, fname))
setup(
name = 'enjuewemela',
version = '0.4.1',
license = 'GPL-3',
author = 'Facundo Batista',
author_email = 'facundo@taniquetil.com.ar',
description = "The crazy gems game",
long_description = "Crazy game with a lot of gems that tend to dissappear"\
" strangely following user actions.",
url = 'http://launchpad.net/enjuewemela/',
packages = ['enjuewemela'] +
get_sub_packages("enjuewemela/cocos/cocos"),
package_data = {
'enjuewemela': recursive('enjuewemela', ['audio', 'fonts', 'images',
'jewels', 'locale']),
'enjuewemela.cocos': ['README'] + glob.glob('LICENSE*'),
'enjuewemela.cocos.cocos': ['resources/*'],
},
scripts = ["bin/enjuewemela"],
cmdclass = {
'install': CustomInstall,
}
)
|