Skip to content

Instantly share code, notes, and snippets.

@Wuvist
Created October 19, 2012 07:51
Show Gist options
  • Save Wuvist/3916799 to your computer and use it in GitHub Desktop.
Save Wuvist/3916799 to your computer and use it in GitHub Desktop.
Switch config files
#!/usr/bin/env python
import sys, os
import shutil
if len(sys.argv) < 3:
print "Usage: ./configs.py [backup|restore] venture"
sys.exit()
current_path = os.path.dirname(os.path.abspath(__file__)) + os.sep
config_files = [
"alice/alice/protected/config/config.php",
"bob/application/configs/dev.ini",
"bob/application/configs/log.php"
]
def backup(venture):
for config_file in config_files:
name = config_file.split("/")[-1]
src = current_path + venture + os.sep + config_file.replace("/", os.sep)
dest = current_path + "_configs" + os.sep + venture + "_" + name
shutil.copyfile(src, dest)
print "cp %s %s " % (src, dest)
def restore(venture):
for config_file in config_files:
name = config_file.split("/")[-1]
src = current_path + "_configs" + os.sep + venture + "_" + name
dest = current_path + venture + os.sep + config_file.replace("/", os.sep)
shutil.copyfile(src, dest)
print "cp %s %s " % (src, dest)
def cp(venture):
dest_venture = sys.argv[3].rstrip(os.sep)
for config_file in config_files:
name = config_file.split("/")[-1]
src = current_path + "_configs" + os.sep + venture + "_" + name
dest = current_path + dest_venture + os.sep + config_file.replace("/", os.sep)
shutil.copyfile(src, dest)
print "cp %s %s " % (src, dest)
cmd = sys.argv[1]
venture = sys.argv[2].rstrip(os.sep)
method = globals()[cmd]
method(venture)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment