Changeset 1268:70fea4390d3d

Show
Ignore:
Timestamp:
05/02/08 13:05:40 (8 months ago)
Author:
Nate Coraor <nate@bx.psu.edu>
branch:
default
convert_revision:
svn:9bcadc22-80f8-0310-8a53-c8f022958886/galaxy/trunk@2629
Message:

dist-scramble, scrambles eggs for distribution.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lib/galaxy/eggs/__init__.py

    r1193 r1268  
    2323class PlatformNotSupported( Exception ): 
    2424    pass 
     25 
     26# TODO: we should really be using exceptions instead of returns for everything 
    2527 
    2628# need the options to remain case sensitive 
     
    4951        self.doppelgangers = [] 
    5052        self.buildpath = None 
     53        self.dir = None 
     54        self.build_host = None 
     55        self.python = sys.executable 
     56    def set_dir( self ): 
     57        if self.build_host is not None: 
     58            self.dir = os.path.join( galaxy_dir, "dist-eggs", self.platform['galaxy'] ) 
     59        else: 
     60            self.dir = os.path.join( galaxy_dir, "eggs", self.platform['galaxy'] ) 
     61        print "set dir to %s" % self.dir 
    5162    def get_namever( self ): 
    5263        return( "%s-%s" %( self.name, self.version ) ) 
     
    6879    def find( self ): 
    6980        # TODO: should be able to set a search path in eggs.ini 
    70         self.path = os.path.join( galaxy_dir, "eggs", self.platform['galaxy'], self.get_filename() ) 
    71         self.doppelgangers = glob.glob( os.path.join( galaxy_dir, "eggs", self.platform['galaxy'], "%s-*-%s.egg" % (self.name, self.platform['peak'] ) ) ) 
     81        if self.dir is None: 
     82            self.set_dir() 
     83        self.path = os.path.join( self.dir, self.get_filename() ) 
     84        self.doppelgangers = glob.glob( os.path.join( self.dir, "%s-*-%s.egg" % (self.name, self.platform['peak'] ) ) ) 
    7285        if os.access( self.path, os.F_OK ): 
    7386            self.have = True 
     
    115128        log.warning( "scramble(): Beginning build" ) 
    116129        # subprocessed to sterilize the env 
    117         cmd = "%s -ES %s" % ( sys.executable, "scramble.py" ) 
     130        if self.build_host is not None: 
     131            cmd = "ssh %s 'cd %s; %s -ES %s'" % ( self.build_host, self.buildpath, self.python, "scramble.py" ) 
     132        else: 
     133            cmd = "%s -ES %s" % ( self.python, "scramble.py" ) 
    118134        p = subprocess.Popen( args = cmd, shell = True, cwd = self.buildpath ) 
    119135        r = p.wait() 
     
    337353                return self.eggs[key] 
    338354 
     355class 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 
    339438class GalaxyConfig: 
    340439    config_file = os.path.join( galaxy_dir, "universe_wsgi.ini" )