~ubuntu-branches/ubuntu/natty/nvidia-cg-toolkit/natty

« back to all changes in this revision

Viewing changes to update-nvidia-cg-toolkit

  • Committer: Bazaar Package Importer
  • Author(s): Federico Di Gregorio
  • Date: 2005-02-27 16:46:29 UTC
  • Revision ID: james.westby@ubuntu.com-20050227164629-y2rkvno46w0jpjdt
Tags: 1.3.0501.0700-1
New upstream release of the Cg tools from NVIDIA.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
#
 
3
# Copyright (C) 2004 Federico Di Gregorio <fog@debian.org>
 
4
#
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by the
 
7
# Free Software Foundation; either version 2, or (at your option) any later
 
8
# version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful, but
 
11
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
 
12
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 
13
# for more details.
 
14
 
 
15
import sys
 
16
import os
 
17
import os.path
 
18
import optparse
 
19
import shutil
 
20
import time
 
21
import glob
 
22
import urllib2
 
23
import md5
 
24
 
 
25
 
 
26
CG_LIBRARIES = ('libCg.so', 'libCgFX.so', 'libCgGL.so', 'libCgFXGL.so')
 
27
CG_PDFS = ('CgManualAddendum.pdf', 'CgReleaseNotes.pdf', 'Cg_Toolkit.pdf',
 
28
           'GettingStarted.pdf')
 
29
 
 
30
pipe = os.popen('dpkg --print-architecture', 'r')
 
31
arch = pipe.read().strip()
 
32
pipe.close()
 
33
 
 
34
if arch == 'i386':
 
35
    CG_URL  = 'ftp://download.nvidia.com/developer/cg/Cg_1.3/Linux/'
 
36
    CG_FILE = 'Cg-1.3.0501-0700.i386.tar.gz'
 
37
    CG_MD5  = 'c122d853eca52e9863832480dc3ab843'
 
38
    CG_USR_LIB = '/usr/lib'
 
39
elif arch == 'amd64':
 
40
    CG_URL  = 'ftp://download.nvidia.com/developer/cg/Cg_1.3/Linux64/'
 
41
    CG_FILE = 'Cg-1.3.0501-0700.x86_64.tar.gz'
 
42
    CG_MD5  = 'a9b4cb044e5975783e34edfcb82d5d71'
 
43
    CG_USR_LIB = '/usr/lib64'
 
44
else:
 
45
    sys.stderr.write("Error: architecture %s is not supported\n" % arch)
 
46
    sys.exit(1)
 
47
 
 
48
def cg_uninstall():
 
49
    """Uninstall all components."""
 
50
    print "Uninstalling NVIDIA Cg Toolkit components:"
 
51
 
 
52
    print "  Cg compiler,",
 
53
    try:
 
54
        os.unlink('/usr/bin/cgc')
 
55
    except OSError:
 
56
        pass
 
57
 
 
58
    print "header files,",
 
59
    shutil.rmtree('/usr/include/Cg', ignore_errors=True)
 
60
    shutil.rmtree('/usr/include/CgFX', ignore_errors=True)    
 
61
 
 
62
    print "libraries,",
 
63
    for l in CG_LIBRARIES:
 
64
        try:
 
65
            os.unlink(os.path.join(CG_USR_LIB, l))
 
66
        except OSError:
 
67
            pass
 
68
 
 
69
    print "documentation,"
 
70
    for l in CG_PDFS:
 
71
        try:
 
72
            os.unlink(os.path.join('/usr/share/doc/nvidia-cg-toolkit', l))
 
73
        except OSError:
 
74
            pass
 
75
 
 
76
    shutil.rmtree('/usr/share/doc/nvidia-cg-toolkit/html', ignore_errors=True)
 
77
    shutil.rmtree('/usr/share/doc/nvidia-cg-toolkit/txt', ignore_errors=True)
 
78
 
 
79
    print "  examples,",
 
80
    shutil.rmtree('/usr/share/doc/nvidia-cg-toolkit/examples',
 
81
                  ignore_errors=True)
 
82
 
 
83
    print "manual pages,",
 
84
    for f in glob.glob('/usr/share/man/man3/*.3nvidiacg.gz'):
 
85
        try:
 
86
            os.unlink(f)
 
87
        except OSError:
 
88
            pass
 
89
        
 
90
    print "done."
 
91
    
 
92
def cg_install(filename):
 
93
    """Install from give file."""
 
94
    print "Checking md5 checksum on " + filename
 
95
    md5sum = md5.new(open(filename).read()).hexdigest()
 
96
    if md5sum != CG_MD5:
 
97
        e = "Error: md5sum mismatch: %s != %s"
 
98
        sys.stderr.write(e % (CG_MD5, md5sum))
 
99
        sys.exit(2)
 
100
        
 
101
    target = os.path.join('/tmp', 'cg.%f' % time.time())
 
102
    try:
 
103
        os.mkdir(target)
 
104
    except:
 
105
        e = "Error: can't create directory: %s."
 
106
        sys.stderr.write(e % target)
 
107
        sys.exit(2)
 
108
 
 
109
    cg_uninstall()
 
110
    
 
111
    print "Uncompressing NVIDIA Cg toolkit into " + target
 
112
    os.system("/bin/tar xzf %s -C %s" % (filename, target))
 
113
 
 
114
    print "Moving files to their final destinations:"
 
115
 
 
116
    print "  cg compiler,",
 
117
    shutil.move(os.path.join(target, 'usr/bin/cgc'), '/usr/bin/cgc')
 
118
    
 
119
    print "header files,",
 
120
    shutil.move(os.path.join(target, 'usr/include/Cg'), '/usr/include/Cg')
 
121
    shutil.move(os.path.join(target, 'usr/include/CgFX'), '/usr/include/CgFX')
 
122
 
 
123
    print "libraries,",
 
124
    for l in CG_LIBRARIES:
 
125
        shutil.move(os.path.join(target, 'usr/lib', l),
 
126
                    os.path.join(CG_USR_LIB, l))
 
127
 
 
128
    print "documentation,"
 
129
    for l in CG_PDFS:
 
130
        shutil.move(os.path.join(target, 'usr/local/Cg/docs', l),
 
131
                    os.path.join('/usr/share/doc/nvidia-cg-toolkit', l))
 
132
    shutil.move(os.path.join(target, 'usr/local/Cg/docs/runtime/html'),
 
133
                '/usr/share/doc/nvidia-cg-toolkit/html')
 
134
    shutil.move(os.path.join(target, 'usr/local/Cg/docs/runtime/cgGL/html'),
 
135
                '/usr/share/doc/nvidia-cg-toolkit/html/cgGL')
 
136
    shutil.move(os.path.join(target, 'usr/local/Cg/docs/runtime/txt'),
 
137
                '/usr/share/doc/nvidia-cg-toolkit/txt')
 
138
    shutil.move(os.path.join(target, 'usr/local/Cg/docs/runtime/cgGL/txt'),
 
139
                '/usr/share/doc/nvidia-cg-toolkit/txt/cgGL')
 
140
 
 
141
    print "  examples,",
 
142
    shutil.move(os.path.join(target, 'usr/local/Cg/examples'),
 
143
                '/usr/share/doc/nvidia-cg-toolkit/examples')
 
144
 
 
145
    print "manual pages",
 
146
    for f in os.listdir(os.path.join(target, 'usr/share/man/man3')):
 
147
        src = os.path.join(target, 'usr/share/man/man3', f)
 
148
        dst = os.path.join('/usr/share/man/man3', f+'nvidiacg')
 
149
        shutil.move(src, dst)
 
150
 
 
151
    print "(compressing),",
 
152
    os.system('/bin/gzip -9 /usr/share/man/man3/*.3nvidiacg')
 
153
 
 
154
    shutil.rmtree(target)
 
155
    print "done."
 
156
 
 
157
def cg_wget():
 
158
    """Get toolkit archive from the network."""
 
159
    target = os.path.join('/tmp', 'cg.%f' % time.time())
 
160
    try:
 
161
        os.mkdir(target)
 
162
    except:
 
163
        e = "Error: can't create directory: %s."
 
164
        sys.stderr.write(e % target)
 
165
        sys.exit(2)
 
166
    dst = open(os.path.join(target, CG_FILE), 'w')
 
167
 
 
168
    print "Downloading NVIDIA Cg Toolkit to " + dst.name
 
169
    src = urllib2.urlopen(CG_URL+CG_FILE)
 
170
    dst.write(src.read())
 
171
    return dst.name
 
172
 
 
173
def cg_path(path, filename):
 
174
    """Return the path to an existing file or None."""
 
175
    if filename and os.path.exists(filename):
 
176
        return filename
 
177
    if path:
 
178
        filename = os.path.join(path, CG_FILE)
 
179
        if filename and os.path.exists(filename):
 
180
            return filename
 
181
 
 
182
    
 
183
parser = optparse.OptionParser(usage="%prog [options] <file or URL>")   
 
184
parser.add_option('-i', '--install', action='store_true',
 
185
                  help="install the NVIDIA Cg Toolkit")
 
186
parser.add_option('-u', '--uninstall', action='store_true',
 
187
                  help="uninstall the NVIDIA Cg Toolkit")
 
188
parser.add_option('-l', '--local-file', action='store',
 
189
                  help="install from given file")
 
190
parser.add_option('-s', '--search-path', action='store',
 
191
                  help="search for files in given path")
 
192
parser.add_option('-d', '--delete-after', action='store_true',
 
193
                  help="remove toolkit archive after install")
 
194
opts, args = parser.parse_args()
 
195
 
 
196
 
 
197
if opts.install:
 
198
    local_file = cg_path(opts.search_path, opts.local_file)
 
199
    if not local_file or not os.path.exists(local_file):
 
200
        local_file = cg_wget()
 
201
    cg_install(local_file)
 
202
    if opts.delete_after:
 
203
        os.unlink(local_file)
 
204
 
 
205
elif opts.uninstall:      
 
206
    cg_uninstall()
 
207
 
 
208
else:
 
209
    e = "Error: one action (--install or --uninstall) is required.\n"
 
210
    sys.stderr.write(e)
 
211
    sys.exit(1)