Added Windows support

I have added Windows support using PowerShell. I made a script that does effectively what the GNU awk and grep commands do but in PowerShell for Windows compatibility.
pull/553/head
owengaspard 3 years ago
parent 928e50e08f
commit ddc402c48d

1
.gitignore vendored

@ -171,3 +171,4 @@ reddit-bot-351418-5560ebc49cac.json
*.pyc *.pyc
/video_creation/data/videos.json /video_creation/data/videos.json
utils/envUpdate.py.old utils/envUpdate.py.old
envVars.txt

@ -4,21 +4,16 @@ import tempfile
import logging import logging
from os import path from os import path
from sys import platform from sys import platform, stderr
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def envUpdate(): def envUpdate():
if path.exists(".env.template"): if path.exists(".env.template"):
if platform == "win32" or platform == "cygwin": if platform == "win32" or platform == "cygwin":
envTemplate = subprocess.run( runPS('utils\envUpdateWin.ps1')
[r'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe', f = open("envVars.txt", "rb")
r'.\envUpdateWin.ps1'], envTemplate = f.read()
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
shell=True
print("Updating .env is unsupported on Windows.")
)
return
elif platform == "darwin" or platform == "linux": elif platform == "darwin" or platform == "linux":
envTemplate = subprocess.check_output( envTemplate = subprocess.check_output(
"awk -F '=' 'NF {print $1}' .env.template | grep --regexp=^[a-zA-Z]", "awk -F '=' 'NF {print $1}' .env.template | grep --regexp=^[a-zA-Z]",
@ -47,3 +42,7 @@ def envUpdate():
f"[ERROR] The following environment variables are missing: {missing}.)" f"[ERROR] The following environment variables are missing: {missing}.)"
) )
exit(-1) exit(-1)
def runPS(cmd):
completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True)
return completed

@ -1,3 +1,9 @@
#$envVars = Get-Content '.\.env' $envFile = Get-Content ".\.env.template"
#$envVars -split "="
Write-Host 'Updating the env is unsupported on Windows.' $envFile -split "=" | Where-Object {$_ -notmatch '\"'} | Set-Content ".\envVarsbefSpl.txt"
Get-Content ".\envVarsbefSpl.txt" | Where-Object {$_ -notmatch '\#'} | Set-Content ".\envVarsN.txt"
Get-Content ".\envVarsN.txt" | Where-Object {$_ -ne ''} | Set-Content ".\envVars.txt"
Remove-Item ".\envVarsbefSpl.txt"
Remove-Item ".\envVarsN.txt"
Write-Host $nowSplit
Loading…
Cancel
Save