import sys
import os

# This only works if you're running schematic from the zamboni root.
sys.path.insert(0, os.path.realpath('.'))

# Set up zamboni.
import manage
from django.conf import settings

config = settings.DATABASES['default']
config['HOST'] = config.get('HOST', 'localhost')
config['PORT'] = config.get('PORT', '3306')

if config['HOST'].endswith('.sock'):
    """ Oh you meant 'localhost'! """
    config['HOST'] = 'localhost'

s = 'mysql --silent {NAME} -h{HOST} -P{PORT} -u{USER}'

if config['PASSWORD']:
    s += ' -p{PASSWORD}'
else:
    del config['PASSWORD']

db = s.format(**config)
table = 'schema_version'

import sys
import os

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

# Set up zamboni.
import manage
from django.conf import settings

config = settings.DATABASES['default']
config['HOST'] = config.get('HOST', 'localhost')
config['PORT'] = config.get('PORT', '3306')

if not config['HOST'] or config['HOST'].endswith('.sock'):
    """ Oh you meant 'localhost'! """
    config['HOST'] = 'localhost'

s = 'mysql --silent {NAME} -h{HOST} -u{USER}'

if config['PASSWORD']:
    s += ' -p{PASSWORD}'
else:
    del config['PASSWORD']
if config['PORT']:
    s += ' -P{PORT}'
else:
    del config['PORT']

db = s.format(**config)
table = 'schema_version'

Make the settings work when there's no port, and fix up the path manipulation
Make the settings work when there's no port, and fix up the path manipulation

  import sys
  import os
  
+ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
- # This only works if you're running schematic from the zamboni root.
- sys.path.insert(0, os.path.realpath('.'))
  
  # Set up zamboni.
  import manage
  from django.conf import settings
  
  config = settings.DATABASES['default']
  config['HOST'] = config.get('HOST', 'localhost')
  config['PORT'] = config.get('PORT', '3306')
  
- if config['HOST'].endswith('.sock'):
+ if not config['HOST'] or config['HOST'].endswith('.sock'):
      """ Oh you meant 'localhost'! """
      config['HOST'] = 'localhost'
  
- s = 'mysql --silent {NAME} -h{HOST} -P{PORT} -u{USER}'
+ s = 'mysql --silent {NAME} -h{HOST} -u{USER}'
  
  if config['PASSWORD']:
      s += ' -p{PASSWORD}'
  else:
      del config['PASSWORD']
+ if config['PORT']:
+     s += ' -P{PORT}'
+ else:
+     del config['PORT']
  
  db = s.format(**config)
  table = 'schema_version'
  
Make the settings work when there's no port, and fix up the path manipulation
## Code Before:
import sys
import os

# This only works if you're running schematic from the zamboni root.
sys.path.insert(0, os.path.realpath('.'))

# Set up zamboni.
import manage
from django.conf import settings

config = settings.DATABASES['default']
config['HOST'] = config.get('HOST', 'localhost')
config['PORT'] = config.get('PORT', '3306')

if config['HOST'].endswith('.sock'):
    """ Oh you meant 'localhost'! """
    config['HOST'] = 'localhost'

s = 'mysql --silent {NAME} -h{HOST} -P{PORT} -u{USER}'

if config['PASSWORD']:
    s += ' -p{PASSWORD}'
else:
    del config['PASSWORD']

db = s.format(**config)
table = 'schema_version'

## Instruction:
Make the settings work when there's no port, and fix up the path manipulation
## Code After:
import sys
import os

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

# Set up zamboni.
import manage
from django.conf import settings

config = settings.DATABASES['default']
config['HOST'] = config.get('HOST', 'localhost')
config['PORT'] = config.get('PORT', '3306')

if not config['HOST'] or config['HOST'].endswith('.sock'):
    """ Oh you meant 'localhost'! """
    config['HOST'] = 'localhost'

s = 'mysql --silent {NAME} -h{HOST} -u{USER}'

if config['PASSWORD']:
    s += ' -p{PASSWORD}'
else:
    del config['PASSWORD']
if config['PORT']:
    s += ' -P{PORT}'
else:
    del config['PORT']

db = s.format(**config)
table = 'schema_version'
