Install script for memcached-1.2.1

-----BEGIN WEBFACTION INSTALL SCRIPT-----
#!/usr/local/bin/python2.5

"""
 memcached 1.2.1

After installation memcached will be listening on the port assigned to the application. Upon execution ~/webapps/(Application Name)/start.py and ~/webapps/(Application Name)/stop.py will start and stop memcached respetively.

"autostart": not applicable
"extra info": The maximum amount of memory that memcached will use in megabytes as an integer.
"""

from sys import argv, exit
from xmlrpclib import Server

def create(app_name, server, session_id):
    app = server.create_app(session_id, app_name, 'custom_app_with_port', False, '')

    cmd = ''
    cmd += 'wget http://wiki.webfaction.com/attachment/wiki/memcachedFiles/memcached.zip?format=raw > /dev/null 2>&1;'
    cmd += 'unzip memcached.zip?format=raw > /dev/null 2>&1;'
    cmd += 'rm memcached.zip?format=raw;'
    cmd += 'chmod u+x start.py;'
    cmd += 'chmod u+x stop.py;'
    server.system(session_id, cmd)

    server.replace_in_file(session_id, 'start.py',
        ('${MEMORY}', extra_info),
        ('${PORT}', app['port']),
    )

    server.system(session_id, './start.py > /dev/null 2>&1')

    print app['id']

def delete(app_name, server, session_id):
    try:
        server.system(session_id, './stop.py > /dev/null 2>&1')
    except: pass

    server.delete_app(session_id, app_name)

if __name__ == '__main__':
    action, username, password, machine, app_name, autostart, extra_info = argv[1:]
    server = Server('https://api.webfaction.com/')
    session_id, account = server.login(username, password, machine)

    try:
        int(extra_info)
    except:
        print 'Extra information must be an integer.'
        exit()

    locals()[action](app_name, server, session_id)
-----END WEBFACTION INSTALL SCRIPT-----