/scripts/make_egg_packager.py

https://bitbucket.org/cistrome/cistrome-harvard/ · Python · 71 lines · 58 code · 12 blank · 1 comment · 4 complexity · ba60304abacb5ce67469e07b6c6890f8 MD5 · raw file

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