root/trunk/setup.py @ 4273

Revision 4273, 13.3 kB (checked in by gpolo, 4 years ago)

typo fix

  • 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
22import os
23import re
24import sys
25from stat import *
26from glob import glob
27
28from distutils.core import setup
29from distutils.command.install import install
30from distutils.command.sdist import sdist
31from distutils.command.build import build
32from distutils import log, dir_util
33
34from umit.core.Version import VERSION
35from utils import msgfmt
36
37from install_scripts.common import BIN_DIRNAME, PIXMAPS_DIR, ICONS_DIR, \
38        DOCS_DIR, LOCALE_DIR, CONFIG_DIR, MISC_DIR, SQL_DIR
39
40py2exe_cmdclass = py2exe_options = py2app_options = None
41if 'py2exe' in sys.argv:
42    from install_scripts.windows.py2exe_setup import py2exe_cmdclass, \
43            py2exe_options
44if 'py2app' in sys.argv:
45    from install_scripts.macosx.py2app_setup import py2app_options
46
47
48def extension_find(result, dirname, fnames, suffix):
49    files = []
50    for f in fnames:
51        p = os.path.join(dirname, f)
52        if os.path.isfile(p) and f.endswith(suffix):
53            files.append(p)
54
55    if files:
56        result.append((dirname, files))
57
58def mo_find(result, dirname, fnames):
59    return extension_find(result, dirname, fnames, ".mo")
60
61def po_find(result, dirname, fnames):
62    return extension_find(result, dirname, fnames, ".po")
63
64
65###############################################################################
66# Installation variables
67
68# What to copy to the destiny
69# Here, we define what should be put inside the directories set in the
70# beginning of this file. This list contain tuples where the first element
71# contains a path to where the other elements of the tuple should be installed.
72# The first element is a path in the INSTALLATION PREFIX, and the other
73# elements are the path in the source base.
74# Ex: [("share/pixmaps", "/umit/trunk/share/pixmaps/test.png")]
75# This will install the test.png file in the installation dir share/pixmaps.
76svg = glob(os.path.join('share', 'pixmaps', '*.svg'))
77data_files = [
78        (PIXMAPS_DIR,
79            glob(os.path.join(PIXMAPS_DIR, '*.svg')) +
80            glob(os.path.join(PIXMAPS_DIR, '*.png')) +
81            glob(os.path.join(PIXMAPS_DIR, '*.xpm')) +
82            glob(os.path.join(PIXMAPS_DIR, 'umit.o*'))),
83
84        (CONFIG_DIR,
85            [os.path.join(CONFIG_DIR, 'umit.conf')] +
86            [os.path.join(CONFIG_DIR, 'scan_profile.usp')] +
87            [os.path.join(CONFIG_DIR, 'umit_version')] +
88            [os.path.join(CONFIG_DIR, 'umitng.db')] +
89            [os.path.join(CONFIG_DIR, 'timeline-settings.conf')] +
90            [os.path.join(CONFIG_DIR, 'tl_colors_evt_std.conf')] +
91            [os.path.join(CONFIG_DIR, 'scheduler-schemas.conf')] +
92            [os.path.join(CONFIG_DIR, 'scheduler-profiles.conf')] +
93            [os.path.join(CONFIG_DIR, 'scheduler.log')] +
94            [os.path.join(CONFIG_DIR, 'smtp-schemas.conf')] +
95            glob(os.path.join(CONFIG_DIR, '*.xml'))+
96            glob(os.path.join(CONFIG_DIR, '*.txt'))),
97
98        # umit.db SQL
99        (SQL_DIR, glob(os.path.join(SQL_DIR, '*.sql'))),
100
101        (MISC_DIR, glob(os.path.join(MISC_DIR, '*.dmp'))),
102
103        # Radialnet
104        (os.path.join(PIXMAPS_DIR, 'radialnet', 'application'),
105            glob(os.path.join(PIXMAPS_DIR, 'radialnet', 'application',
106                '*.png'))),
107        (os.path.join(PIXMAPS_DIR, 'radialnet', 'icons'),
108            glob(os.path.join(PIXMAPS_DIR, 'radialnet', 'icons','*.png'))),
109
110        # Network Inventory
111        (os.path.join(PIXMAPS_DIR, 'networkinventory'),
112            glob(os.path.join(PIXMAPS_DIR, 'networkinventory', '*.png'))),
113
114        # InterfaceEditor
115        (os.path.join(PIXMAPS_DIR, 'uie'),
116            glob(os.path.join(PIXMAPS_DIR, 'uie', '*.png'))),
117
118        (ICONS_DIR,
119            glob(os.path.join('share', 'icons', 'umit', '*.ico')) +
120            glob(os.path.join('share', 'icons', 'umit', '*.png'))),
121
122        (DOCS_DIR,
123            glob(os.path.join(DOCS_DIR, '*.html')) +
124            glob(os.path.join(DOCS_DIR, 'comparing_results', '*.xml')) +
125            glob(os.path.join(DOCS_DIR, 'profile_editor', '*.xml')) +
126            glob(os.path.join(DOCS_DIR, 'scanning', '*.xml')) +
127            glob(os.path.join(DOCS_DIR, 'searching', '*.xml')) +
128            glob(os.path.join(DOCS_DIR, 'wizard', '*.xml')) +
129            glob(os.path.join(DOCS_DIR, 'scheduler', '*.xml')) +
130            glob(os.path.join(DOCS_DIR, 'smtpsetup', '*.xml')) +
131            glob(os.path.join(DOCS_DIR, 'screenshots', '*.png')))]
132
133# Add i18n files to data_files list
134os.path.walk(LOCALE_DIR, mo_find, data_files)
135
136
137##############################################################################
138# Distutils subclasses
139
140class umit_build(build):
141
142    def delete_mo_files(self):
143        """ Remove *.mo files """
144        tmp = []
145        os.path.walk(LOCALE_DIR, mo_find, tmp)
146        for (path, t) in tmp:
147            os.remove(t[0])
148
149    def build_mo_files(self):
150        """Build mo files from po and put it into LC_MESSAGES """
151        tmp = []
152        os.path.walk(LOCALE_DIR, po_find, tmp)
153        for (path, t) in tmp:
154            full_path = os.path.join(path , "LC_MESSAGES", "umit.mo")
155            self.mkpath(os.path.dirname(full_path))
156            self.announce("Compiling %s -> %s" % (t[0],full_path))
157            msgfmt.make(t[0], full_path, False)
158        # like guess
159        os.path.walk(LOCALE_DIR, mo_find, data_files)
160
161    def run(self):
162        self.delete_mo_files()
163        self.build_mo_files()
164        build.run(self)
165
166
167class umit_install(install):
168
169    def run(self):
170        # Add i18n files to data_files list
171        os.path.walk(LOCALE_DIR, mo_find, data_files)
172        install.run(self)
173
174        self.set_perms()
175        self.set_modules_path()
176        self.fix_paths()
177        self.create_uninstaller()
178        self.finish_banner()
179
180    def create_uninstaller(self):
181        uninstaller_filename = os.path.join(
182                self.install_scripts, "uninstall_umit")
183        uninstaller = """#!/usr/bin/env python
184import os, os.path, sys
185
186print
187print '%(line)s Uninstall Umit %(version)s %(line)s'
188print
189
190answer = raw_input('Are you sure that you want to completly uninstall \
191Umit %(version)s? (yes/no) ')
192
193if answer != 'yes' and answer != 'y':
194    sys.exit(0)
195
196print
197print '%(line)s Uninstalling Umit %(version)s... %(line)s'
198print
199""" % {'version':VERSION, 'line':'-'*10}
200
201        for output in self.get_outputs():
202            uninstaller += "print 'Removing %s...'\n" % output
203            uninstaller += "if os.path.exists('%s'): os.remove('%s')\n" % \
204                        (output, output)
205
206        uninstaller += "print 'Removing uninstaller itself...'\n"
207        uninstaller += "os.remove('%s')\n" % uninstaller_filename
208
209        uninstaller_file = open(uninstaller_filename, 'w')
210        uninstaller_file.write(uninstaller)
211        uninstaller_file.close()
212
213        # Set exec bit for uninstaller
214        mode = ((os.stat(uninstaller_filename)[ST_MODE]) | 0555) & 07777
215        os.chmod(uninstaller_filename, mode)
216
217    def set_modules_path(self):
218        umit = os.path.join(self.install_scripts, "umit")
219        modules = self.install_lib
220
221        re_sys = re.compile("^import sys$")
222
223        ufile = open(umit, "r")
224        ucontent = ufile.readlines()
225        ufile.close()
226
227        uline = None
228        for line in xrange(len(ucontent)):
229            if re_sys.match(ucontent[line]):
230                uline = line + 1
231                break
232
233        ucontent.insert(uline, "sys.path.insert(0,'%s')\n" % modules )
234
235        ufile = open(umit, "w")
236        ufile.writelines(ucontent)
237        ufile.close()
238
239    def set_perms(self):
240        re_bin = re.compile("(bin)")
241        for output in self.get_outputs():
242            if re_bin.findall(output):
243                continue
244
245            if os.path.isdir(output):
246                os.chmod(output, S_IRWXU | \
247                                 S_IRGRP | \
248                                 S_IXGRP | \
249                                 S_IROTH | \
250                                 S_IXOTH)
251            else:
252                os.chmod(output, S_IRWXU | \
253                                 S_IRGRP | \
254                                 S_IROTH)
255
256    def fix_paths(self):
257        interesting_paths = {"CONFIG_DIR": CONFIG_DIR,
258                             "DOCS_DIR": DOCS_DIR,
259                             "LOCALE_DIR": LOCALE_DIR,
260                             "MISC_DIR": MISC_DIR,
261                             "PIXMAPS_DIR": PIXMAPS_DIR,
262                             "ICONS_DIR": ICONS_DIR}
263
264        pcontent = ""
265        paths_file = os.path.join("umit", "core", "BasePaths.py")
266        installed_files = self.get_outputs()
267
268        # Finding where the Paths.py file was installed.
269        for f in installed_files:
270            if re.findall("(%s)" % re.escape(paths_file), f):
271                paths_file = f
272                pf = open(paths_file)
273                pcontent = pf.read()
274                pf.close()
275                break
276
277        for path in interesting_paths:
278            for f in installed_files:
279                result = re.findall("(.*%s)" %\
280                                    re.escape(interesting_paths[path]),
281                                    f)
282                if len(result) == 1:
283                    result = result[0]
284                    pcontent = re.sub("%s\s+=\s+.+" % path,
285                                      "%s = \"%s\"" % (path, result),
286                                      pcontent)
287                    break
288
289        pf = open(paths_file, "w")
290        pf.write(pcontent)
291        pf.close()
292
293    def finish_banner(self):
294        print
295        print "%s Thanks for using Umit %s %s" % \
296              ("#"*10, VERSION, "#"*10)
297        print
298
299
300class umit_sdist(sdist):
301
302    def read_manifest_no_mo(self):
303        """Read Manifest without mo file."""
304        for line in open(self.manifest):
305            if not line:
306                break
307
308            if line[-1] == '\n':
309                line = line[:-1]
310            if line.find('umit.mo') != -1:
311                self.filelist.files.remove(line)
312
313    def run(self):
314        from distutils.filelist import FileList
315        self.keep_temp = 1
316        #Rewrite: sdist.run(self)
317        self.manifest = "MANIFEST"
318        self.filelist = FileList()
319        self.check_metadata()
320        self.get_file_list()
321        ## Exclude mo files:
322        self.read_manifest_no_mo()
323        if self.manifest_only:
324            return
325        self.make_distribution()
326
327        self.finish_banner()
328
329    def finish_banner(self):
330        print
331        print "%s The packages for Umit %s are in ./dist %s" % \
332              ("#" * 10, VERSION, "#" * 10)
333        print
334
335
336##################### Umit banner ########################
337print
338print "%s Umit for Linux %s %s" % ("#" * 10, VERSION, "#" * 10)
339print
340##########################################################
341
342
343cmdclasses = {
344        "install": umit_install,
345        "build": umit_build,
346        "sdist": umit_sdist}
347
348if py2exe_cmdclass:
349    cmdclasses.update(py2exe_cmdclass)
350
351standard_options = dict(
352        name = 'umit',
353        license = 'GNU GPL (version 2 or later)',
354        url = 'http://www.umitproject.org',
355        download_url = 'http://www.umitproject.org',
356        author = 'Adriano Monteiro & Cleber Rodrigues',
357        author_email = 'adriano@umitproject.org, cleber@globalred.com.br',
358        maintainer = 'Adriano Monteiro',
359        maintainer_email = 'adriano@umitproject.org',
360        description = ("Umit is a network scanning frontend, developed in "
361            "Python and GTK and was started with the sponsoring of "
362            "Google's Summer of Code."),
363        long_description = ("The project goal is to develop a network "
364            "scanning frontend that is really useful for advanced users and "
365            "easy to be used by newbies. With Umit, a network admin can "
366            "create scan profiles for faster and easier network scanning "
367            "or even compare scan results to easily see any changes. "
368            "A regular user will also be able to construct powerful scans "
369            "with Umit command creator wizards."),
370        version = VERSION,
371        scripts = [
372            os.path.join(BIN_DIRNAME, 'umit'),
373            os.path.join(BIN_DIRNAME, 'umit_scheduler.py')],
374        packages = [
375            'umit', 'umit.core', 'umit.core.radialnet', 'umit.db',
376            'umit.gui', 'umit.gui.radialnet', 'umit.interfaceeditor',
377            'umit.interfaceeditor.selectborder', 'umit.inventory',
378            'umit.plugin', 'higwidgets'],
379        data_files = data_files,
380        cmdclass = cmdclasses
381        )
382
383if py2exe_options:
384    standard_options.update(py2exe_options)
385
386if py2app_options:
387    standard_options.update(py2app_options)
388
389setup(**standard_options)
Note: See TracBrowser for help on using the browser.