File: install.py

package info (click to toggle)
eric 3.6.2-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,308 kB
  • ctags: 8,668
  • sloc: python: 52,713; sh: 265; makefile: 47
file content (595 lines) | stat: -rw-r--r-- 19,312 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2002-2005 Detlev Offenbach <detlev@die-offenbachs.de>
#
# This is the install script for eric3. It is based on the
# build script found in the PyQt distribution. The original is 
# Copyright (c) 2002 Riverbank Computing Limited <info@riverbankcomputing.co.uk>

"""
Installation script for the eric3 IDE and all eric3 related tools.
"""

import sys
import os
import string
import re
import compileall
import glob
import shutil
import fnmatch
import distutils.sysconfig

# Define the globals.
progName = None
modDir = None
platBinDir = None
distDir = None
doCleanup = 1
cfg = {}

def usage(rcode = 2):
    """
    Display a usage message and exit.

    @param rcode the return code passed back to the calling process.
    """
    global progName, platBinDir, modDir, distDir

    print
    print "Usage:"
    print "    %s [-hxc] [-b dir] [-d dir] [-f file] [-i dir]" % (progName)
    print "where:"
    print "    -h        display this help message"
    print "    -b dir    where the binaries will be installed"
    print "              (default: %s)" % (platBinDir)
    print "    -d dir    where eric3 python files will be installed"
    print "              (default: %s)" % (modDir)
    print "    -f file   configuration file naming the various installation paths"
    if sys.platform <> "win32":
        print "    -i dir    temporary install prefix"
        print "              (default: %s)" % (distDir)
    print "    -x        don't perform dependency checks (use on your own risk)"
    print "    -c        don't cleanup old installation first"
    print
    print "The file given to the -f option must be valid Python code defining a"
    print "dictionary called 'cfg' with the keys 'ericDir', 'ericPixDir', 'ericIconDir',"
    print "'ericDTDDir', 'ericDocDir', 'ericExamplesDir', 'ericTranslationsDir',"
    print "'ericWizardsDir', 'bindir' and 'mdir'. These define the directories for the"
    print "installation of the various parts of eric3."

    sys.exit(rcode)


def initGlobals():
    """
    Sets the values of globals that need more than a simple assignment.
    """
    global platBinDir, modDir

    if sys.platform == "win32":
        platBinDir = sys.exec_prefix
    else:
        platBinDir = "/usr/local/bin"

    modDir = distutils.sysconfig.get_python_lib()


def copyToFile(name,text):
    """
    Copy a string to a file.

    @param name the name of the file.
    @param text the contents to copy to the file.
    """
    f = open(name,"w")
    f.write(text)
    f.close()


def wrapperName(dname,wfile):
    """
    Create the platform specific name for the wrapper script.
    
    @param dname name of the directory to place the wrapper into
    @param wfile basename (without extension) of the wrapper script
    @return the name of the wrapper script
    """
    if sys.platform == "win32":
        wname = dname + "\\" + wfile + ".bat"
    else:
        wname = dname + "/" + wfile

    return wname


def createPyWrapper(pydir,wfile):
    """
    Create an executable wrapper for a Python script.

    @param pydir the name of the directory where the Python script will eventually
        be installed
    @param wfile the basename of the wrapper
    @return the platform specific name of the wrapper
    """
    if sys.platform == "win32":
        wname = wfile + ".bat"
        wrapper = \
"""@%s\\pythonw %s\\%s.py %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9
""" % (platBinDir,pydir,wfile)
    elif sys.platform == "darwin":
        wname = wfile
        wrapper = \
"""#!/bin/sh

exec %sw %s/%s.py $*
""" % (sys.executable,pydir,wfile)
    else:
        wname = wfile
        wrapper = \
"""#!/bin/sh

exec %s %s/%s.py $*
""" % (sys.executable,pydir,wfile)

    copyToFile(wname,wrapper)
    os.chmod(wname,0755)

    return wname


def copyTree(src, dst, filters, excludeDirs=[]):
    """
    Copy Python, translation, documentation, wizards configuration,
    designer template files and DTDs of a directory tree.
    
    @param src name of the source directory
    @param dst name of the destination directory
    @param filters list of filter pattern determining the files to be copied
    @param excludeDirs list of (sub)directories to exclude from copying
    """
    names = os.listdir(src)
    for name in names:
        srcname = os.path.join(src, name)
        dstname = os.path.join(dst, name)
        for filter in filters:
            if fnmatch.fnmatch(srcname, filter):
                if not os.path.isdir(dst):
                    os.makedirs(dst)
                shutil.copy2(srcname, dstname)
                break
        else:
            if os.path.isdir(srcname) and not srcname in excludeDirs:
                copyTree(srcname, dstname, filters)


def cleanUp():
    """
    Uninstall the old eric files.
    """
    from eric3config import getConfig
    
    # Remove the wrapper scripts
    rem_wnames = ["eric3", "eric3-unittest", "eric3-helpviewer",
        "eric3-doc", "eric3-qregexp", "eric3-re", "eric3-api",
        "eric3-uipreviewer", "eric3-trpreviewer",
        "qtunittest", "helpviewer"]
    for rem_wname in rem_wnames:
        rwname = wrapperName(getConfig('bindir'),rem_wname)
        if os.path.exists(rwname):
            os.remove(rwname)
    
    # Cleanup our config file
    for name in ['eric3config.py', 'eric3config.pyc']:
        e3cfile = os.path.join(getConfig('mdir'), name)
        if os.path.exists(e3cfile):
            os.remove(e3cfile)
        
    # Cleanup the install directories
    for name in ['ericExamplesDir', 'ericDocDir', 'ericDTDDir',
                 'ericIconDir', 'ericPixDir', 'ericDir', 'ericTemplatesDir',
                 'ericOthersDir']:
        try:
            shutil.rmtree(getConfig(name), 1)
        except:
            pass
    
    # Cleanup translations
    for name in glob.glob(os.path.join(getConfig('ericTranslationsDir'), 'eric3_*.qm')):
        try:
            os.remove(name)
        except:
            pass


def installEric():
    """
    Actually perform the installation steps.
    """
    global distDir, doCleanup, cfg
    
    # Create the platform specific wrappers.
    wnames = []
    wnames.append(createPyWrapper(cfg['ericDir'],"eric3"))
    wnames.append(createPyWrapper(cfg['ericDir'],"eric3-unittest"))
    wnames.append(createPyWrapper(cfg['ericDir'],"eric3-helpviewer"))
    wnames.append(createPyWrapper(cfg['ericDir'],"eric3-doc"))
    wnames.append(createPyWrapper(cfg['ericDir'],"eric3-qregexp"))
    wnames.append(createPyWrapper(cfg['ericDir'],"eric3-re"))
    wnames.append(createPyWrapper(cfg['ericDir'],"eric3-api"))
    wnames.append(createPyWrapper(cfg['ericDir'],"eric3-uipreviewer"))
    wnames.append(createPyWrapper(cfg['ericDir'],"eric3-trpreviewer"))
    
    # Create a config file and delete the default one
    createConfig()

    # set install prefix, if not None
    #
    # ToDo: This has to be reworked, if there is a need
    #       for distDir on "win32".
    #       Don't use os.path.join because absolute paths
    #       seem to be assumed, but not assured.
    #       At least for linux, double slashes make no problems.
    #
    if distDir:
        for key in cfg.keys():
            cfg[key] = distDir + os.sep + cfg[key]
    
    if doCleanup:
        if distDir:
            shutil.rmtree(distDir, 1)
        else:
            cleanUp()

    # Install the files
    # make the install directories
    for key in cfg.keys():
        if not os.path.isdir(cfg[key]):
            os.makedirs(cfg[key])
    
    # copy the new sitecustomize.py
    shutil.copy('sitecustomize.py', cfg['mdir'])
    
    # copy the eric3 config file
    shutil.copy('eric3config.py', cfg['mdir'])
    
    # copy the various parts of eric3
    copyTree('eric', cfg['ericDir'], ['*.py', '*.pyc', '*.pyo'], 
        ['eric%sExamples' % os.sep])
    copyTree('eric%sDocumentation' % os.sep, cfg['ericDocDir'], ['*.html'])
    copyTree('eric%sWizards' % os.sep, cfg['ericWizardsDir'], ['*.e3w'])
    copyTree('eric%sDTDs' % os.sep, cfg['ericDTDDir'], ['*.dtd'])
    copyTree('eric', cfg['ericTranslationsDir'], ['*.qm'])
    copyTree('eric%sicons' % os.sep, cfg['ericIconDir'], ['*.png', 'LICENSE*.*'])
    copyTree('eric%spixmaps' % os.sep, cfg['ericPixDir'], ['*.png', '*.xpm'])
    copyTree('eric%sDesignerTemplates' % os.sep, cfg['ericTemplatesDir'], ['*.tmpl'])
    copyTree('eric%sExamples' % os.sep, cfg['ericExamplesDir'], ['*.py', '*.pyc', '*.pyo'])
    
    # copy the wrappers
    for wname in wnames:
        shutil.copy(wname, cfg['bindir'])
    
    # copy the license file
    shutil.copy('eric%sLICENSE.GPL' % os.sep, cfg['ericDir'])
    
    # copy some text files to the doc area
    for name in ["LICENSE.GPL", "THANKS", "HISTORY"]:
        shutil.copy('eric%s%s' % (os.sep, name), cfg['ericDocDir'])
    for name in glob.glob(os.path.join('eric', 'README*.*')):
        shutil.copy(name, cfg['ericDocDir'])
        
    # copy some more stuff
    for name in ['default.e3k']:
        shutil.copy('eric%s%s' % (os.sep, name), cfg['ericOthersDir'])
    for name in ['eric3.api']:
        shutil.copy('eric%sDocumentation%s%s' % (os.sep, os.sep, name), cfg['ericOthersDir'])
        
    # copy some text files of BRM
    brmDocDir = os.path.join(cfg['ericDocDir'], 'brm')
    if not os.path.isdir(brmDocDir):
        os.makedirs(brmDocDir)
    for name in ['AUTHORS', 'COPYING', 'ChangeLog', 'DESIGN.html', 'NEWS', 'README']:
        shutil.copy(os.path.join('eric', 'ThirdParty', 'brm', name), brmDocDir)


def createSitecustomize():
    """
    Generate the sitecustomize.py script merging an already installed script with our additions.
    """
    global modDir, distDir

    exists = 1

    if not distDir:
        try:
            f = open(os.path.join(modDir, 'sitecustomize.py'), 'r')
        except:
            exists = 0
    else:
        exists = 0

    if exists:
        lines = f.readlines()
        f.close()
        s = open("sitecustomize.py", "w")
        if not "sys.setappdefaultencoding = sys.setdefaultencoding\n" in lines:
            s.write("#\n# added by the eric install script\n#\n\n")
            s.write("import sys\n\n")
            s.write("sys.setappdefaultencoding = sys.setdefaultencoding\n\n")
        for line in lines:
            s.write(line)
        s.close()
    else:
        s = open("sitecustomize.py", "w")
        s.write("#\n# sitecustomize.py - saving a useful function.\n")
        s.write("# generated by the eric install script\n#\n\n")
        s.write("import sys\n\n")
        s.write("sys.setappdefaultencoding = sys.setdefaultencoding\n\n")
        s.close()

def createInstallConfig():
    """
    Create the installation config dictionary.
    """
    global modDir, platBinDir, cfg
        
    ericdir = os.path.join(modDir, "eric3")
    cfg = {
        'ericDir'             : ericdir,
        'ericPixDir'          : os.path.join(ericdir, "pixmaps"),
        'ericIconDir'         : os.path.join(ericdir, "icons"),
        'ericDTDDir'          : os.path.join(ericdir, "DTDs"),
        'ericDocDir'          : os.path.join(ericdir, "Documentation"),
        'ericExamplesDir'     : os.path.join(ericdir, "Examples"),
        'ericTranslationsDir' : ericdir,
        'ericWizardsDir'      : os.path.join(ericdir, "Wizards"),
        'ericTemplatesDir'    : os.path.join(ericdir, "DesignerTemplates"),
        'ericOthersDir'       : ericdir,
        'bindir'              : platBinDir,
        'mdir'                : modDir,
    }
configLength = 12
    
def createConfig():
    """
    Create a config file with the respective config entries.
    """
    global cfg
    
    fn = 'eric3config.py'
    config = \
"""# -*- coding: utf-8 -*-
#
# This module contains the configuration of the individual eric installation
#

_pkg_config = {
    'ericDir'             : '%s',
    'ericPixDir'          : '%s',
    'ericIconDir'         : '%s',
    'ericDTDDir'          : '%s',
    'ericDocDir'          : '%s',
    'ericExamplesDir'     : '%s',
    'ericTranslationsDir' : '%s',
    'ericWizardsDir'      : '%s',
    'ericTemplatesDir'    : '%s',
    'ericOthersDir'       : '%s',
    'bindir'              : '%s',
    'mdir'                : '%s',
}

def getConfig(name):
    '''
    Module function to get a configuration value.

    @param name the name of the configuration value (string).
    '''
    try:
        return _pkg_config[name]
    except KeyError:
        pass

    raise AttributeError, '"%%s" is not a valid configuration value' %% name
""" % (cfg['ericDir'], cfg['ericPixDir'], cfg['ericIconDir'], 
       cfg['ericDTDDir'], cfg['ericDocDir'], cfg['ericExamplesDir'],
       cfg['ericTranslationsDir'], cfg['ericWizardsDir'],
       cfg['ericTemplatesDir'], cfg['ericOthersDir'],
       cfg['bindir'], cfg['mdir'])
    copyToFile(fn, config)
    
def main(argv):
    """
    The main function of the script.

    @param argv the list of command line arguments.
    """
    import getopt

    # Parse the command line.
    global progName, modDir, doCleanup, cfg
    progName = os.path.basename(argv[0])

    initGlobals()

    try:
        if sys.platform == "win32":
            optlist, args = getopt.getopt(argv[1:],"chxb:d:f:")
        else:
            optlist, args = getopt.getopt(argv[1:],"chxb:d:f:i:")
    except getopt.GetoptError:
        usage()

    global platBinDir
    
    depChecks = 1

    for opt, arg in optlist:
        if opt == "-h":
            usage(0)
        elif opt == "-b":
            platBinDir = arg
        elif opt == "-d":
            global modDir
            modDir = arg
        elif opt == "-i":
            global distDir
            distDir = os.path.normpath(arg)
        elif opt == "-x":
            depChecks = 0
        elif opt == "-c":
            doCleanup = 0
        elif opt == "-f":
            try:
                execfile(arg, globals())
                if len(cfg) != configLength:
                    print "The configuration dictionary in '%s' is incorrect. Aborting" % arg
                    sys.exit(6)
            except:
                cfg = {}
    
    if len(cfg) == 0:
        createInstallConfig()
    
    if depChecks:
        # perform dependency checks
        if sys.version_info < (2,2,0):
            print 'Sorry, you must have Python 2.2.0 or higher.'
            sys.exit(5)
            
        try:
            from qt import qVersion, PYQT_VERSION
        except ImportError, msg:
            print 'Sorry, please install PyQt.'
            print 'Error: %s' % msg
            sys.exit(1)
            
        try:
            from qtnetwork import QServerSocket
        except ImportError, msg:
            print 'Sorry, PyQt is missing QtNetwork support.'
            print 'Error: %s' % msg
            sys.exit(1)
            
        try:
            from qtcanvas import QCanvas
        except ImportError, msg:
            print 'Sorry, PyQt is missing QtCanvas support.'
            print 'Error: %s' % msg
            sys.exit(1)
            
        try:
            from qttable import QTable
        except ImportError, msg:
            print 'Sorry, PyQt is missing QtTable support.'
            print 'Error: %s' % msg
            sys.exit(1)
            
        try:
            from qtext import QextScintilla
        except ImportError, msg:
            print 'Sorry, please install QScintilla and/or reinstall'
            print 'PyQt with QScintilla support.'
            print 'Error: %s' % msg
            sys.exit(1)
            
        # check version of Qt
        qtMajor = int(qVersion().split('.')[0])
        qtMinor = int(qVersion().split('.')[1])
        if qtMajor < 3 or (qtMajor == 3 and qtMinor < 1):
            print 'Sorry, you must have Qt version 3.1.0 or higher.'
            sys.exit(2)
            
        #check version of PyQt
        try:
            from qt import PYQT_VERSION_STR
            pyqtVersion = PYQT_VERSION_STR
        except:
            pyqtVersion = PYQT_VERSION
        if pyqtVersion[:9] == "snapshot-":
            if long(pyqtVersion[9:]) < 20030418L:
                print 'Sorry, you must have PyQt snapshot-20030418 or higher.'
                sys.exit(3)
        else:
            while pyqtVersion.count('.') < 2:
                pyqtVersion += '.0'
            (maj, min, pat) = pyqtVersion.split('.')
            maj = int(maj)
            min = int(min)
            pat = int(pat)
            if maj < 3 or (maj == 3 and min < 6):
                print 'Sorry, you must have PyQt 3.6.0 or snapshot-20030418 or higher.'
                sys.exit(3)
            if maj == 3 and min == 9:
                print 'PyQt 3.9 contains a bug, which prevents eric3 from functioning.'
                print 'Please get PyQt 3.8 or 3.10 or newer (or snapshot-20031226 or newer).'
                sys.exit(3)
            
        #check version of QScintilla
        try:
            from qtext import QSCINTILLA_VERSION_STR
            scintillaVersion = QSCINTILLA_VERSION_STR
            if scintillaVersion[:9] == "snapshot-":
                if long(scintillaVersion[9:]) < 20041001L:
                    print 'Sorry, you must have QScintilla snapshot-20041001 or higher.'
                    sys.exit(4)
            else:
                while scintillaVersion.count('.') < 2:
                    scintillaVersion += '.0'
                (maj, min, pat) = scintillaVersion.split('.')
                maj = int(maj)
                min = int(min)
                pat = int(pat)
                if maj < 1 or (maj == 1 and min < 3):
                    print 'Sorry, you must have QScintilla 1.3 or snapshot-20041001 or higher.'
                    sys.exit(4)
        except:
            print 'Sorry, you must have QScintilla 1.4 or snapshot-20041001 or higher.'
            sys.exit(4)
        
    # get rid of development config file, if it exists
    try:
        os.remove(os.path.join("eric", "eric3config.py"))
    except:
        pass
    
    createSitecustomize()
    print "Compiling debugger files."
    if distDir:
        compileall.compile_dir("eric", ddir=os.path.join(distDir, modDir))
    else:
        compileall.compile_dir("eric", ddir=modDir)
    print "\nInstalling eric3 ..."
    installEric()
    print "\nInstallation complete."
    print "\nIf you would like to use the autocompletion feature please call"
    print "the gen_sip_api.py and/or gen_python_api.py script available"
    print "on the eric3 contribution page or get ready made api-files"
    print "from this contribution page."
    print
        
    # check PyXML version and output a message for broken PyXML 0.8.3
    try:
        import _xmlplus
        v = _xmlplus.version_info
        if v < (0, 8, 5):
            print "NOTE:"
            print "PyXML < 0.8.5 needs a patch to work correctly with foreign characters."
            print "Please see 'README-PyXML-0.8.3.txt' for details."
            print
    except:
        pass
    
    
if __name__ == "__main__":
    try:
        main(sys.argv)
    except SystemExit:
        raise
    except:
        print \
"""An internal error occured.  Please report all the output of the program,
including the following traceback, to eric-bugs@die-offenbachs.de.
"""
        raise