root/trunk/install_scripts/unix/setup.py @ 3174

Revision 3174, 10.9 kB (checked in by luis, 5 years ago)

- Fixed icons install (and in uninstall_umit)
- Added functions to build mo files 'on the fly'
- Remove mo files from sdist

(this changes it's necessary to debian package)

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2#
3# Copyright (C) 2005-2006 Insecure.Com LLC.
4# Copyright (C) 2007-2008 Adriano Monteiro Marques
5#
6# Author: Adriano Monteiro Marques <adriano@umitproject.org>
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22import sys
23import os
24import os.path
25import re
26
27from distutils.core import setup
28from distutils.command.install import install
29from distutils.command.sdist import sdist
30from distutils.command.build import build
31from distutils import log, dir_util
32
33from glob import glob
34from stat import *
35
36from umitCore.Version import VERSION
37from umitCore import msgfmt
38# Directories for POSIX operating systems
39# These are created after a "install" or "py2exe" command
40# These directories are relative to the installation or dist directory
41# Ex: python setup.py install --prefix=/tmp/umit
42# Will create the directory /tmp/umit with the following directories
43pixmaps_dir = os.path.join('share', 'pixmaps', 'umit')
44icons_dir = os.path.join('share', 'icons', 'umit')
45locale_dir = os.path.join('share', 'locale')
46config_dir = os.path.join('share', 'umit', 'config')
47docs_dir = os.path.join('share', 'doc', 'umit')
48misc_dir = os.path.join('share', 'umit', 'misc')
49
50def extension_find(result, dirname, fnames, suffix):
51    files = []
52    for f in fnames:
53        p = os.path.join(dirname, f)
54        if os.path.isfile(p) and f.endswith(suffix):
55            files.append(p)
56       
57    if files:
58        result.append((dirname, files))
59
60def mo_find(result, dirname, fnames):
61    return extension_find(result, dirname, fnames, ".mo")
62
63def po_find(result, dirname, fnames):
64    return extension_find(result, dirname, fnames, ".po")
65
66
67################################################################################
68# Installation variables
69
70svg = glob(os.path.join('share', 'pixmaps', '*.svg'))
71data_files = [ (pixmaps_dir, glob(os.path.join(pixmaps_dir, '*.svg')) +
72                             glob(os.path.join(pixmaps_dir, '*.png')) +
73                             glob(os.path.join(pixmaps_dir, 'umit.o*'))),
74
75               (config_dir, [os.path.join(config_dir, 'umit.conf')] +
76                            [os.path.join(config_dir, 'scan_profile.usp')] +
77                            [os.path.join(config_dir, 'umit_version')] +
78                            glob(os.path.join(config_dir, '*.xml'))+
79                            glob(os.path.join(config_dir, '*.txt'))),
80
81               (misc_dir, glob(os.path.join(misc_dir, '*.dmp'))), 
82
83               (icons_dir, glob(os.path.join('share', 'icons', 'umit',
84                                             '*.ico'))+
85                           glob(os.path.join('share', 'icons', 'umit', 
86                                             '*.png'))),
87
88               (docs_dir, glob(os.path.join(docs_dir, '*.html'))+
89                          glob(os.path.join(docs_dir,
90                                            'comparing_results', '*.xml'))+
91                          glob(os.path.join(docs_dir,
92                                            'profile_editor', '*.xml'))+
93                          glob(os.path.join(docs_dir,
94                                            'scanning', '*.xml'))+
95                          glob(os.path.join(docs_dir,
96                                            'searching', '*.xml'))+
97                          glob(os.path.join(docs_dir,
98                                            'wizard', '*.xml'))+
99                          glob(os.path.join(docs_dir,
100                                            'screenshots', '*.png')))]
101
102# Add i18n files to data_files list
103os.path.walk(locale_dir, mo_find, data_files)
104
105
106################################################################################
107# Distutils subclasses
108
109class umit_build(build):
110    def build_mo_files(self):
111        """Build mo files from po and put it into LC_MESSAGES """
112        tmp = [] 
113        os.path.walk(locale_dir, po_find, tmp)
114        for (path, t) in tmp:
115            full_path = os.path.join(path , "LC_MESSAGES", "umit.mo")
116            self.mkpath(os.path.dirname(full_path))
117            self.announce("Compiling %s -> %s" % (t[0],full_path))
118            msgfmt.make(t[0], full_path, False)
119        # like guess
120        os.path.walk(locale_dir, mo_find, data_files)
121    def run(self):
122        self.build_mo_files()
123        build.run(self)
124
125
126
127
128class umit_install(install):
129    def run(self):
130        # Add i18n files to data_files list
131        os.path.walk(locale_dir, mo_find, data_files)
132        install.run(self)
133
134        self.set_perms()
135        self.set_modules_path()
136        self.fix_paths()
137        self.create_uninstaller()
138        self.finish_banner()
139
140    def create_uninstaller(self):
141        uninstaller_filename = os.path.join(self.install_scripts,
142                                            "uninstall_umit")
143        uninstaller = """#!/usr/bin/env python
144import os, os.path, sys
145
146print
147print '%(line)s Uninstall Umit %(version)s %(line)s'
148print
149
150answer = raw_input('Are you sure that you want to completly uninstall \
151Umit %(version)s? (yes/no) ')
152
153if answer != 'yes' and answer != 'y':
154    sys.exit(0)
155
156print
157print '%(line)s Uninstalling Umit %(version)s... %(line)s'
158print
159""" % {'version':VERSION, 'line':'-'*10}
160
161        for output in self.get_outputs():
162            uninstaller += "print 'Removing %s...'\n" % output
163            uninstaller += "if os.path.exists('%s'): os.remove('%s')\n" % \
164                        (output, output)
165
166        uninstaller += "print 'Removing uninstaller itself...'\n"
167        uninstaller += "os.remove('%s')\n" % uninstaller_filename
168
169        uninstaller_file = open(uninstaller_filename, 'w')
170        uninstaller_file.write(uninstaller)
171        uninstaller_file.close()
172
173        # Set exec bit for uninstaller
174        mode = ((os.stat(uninstaller_filename)[ST_MODE]) | 0555) & 07777
175        os.chmod(uninstaller_filename, mode)
176
177    def set_modules_path(self):
178        umit = os.path.join(self.install_scripts, "umit")
179        modules = self.install_lib
180
181        re_sys = re.compile("^import sys$")
182
183        ufile = open(umit, "r")
184        ucontent = ufile.readlines()
185        ufile.close()
186
187        uline = None
188        for line in xrange(len(ucontent)):
189            if re_sys.match(ucontent[line]):
190                uline = line + 1
191                break
192
193        ucontent.insert(uline, "sys.path.append('%s')\n" % modules)
194
195        ufile = open(umit, "w")
196        ufile.writelines(ucontent)
197        ufile.close()
198
199    def set_perms(self):
200        re_bin = re.compile("(bin)")
201        for output in self.get_outputs():
202            if re_bin.findall(output):
203                continue
204
205            if os.path.isdir(output):
206                os.chmod(output, S_IRWXU | \
207                                 S_IRGRP | \
208                                 S_IXGRP | \
209                                 S_IROTH | \
210                                 S_IXOTH)
211            else:
212                os.chmod(output, S_IRWXU | \
213                                 S_IRGRP | \
214                                 S_IROTH)
215
216
217    def fix_paths(self):
218        interesting_paths = {"CONFIG_DIR":config_dir,
219                             "DOCS_DIR":docs_dir,
220                             "LOCALE_DIR":locale_dir,
221                             "MISC_DIR":misc_dir,
222                             "PIXMAPS_DIR":pixmaps_dir,
223                             "ICONS_DIR":icons_dir}
224
225        pcontent = ""
226        paths_file = os.path.join("umitCore", "BasePaths.py")
227        installed_files = self.get_outputs()
228       
229        # Finding where the Paths.py file was installed.
230        for f in installed_files:
231            if re.findall("(%s)" % re.escape(paths_file), f):
232                paths_file = f
233                pf = open(paths_file)
234                pcontent = pf.read()
235                pf.close()
236                break
237
238        for path in interesting_paths:
239            for f in installed_files:
240                result = re.findall("(.*%s)" %\
241                                    re.escape(interesting_paths[path]),
242                                    f)
243                if len(result) == 1:
244                    result = result[0]
245                    pcontent = re.sub("%s\s+=\s+.+" % path,
246                                      "%s = \"%s\"" % (path, result),
247                                      pcontent)
248                    break
249
250        pf = open(paths_file, "w")
251        pf.write(pcontent)
252        pf.close()
253
254    def finish_banner(self):
255        print 
256        print "%s Thanks for using Umit %s %s" % \
257              ("#"*10, VERSION, "#"*10)
258        print
259
260
261
262class umit_sdist(sdist):
263    def delete_mo_files(self):
264        """ Remove *.mo files """
265        tmp = [] 
266        os.path.walk(locale_dir, mo_find, tmp)
267        for (path, t) in tmp:
268            os.remove(t[0])
269    def run(self):
270        self.keep_temp = 1
271        self.delete_mo_files()
272        sdist.run(self)
273        self.finish_banner()
274
275    def finish_banner(self):
276        print 
277        print "%s The packages for Umit %s are in ./dist %s" % \
278              ("#" * 10, VERSION, "#" * 10)
279        print
280
281##################### Umit banner ########################
282print
283print "%s Umit for Linux %s %s" % ("#" * 10, VERSION, "#" * 10)
284print
285##########################################################
286
287setup(name = 'umit',
288      license = 'GNU GPL (version 2 or later)',
289      url = 'http://www.umitproject.org',
290      download_url = 'http://www.umitproject.org',
291      author = 'Adriano Monteiro & Cleber Rodrigues',
292      author_email = 'adriano@umitproject.org, cleber@globalred.com.br',
293      maintainer = 'Adriano Monteiro',
294      maintainer_email = 'adriano@gmail.com',
295      description = """Umit is a network scanning frontend, developed in \
296Python and GTK and was started with the sponsoring of Google's Summer \
297of Code.""",
298      long_description = """The project goal is to develop a network scanning \
299frontend that is really useful for advanced users and easy to be used by \
300newbies. With Umit, a network admin could create scan profiles for faster and \
301easier network scanning or even compare scan results to easily see any \
302changes. A regular user will also be able to construct powerful scans with \
303Umit command creator wizards.""",
304      version = VERSION,
305      scripts = ['umit'],
306      packages = ['', 'umitCore', 'umitGUI', 'higwidgets'],
307      data_files = data_files,
308      cmdclass = {"install":umit_install,
309                  "build":umit_build,
310                  "sdist":umit_sdist})
Note: See TracBrowser for help on using the browser.