Last active
March 2, 2016 19:08
-
-
Save sylistine/9023c9d7ba278705baf9 to your computer and use it in GitHub Desktop.
This file contains 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
# -*- coding: utf-8 -*- | |
import sys | |
import subprocess | |
# 'environment variables' for the script. | |
# I guess you can import os.environ, but w/e | |
env = {"FUEL_ENV": "sandbox"} | |
def Execute(cmd): | |
print cmd | |
# subprocess.Popen runs the command, | |
# wait() pauses till process finishes and returns success code. | |
if subprocess.Popen(cmd, shell=True, env=env).wait() > 0: | |
raise Exception("command failed") | |
def CleanDB(): | |
print "Cleaning db" | |
Execute("php oil refine database:uninstall") | |
Execute("php oil refine database:install") | |
Execute("php oil refine migrate --all") | |
def Default(): | |
CleanDB() | |
def Fail(): | |
print "Unable to find command." | |
# syntax: python fresh.py [<command>] | |
# If you've entered a command, match it to the command map or fail (python's version of a switch) | |
# Run default if no command was supplied. | |
def main(args): | |
command = { | |
"db": CleanDB | |
} | |
if len(args) > 1: | |
command.get(args[1], Fail)() | |
else: | |
Default() | |
# Code outside of methods gets run instead of simply being parsed. | |
# In the top scope, __name__ == "__main__" so this will only run if it's the top script. | |
if __name__ == "__main__": | |
main(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment