RegionGenerator

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
Line 9: Line 9:
 
import uuid
 
import uuid
 
import os
 
import os
 +
import pickle
  
 
# START OF CONFIGURATION
 
# START OF CONFIGURATION
 
s = {}
 
s = {}
 +
 
# Region Configuration
 
# Region Configuration
s['regionname'] = "myland"    # Type the name of your island
+
s['regionname'] = "LandsNameHere"    # Type the name of your land
 
s['x'] = [2900,3000]                # From - To x position
 
s['x'] = [2900,3000]                # From - To x position
 
s['y'] = [2900,3000]                # From - To y position
 
s['y'] = [2900,3000]                # From - To y position
 +
 +
 
# User Configuration
 
# User Configuration
s['firstname'] = "firstname"          # Account firstname
+
s['firstname'] = "John"          # Account firstname
s['lastname'] = "lastname"              # Account lastname
+
s['lastname'] = "Doe"              # Account lastname
 
s['useruuid'] = 'your clients uuid goes here'
 
s['useruuid'] = 'your clients uuid goes here'
s['password'] = 'password'          # Account password
+
s['password'] = 'mypass'          # Account password
 +
 
 +
 
 
# Network Configuration
 
# Network Configuration
 
s['startport'] = 9000              # Port the regions start on
 
s['startport'] = 9000              # Port the regions start on
 
                                     # incrimented by 1 each time
 
                                     # incrimented by 1 each time
s['internalip'] = "23.984.259.770"  # Server ip
+
s['internalip'] = "123.456.789.123"  # Server ip
s['externalhost'] = "myhost"  # Domain name or ip of server
+
s['externalhost'] = "mydomain.org"  # Domain name or ip of server
 
                                     # (accessed externally)
 
                                     # (accessed externally)
 
# ------------------------------
 
# ------------------------------
  
regionsdir = 'Regions'             # Files created in this directory, created if not found.
+
# Files are put in here.
# Template
+
regionsdir = 'Regions'
 +
 
 
template = """<Root>
 
template = """<Root>
 
<Config sim_UUID="$uuid" sim_name="$regionname" sim_location_x="$x" sim_location_y="$y" internal_ip_address="$s.internalip" internal_ip_port="$port" allow_alternate_ports="false" external_host_name="$s.externalhost" master_avatar_uuid="$s.useruuid" estate_covenant_uuid="00000000-0000-0000-0000-000000000000" master_avatar_first="$s.firstname" master_avatar_last="$s.lastname" master_avatar_pass="$s.password" />
 
<Config sim_UUID="$uuid" sim_name="$regionname" sim_location_x="$x" sim_location_y="$y" internal_ip_address="$s.internalip" internal_ip_port="$port" allow_alternate_ports="false" external_host_name="$s.externalhost" master_avatar_uuid="$s.useruuid" estate_covenant_uuid="00000000-0000-0000-0000-000000000000" master_avatar_first="$s.firstname" master_avatar_last="$s.lastname" master_avatar_pass="$s.password" />
 
</Root>"""
 
</Root>"""
 +
 +
savefile = "regiongen_save.pkl"
 
# END OF CONFIGURATION
 
# END OF CONFIGURATION
  
def maketemplate(regionname,x,y,port):
+
def maketemplate(regionname, x, y, port, uid):
 
     t = Template(template)
 
     t = Template(template)
 
     t.s = s
 
     t.s = s
     t.uuid = str(uuid.uuid1())
+
     t.uuid = uid
 
     t.regionname = regionname
 
     t.regionname = regionname
 
     t.x = x
 
     t.x = x
Line 46: Line 55:
 
     return str(t)
 
     return str(t)
  
 +
# Make directory to put regions in if not there
 
try:
 
try:
 
     os.mkdir(regionsdir)
 
     os.mkdir(regionsdir)
 
except OSError:
 
except OSError:
 +
    pass
 +
 +
settings = {}
 +
 +
# Load settings file
 +
try:
 +
    settingsfile = open(savefile)
 +
    settings = pickle.load(settingsfile)
 +
    settingsfile.close()
 +
except IOError:
 
     pass
 
     pass
  
Line 55: Line 75:
 
     for ynum in range(s['y'][0], s['y'][1]):
 
     for ynum in range(s['y'][0], s['y'][1]):
 
         counter += 1
 
         counter += 1
 +
        default = False
 
          
 
          
 +
        # Figure out region name
 
         if counter == 1:
 
         if counter == 1:
 +
            default = True
 
             regionname = s['regionname']
 
             regionname = s['regionname']
 
         else:
 
         else:
 
             regionname = s['regionname'] + str(counter)
 
             regionname = s['regionname'] + str(counter)
 
          
 
          
         path = os.path.join(regionsdir,"%s.%s.%s.xml" % (regionname, xnum, ynum))
+
         # Figure out paths
 +
        if default:
 +
            path = os.path.join(regionsdir,"default.xml")
 +
        else:
 +
            path = os.path.join(regionsdir,"%s.%s.%s.xml" % \
 +
                    (regionname, xnum, ynum))
 +
       
 +
        # Calculate port
 +
        port = s['startport'] + (counter - 1)
 +
        # Try to get UUID from settings
 +
        # Generate + Save if not found
 +
        if settings.has_key(regionname):
 +
            uid = settings[regionname]
 +
        else:
 +
            uid = str(uuid.uuid1())
 +
            settings[regionname] = uid
 +
        # Make template
 +
        tmpldata = maketemplate(regionname, xnum, ynum, port, uid)
 +
       
 +
        # Save file
 
         tmplfile = open(path, 'w')
 
         tmplfile = open(path, 'w')
         tmplfile.write(maketemplate(regionname, xnum, ynum, s['startport'] + (counter - 1)))
+
         tmplfile.write(tmpldata)
        tmplfile.close()</pre>
+
        tmplfile.close()
 +
       
 +
        # Print progress
 +
        print regionname
 +
 
 +
# Save settings file
 +
try:
 +
    settingsfile = open(savefile, 'w')
 +
    pickle.dump(settings, settingsfile)
 +
    settingsfile.close()
 +
except IOError:
 +
    pass
 +
</pre>

Revision as of 05:11, 13 July 2008

Heres a Region Generator in Python

It generates a square piece of land.

It requires the cheetah templating module and python 2.5

#!/usr/bin/python
from Cheetah.Template import Template
import uuid
import os
import pickle

# START OF CONFIGURATION
s = {}

# Region Configuration
s['regionname'] = "LandsNameHere"     # Type the name of your land
s['x'] = [2900,3000]                # From - To x position
s['y'] = [2900,3000]                # From - To y position


# User Configuration
s['firstname'] = "John"           # Account firstname
s['lastname'] = "Doe"              # Account lastname
s['useruuid'] = 'your clients uuid goes here'
s['password'] = 'mypass'           # Account password


# Network Configuration
s['startport'] = 9000               # Port the regions start on
                                    # incrimented by 1 each time
s['internalip'] = "123.456.789.123"   # Server ip
s['externalhost'] = "mydomain.org"  # Domain name or ip of server
                                    # (accessed externally)
# ------------------------------

# Files are put in here.
regionsdir = 'Regions'

template = """<Root>
<Config sim_UUID="$uuid" sim_name="$regionname" sim_location_x="$x" sim_location_y="$y" internal_ip_address="$s.internalip" internal_ip_port="$port" allow_alternate_ports="false" external_host_name="$s.externalhost" master_avatar_uuid="$s.useruuid" estate_covenant_uuid="00000000-0000-0000-0000-000000000000" master_avatar_first="$s.firstname" master_avatar_last="$s.lastname" master_avatar_pass="$s.password" />
</Root>"""

savefile = "regiongen_save.pkl"
# END OF CONFIGURATION

def maketemplate(regionname, x, y, port, uid):
    t = Template(template)
    t.s = s
    t.uuid = uid
    t.regionname = regionname
    t.x = x
    t.y = y
    t.port = port
    return str(t)

# Make directory to put regions in if not there
try:
    os.mkdir(regionsdir)
except OSError:
    pass

settings = {}

# Load settings file
try:
    settingsfile = open(savefile)
    settings = pickle.load(settingsfile)
    settingsfile.close()
except IOError:
    pass

counter = 0
for xnum in range(s['x'][0], s['x'][1]):
    for ynum in range(s['y'][0], s['y'][1]):
        counter += 1
        default = False
        
        # Figure out region name
        if counter == 1:
            default = True
            regionname = s['regionname']
        else:
            regionname = s['regionname'] + str(counter)
        
        # Figure out paths
        if default:
            path = os.path.join(regionsdir,"default.xml")
        else:
            path = os.path.join(regionsdir,"%s.%s.%s.xml" % \
                    (regionname, xnum, ynum))
        
        # Calculate port
        port = s['startport'] + (counter - 1)
        # Try to get UUID from settings
        # Generate + Save if not found
        if settings.has_key(regionname):
            uid = settings[regionname]
        else:
            uid = str(uuid.uuid1())
            settings[regionname] = uid
        # Make template
        tmpldata = maketemplate(regionname, xnum, ynum, port, uid)
        
        # Save file
        tmplfile = open(path, 'w')
        tmplfile.write(tmpldata)
        tmplfile.close()
        
        # Print progress
        print regionname

# Save settings file
try:
    settingsfile = open(savefile, 'w')
    pickle.dump(settings, settingsfile)
    settingsfile.close()
except IOError:
    pass
Personal tools
General
About This Wiki