/scripts/dist-scramble.py

https://bitbucket.org/cistrome/cistrome-harvard/ · Python · 91 lines · 72 code · 2 blank · 17 comment · 6 complexity · a1322b3f7f585824e877970bad0fba2f MD5 · raw file

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