A4

Merge lp:~francesco-marella/a4/improve-setup into lp:a4

Proposed by Francesco Marella
Status: Merged
Merged at revision: 111
Proposed branch: lp:~francesco-marella/a4/improve-setup
Merge into: lp:a4
Diff against target: 223 lines (+197/-18)
1 file modified
setup.py (+197/-18)
To merge this branch: bzr merge lp:~francesco-marella/a4/improve-setup
Reviewer Review Type Date Requested Status
Andrea Gasparini Approve
Review via email: mp+50411@code.launchpad.net
To post a comment you must log in.
110. By Francesco Marella

setup.py: Fix the locale directory for the generated mo files

Thanks to Andrea Gasparini for reporting and testing.

111. By Francesco Marella

setup.py: fix all the pep8 warnings

Revision history for this message
Andrea Gasparini (gaspa) wrote :

just merged. I fixed a little pep8 error, the rest is really verbose but it's ok for now.

We should although keep in mind that:
* we should handle better the install path of the .po files.
* I just found this: http://www.glatzor.de/projects/python-distutils-extra
  perhaps we can use it to simplify the setup.py.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'setup.py' (properties changed: +x to -x)
--- setup.py 2010-08-02 13:02:07 +0000
+++ setup.py 2011-02-23 23:39:05 +0000
@@ -1,22 +1,201 @@
1#!/usr/bin/env python1#!/usr/bin/python
2# -*- coding: utf-8 -*-
23
3from distutils.core import setup4from distutils.core import setup
5from distutils.dist import Distribution
6from distutils.cmd import Command
7from distutils.command.install_data import install_data
8from distutils.command.build import build
9from distutils.dep_util import newer
10from distutils.log import warn, info, error
11from distutils.errors import DistutilsFileError
12import glob
13import os
14import sys
15import subprocess
16import platform
17
4from a4lib import __version__18from a4lib import __version__
519
6setup(name='A4',20PO_DIR = 'po'
7 version=__version__,21MO_DIR = os.path.join('build', 'mo')
8 description='A cool tool to create amazing presentations',22
9 author='A4 Developers',23
10 author_email='a4-dev@lists.launchpad.net',24class CustomDist(Distribution):
11 url='https://launchpad.net/a4',25
12 license='GNU GPL3',26 global_options = Distribution.global_options + [('without-gettext',
13 packages=['a4lib'],27 None, "Don't build/install gettext .mo files"),
14 scripts=['a4'],28 ('without-icon-cache', None,
15 data_files=[('share/a4/data', ['data/window_main.glade']),29 "Don't attempt to run gtk-update-icon-cache")]
16 ('share/a4/tests/images', 30
17 ['tests/images/A4_nested_transforms.svg',31 def __init__(self, *args):
18 'tests/images/rotations.svg', 'tests/images/roi.svg']),32 self.without_gettext = False
19 ('share/man/man1', ['data/a4.1']),33 self.without_icon_cache = False
20 ('share/applications', ['data/a4.desktop']),34 Distribution.__init__(self, *args)
21 ('share/pixmaps', ['data/a4.png'])]35
22 )36
37class BuildData(build):
38
39 def run(self):
40 build.run(self)
41
42 if self.distribution.without_gettext:
43 return
44
45 for po in glob.glob(os.path.join(PO_DIR, '*.po')):
46 lang = os.path.basename(po[:-3])
47 mo = os.path.join(MO_DIR, lang, 'LC_MESSAGES', 'a4.mo')
48
49 directory = os.path.dirname(mo)
50 if not os.path.exists(directory):
51 info('creating %s' % directory)
52 os.makedirs(directory)
53
54 if newer(po, mo):
55 info('compiling %s -> %s' % (po, mo))
56 try:
57 rc = subprocess.call(['msgfmt', '-o', mo, po])
58 if rc != 0:
59 raise Warning('msgfmt returned %d' % rc)
60 except Exception, e:
61 error('Building gettext files failed. \
62Try setup.py --without-gettext [build|install]'
63 )
64 error('Error: %s' % str(e))
65 sys.exit(1)
66
67 TOP_BUILDDIR = '.'
68 INTLTOOL_MERGE = 'intltool-merge'
69 desktop_in = 'data/a4.desktop.in'
70 desktop_data = 'data/a4.desktop'
71 os.system('C_ALL=C ' + INTLTOOL_MERGE + ' -d -u -c '
72 + TOP_BUILDDIR + '/po/.intltool-merge-cache '
73 + TOP_BUILDDIR + '/po ' + desktop_in + ' '
74 + desktop_data)
75
76
77class Uninstall(Command):
78
79 description = 'Attempt an uninstall from an install --record file'
80
81 user_options = [('manifest=', None, 'Installation record filename')]
82
83 def initialize_options(self):
84 self.manifest = None
85
86 def finalize_options(self):
87 pass
88
89 def get_command_name(self):
90 return 'uninstall'
91
92 def run(self):
93 f = None
94 self.ensure_filename('manifest')
95 try:
96 try:
97 if not self.manifest:
98 raise DistutilsFileError('Pass manifest with \
99--manifest=file')
100 f = open(self.manifest)
101 files = [file.strip() for file in f]
102 except IOError, e:
103 raise DistutilsFileError('unable to open install manifest: %s',
104 str(e))
105 finally:
106 if f:
107 f.close()
108
109 for file in files:
110 if os.path.isfile(file) or os.path.islink(file):
111 info('removing %s' % repr(file))
112 if not self.dry_run:
113 try:
114 os.unlink(file)
115 except OSError, e:
116 warn('could not delete: %s' % repr(file))
117 elif not os.path.isdir(file):
118 info('skipping %s' % repr(file))
119
120 dirs = set()
121 for file in reversed(sorted(files)):
122 dir = os.path.dirname(file)
123 if dir not in dirs and os.path.isdir(dir) \
124 and len(os.listdir(dir)) == 0:
125 dirs.add(dir)
126
127 # Only nuke empty Python library directories, else we could destroy
128 # e.g. locale directories we're the only app with a .mo installed for
129
130 if dir.find('site-packages/') > 0:
131 info('removing %s' % repr(dir))
132 if not self.dry_run:
133 try:
134 os.rmdir(dir)
135 except OSError, e:
136 warn('could not remove directory: %s'
137 % str(e))
138 else:
139 info('skipping empty directory %s' % repr(dir))
140
141
142class InstallData(install_data):
143
144 def run(self):
145 self.data_files.extend(self._find_mo_files())
146 install_data.run(self)
147 if not self.distribution.without_icon_cache:
148 self._update_icon_cache()
149
150 # We should do this on uninstall too
151
152 def _update_icon_cache(self):
153 info('running gtk-update-icon-cache')
154 try:
155 subprocess.call(['gtk-update-icon-cache', '-q', '-f', '-t',
156 os.path.join(self.install_dir,
157 'share/icons/hicolor')])
158 except Exception, e:
159 warn('updating the GTK icon cache failed: %s' % str(e))
160
161 def _find_mo_files(self):
162 data_files = []
163
164 if not self.distribution.without_gettext:
165 for mo in glob.glob(os.path.join(MO_DIR, '*', 'LC_MESSAGES',
166 'a4.mo')):
167 lang = \
168 os.path.basename(os.path.dirname(os.path.dirname(mo)))
169 dest = os.path.join('share', 'locale', lang,
170 'LC_MESSAGES')
171 data_files.append((dest, [mo]))
172
173 return data_files
174
175
176if platform.system() == 'FreeBSD':
177 man_dir = 'man'
178else:
179 man_dir = 'share/man'
180
181setup(
182 name='A4',
183 version=__version__,
184 description='A cool tool to create amazing presentations',
185 author='A4 Developers',
186 author_email='a4-dev@lists.launchpad.net',
187 url='https://launchpad.net/a4',
188 license='GNU GPL3',
189 packages=['a4lib'],
190 scripts=['a4'],
191 data_files=[('share/a4/data', ['data/window_main.glade']),
192 ('share/a4/tests/images',
193 ['tests/images/A4_nested_transforms.svg',
194 'tests/images/rotations.svg', 'tests/images/roi.svg']),
195 (os.path.join(man_dir, 'man1'), ['data/a4.1']),
196 ('share/applications', ['data/a4.desktop']),
197 ('share/pixmaps', ['data/a4.png'])],
198 cmdclass={'build': BuildData, 'install_data': InstallData,
199 'uninstall': Uninstall},
200 distclass=CustomDist,
201 )

Subscribers

People subscribed via source and target branches