2 # -*- coding: iso-8859-1 -*-
6 # Copyright (C) 2005 Frédéric Jolliton <frederic@jolliton.com>
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.
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.
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
23 #--[ Configuration ]----------------------------------------------------------
25 from install_conf import *
27 #--[ Global variables ]-------------------------------------------------------
32 #-----------------------------------------------------------------------------
39 from getopt import GetoptError
41 from getopt import gnu_getopt as getopt
43 from getopt import getopt
45 from distutils.sysconfig import get_python_lib
47 def touch( filename ) :
49 open( filename , 'a+' ).close()
51 def createFile( filename , contents ) :
53 f = open( filename , 'w' )
57 def byteCompile( filename ) :
60 print 'Byte-compiling %s' % filename
61 py_compile.compile( filename )
65 '''Install Python path.'''
67 path = get_python_lib()
68 path += '/' + g_globalModule + '.pth'
69 target = g_targetPrefix
70 if g_verbose or g_pretend :
71 print 'Creating Python path from %s to %s.' % ( path , target )
74 createFile( path , target )
76 print '** Error creating Python path into %s' % path
81 '''Install modules.'''
83 myPrefix = g_targetPrefix + '/' + g_globalModule
85 if g_verbose or g_pretend :
86 print 'Creating directory %s' % myPrefix
89 os.makedirs( myPrefix )
91 if e[ 0 ] == errno.EEXIST :
96 if g_verbose or g_pretend :
97 print 'Creating module %s' % g_globalModule
99 p = myPrefix + '/__init__.py'
103 print '** Error touching %s' % p
106 for module in g_modules :
107 if g_verbose or g_pretend :
108 print 'Copying module %s -> %s' % ( module , myPrefix + '/' )
110 mod = open( module ).read()
112 createFile( myPrefix + '/' + module , mod )
114 print '** Error copying %s -> %s' % ( module , myPrefix + '/' )
117 byteCompile( myPrefix + '/' + module )
121 print '''Usage: install [OPTIONS]
123 -h, --help Print this help.
124 -n, --pretend Display operations, but do nothing.
125 -v, --verbose Verbose output.
126 --pth Install Python path (.pth) only.
128 Report bugs to <fj@tuxee.net>.'''
136 options , paramaters = getopt( sys.argv[ 1 : ] ,
137 'hnv' , ( 'help' , 'pth' , 'pretend' , 'verbose' ) )
138 except GetoptError , e :
140 print 'Try `install --help\' for more information.'
145 for option , argument in options :
146 if option in [ '-h' , '--help' ] :
149 elif option in [ '-v' , '--verbose' ] :
151 elif option in [ '-n' , '--pretend' ] :
153 elif option in [ '--pth' ] :
160 if __name__ == '__main__' :