File: install.py

package info (click to toggle)
luma 2.3-1.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 4,108 kB
  • ctags: 1,260
  • sloc: python: 17,617; makefile: 19
file content (216 lines) | stat: -rwxr-xr-x 6,209 bytes parent folder | download
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

###########################################################################
#    Copyright (C) 2003-2005 by Wido Depping
#    <widod@users.sourceforge.net>
#
# Copyright: See COPYING file that comes with this distribution
#
###########################################################################

import sys
import os.path
import os
from popen2 import Popen3
import py_compile

# This is the prefix directory where luma will be installed.
prefixDir = os.path.join("usr", "local")

# Determines if python source files are only compiled and not installed
compileOnly = False


def doImportCheck():
    """ Checks for installed packages which are needed in order to run Luma.
    Gives only a warning for missing packages.
    """
    
    print "Check for preinstalled modules:\n"
    
    # Check for python-ldap
    try:
        import ldap
        vString = "2.0.1"
        print "python-ldap is installed..."
        print "\tInstalled version: " + ldap.__version__
        print "\tMinimum version: " + vString
        print ""
    except ImportError:
        print """ERROR: python-ldap not installed!!!
You can get the module here: http://python-ldap.sourceforge.net
"""

    # Check for PyQt. If successful, check for Qt, too.
    try:
        import qt
        pyqtVersionString = "3.10"
        qtVersionString = "3.2"
        print "PyQt is installed..."
        print "\tInstalled version: " + qt.PYQT_VERSION_STR
        print "\tMinimum version: " + pyqtVersionString
        print ""
        print "Qt version..."
        print "\tInstalled version: " + qt.QT_VERSION_STR
        print "\tMinimum version: " + qtVersionString
        print ""
    except ImportError:
        print """\nERROR: PyQt not installed!!!
You can get the module here: http://www.riverbankcomputing.co.uk/pyqt
"""

    # Check for the smbpasswd module. Needed for lmhash and nthash password
    # creation. No version checking needed.
    try:
        import smbpasswd
        print "smbpasswd module is installed."
    except ImportError:
        print """\nWARNING: smbpasswd module is not installed.
You will be able to tun Luma, but no nthash and lmhash passwords are available.
You can get the module here: http://barryp.org/software/py-smbpasswd
"""

    print ""

###############################################################################

def doChecks():
    """Checks if prefix diretory exists. After that Luma will be compiled and installed. 
    Installation fails if prefix directory doesn't exist.
    
    TODO: try to create the installation directory
    """

    if os.path.exists(prefixDir):
        doCompile()
        doInstall()
    else:
        print "Prefix directory does not exist!"
        sys.exit(1)

###############################################################################

def doInstall():
    """Installs compiled sourcefiles to the installation directory.
    """
    
    print "Copy program files...\n"
    
    try:
        for tmpDir in ["bin", "lib", "share"]:
            a = Popen3("cp -R " + tmpDir + " " + prefixDir)
            while a.poll() == -1:
                pass
            if a.poll() > 0:
                raise "CopyError", "Error!!! Could not copy File. Maybe wrong permissions?"
                
        print "Finished copying program files.\n"
        print "LUMA installed succesfully! :)"
        
    except "CopyError", errorMessage:
        print errorMessage
        sys.exit(1)
    
###############################################################################

def checkPath():
    """ Checks if the install directory for luma is in the local PATH of the user and give him feedback.
    """
    
    
    pathVariable = os.environ['PATH']
    pathValues = pathVariable.split(':')
    tmpPath = os.path.join(prefixDir, "bin")
    
    
    if tmpPath in pathValues:
        print """
Good: The specified prefix is present in your PATH variable.
Start LUMA by typing 'luma' from anywhere in the console.
"""
    else:
        print """
WARNING: The specified prefix is NOT present in your PATH variable.
Add PREFIX to your PATH and then Start LUMA by typing 'luma' from
anywhere in the console.
"""

###############################################################################

def printHelp():
    """Prints a help text for the Luma installation program.
    """
    
    helpString = """Install options:
 --prefix=PATH \t\t Install path (default is /usr/local)
 --compile-only \t Just compile source files. No installation.
 \n"""
 
    print helpString
    
    sys.exit(1)
    
###############################################################################
    
def doCompile():
    """Compiles all source files to python bytecode.
    """
    
    print "Compiling python source files ...\n"
    
    input, output = os.popen2("find . -name \"*.py\"")
    tmpArray = output.readlines()
    fileList = []
    for x in tmpArray:
        if x[:11] == "./lib/luma/":
            fileList.append(x[:-1])
    for x in fileList:
        print "compiling " + x
        py_compile.compile(x)
        
    print "\nFinished compiling.\n"
         
###############################################################################

def evalArguments():
    """ Evaluate options given to the install script by the user.
    """
    
    if len(sys.argv) == 1:
        printHelp()
        return
        
    for x in sys.argv[1:]:
        if x == "--compile-only":
            global compileOnly
            compileOnly = True
        elif x[:9] == "--prefix=":
            global prefixDir
            prefixDir = x[9:]
            if (prefixDir[-1] == "/") and (len(prefixDir) > 1):
                prefixDir = prefixDir[:-1]
        else:
            print "Unknown options. Exiting..."
            sys.exit(1)

###############################################################################


print "Luma 2.2 (C) 2003-2005 Wido Depping\n"

doImportCheck()
print ""

evalArguments()
    
doCompile()

if not compileOnly:
    # Check if prefixDir exists
    if not(os.path.exists(prefixDir)):
        print "Prefix directory does not exist!"
        sys.exit(1)

    doInstall()
    checkPath()