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

Revision 3175, 11.5 kB (checked in by luis, 5 years ago)

- Moved msgfmt.py from umitCore to utils/msgfmt.py (External libs now lives on utils/ )
- Added header in Email (all files have enviroment path )
- Added umit menu (xpm format) - necessary for alternatives window managers, like fluxbox, etc
- Added new files to manifest file
- Fixed deletion *.mo files in sdist (overwrite sdist.run ) and add xpm file to data_files - setup.py

  • 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 utils 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, '*.xpm')) +
74                             glob(os.path.join(pixmaps_dir, 'umit.o*'))),
75
76               (config_dir, [os.path.join(config_dir, 'umit.conf')] +
77                            [os.path.join(config_dir, 'scan_profile.usp')] +
78                            [os.path.join(config_dir, 'umit_version')] +
79                            glob(os.path.join(config_dir, '*.xml'))+
80                            glob(os.path.join(config_dir, '*.txt'))),
81
82               (misc_dir, glob(os.path.join(misc_dir, '*.dmp'))), 
83
84               (icons_dir, glob(os.path.join('share', 'icons', 'umit',
85                                             '*.ico'))+
86                           glob(os.path.join('share', 'icons', 'umit', 
87                                             '*.png'))),
88
89               (docs_dir, glob(os.path.join(docs_dir, '*.html'))+
90                          glob(os.path.join(docs_dir,
91                                            'comparing_results', '*.xml'))+
92                          glob(os.path.join(docs_dir,
93                                            'profile_editor', '*.xml'))+
94                          glob(os.path.join(docs_dir,
95                                            'scanning', '*.xml'))+
96                          glob(os.path.join(docs_dir,
97                                            'searching', '*.xml'))+
98                          glob(os.path.join(docs_dir,
99                                            'wizard', '*.xml'))+
100                          glob(os.path.join(docs_dir,
101                                            'screenshots', '*.png')))]
102
103# Add i18n files to data_files list
104os.path.walk(locale_dir, mo_find, data_files)
105
106
107################################################################################
108# Distutils subclasses
109
110class umit_build(build):
111    def delete_mo_files(self):
112        """ Remove *.mo files """
113        tmp = [] 
114        os.path.walk(locale_dir, mo_find, tmp)
115        for (path, t) in tmp:
116            os.remove(t[0])
117    def build_mo_files(self):
118        """Build mo files from po and put it into LC_MESSAGES """
119        tmp = [] 
120        os.path.walk(locale_dir, po_find, tmp)
121        for (path, t) in tmp:
122            full_path = os.path.join(path , "LC_MESSAGES", "umit.mo")
123            self.mkpath(os.path.dirname(full_path))
124            self.announce("Compiling %s -> %s" % (t[0],full_path))
125            msgfmt.make(t[0], full_path, False)
126        # like guess
127        os.path.walk(locale_dir, mo_find, data_files)
128    def run(self):
129        self.delete_mo_files()
130        self.build_mo_files()
131        build.run(self)
132
133
134
135
136class umit_install(install):
137    def run(self):
138        # Add i18n files to data_files list
139        os.path.walk(locale_dir, mo_find, data_files)
140        install.run(self)
141
142        self.set_perms()
143        self.set_modules_path()
144        self.fix_paths()
145        self.create_uninstaller()
146        self.finish_banner()
147
148    def create_uninstaller(self):
149        uninstaller_filename = os.path.join(self.install_scripts,
150                                            "uninstall_umit")
151        uninstaller = """#!/usr/bin/env python
152import os, os.path, sys
153
154print
155print '%(line)s Uninstall Umit %(version)s %(line)s'
156print
157
158answer = raw_input('Are you sure that you want to completly uninstall \
159Umit %(version)s? (yes/no) ')
160
161if answer != 'yes' and answer != 'y':
162    sys.exit(0)
163
164print
165print '%(line)s Uninstalling Umit %(version)s... %(line)s'
166print
167""" % {'version':VERSION, 'line':'-'*10}
168
169        for output in self.get_outputs():
170            uninstaller += "print 'Removing %s...'\n" % output
171            uninstaller += "if os.path.exists('%s'): os.remove('%s')\n" % \
172                        (output, output)
173
174        uninstaller += "print 'Removing uninstaller itself...'\n"
175        uninstaller += "os.remove('%s')\n" % uninstaller_filename
176
177        uninstaller_file = open(uninstaller_filename, 'w')
178        uninstaller_file.write(uninstaller)
179        uninstaller_file.close()
180
181        # Set exec bit for uninstaller
182        mode = ((os.stat(uninstaller_filename)[ST_MODE]) | 0555) & 07777
183        os.chmod(uninstaller_filename, mode)
184
185    def set_modules_path(self):
186        umit = os.path.join(self.install_scripts, "umit")
187        modules = self.install_lib
188
189        re_sys = re.compile("^import sys$")
190
191        ufile = open(umit, "r")
192        ucontent = ufile.readlines()
193        ufile.close()
194
195        uline = None
196        for line in xrange(len(ucontent)):
197            if re_sys.match(ucontent[line]):
198                uline = line + 1
199                break
200
201        ucontent.insert(uline, "sys.path.append('%s')\n" % modules)
202
203        ufile = open(umit, "w")
204        ufile.writelines(ucontent)
205        ufile.close()
206
207    def set_perms(self):
208        re_bin = re.compile("(bin)")
209        for output in self.get_outputs():
210            if re_bin.findall(output):
211                continue
212
213            if os.path.isdir(output):
214                os.chmod(output, S_IRWXU | \
215                                 S_IRGRP | \
216                                 S_IXGRP | \
217                                 S_IROTH | \
218                                 S_IXOTH)
219            else:
220                os.chmod(output, S_IRWXU | \
221                                 S_IRGRP | \
222                                 S_IROTH)
223
224
225    def fix_paths(self):
226        interesting_paths = {"CONFIG_DIR":config_dir,
227                             "DOCS_DIR":docs_dir,
228                             "LOCALE_DIR":locale_dir,
229                             "MISC_DIR":misc_dir,
230                             "PIXMAPS_DIR":pixmaps_dir,
231                             "ICONS_DIR":icons_dir}
232
233        pcontent = ""
234        paths_file = os.path.join("umitCore", "BasePaths.py")
235        installed_files = self.get_outputs()
236       
237        # Finding where the Paths.py file was installed.
238        for f in installed_files:
239            if re.findall("(%s)" % re.escape(paths_file), f):
240                paths_file = f
241                pf = open(paths_file)
242                pcontent = pf.read()
243                pf.close()
244                break
245
246        for path in interesting_paths:
247            for f in installed_files:
248                result = re.findall("(.*%s)" %\
249                                    re.escape(interesting_paths[path]),
250                                    f)
251                if len(result) == 1:
252                    result = result[0]
253                    pcontent = re.sub("%s\s+=\s+.+" % path,
254                                      "%s = \"%s\"" % (path, result),
255                                      pcontent)
256                    break
257
258        pf = open(paths_file, "w")
259        pf.write(pcontent)
260        pf.close()
261
262    def finish_banner(self):
263        print 
264        print "%s Thanks for using Umit %s %s" % \
265              ("#"*10, VERSION, "#"*10)
266        print
267
268
269
270class umit_sdist(sdist):
271    def read_manifest_no_mo(self):
272        """ Read Manifest without mo files """
273        manifest = open(self.manifest)
274        while 1:
275            line = manifest.readline()
276            if line == '':
277                break 
278            if line[-1] == '\n':
279                line = line[0:-1]
280            if line.find("umit.mo")!=-1:
281                self.filelist.files.remove(line)
282    def run(self):
283        self.keep_temp = 1
284        from distutils.filelist import FileList
285        #Rewrite: sdist.run(self)
286        self.manifest = "MANIFEST"
287        self.filelist = FileList()
288        self.check_metadata()   
289        self.get_file_list()
290        ## Exclude mo files:
291        self.read_manifest_no_mo()
292        if self.manifest_only:
293            return 
294        self.make_distribution()
295       
296        self.finish_banner()
297   
298    def finish_banner(self):
299        print 
300        print "%s The packages for Umit %s are in ./dist %s" % \
301              ("#" * 10, VERSION, "#" * 10)
302        print
303
304##################### Umit banner ########################
305print
306print "%s Umit for Linux %s %s" % ("#" * 10, VERSION, "#" * 10)
307print
308##########################################################
309
310setup(name = 'umit',
311      license = 'GNU GPL (version 2 or later)',
312      url = 'http://www.umitproject.org',
313      download_url = 'http://www.umitproject.org',
314      author = 'Adriano Monteiro & Cleber Rodrigues',
315      author_email = 'adriano@umitproject.org, cleber@globalred.com.br',
316      maintainer = 'Adriano Monteiro',
317      maintainer_email = 'adriano@gmail.com',
318      description = """Umit is a network scanning frontend, developed in \
319Python and GTK and was started with the sponsoring of Google's Summer \
320of Code.""",
321      long_description = """The project goal is to develop a network scanning \
322frontend that is really useful for advanced users and easy to be used by \
323newbies. With Umit, a network admin could create scan profiles for faster and \
324easier network scanning or even compare scan results to easily see any \
325changes. A regular user will also be able to construct powerful scans with \
326Umit command creator wizards.""",
327      version = VERSION,
328      scripts = ['umit'],
329      packages = ['', 'umitCore', 'umitGUI', 'higwidgets'],
330      data_files = data_files,
331      cmdclass = {"install":umit_install,
332                  "build":umit_build,
333                  "sdist":umit_sdist})
Note: See TracBrowser for help on using the browser.