Menu

[fd4f5b]: / setup.py  Maximize  Restore  History

Download this file

258 lines (228 with data), 8.9 kB

  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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/usr/bin/env python
# -*- coding:Utf-8 -*-
# Copyright (C) 2010 Nicolas Doby <nicolas.doby@gmail.com>
# Copyright (C) 2010 Samuel Gallard <samuel.gallard@gmail.com>
#
# Licensed under the GNU General Public License Version 2
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY 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/>.
import sys, os, glob, shutil
import subprocess
from stat import *
from distutils.core import setup
from distutils.command.install import install as _install
from distutils.command.install_data import install_data as _install_data
from distutils.command.clean import clean as _clean
INSTALLED_FILES = "installed_files"
class install (_install):
def run (self):
_install.run (self)
outputs = self.get_outputs ()
length = 0
if self.root:
length += len (self.root)
if self.prefix:
length += len (self.prefix)
if length:
for counter in xrange (len (outputs)):
outputs[counter] = outputs[counter][length:]
data = "\n".join (outputs)
try:
file = open (INSTALLED_FILES, "w")
except:
self.warn ("Could not write installed files list %s" % \
INSTALLED_FILES)
return
file.write (data)
file.close ()
class install_data (_install_data):
def run (self):
def chmod_data_file (file):
try:
os.chmod (file, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
except:
self.warn ("Could not chmod data file %s" % file)
_install_data.run (self)
map (chmod_data_file, self.get_outputs ())
class uninstall (_install):
def run (self):
try:
file = open (INSTALLED_FILES, "r")
except:
self.warn ("Could not read installed files list %s" % \
INSTALLED_FILES)
return
files = file.readlines ()
file.close ()
prepend = ""
if self.root:
prepend += self.root
if self.prefix:
prepend += self.prefix
if len (prepend):
for counter in xrange (len (files)):
files[counter] = prepend + files[counter].rstrip ()
for file in files:
print "Uninstalling %s" % file
try:
os.unlink (file)
except:
self.warn ("Could not remove file %s" % file)
class clean (_clean):
def run (self):
files = [os.path.join("libuzic/Constants.py"),
"libuzic.desktop",
"MANIFEST",
INSTALLED_FILES
]
dirs = ["script", "build", "dist"]
for file in files:
try:
os.remove (file)
except:
pass
for dir in dirs:
try:
shutil.rmtree (dir)
except:
pass
ops = ("install", "build", "sdist", "uninstall", "clean")
if len (sys.argv) < 2 or sys.argv[1] not in ops:
print "Please specify operation : %s" % " | ".join (ops)
raise SystemExit
prefix = None
if len (sys.argv) > 2:
i = 0
for o in sys.argv:
if o.startswith ("--prefix"):
if o == "--prefix":
if len (sys.argv) >= i:
prefix = sys.argv[i + 1]
sys.argv.remove (prefix)
elif o.startswith ("--prefix=") and len (o[9:]):
prefix = o[9:]
sys.argv.remove (o)
break
i += 1
if not prefix and "PREFIX" in os.environ:
prefix = os.environ["PREFIX"]
if not prefix or not len (prefix):
prefix = "/usr"
if sys.argv[1] in ("install", "uninstall") and len (prefix):
sys.argv += ["--prefix", prefix]
version_file = open ("VERSION", "r")
version = version_file.read ().strip ()
if "=" in version:
version = version.split ("=")[1]
data_files = []
if sys.argv[1] != "clean":
f = open (os.path.join ("libuzic/Constants.py.in"), "rt")
data = f.read ()
f.close ()
data = data.replace ("@version@", version)
data = data.replace ("@prefix@", prefix)
f = open (os.path.join ("libuzic/Constants.py"), "wt")
f.write (data)
f.close ()
# Create the script
f = open ("libuzic.py", "rt")
data = f.read ()
f.close ()
if not os.path.exists ("script"):
os.mkdir ("script")
f = open (os.path.join ("script/libuzic"), "wt")
f.write (data)
f.close ()
custom_images = []
data_files = []
if sys.platform != "win32" and sys.platform != "cygwin":
try:
cmd = "intltool-merge -d -u po/ libuzic.desktop.in libuzic.desktop".split(" ")
proc = subprocess.Popen(cmd)
proc.wait()
data_files.append(("share/applications", ["libuzic.desktop"]))
except OSError:
print ("The command intltool could not be found, please install it and retry")
raise SystemExit
global_icon_path = "share/icons/hicolor/"
local_icon_path = "share/libuzic/icons/hicolor/"
for dir, subdirs, files in os.walk("images/"):
if dir == "images/":
for file in files:
custom_images.append(dir + file)
else:
images = []
global_images = []
for file in files:
if file.find(".svg") or file.find(".png"):
file_path = "%s/%s" % (dir, file)
# global image
if file[:-4] == "libuzic":
global_images.append(file_path)
# local image
else:
images.append(file_path)
# local
if len(images) > 0:
data_files.append((local_icon_path + dir[7:], images))
# global
if len(global_images) > 0:
data_files.append((global_icon_path + dir[7:], global_images))
data_files.append(("share/libuzic/images", custom_images))
podir = os.path.join (os.path.realpath ("."), "po")
if os.path.isdir (podir):
buildcmd = "msgfmt -o build/locale/%s/libuzic.mo po/%s.po"
mopath = "build/locale/%s/libuzic.mo"
destpath = "share/locale/%s/LC_MESSAGES"
for name in os.listdir (podir):
if name[-2:] == "po":
name = name[:-3]
if sys.argv[1] == "build" \
or (sys.argv[1] == "install" and \
not os.path.exists (mopath % name)):
if not os.path.isdir ("build/locale/" + name):
os.makedirs ("build/locale/" + name)
os.system (buildcmd % (name, name))
data_files.append ((destpath % name, [mopath % name]))
setup (
name = "libuzic",
version = version,
description = "Manage your team sport's clubs",
author = "Nicolas Doby",
author_email = "nicolas.doby@gmail.org",
url = "http://libuzic.sourceforge.net/",
license = "GPL",
data_files = data_files,
packages = ['libuzic', 'libuzic.mapping', 'libuzic.mapping.object',
'libuzic.mapping.database', 'libuzic.output', 'libuzic.ui',
'libuzic.ui.box', 'libuzic.ui.container', 'libuzic.ui.administration',
'libuzic.ui.tab', 'libuzic.ui.widget', 'libuzic.ui.window',
'libuzic.tools'],
scripts = [os.path.join("script/libuzic")],
cmdclass = {"uninstall" : uninstall,
"install" : install,
"install_data" : install_data,
"clean" : clean}
)
if sys.argv[1] == "install":
gtk_update_icon_cache = '''gtk-update-icon-cache -f -t \
%s/share/libuzic/icons/hicolor''' % prefix
root_specified = len (filter (lambda s: s.startswith ("--root"),
sys.argv)) > 0
if not root_specified:
print "Updating Gtk icon cache."
os.system (gtk_update_icon_cache)
else:
print '''*** Icon cache not updated. After install, run this:
*** %s''' % gtk_update_icon_cache