Source

orange / install-scripts / linux / setup.py

Full commit
  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
#!/usr/bin/env python
# To use:
#       python setup.py install

# all kind of checks

# Change this to something else than ADDVERSION
OrangeVer="ADDVERSION"

# got* is used to gather information of the system and print it out at the end
gotPython = '';
gotQt = '';
gotPyQt = '';
gotNumPy = '';
gotGcc = '';
gotQwt = '';

try:
    import sys,commands,traceback,os
    from distutils import sysconfig
    from distutils.core import setup,Extension
    from glob import glob
    from stat import *
except:
    traceback.print_exc()
    print "Unable to import python distutils."
    print "You may want to install the python-dev package on your distribution."
    sys.exit(1)

gotPython = sys.version.split()[0]

if not hasattr(sys, 'version_info') or sys.version_info < (2,3,0,'alpha',0):
    raise SystemExit, "Python 2.3 or later is required to build Orange."

#if os.geteuid() != 0:
#    print "This script should be run as superuser!"
#    sys.exit(1)

try:
    import qt,pyqtconfig
except:
    print "NOTE: Python Qt not installed, OrangeCanvas and OrangeWidgets will not work."
    print "You can get it at: http://www.riverbankcomputing.co.uk/pyqt/index.php"
    # we are using Qt 2.3 - Qt 3.3

try:
    gotPyQt = pyqtconfig.Configuration().pyqt_version_str;
except:
    gotPyQt = ''
    # any PyQt that supports Qt 2.3-3.8

try:
    import sipconfig
    tmp = "%x" % sipconfig.Configuration().qt_version
    gotPy = tmp.replace('0','.')
except:
    print "Sipconfig not found, Qt version could not be found!"
    gotPy = ''
    # depends on version of PyQt

try:
    import numpy
except:
    print "NumPy should be installed!"
    print "You can get it at: http://numpy.scipy.org/"
    sys.exit(1)
    # use latest, from 23.0 on

try:
    import numpy
    gotNumPy = numpy.__version__
except:
    print "Can not determine NumPy version!"
    gotNumPy = "n/a"

try:
    import qwt
    gotQwt = "n/a"
except:
    print "PyQwt not installed!"
    print "You can get it at: http://pyqwt.sourceforge.net/"
    # depends on PyQt
    
if os.system("gcc --version > /dev/null 2>&1") != 0:
    print "GCC should be installed!"
    sys.exit(1)

# catching version of GCC
try:
    (stdout_err, stdin) = popen2.popen4("gcc --version");
    tmp = stdout_err.readlines()[0]
    gotGcc = tmp.split()[2]
except:
    print "Can not determine GCC version!"
    gotGcc = "n/a"
    # version 3.3 on

if OrangeVer is "ADDVERSION":
    print "Version should be added manually (edit setup.py and replace ADDVERSION)"
    sys.exit(1)

if "FreeBSD" in sys.version:
    HostOS="FreeBSD"
elif "Linux" in sys.version:
    HostOS="Linux"
else:
    HostOS="unknown"

# creating custom commands
# uninstall deletes everything which was installed
from distutils.core import Command
from distutils.command.install import install
from distutils.command.install_data import install_data

class uninstall(Command):
    description = "uninstall current version"

    user_options = [('orangepath=', None, "Orange installation path"),
                    ('docpath=', None, "Orange documentaiton path"),
                    ('libpath=', None, "Orange library path")]

    
    def initialize_options (self):
        self.orangepath = None
        self.docpath = None
        self.libpath = None
        self.systemUninstall = False
        
    def finalize_options(self):
        if self.orangepath == None and 'root' in self.__dict__.keys() and self.root <> None:
            self.orangepath = self.root
            self.root = None

        if self.orangepath is None:
            try:
                fo = file(sys.argv[0].replace("/setup.py", "/user_install"), "r")
                self.orangepath=fo.read()
                fo.close
            except:
                print "user_install file could not be opened, performing system uninstall"

        else:
            self.systemUninstall = False
            
        if self.orangepath is None:
            self.systemUninstall = True
            if self.orangepath is None:
                self.orangepath = os.path.join("lib", PythonVer,
                                               "site-packages", "orange")
            if self.docpath is None:
                self.docpath = os.path.join(sys.prefix, "share", "doc", "orange")
            if self.libpath is None:
                self.libpath = os.path.join(sys.prefix, "lib")
        else:
            if self.docpath is None:
                self.docpath = os.path.join(self.orangepath, "doc")
                self.orangepath = os.path.join(self.orangepath, "orange")
                
    def run(self):
        if self.systemUninstall is True:
            if os.geteuid() != 0:
                print "Uninstallation should be run as superuser!"
                sys.exit(1)
            self.orangepath = os.path.join(sys.prefix, self.orangepath)
            sysBinFile = os.path.join("/", "usr", "bin", "orange")
            print "Performing system uninstallation from: "+self.orangepath
        else:
            sysBinFile = None
            print "Performing user uninstallation from: "+self.orangepath
        print "Removing orange.pth file...",
        os.remove(os.path.join(self.orangepath, "..", "orange.pth"))
        print "done!"
        print "Removing installation directory "+self.orangepath+" ...",
        self.rmdir(self.orangepath)
        os.rmdir(self.orangepath)
        print "done!"
        print "Removing documentation directory "+self.docpath+" ...",
        self.rmdir(self.docpath)
        os.rmdir(self.docpath)
        print "done!"
        if self.systemUninstall is True:
            print "Removing symbolic links for the orange libraries ...",
            for orngLib in OrangeLibList:
                os.remove(os.path.join(self.libpath, "lib"+orngLib))
            print "done!"
            print "Removing Orange Canvas shortcut "+sysBinFile+"...",
            os.remove(sysBinFile);
            print "done!"

    def rmdir(self,top):
        for root, dirs, files in os.walk(top, topdown=False):
            for name in files:
                os.remove(os.path.join(root, name))
            for name in dirs:
                os.rmdir(os.path.join(root, name))

# compile goes to orange/source directory and compiles orange
class compile(Command):
    # add Different make programs support"
    description = "compiles Orange"

    user_options = [('coptions=', None, "special compiling options")]

    def initialize_options(self):
        self.coptions = None
        self.makeCmd = None

    def finalize_options(self):
        if self.coptions is None:
            print "Default compiler options are taken..."
        if HostOS is "FreeBSD":
            self.makeCmd = "gmake"
        else:
            self.makeCmd = "make"
            
    def run(self):
        #compile Orange with make files
        SourceDir = os.path.join("source")
        os.chdir(SourceDir)
        print "Compiling... this might take a while, logging into compiling.log...",
        make=self.makeCmd+"> ../compiling.log"
        retval = os.system(make)
        if retval != 0:
            print "Compiling Orange failed... exiting!"
            sys.exit(1)
        print "done"
        os.chdir(BaseDir)

# change correct directories in data_files (we don't know target directory in
# the 'main' script

class install_data_wrap(install_data):
    description = "Orange specific data installation"

    print "Orange specific data installation"

    global OrangeInstallDir
    
    user_options = install_data.user_options
    
    def initialize_options(self):
        install_data.initialize_options(self)

    def finalize_options(self):
        install_data.finalize_options(self)
        if self.install_dir != os.path.join(self.root, sys.prefix):
            OrangeInstallDir = os.path.join(self.install_dir, "orange")
            OrangeInstallDoc = os.path.join(self.install_dir, "doc", "orange")
#            OrangeInstallLib = os.path.join(self.install_dir, "lib")
            self.data_files = [(OrangeInstallDir, OrangeLibs),
                               (os.path.join(OrangeInstallDir,
                                             "OrangeWidgets", "icons"),
                                OrangeWidgetIcons),
                               (os.path.join(OrangeInstallDir,
                                             "OrangeCanvas", "icons"),
                                OrangeCanvasIcons),
                               (os.path.join(OrangeInstallDir, "OrangeCanvas"),
                                OrangeCanvasPyw)]
            for root, dirs, files in os.walk(os.path.join("doc")):
                OrangeDocs = glob(os.path.join("", "")) # Create a Docs file list
                if 'CVS' in dirs:
                    dirs.remove('CVS')  # don't visit CVS directories
                for name in files:
                    OrangeDocs += glob(os.path.join(root,name))
                if(root.split('doc/')[-1] == 'doc/'):
                    root = ''
                self.data_files += [(os.path.join(OrangeInstallDoc,
                                             root.split('doc/')[-1]), OrangeDocs)]

            self.data_files += [(OrangeInstallDoc,['setup.py'])]
            
    def run(self):
        install_data.run(self)

# install is 'normal distutils' install, after installation symlinks libraries
# and calles ldconfig
class install_wrap(install):
    description = "Orange specific installation"

    user_options = install.user_options + [('orangepath=',
                                            None, "Orange install directory")]

    def initialize_options(self):
        install.initialize_options(self)
        self.orangepath = None;

    def finalize_options(self):
        if self.orangepath == None and self.root <> None:
            self.orangepath = self.root
            self.root = None

        if self.orangepath == None:
            print "Using default system initialization, checking for privileges..."
            if os.geteuid() != 0:
                print "should be run as superuser or --orangepath should be used"
                sys.exit(1)
            print "done"
            self.OrangeInstallDir = os.path.join("lib", PythonVer,
                                            "site-packages", "orange")
            self.OrangeInstallDoc = os.path.join(sys.prefix, "share", "doc",
                                            "orange")
            self.OrangeInstallLib = os.path.join(sys.prefix, "lib")
        else:
            self.install_purelib = self.orangepath;
            self.install_data = self.orangepath;

        install.finalize_options(self);
 
    def run(self):
        install.run(self)

        if self.orangepath == None:
	    binFile = os.path.join(sys.prefix, self.OrangeInstallDir, "OrangeCanvas", "orngCanvas.pyw")
	    sysBinFile = os.path.join("/", "usr", "bin", "orange")
	    os.system("echo python "+binFile+" >> "+sysBinFile)
            os.chmod(sysBinFile,
                      S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)

            print "Linking libraries...",
            for currentLib in OrangeLibList:
                try:
                    os.symlink(os.path.join(sys.prefix,
                                            self.OrangeInstallDir,currentLib),
                               os.path.join(self.OrangeInstallLib,"lib"+currentLib))
                    
                except:
                    print "problems with "+currentLib+"... ignoring... ",
                    
                os.system("/sbin/ldconfig")
                print "success"
        else:
	    sysBinFile = None
            # link orange.so into liborange.so
            try:
                os.symlink(os.path.join(self.orangepath, "orange", "orange.so"), os.path.join(self.orangepath, "orange", "liborange.so"))
            except:
                print "problems creating link to liborange.so:", os.path.join(self.orangepath, "orange", "liborange.so")
            print "Libraries were not exported to the system library path (using 'non-system' installation)"
            
        print "Creating path file...",
        if self.orangepath == None:
            pth = os.path.join(sys.prefix,self.OrangeInstallDir,"..","orange.pth")
        else:
            pth = os.path.join(self.orangepath, "orange.pth")

        if os.access(pth, os.F_OK) is True:
            os.remove(pth)

        fo = file(pth,"w+")

        if self.orangepath == None:
            pthInstallDir = os.path.join(sys.prefix, self.OrangeInstallDir)
        else:
            pthInstallDir = os.path.join(self.orangepath, "orange")
            
        fo.write(pthInstallDir+"\n")
        for root,dirs,files in os.walk(pthInstallDir):
            for name in dirs:
                fo.write(os.path.join(root,name)+"\n")
        fo.close()
        print "success"

       	print "Preparing filename masks...",
	for root, dirs, files in os.walk(pthInstallDir):
	    for name in files:
		if name in OrangeLibList: # libraries must have +x flag too
			os.chmod(os.path.join(root,name),   
				 S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)

		else:
	        	os.chmod(os.path.join(root,name),
        	        	 S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH)
	    for name in dirs:
        	os.chmod(os.path.join(root,name),
                	 S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
        print "success"
	print ""
        print "Python version: "+gotPython
        print "PyQt version: "+gotPyQt
        print "Qt version: "+gotPy
        print "NumPy version: "+gotNumPy
        print "Qwt version: "+gotQwt
        print "GCC version: "+gotGcc

        if self.orangepath != None:
            # we save orangepath for uninstallation to the file user_install
            fo = file(os.path.join(self.orangepath, "doc",
                                  "orange", "user_install"), "w+")
            fo.write(self.orangepath)
            fo.close()
            OrangeInstallDir = os.path.join(self.orangepath, "orange")
            OrangeInstallDoc = os.path.join(self.orangepath, "doc", "orange")
            print "Orange installation dir: "+OrangeInstallDir
            print "Orange documentation dir: "+OrangeInstallDoc
            print "To uninstall Orange type:"
            print ""
            print "    python "+OrangeInstallDoc+"/setup.py uninstall"
        else:
            print "Orange installation dir: "+sys.prefix+self.OrangeInstallDir
            print "Orange library links in: "+self.OrangeInstallLib
            print "Orange documentation dir: "+self.OrangeInstallDoc
            print "To uninstall Orange type:"
            print ""
            print "    python "+self.OrangeInstallDoc+"/setup.py uninstall"
            
        print ""
        print "It will remove Orange, Orange documentation and links to Orange libraries"
        if sysBinFile != None:
		print ""
		print "To run Orange Canvas run: "+sysBinFile
	else:
		print ""
		print "Orange Canvas shortcut not created ('non-system' installation)"
		print ""
		print "PLEASE ADD to your environment: LD_LIBRARY_PATH="+OrangeInstallDir+":$LD_LIBRARY_PATH ; export LD_LIBRARY_PATH"
		print ""
    
# preparing data for Distutils

PythonVer = "python"+sys.version[:3]

OrangeInstallDir = os.path.join("lib", PythonVer, "site-packages", "orange")
OrangeInstallDoc = os.path.join(sys.prefix, "share", "doc",
                                "orange")
OrangeInstallLib = os.path.join(sys.prefix, "lib")

OrangeLibList = ['orange.so', 'orangene.so','orangeom.so','statc.so','corn.so']
        
BaseDir = os.getcwd()
OrangeDirs = ["orange", "orange.OrangeCanvas", "orange.OrangeWidgets"]
OrangeWidgetsDirs = []
for root,dirs,files in os.walk(os.path.join("OrangeWidgets"), topdown=False):
    if 'CVS' in dirs:
        dirs.remove('CVS')
    for name in dirs:
	tmp = "orange."+root+"."+name
        OrangeWidgetsDirs.append(tmp.replace('/','.'))
OrangeDirs += OrangeWidgetsDirs

packages =  OrangeDirs
package_dir = {"orange" : ""}

OrangeLibs = []
for currentLib in OrangeLibList:
    OrangeLibs += [os.path.join(currentLib)]

OrangeWidgetIcons = glob(os.path.join("OrangeWidgets", "icons", "*.png"))
OrangeCanvasIcons = glob(os.path.join("OrangeCanvas",  "icons", "*.png"))
OrangeCanvasPyw   = glob(os.path.join("OrangeCanvas", "orngCanvas.pyw"));

data_files = [(OrangeInstallDir, OrangeLibs),
              (os.path.join(OrangeInstallDir, "OrangeWidgets", "icons"),
               OrangeWidgetIcons),
              (os.path.join(OrangeInstallDir, "OrangeCanvas", "icons"),
               OrangeCanvasIcons),
	      (os.path.join(OrangeInstallDir, "OrangeCanvas"), OrangeCanvasPyw)]

# Adding each doc/* directory by itself
for root, dirs, files in os.walk(os.path.join("doc")):
    OrangeDocs = glob(os.path.join("", "")) # Create a Docs file list
    if 'CVS' in dirs:
        dirs.remove('CVS')  # don't visit CVS directories
    for name in files:
        OrangeDocs += glob(os.path.join(root,name))
    if(root.split('doc/')[-1] == 'doc/'):
        root = ''
    data_files += [(os.path.join(OrangeInstallDoc,root.split('doc/')[-1]),
                                 OrangeDocs)]

# we save setup.py, so we can uninstall complete orange installation
data_files += [(OrangeInstallDoc,['setup.py'])]

long_description = """Orange, data-mining software"""

setup (name = "orange",
       version = OrangeVer,
       maintainer = "Jure Menart",
       maintainer_email = "jurem@najdi.si",
       description = "Orange Extension for Python",
       long_description = long_description,
       url = "http://www.ailab.si/orange",
       packages = packages,
       package_dir = package_dir,
       data_files = data_files,
       cmdclass = { 'uninstall': uninstall,
                    'compile'  : compile,
                    'install'  : install_wrap,
                    'install_data' : install_data_wrap}
       )