Esempio n. 1
0
def make_project (type, pname, dir):

	rootdir = os.path.abspath (dir)
	if not os.path.isdir (dir):
		U.error ('Root directory doesn\'t exist')

	proot = os.path.join (rootdir, pname)
	if os.path.exists (proot):
		U.error ('Project directory already exists')
	os.mkdir (proot)

	org = '''

		_%s_

		* %s

	''' % (pname, pname)
	orgfile = os.path.join (proot, (pname + '.org'))
	orgf = open (orgfile, 'w')
	orgf.write (tw.dedent (org))

	if type == 'bash':
		scriptname = os.path.join (proot, (pname + '.bash'))
		make_script (type='bash', filename=scriptname)

	elif type == 'python-script':
		scriptname = os.path.join (proot, (pname + '.py'))
		make_script (type='python', filename=scriptname)
		source_util = '/home/sm/resources/python/Util.py'
		# symlink Util.py
		dest_util = os.path.join (proot, 'Util.py')
		os.symlink (source_util, dest_util)

	elif type == 'website':
		# make folders
		paths = {'site':['images', 'js', 'css'],
				 'media':['icons', 'links']}
		make_paths (root=proot, paths=paths)
		# os.chdir (os.path.join (proot, 'site'))
		scriptname = os.path.join (proot, (pname + '.bash'))
		make_script (type='html', filename='index.html', location=os.path.join (proot, 'site'))
		make_script (type='css', filename=(pname + '.css'), location=os.path.join (proot, 'site', 'css'))
		make_script (type='js', filename=(pname + '.js'), location=os.path.join (proot, 'site', 'js'))




		# make index

		# files to copy:
		# index.html
		# jquery
		# easy-css
		# symlink icons

		# run make-new-site to setup apache

	elif type == 'web2py':
		paths = {'media':['icons']}
		make_paths (root=proot, paths=paths)
		w2p_app = '/home/sm/bin/web2py-1.94.6/appliations'
		os.mkdir (os.join (w2p_app, pname))
Esempio n. 2
0
def make_script(type, filename, location):
    # print '>>> %s -- %s -- %s' % (type, filename, location)
    # filename = os.path.join (location, filename)
    if os.path.exists(filename):
        U.error("%s already exists" % (filename))

    content = ""
    if type == "bash":
        content = """#!/usr/bin/env bash

# include the color variables and
# an error function
source ~/bin/color_and_error.bash
# color_and_error:
#	  error [optional message]
#	  colorize 'text to colorize' <color variable name> [optional 'nonl' for no newline]
# run ~/bin/color_and_error.bash for examples

help() {
	echo 'usage: $(basename $0) [-a] [-b]'
	exit
}
firstopt=a
secondopt=b
while getopts '$firstopt$secondopt' flag; do
	case $flag in
		$firstopt)
			# do something here
		;;
		$secondopt)
			# do something here
		;;
		*)
			help
	esac
done
shift $(($OPTIND -1))
help
"""

    elif type == "python":
        content = """#!/usr/bin/env python

import StringIO
import datetime
import os
import re
import sqlite3
import time
import urllib, urllib2
# from optparse import OptionParser
from argparse import ArgumentParser
import pprint
from Util import U

if __name__ == '__main__':

	parser = ArgumentParser (description='Create projects of various types.')

	parser.add_argument(
		'-a', '--long-a-option',
		help='This is option a',
	)
	parser.add_argument('--version', action='version', version='%(prog)s 0.1')

	args = parser.parse_args()
	print args

"""

    elif type == "html":
        content = """
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Some title</title>
    <script type="text/javascript" src="project.js"></script>
    <style type="text/css" media="screen">@import "project.css";</style>
  </head>
  <body>
    <h1>Some Title</h1>
  </body>
</html>
"""

    elif type == "js":
        content = """
			// js
			alert ("Yo dawg.")
			"""

    elif type == "css":
        content = """
			/* css */
			body {background: grey;}
			"""

    content = textwrap.dedent(content)
    f = open(filename, "w")
    f.write(tw.dedent(content))
    if type not in ["html", "js", "css"]:
        os.chmod(filename, 0755)  # make executable