Created
May 21, 2009 15:52
-
-
Save Oshuma/115545 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env python | |
| import os | |
| import sys | |
| from optparse import OptionParser | |
| global DEBUG | |
| global APP_DIR | |
| global CAKE_DIR | |
| global CONSOLE_DIR | |
| APP_DIR = os.path.dirname(__file__) | |
| CAKE_DIR = APP_DIR + '/../cake' | |
| CONSOLE_DIR = CAKE_DIR + '/console' | |
| class Task(object): | |
| """Some helpful tasks for setting up the CakePHP app and production server.""" | |
| def __init__(self): | |
| self.parser = OptionParser() | |
| self.setup_options() | |
| DEBUG = self.options.debug | |
| def setup_options(self): | |
| # Set some defaults. | |
| self.parser.set_defaults(debug = False) | |
| # Enable debugging output? | |
| self.parser.add_option('--debug', | |
| action = 'store_true', | |
| dest = 'debug', | |
| help = 'Enable debugging output.') | |
| # Migrate the database. | |
| self.parser.add_option('--migrate', '-m', | |
| action = 'store_true', | |
| dest = 'migrate', | |
| help = 'Migrate the database (destructive).') | |
| self.parser.add_option('--load', '-l', | |
| action = 'store_true', | |
| dest = 'load', | |
| help = 'Load the initial data (should run setup first).') | |
| self.parser.add_option('--setup', '-s', | |
| action = 'store_true', | |
| dest = 'setup', | |
| help = 'Fully setup the production environment; migrates the database and loads the initial data.') | |
| # Parse those fuckers. | |
| self.options, self.arguments = self.parser.parse_args() | |
| if self.options.debug: print "options: %s" % self.options | |
| if self.options.debug: print "arguments: %s" % self.arguments | |
| # This method is what makes things go. | |
| def run(self): | |
| if self.options.setup: return self.full_setup() | |
| if self.options.migrate: return self.migrate_database() | |
| if self.options.load: return self.load_data() | |
| def full_setup(self): | |
| print 'Setting up production environment...' | |
| self.migrate_database() | |
| self.load_data() | |
| if raw_input("\nCreate Admin User? (yes/no) ") == 'yes': | |
| cake('admin user create') | |
| def load_data(self): | |
| self.load_zip_codes() | |
| cake('fixtures tool') | |
| cake('fixtures user_type') | |
| def migrate_database(self): | |
| cake('schema run create') | |
| def load_zip_codes(self): | |
| print "\nLoading Zip Codes into the database..." | |
| mysql = 'mysql -h localhost -u apstele_apsuser -D apstele_arc -p' | |
| sql_file = APP_DIR + '/config/sql/zip_codes.sql' | |
| os.system("%s < %s" % (mysql, sql_file)) | |
| # Wrapper to execute a CakePHP shell command. | |
| def cake(command): | |
| os.system(CONSOLE_DIR + '/cake ' + command) | |
| # Run that bitch. | |
| if __name__ == '__main__': | |
| sys.exit( Task().run() ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment