PageRenderTime 25ms CodeModel.GetById 11ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

/scripts/make_egg_packager.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 71 lines | 59 code | 11 blank | 1 comment | 7 complexity | ba60304abacb5ce67469e07b6c6890f8 MD5 | raw file
 1#!/usr/bin/env python
 2
 3import os, sys, logging, shutil
 4from optparse import OptionParser
 5
 6parser = OptionParser()
 7parser.add_option( '-c', '--config', dest='config', help='Path to Galaxy config file (universe_wsgi.ini)', default='universe_wsgi.ini' )
 8parser.add_option( '-p', '--platform', dest='platform', help='Fetch for a specific platform (by default, eggs are fetched for *this* platform' )
 9( options, args ) = parser.parse_args()
10
11if not os.path.exists( options.config ):
12    print "Config file does not exist (see 'python %s --help'): %s" % ( sys.argv[0], options.config )
13    sys.exit( 1 )
14
15root = logging.getLogger()
16root.setLevel( 10 )
17root.addHandler( logging.StreamHandler( sys.stdout ) )
18
19lib = os.path.abspath( os.path.join( os.path.dirname( __file__ ), "..", "lib" ) )
20sys.path.append( lib )
21
22from galaxy.eggs import Crate, EggNotFetchable, py
23import pkg_resources
24
25try:
26    assert options.platform
27    platform = options.platform
28    c = Crate( options.config, platform = platform )
29    print "Platform forced to '%s'" % platform
30except:
31    platform = '-'.join( ( py, pkg_resources.get_platform() ) )
32    c = Crate( options.config )
33    print "Using Python interpreter at %s, Version %s" % ( sys.executable, sys.version )
34    print "This platform is '%s'" % platform
35    print "Override with:"
36    print "  make_egg_packager.py <forced-platform>"
37
38shutil.copy( os.path.join( os.path.dirname( __file__ ), 'egg_packager_template.py' ), 'egg_packager-%s.py' % platform )
39
40packager = open( 'egg_packager-%s.py' % platform, 'a' )
41packager.write( "py = '%s'\n" % py )
42packager.write( "url = '%s'\n" % c.repo )
43packager.write( "platform = '%s'\n" % platform )
44packager.write( "dists = [\n" )
45
46for egg in c.all_eggs:
47    if egg.name in c.no_auto:
48        continue
49    packager.write( "          Distribution( '%s', '%s', '%s', '%s', '%s' ),\n" % ( egg.distribution.egg_name(), egg.distribution.project_name, egg.distribution.version, egg.distribution.py_version, egg.distribution.platform ) )
50
51packager.write( """]
52
53for d in dists:
54    e = Egg( d )
55    if not e.fetch( None ):
56        failures.append( e )
57
58if failures:
59    print ""
60    print "Failed:"
61    for e in failures:
62        print e.distribution.project_name
63else:
64    create_zip()
65clean()
66""" ) 
67
68print "Completed packager is 'egg_packager-%s.py'.  To" % platform
69print "fetch eggs, please copy this file to a system with internet access and run"
70print "with:"
71print "  python egg_packager-%s.py" % platform