Last active
October 7, 2020 20:20
-
-
Save tobyjoiner/3edb848c49d4976517c95e98b1d5c786 to your computer and use it in GitHub Desktop.
This will switch projects using Laravel Valet to only load the current project and an api if needed.
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/local/bin/python3 | |
import os | |
class ActiveSite: | |
def __init__(self, dbg=False): | |
self.debug = dbg | |
self.apiLocation = '<oldapilocation>' | |
self.newApiLocation = '<newapilocation>' | |
def run_command(self, command): | |
if self.debug: | |
print(command) | |
stream = os.popen(command) | |
return stream.read() | |
def unlink_existing(self): | |
stream = os.popen('valet links') | |
output = stream.read() | |
# Remove all sites | |
for line in str.splitlines(output)[3:-1]: | |
print(line) | |
data = line.split('|') | |
if self.debug: | |
print('Working on {0}'.format(data[1].strip())) | |
if data[1].strip() == 'apiwps' or data[1].strip() == 'apimysql': | |
continue | |
outval = self.run_command('valet unlink {0}'.format(data[1].strip())) | |
if self.debug: | |
print(outval) | |
def linkApi(self): | |
command = 'valet link {0}'.format(self.apiLocation) | |
self.run_command(command) | |
command2 = 'valet link {0}'.format(self.newApiLocation) | |
self.run_command(command2) | |
def run(self): | |
self.unlink_existing() | |
self.linkApi() | |
command = 'valet link .' | |
output = self.run_command(command) | |
print(self.run_command('clear')) | |
print(self.run_command('valet links')) | |
if __name__ == "__main__": | |
active = ActiveSite() | |
active.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment