#!/usr/bin/env python

import sys, os
import subprocess
from optparse import OptionParser

option_parser = OptionParser(usage='''
%prog [options] GRAPHITE_ROOT
''')
option_parser.add_option('--port', default=8080, action='store', type=int, help='Port to listen on')
option_parser.add_option('--libs', default=None, help='Path to the directory containing the graphite python package')
option_parser.add_option('--noreload', action='store_true', help='Disable monitoring for changes')

(options, args) = option_parser.parse_args()

if not args:
  option_parser.print_usage()
  sys.exit(1)

graphite_root = args[0]

django_admin = None
for name in ('django-admin', 'django-admin.py'):
  try:
    django_admin = subprocess.check_output(['which', name])
    break
  except subprocess.CalledProcessError:
    pass

if not django_admin:
  print "Could not find a django-admin script!"
  sys.exit(1)

python_path = os.path.join(graphite_root, 'webapp')

if options.libs:
  libdir = os.path.expanduser(options.libs)
  print 'Adding %s to your PYTHONPATH' % libdir
  os.environ['PYTHONPATH'] = libdir + ':' + os.environ.get('PYTHONPATH','')

print "Running Graphite from %s under django development server\n" % graphite_root

command = [
  django_admin,
  'runserver',
  '--pythonpath', python_path,
  '--settings', 'graphite.settings',
  '0.0.0.0:%d' % options.port
]

if options.noreload:
  command.append('--noreload')

print ' '.join(command)
os.execvp(django_admin, command)

@@ -681,29 +681,15 @@
 :%0A  
-try:%0A    django_admin
+process
  = s
@@ -702,20 +702,13 @@
 ess.
-check_output
+Popen
 (%5B'w
@@ -723,68 +723,136 @@
 ame%5D
-)%0A    break%0A  except subprocess.CalledProcessError:%0A    pass
+, stdout=subprocess.PIPE)%0A  output = process.stdout.read().strip()%0A  if process.wait() == 0:%0A    django_admin = output%0A    break
 %0A%0Aif

Fix python2.4 compatibility for run-graphite-devel-server.py