diff --git a/.env.template b/.env.template index 173bacf..c94fa6a 100644 --- a/.env.template +++ b/.env.template @@ -36,4 +36,4 @@ VOICE="Matthew" # e.g. en_us_002 TTsChoice="polly" # todo add docs # IN-PROGRESS - not yet implemented -STORYMODE="False" +STORYMODE="False" \ No newline at end of file diff --git a/.gitignore b/.gitignore index d365d9e..1c28a20 100644 --- a/.gitignore +++ b/.gitignore @@ -170,4 +170,5 @@ reddit-bot-351418-5560ebc49cac.json /.idea *.pyc /video_creation/data/videos.json -utils/envUpdate.py.old \ No newline at end of file +utils/envUpdate.py.old +envVars.txt \ No newline at end of file diff --git a/utils/envUpdate.py b/utils/envUpdate.py index 05b08da..f225419 100644 --- a/utils/envUpdate.py +++ b/utils/envUpdate.py @@ -4,21 +4,16 @@ import tempfile import logging from os import path -from sys import platform +from sys import platform, stderr log = logging.getLogger(__name__) def envUpdate(): if path.exists(".env.template"): if platform == "win32" or platform == "cygwin": - envTemplate = subprocess.run( - [r'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe', - r'.\envUpdateWin.ps1'], - stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - shell=True - print("Updating .env is unsupported on Windows.") - ) - return + runPS('utils\envUpdateWin.ps1') + f = open("envVars.txt", "rb") + envTemplate = f.read() elif platform == "darwin" or platform == "linux": envTemplate = subprocess.check_output( "awk -F '=' 'NF {print $1}' .env.template | grep --regexp=^[a-zA-Z]", @@ -46,4 +41,8 @@ def envUpdate(): log.error( f"[ERROR] The following environment variables are missing: {missing}.)" ) - exit(-1) \ No newline at end of file + exit(-1) + +def runPS(cmd): + completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True) + return completed \ No newline at end of file diff --git a/utils/envUpdateWin.ps1 b/utils/envUpdateWin.ps1 index 79c8a04..1eb8f64 100644 --- a/utils/envUpdateWin.ps1 +++ b/utils/envUpdateWin.ps1 @@ -1,3 +1,9 @@ -#$envVars = Get-Content '.\.env' -#$envVars -split "=" -Write-Host 'Updating the env is unsupported on Windows.' \ No newline at end of file +$envFile = Get-Content ".\.env.template" + +$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 \ No newline at end of file