Source

BlingNode / setup.py

import os 
import platform
from optparse import OptionParser, make_option
import initial_preperation
try:
    import common
    common = __import__('common')
except:
    initial_preperation.install_requirements()
    import common
    common = __import__('common') 
import tools_preperation, tools_init, django_ve_preperation, django_ve_init, customized_linux_tools

def execute_tools_preperation(options, args):
    script_wanted = common.ask_yes_or_no("\n\nWould you like to execute tools_preperation.py? (y/n) ")
    if script_wanted == "y":
        print "\nYou decided to EXECUTE tools_preperation.py"
        tools_preperation.main(options, args)
    else:
        print "\nYou decided NOT to execute tools_preperation.py"

def execute_tools_init(options, args):
    script_wanted = common.ask_yes_or_no("\n\nWould you like to execute tools_init.py? (y/n) ")
    if script_wanted == "y":
        print "\nYou decided to EXECUTE tools_init.py"
        tools_init.main(options, args)
    else:
        print "\nYou decided NOT to execute tools_init.py"

def execute_django_ve_preperation(options, args):
    script_wanted = common.ask_yes_or_no("\n\nWould you like to execute django_ve_preperation.py? (y/n) ")
    if script_wanted == "y":
        print "\nYou decided to EXECUTE django_ve_preperation.py"
        #django_ve_preperation.main(options, args) #does not have options yet.
        django_ve_preperation.main()
    else:
        print "\nYou decided NOT to execute django_ve_preperation.py"

def execute_django_ve_init(options, args):
    script_wanted = common.ask_yes_or_no("\n\nWould you like to execute django_ve_init.py? (y/n) ")
    if script_wanted == "y":
        print "\nYou decided to EXECUTE django_ve_init.py"
        #django_ve_init.main(options, args) #does not have options yet.
        django_ve_init.main(options, args)
    else:
        print "\nYou decided NOT to execute django_ve_init.py"
        
def execute_customized_linux_tools(options, args):
    script_wanted = common.ask_yes_or_no("\n\nWould you like to execute customized_linux_tools.py? (y/n) ")
    if script_wanted == "y":
        print "\nYou decided to EXECUTE customized_linux_tools.py"
        customized_linux_tools.main(options, args)
    else:
        print "\nYou decided NOT to execute customized_linux_tools.py"


def main(options, args):
    if not common.is_user_root():
        common.error_exit(msg="\nERROR: Run this script as root. Try sudo python setup.py\n")

    print "\n\nWelcome to BlingNode."
    print "Please follow the steps necessary to setup your very own"
    print "Django environment."
    print "Plus awesome tools such as: Trac, Mercurial, File Storage."
    print

# Not working at the moment. Awaiting fix. ~Nick Wortley 7-13-10

# Try this. It uses platform.platform() instead of os.uname().
#  Added version checking too, though I will think of a better
#  way so that it handles other versions too. If you want to add
#  an OS, just add it to the SUPPORTED_OS list in check_os().
#  You may want to see first what platform.platform().lower()
#  outputs so that check_os() can verify it accordingly.
#  ~Kaye 7-14-10
    print "Checking your OS..."
    common.check_os()

    print "Step 1: Prepare tools"
    print "  We need to download the prerequisites for starting your project."
    print "  This includes many packages required for Python, Trac, Mercurial, etc."
    print "  This might take a while, depending on your network connection."
    print
    execute_tools_preperation(options, args)
    
    print "\n\n\nStep 2: Django virtual environment pre-requisite setup"
    print
    execute_django_ve_preperation(options, args)

    print "\n\n\nStep 3: Initialize a New Django virtual environment project"
    print
    execute_django_ve_init(options, args)

    print "\n\n\nStep 4: Initialize tools"
    print "  Please answer all the questions below to setup your project tools."
    print
    execute_tools_init(options, args)
    
    print "\n\n\nStep 5: Install customized linux tools"
    print "  Setup will now proceed to install/update some linux tools as well"
    print "  as install customized settings for them. The current system settings"
    print "  of the tools will be backed up in the lib/customizations/setting-backup"
    print "  directory of the blingnode installation."
    print
    execute_customized_linux_tools(options, args)
    
    print "\n\nsetup.py has finished running\n\n"


if __name__ == "__main__":
    options = ( 
        make_option('-p', '--password', dest='password', action='store',
            help="User password to send to sudo. Note that this will"
            "appear in the operating system's process list."),
    )

    parser = OptionParser(option_list=options)
    (options, args) = parser.parse_args()
    main(options, args)