root/branch/umitweb-ng/install_scripts/unix/setup.py @ 4759

Revision 4759, 14.8 kB (checked in by rcarvalho, 4 years ago)

Merged revisions 4158-4168 via svnmerge from
http://svn.umitproject.org/svnroot/umit/trunk

........

r4158 | gpolo | 2009-02-21 17:39:10 -0300 (Sáb, 21 Fev 2009) | 1 line


Bump to 1.0beta2

........

r4159 | gpolo | 2009-02-21 18:13:06 -0300 (Sáb, 21 Fev 2009) | 1 line


Make it work under Windows too (os.uname is not available there).

........

r4160 | gpolo | 2009-02-21 18:15:04 -0300 (Sáb, 21 Fev 2009) | 1 line


Revert UMIT_DEVELOPMENT change

........

r4161 | gpolo | 2009-02-21 18:19:13 -0300 (Sáb, 21 Fev 2009) | 1 line


Reverting other things that shouldn't have been committed.

........

r4162 | gpolo | 2009-02-21 18:25:18 -0300 (Sáb, 21 Fev 2009) | 1 line


milestone

........

r4163 | luis | 2009-02-21 18:35:29 -0300 (Sáb, 21 Fev 2009) | 1 line


Including utils to unix setup -- generate mo files

........

r4164 | gpolo | 2009-02-21 18:42:06 -0300 (Sáb, 21 Fev 2009) | 1 line


umits -> umit

........

r4165 | gpolo | 2009-02-21 18:44:22 -0300 (Sáb, 21 Fev 2009) | 1 line


Include .db files

........

r4166 | luis | 2009-02-21 18:56:15 -0300 (Sáb, 21 Fev 2009) | 1 line


including some missing files at unix tarball

........

r4167 | luis | 2009-02-21 19:00:22 -0300 (Sáb, 21 Fev 2009) | 1 line


include missing images at unix tarball

........

r4168 | gpolo | 2009-02-21 20:04:33 -0300 (Sáb, 21 Fev 2009) | 1 line


Fixed ticket #214: Bugs while reporting bugs

........

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