PageRenderTime 25ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/scripts/dist-scramble.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 91 lines | 72 code | 2 blank | 17 comment | 8 complexity | a1322b3f7f585824e877970bad0fba2f MD5 | raw file
 1"""
 2Scrambles eggs for distribution on multiple platforms.
 3
 4(from http://wiki.g2.bx.psu.edu/Admin/Config/Eggs)
 5This is mostly designed for use by Galaxy Developers at Penn State who are
 6building eggs for distribution via the Galaxy Eggs distribution site.
 7dist-scramble.py uses the dist-eggs.ini config file to determine what platforms
 8to build for, and which hosts to build on.
 9
10dist-scramble.py works the same way as scramble.py: ::
11
12% python scripts/dist-scramble.py galaxy_egg
13
14Called with only the egg argument, dist-scramble.py will build for all the
15platforms under the all group in its config file (for platform-specific eggs)
16or the noplatform group (for platform-inspecific eggs). The [[hosts]|section
17contains information about which hosts will be used for building on each desired
18platform. If you don't want to build for all the platforms listed under the all
19group, you can add a platform argument (any lvalue in the [hosts]] or [groups]
20section is valid): ::
21
22% python scripts/dist-scramble.py galaxy_egg linux
23
24The platform argument is ignored for platform-inspecific eggs. An assumption is
25made that your Galaxy distribution is located at the same place on all of the
26hosts on which you're building (i.e. via a network filesystem).
27
28Once dist-scramble.py finishes, it will output a list of platforms on which it
29failed to scramble the egg. Successful eggs will be put in a new dist-eggs
30subdirectory of your Galaxy distribution. These eggs can then be copied to your
31distribution site.
32"""
33
34import os, sys, logging
35from optparse import OptionParser
36
37parser = OptionParser()
38parser.add_option( '-e', '--egg-name', dest='egg_name', help='Egg name (as defined in eggs.ini) to scramble (required)' )
39parser.add_option( '-p', '--platform', dest='platform', help='Scramble for a specific platform (by default, eggs are scrambled for all platforms, see dist-eggs.ini for platform names)' )
40( options, args ) = parser.parse_args()
41
42root = logging.getLogger()
43root.setLevel( 10 )
44root.addHandler( logging.StreamHandler( sys.stdout ) )
45
46lib = os.path.abspath( os.path.join( os.path.dirname( __file__ ), '..', 'lib' ) )
47sys.path.append( lib )
48
49from galaxy.eggs.dist import DistScrambleCrate, ScrambleFailure
50from galaxy.eggs import EggNotFetchable
51
52if not options.egg_name:
53    print "ERROR: You must specify an egg to scramble (-e)"
54    parser.print_help()
55    sys.exit( 1 )
56
57if options.platform:
58    c = DistScrambleCrate( None, options.platform )
59else:
60    c = DistScrambleCrate( None )
61
62try:
63    eggs = c[options.egg_name]
64except:
65    print "ERROR: %s not in eggs.ini" % options.egg_name
66    sys.exit( 1 )
67failed = []
68for egg in eggs:
69    try:
70        for dependency in egg.dependencies:
71            print "Checking %s on %s dependency: %s" % ( egg.name, egg.platform, dependency )
72            # this could be in a better data structure...
73            dep = filter( lambda x: x.platform == egg.platform, c[dependency] )[0]
74            if not os.path.exists( dep.distribution.location ):
75                dep.fetch( dep.distribution.as_requirement() )
76    except EggNotFetchable, e:
77        degg = e.eggs[0]
78        print "%s build dependency %s %s %s couldn't be" % ( egg.name, degg.name, degg.version, degg.platform )
79        print "downloaded automatically.  There isn't really a graceful"
80        print "way to handle this when dist-scrambling."
81        failed.append( egg.platform )
82        continue
83    try:
84        egg.scramble()
85    except ScrambleFailure:
86        failed.append( egg.platform )
87if len( failed ):
88    print ""
89    print "Scramble failed to build eggs on the following platforms (more details"
90    print "can be found by reviewing the output above):"
91    print "\n".join( failed )