def new(project_name='', app_name='', db_password='', repo_url='', is_new=''): if len(project_name) == 0 or len(app_name) == 0 or len(db_password) == 0 or len(repo_url) == 0: print "Usage: fab new:<project_name>,<app_name>,<db_password>,<repo_url>,<is_new>" print "" print "Common usage:" print " <project_name> should be different than <app_name>" return # triggers usage of the new django file-structure if is_new and is_new == 'True': is_new = True # ensure that project_name and app_name are different if project_name == app_name and not confirm("Your app_name is the same as the project_name. They should be different. Continue?"): return if not create_vagrantfile(): return False # Add the current directory to our sys path so we can import fabric_settings sys.path.append(os.getcwd()) # Create a fake settings file for access to vagrant local("cp %s/fabric_settings.py fabric_settings.py" % os.path.dirname(os.path.realpath(__file__))) env.settings = __import__("fabric_settings", globals(), locals(), [], 0).FABRIC vagrant() # Set appropriate settings from inputs env.proj_path = "/vagrant/%s" % project_name env.proj_name = project_name env.venv_path = "%s/%s" % (env.venv_home, env.proj_name) env.db_pass = db_password env.app_name = app_name env.manage = "%s/bin/python /vagrant/%s/manage.py" % (env.venv_path, env.proj_name) env.repo_url = repo_url # Set up vagrant box with appropriate system packages execute(install_prereq) execute(installdb) execute(fix_db_permissions) execute(installapp) execute(copy_db_ssh_keys) # Set up a virtualenv and mezzanine project execute(create_prereq) execute(create_virtualenv) execute(create_project, is_new=is_new) # Remove temp settings and change local working path permanently into project folder so we can copy deploy templates local("rm fabric_settings.py fabric_settings.pyc") os.chdir(env.proj_name) # Finish setting up the database and copy over appropriate templates createdb(True) execute(createapp2, is_new=is_new) execute(create_rabbit, True) execute(init_db) execute(init_git)
def clone(repo_url=''): if len(repo_url) == 0: print "Usage: fab new:<repo_url>" return if not create_vagrantfile(): return False # We'll create a temporary copy to get the appropriate settings for deployment if exists("temp"): if not confirm("This project already exists, continue anyways?"): return False else: local("mkdir temp") local("git clone %s temp/." % repo_url) #TODO: We still won't have any vagrant_settings.py or FABRIC in settings.py after we deploy and delete temp # Check to see if this project is ready for vagrant deployment - if not we'll 'upgrade' it if not exists("temp/deploy/vagrant_settings.py"): local("cp %s/vagrant_settings.py temp/deploy/vagrant_settings.py" % os.path.dirname(os.path.realpath(__file__))) # Add the current directory to our sys path so we can import fabric_settings sys.path.append(os.getcwd()) os.chdir("temp") sys.path.append(os.getcwd()) #TODO: Auto add fabric_settings.py if it doesn't exist # fabric_settings = import_module("fabric_settings") fabric_settings = __import__("fabric_settings", globals(), locals(), [], 0) #TODO: Auto add vagrant to fabric_settings.py if it doesn't exist env.settings = fabric_settings.FABRIC if 'vagrant' not in env.settings: print 'Please set up "vagrant" mode in fabric_settings.py and rerun this command' return False # And we're ready to go up() # Now clean up temporary copy os.chdir("..") local("rm -rf temp")