Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 63 lines (50 sloc) 1.58 KB
#!/usr/bin/env python
# http://xkcd.com/353/
import urllib
import urllib2
import shutil
import zipfile
import os
# Welcome the user
print "I'm going to ask you for some information about your theme.\n"
print "You have to give your theme a name but you can leave the others blank if you want.\n"
print "Let's get started.\n"
# Get your theme name
name = raw_input('Name? ')
# You need to provide a unique name for the theme
while not name or os.path.exists(name) or os.path.exists(name + '.zip'):
print "\nYou need a name for your theme that doesn't match existing files or directories.\n\n"
name = raw_input('Name? ')
# Get the rest of your customizations
slug = raw_input('Slug? ')
author = raw_input('Author? ')
author_uri = raw_input('Author URI? ')
description = raw_input('Description? ')
# And a few defaults
generate = 1
generate_submit = 'Generate'
# Parse the inputs
data = {
'underscoresme_name': name,
'underscoresme_slug': slug,
'underscoresme_author': author,
'underscoresme_author_uri': author_uri,
'underscoresme_description': description,
'underscoresme_generate': generate,
'underscoresme_generate_submit': generate_submit
}
# Setup the request data
body = urllib.urlencode(data)
headers = {'User-Agent': '_sh'}
# Make the request
request = urllib2.Request('http://underscores.me', body, headers)
response = urllib2.urlopen(request)
# Save the zip file
target = open(name + '.zip', 'wb')
shutil.copyfileobj(response.fp, target)
target.close()
# Unzip it
zip = zipfile.ZipFile(name + '.zip')
zip.extractall()
# Delete the zip file
os.remove(name + '.zip')