1 """distutils.command.bdist_ packager
3 Modified from bdist_dumb by Mark W. Alexander <slash@dotnetslash.net>
5 Implements the Distutils 'bdist_packager' abstract command
6 to be subclassed by binary package creation commands.
9 __revision__
= "$Id: bdist_packager.py,v 0.1 2001/04/4 mwa"
12 from distutils
.core
import Command
13 from distutils
.util
import get_platform
14 from distutils
.dir_util
import create_tree
, remove_tree
15 from distutils
.file_util
import write_file
16 from distutils
.errors
import *
17 from distutils
import log
20 class bdist_packager (Command
):
22 description
= "abstract base for package manager specific bdist commands"
24 # XXX update user_options
27 "base directory for creating built distributions"),
29 "base directory for creating binary packages (defaults to \"binary\" under "),
31 "directory to put final RPM files in "
32 "(and .spec files if --spec-only)"),
34 "Software category (packager dependent format)"),
36 "package revision number"),
39 ('subpackages=', None,
40 "Comma seperated list of seperately packaged trees"),
42 "preinstall script (Bourne shell code)"),
43 ('postinstall=', None,
44 "postinstall script (Bourne shell code)"),
46 "preremove script (Bourne shell code)"),
48 "postremove script (Bourne shell code)"),
50 "capabilities required by this package"),
52 "don't clean up RPM build directory"),
53 ('control-only', None,
54 "Generate package control files and stop"),
55 ('no-autorelocate', None,
56 "Inhibit automatic relocation to installed site-packages"),
59 boolean_options
= ['keep-temp', 'control-only', 'no_autorelocate']
61 def ensure_string_not_none (self
,option
,default
=None):
62 val
= getattr(self
,option
)
65 Command
.ensure_string(self
,option
,default
)
66 val
= getattr(self
,option
)
68 raise DistutilsOptionError
, "'%s' must be provided" % option
70 def ensure_script(self
, arg
):
74 self
.ensure_string(arg
)
77 self
.ensure_filename(arg
)
79 raise RuntimeError, "cannot decipher script option (%s)" % arg
81 def write_script (self
,path
,attr
,default
=None):
82 """ write the script specified in attr to path. if attr is None,
83 write use default instead """
84 val
= getattr(self
,attr
)
89 setattr(self
,attr
,default
)
92 log
.info('Creating %s script', attr
)
93 self
.execute(write_file
,
94 (path
, self
.get_script(attr
)),
95 "writing '%s'" % path
)
97 def get_binary_name(self
):
98 py_ver
= sys
.version
[0:string
.find(sys
.version
,' ')]
99 return self
.name
+ '-' + self
.version
+ '-' + \
100 self
.revision
+ '-' + py_ver
102 def get_script (self
, attr
):
103 # accept a script as a string ("line\012line\012..."),
104 # a filename, or a list
105 # XXX We could probably get away with copy_file, but I'm
106 # guessing this will be more flexible later on....
107 val
= getattr(self
, attr
)
115 ret
= string
.split(f
.read(), "\012");
118 if type(val
) == type(""):
120 ret
= string
.split(val
, "\012")
121 elif type(val
) == type([]):
125 raise RuntimeError, \
126 "cannot figure out what to do with 'request' option (%s)" \
131 def initialize_options (self
):
133 self
.control_only
= 0
134 self
.no_autorelocate
= 0
136 self
.plat_name
= None
139 self
.subpackages
= None
148 #self.author_email = None
149 #self.maintainer = None
150 #self.maintainer_email = None
151 #self.description = None
152 #self.long_description = None
154 #self.platforms = None
155 #self.keywords = None
156 self
.root_package
= None
158 # package installation scripts
159 self
.preinstall
= None
160 self
.postinstall
= None
161 self
.preremove
= None
162 self
.postremove
= None
163 # initialize_options()
166 def finalize_options (self
):
168 if self
.pkg_dir
is None:
169 bdist_base
= self
.get_finalized_command('bdist').bdist_base
170 self
.pkg_dir
= os
.path
.join(bdist_base
, 'binary')
172 if not self
.plat_name
:
173 self
.plat
= self
.distribution
.get_platforms()
174 if self
.distribution
.has_ext_modules():
175 self
.plat_name
= [sys
.platform
,]
177 self
.plat_name
= ["noarch",]
179 d
= self
.distribution
180 self
.ensure_string_not_none('name', d
.get_name())
181 self
.ensure_string_not_none('version', d
.get_version())
182 self
.ensure_string('category')
183 self
.ensure_string('revision',"1")
184 #self.ensure_string('url',d.get_url())
185 if type(self
.distribution
.packages
) == type([]):
186 self
.root_package
=self
.distribution
.packages
[0]
188 self
.root_package
=self
.name
189 self
.ensure_string('root_package',self
.root_package
)
190 #self.ensure_string_list('keywords')
191 #self.ensure_string_not_none('author', d.get_author())
192 #self.ensure_string_not_none('author_email', d.get_author_email())
193 self
.ensure_filename('icon')
194 #self.ensure_string_not_none('maintainer', d.get_maintainer())
195 #self.ensure_string_not_none('maintainer_email',
196 #d.get_maintainer_email())
197 #self.ensure_string_not_none('description', d.get_description())
198 #self.ensure_string_not_none('long_description', d.get_long_description())
199 #if self.long_description=='UNKNOWN':
200 #self.long_description=self.description
201 #self.ensure_string_not_none('license', d.get_license())
202 self
.ensure_string_list('requires')
203 self
.ensure_filename('preinstall')
204 self
.ensure_filename('postinstall')
205 self
.ensure_filename('preremove')
206 self
.ensure_filename('postremove')
213 raise RuntimeError, \
214 "abstract method -- subclass %s must override" % self
.__class
__
215 self
.run_command('build')
217 install
= self
.reinitialize_command('install', reinit_subcommands
=1)
218 install
.root
= self
.pkg_dir
220 log
.info("installing to %s", self
.pkg_dir
)
221 self
.run_command('install')
222 if not self
.keep_temp
:
223 remove_tree(self
.pkg_dir
, dry_run
=self
.dry_run
)
227 # class bdist_packager