PageRenderTime 44ms CodeModel.GetById 31ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/galaxy/eggs/dist.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 92 lines | 79 code | 4 blank | 9 comment | 14 complexity | 205e5a3e049411a77c9b016f585b6cb5 MD5 | raw file
 1"""
 2Manage Galaxy eggs
 3"""
 4
 5import os, sys, subprocess
 6from scramble import ScrambleEgg, ScrambleCrate, ScrambleFailure, galaxy_dir, py
 7from __init__ import Crate, CaseSensitiveConfigParser
 8
 9import logging
10log = logging.getLogger( __name__ )
11log.addHandler( logging.NullHandler() )
12
13class DistScrambleEgg( ScrambleEgg ):
14    def set_dir( self ):
15        self.dir = os.path.join( galaxy_dir, 'dist-eggs', self.name )
16        if not os.path.exists( self.dir ):
17            os.makedirs( self.dir )
18    @property
19    def path( self ):
20        # don't look for compatible eggs, look for exact matches
21        if os.path.exists( self.distribution.location ):
22            return self.distribution.location
23        return None
24    def run_scramble_script( self ):
25        log.warning( "%s(): Beginning build" % sys._getframe().f_code.co_name )
26        # subprocessed to sterilize the env
27        cmd = "ssh %s 'cd %s; PYTHONPATH= %s -ES %s'" % ( self.build_host, self.buildpath, self.python, 'scramble.py' )
28        log.debug( '%s(): Executing:' % sys._getframe().f_code.co_name )
29        log.debug( '  %s' % cmd )
30        p = subprocess.Popen( args = cmd, shell = True )
31        r = p.wait()
32        if r != 0:
33            raise ScrambleFailure( "%s(): Egg build failed for %s %s" % ( sys._getframe().f_code.co_name, self.name, self.version ) )
34    def unpack_if_needed( self ):
35        return # do not unpack dist eggs
36
37class DistScrambleCrate( ScrambleCrate ):
38    """
39    Holds eggs with info on how to build them for distribution.
40    """
41    dist_config_file = os.path.join( galaxy_dir, 'dist-eggs.ini' )
42    def __init__( self, galaxy_config_file, build_on='all' ):
43        self.dist_config = CaseSensitiveConfigParser()
44        self.build_on = build_on
45        ScrambleCrate.__init__( self, galaxy_config_file )
46    def parse( self ):
47        self.dist_config.read( DistScrambleCrate.dist_config_file )
48        self.hosts = dict( self.dist_config.items( 'hosts' ) )
49        self.groups = dict( self.dist_config.items( 'groups' ) )
50        self.ignore = dict( self.dist_config.items( 'ignore' ) )
51        self.platforms = self.get_platforms( self.build_on )
52        self.noplatforms = self.get_platforms( 'noplatform' )
53        Crate.parse( self )
54    def get_platforms( self, wanted ):
55        # find all the members of a group and process them
56        if self.groups.has_key( wanted ):
57            platforms = []
58            for name in self.groups[wanted].split():
59                for platform in self.get_platforms( name ):
60                    if platform not in platforms:
61                        platforms.append( platform )
62            return platforms
63        elif self.hosts.has_key( wanted ):
64            return [ wanted ]
65        else:
66            raise Exception( "unknown platform: %s" % wanted )
67    def parse_egg_section( self, eggs, tags, full_platform=False ):
68        for name, version in eggs:
69            self.eggs[name] = []
70            tag = dict( tags ).get( name, '' )
71            url = '/'.join( ( self.repo, name ) )
72            try:
73                sources = self.config.get( 'source', name ).split()
74            except:
75                sources = []
76            try:
77                dependencies = self.config.get( 'dependencies', name ).split()
78            except:
79                dependencies = []
80            if full_platform:
81                platforms = self.platforms
82            else:
83                platforms = self.noplatforms
84            for platform in platforms:
85                if name in self.ignore and platform in self.ignore[name].split():
86                    continue
87                egg = DistScrambleEgg( name, version, tag, url, platform, self )
88                host_info = self.hosts[platform].split()
89                egg.build_host, egg.python = host_info[:2]
90                egg.sources = sources
91                egg.dependencies = dependencies
92                self.eggs[name].append( egg )