Created
July 17, 2010 23:56
-
-
Save jschaf/479954 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-----BEGIN WEBFACTION INSTALL SCRIPT----- | |
#!/usr/local/bin/python2.4 | |
""" | |
MediaWiki 1.15.4 | |
Notes: | |
- The database will be named after your application, | |
e.g. username_application. | |
"autostart": not applicable | |
"extra info": enter the name of the database, either 'postgresql' | |
or 'mysql'. If empty, the default is postgresql. | |
""" | |
import sys | |
import xmlrpclib | |
def parse_extra_info(arg): | |
db_vendor = extra_info | |
if db_vendor == "": | |
db_vendor = 'postgresql' | |
if db_vendor not in ['postgresql', 'mysql']: | |
raise ValueError(("%s is not a valid database, " | |
"use either 'postgresql' or 'mysql'") | |
% db_vendor) | |
return db_vendor | |
def create(account, app_name, autostart, extra_info, password, server, session_id, username): | |
# Parse and validate arguments. | |
db_name = db_user = '%s_%s' % (username, app_name) | |
db_vendor = parse_extra_info(extra_info) | |
# Create application and database. | |
app = server.create_app(session_id, app_name, 'static', False, '') | |
server.create_db(session_id, db_name, db_vendor, password) | |
wiki_name = 'mediawiki-1.15.4' | |
# Download files. | |
cmd = '' | |
cmd += 'rm index.html;' | |
cmd += 'wget http://download.wikimedia.org/mediawiki/1.15/%s.tar.gz > /dev/null 2>&1;'%wiki_name | |
cmd += 'tar xvzf %s.tar.gz > /dev/null 2>&1;'%wiki_name | |
cmd += 'rm %s.tar.gz;'%wiki_name | |
cmd += 'mv %s/* .'%wiki_name | |
server.system(session_id, cmd) | |
print(app['id']) | |
def delete(account, app_name, autostart, extra_info, password, server, session_id, username): | |
# Delete application and database. | |
server.delete_app(session_id, app_name) | |
db_vendor = parse_extra_info(extra_info) | |
server.delete_db(session_id, '%s_%s' % (username, app_name), db_vendor) | |
if __name__ == '__main__': | |
action, username, password, machine, app_name, autostart, extra_info = sys.argv[1:] | |
server = xmlrpclib.ServerProxy('https://api.webfaction.com/') | |
session_id, account = server.login(username, password, machine) | |
func = locals()[action] | |
func(account, app_name, autostart, extra_info, password, server, session_id, username) | |
-----END WEBFACTION INSTALL SCRIPT----- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment