| | 355 | class DistCrate( Crate ): |
|---|
| | 356 | """ |
|---|
| | 357 | A subclass of Crate that holds eggs with info on how to build them for distribution. |
|---|
| | 358 | """ |
|---|
| | 359 | dist_config_file = os.path.join( galaxy_dir, "dist-eggs.ini" ) |
|---|
| | 360 | def __init__( self, build_on="all" ): |
|---|
| | 361 | self.eggs = {} |
|---|
| | 362 | self.config = CSConfigParser() |
|---|
| | 363 | self.repo = None |
|---|
| | 364 | self.build_on = build_on |
|---|
| | 365 | self.platform = 'platform' |
|---|
| | 366 | self.noplatform = 'noplatform' |
|---|
| | 367 | def parse( self ): |
|---|
| | 368 | if self.config.read( DistCrate.dist_config_file ) == []: |
|---|
| | 369 | raise Exception( "unable to read dist egg config from %s" % DistCrate.dist_config_file ) |
|---|
| | 370 | try: |
|---|
| | 371 | self.hosts = self.dictize_list_of_tuples( self.config.items( "hosts" ) ) |
|---|
| | 372 | self.groups = self.dictize_list_of_tuples( self.config.items( "groups" ) ) |
|---|
| | 373 | except ConfigParser.NoSectionError, e: |
|---|
| | 374 | raise Exception( "eggs.ini is missing required section: %s" % e ) |
|---|
| | 375 | self.platforms = self.get_platforms( self.build_on ) |
|---|
| | 376 | self.noplatforms = self.get_platforms( 'noplatform' ) |
|---|
| | 377 | Crate.parse( self ) |
|---|
| | 378 | def dictize_list_of_tuples( self, lot ): |
|---|
| | 379 | """ |
|---|
| | 380 | Makes a list of 2-value tuples into a dict. |
|---|
| | 381 | """ |
|---|
| | 382 | d = {} |
|---|
| | 383 | for k, v in lot: |
|---|
| | 384 | d[k] = v |
|---|
| | 385 | return d |
|---|
| | 386 | def get_platforms( self, wanted ): |
|---|
| | 387 | # find all the members of a group and process them |
|---|
| | 388 | if self.groups.has_key( wanted ): |
|---|
| | 389 | platforms = [] |
|---|
| | 390 | for name in self.groups[wanted].split(): |
|---|
| | 391 | for platform in self.get_platforms( name ): |
|---|
| | 392 | if platform not in platforms: |
|---|
| | 393 | platforms.append( platform ) |
|---|
| | 394 | return platforms |
|---|
| | 395 | elif self.hosts.has_key( wanted ): |
|---|
| | 396 | return [ wanted ] |
|---|
| | 397 | else: |
|---|
| | 398 | raise Exception( "unknown platform: %s" % wanted ) |
|---|
| | 399 | def parse_egg_section( self, eggs, type ): |
|---|
| | 400 | """ |
|---|
| | 401 | Overrides the base class's method. Here we use the third arg |
|---|
| | 402 | to find out what type of egg we'll be building. |
|---|
| | 403 | """ |
|---|
| | 404 | if type == "platform": |
|---|
| | 405 | platforms = self.platforms |
|---|
| | 406 | elif type == "noplatform": |
|---|
| | 407 | platforms = self.noplatforms |
|---|
| | 408 | for name, version in eggs: |
|---|
| | 409 | for platform in platforms: |
|---|
| | 410 | # can't use the regular methods here because we're not |
|---|
| | 411 | # actually ON the target platform |
|---|
| | 412 | if type == "platform": |
|---|
| | 413 | gplat = platform |
|---|
| | 414 | pplat = platform.rsplit('-', 1)[0] |
|---|
| | 415 | elif type == "noplatform": |
|---|
| | 416 | gplat = "%s-noplatform" % platform.split('-', 1)[0] |
|---|
| | 417 | pplat = platform.split('-', 1)[0] |
|---|
| | 418 | egg = Egg() |
|---|
| | 419 | try: |
|---|
| | 420 | egg.tag = self.config.get( "tags", name ) |
|---|
| | 421 | except: |
|---|
| | 422 | egg.tag = None |
|---|
| | 423 | try: |
|---|
| | 424 | egg.sources = self.config.get( "source", name ).split() |
|---|
| | 425 | except: |
|---|
| | 426 | egg.sources = None |
|---|
| | 427 | egg.name = name |
|---|
| | 428 | egg.version = version |
|---|
| | 429 | egg.platform['galaxy'] = gplat |
|---|
| | 430 | egg.platform['peak'] = pplat |
|---|
| | 431 | egg.url = "%s/%s/%s" %( self.repo, gplat, egg.get_filename() ) |
|---|
| | 432 | egg.build_host, egg.python = self.hosts[platform].split() |
|---|
| | 433 | if not self.eggs.has_key( name ): |
|---|
| | 434 | self.eggs[name] = [ egg ] |
|---|
| | 435 | else: |
|---|
| | 436 | self.eggs[name].append( egg ) |
|---|
| | 437 | |
|---|