# Path: settings.py
# ZONESTARTPORT = 1300
# 
# ZONEENDPORT = 1400
# 
# Path: elixir_models.py
# class RetryDB(RetryOperationalError, SqliteExtDatabase):
# class ComplexEncoder(json.JSONEncoder):
# class BaseModel(Model):
#     class Meta:
# class User(BaseModel):
# class Character(BaseModel):
# class Zone(BaseModel):
# class Message(BaseModel):
# class Object(BaseModel):
# class Message(BaseModel):
# class ScriptedObject(Object):
#     def default(self, obj):
#     def exists(cls, *args, **kwargs):
#     def json_dumps(self):
#     def __repr__(self):
#     def __repr__(self):
#     def loc(self):
#     def loc(self, val):
#     def set_modified(self, date_time=None):
#     def get_objects(since=None, physical=None, limit=None, player=None, scripted=None, name=None):
# def setup(db_uri='simplemmo.sqlite', echo=False):


import xmlrpclib
import supervisor
    import socket
from supervisor.xmlrpc import SupervisorTransport
from settings import ZONESTARTPORT, ZONEENDPORT
from elixir_models import Zone, session
            from settings import PROTOCOL, HOSTNAME
                if "STILL_RUNNING" in exc.faultString:
                    # Process still running just fine, return true.
                    print "Still running, leaving it alone."
                    retval = True
            else:
                print "Restarting stopped/crashed zone."
                # Removing the process worked, delete the zone from the database.
                Zone.query.filter_by(zoneid=zoneid).delete()
                session.commit()
                # Start zone again
                retval = _add_process(s, processgroup, zoneid, settings, port)
        else:
            print exc
            print exc.faultCode, exc.faultString
            raise
    finally:
        session.commit()
        return retval

def start_zone(port=1300, zonename="defaultzone", instancetype="playerinstance", owner="Groxnor", processgroup='zones', autorestart=False):
    s = xmlrpclib.ServerProxy('http://localhost:9001')

    try:
        version = s.twiddler.getAPIVersion()
    except(socket.error), exc:
        raise UserWarning("Could not connect to supervisor: %s" % exc)

    if float(version) >= 0.3:
        # Query through all our zones to get a good port number.
        taken_ports = [p[0] for p in session.query(Zone.port).all()]

# Path: settings.py
# ZONESTARTPORT = 1300
# 
# ZONEENDPORT = 1400
# 
# Path: elixir_models.py
# class RetryDB(RetryOperationalError, SqliteExtDatabase):
# class ComplexEncoder(json.JSONEncoder):
# class BaseModel(Model):
#     class Meta:
# class User(BaseModel):
# class Character(BaseModel):
# class Zone(BaseModel):
# class Message(BaseModel):
# class Object(BaseModel):
# class Message(BaseModel):
# class ScriptedObject(Object):
#     def default(self, obj):
#     def exists(cls, *args, **kwargs):
#     def json_dumps(self):
#     def __repr__(self):
#     def __repr__(self):
#     def loc(self):
#     def loc(self, val):
#     def set_modified(self, date_time=None):
#     def get_objects(since=None, physical=None, limit=None, player=None, scripted=None, name=None):
# def setup(db_uri='simplemmo.sqlite', echo=False):


# Path: start_supervisord_process.py
import xmlrpclib
import supervisor
    import socket
from supervisor.xmlrpc import SupervisorTransport
from settings import ZONESTARTPORT, ZONEENDPORT
from elixir_models import Zone, session
            from settings import PROTOCOL, HOSTNAME

                if "STILL_RUNNING" in exc.faultString:
                    # Process still running just fine, return true.
                    print "Still running, leaving it alone."
                    retval = True
            else:
                print "Restarting stopped/crashed zone."
                # Removing the process worked, delete the zone from the database.
                Zone.query.filter_by(zoneid=zoneid).delete()
                session.commit()
                # Start zone again
                retval = _add_process(s, processgroup, zoneid, settings, port)
        else:
            print exc
            print exc.faultCode, exc.faultString
            raise
    finally:
        session.commit()
        return retval

def start_zone(port=1300, zonename="defaultzone", instancetype="playerinstance", owner="Groxnor", processgroup='zones', autorestart=False):
    s = xmlrpclib.ServerProxy('http://localhost:9001')

    try:
        version = s.twiddler.getAPIVersion()
    except(socket.error), exc:
        raise UserWarning("Could not connect to supervisor: %s" % exc)

    if float(version) >= 0.3:
        # Query through all our zones to get a good port number.
        taken_ports = [p[0] for p in session.query(Zone.port).all()]

        for port in xrange(ZONESTARTPORT, ZONEENDPORT):