This repository has been archived by the owner on Jul 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build botway telegram python
poetry
handler to botway CLI
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package poetry | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"runtime" | ||
|
||
"github.com/abdfnx/botway/constants" | ||
"github.com/abdfnx/botway/templates" | ||
"github.com/abdfnx/botway/templates/telegram/python" | ||
"github.com/abdfnx/looker" | ||
) | ||
|
||
func PyProjectContent(botName string) string { | ||
return templates.Content("pyproject.toml", "discord-python", botName) | ||
} | ||
|
||
func TelegramPythonPoetry(botName string) { | ||
pythonPath := "python3" | ||
|
||
if runtime.GOOS == "windows" { | ||
pythonPath = "python" | ||
} | ||
|
||
_, err := looker.LookPath(pythonPath) | ||
poetry, perr := looker.LookPath("poetry") | ||
|
||
if err != nil { | ||
fmt.Print(constants.FAIL_BACKGROUND.Render("ERROR")) | ||
fmt.Println(constants.FAIL_FOREGROUND.Render(" python is not installed")) | ||
} else if perr != nil { | ||
fmt.Print(constants.FAIL_BACKGROUND.Render("ERROR")) | ||
fmt.Println(constants.FAIL_FOREGROUND.Render(" poetry is not installed")) | ||
} else { | ||
dockerFileContent := templates.Content("poetry.dockerfile", "dockerfiles", botName) | ||
|
||
mainFile := os.WriteFile(filepath.Join(botName, "src", "main.py"), []byte(python.MainPyContent()), 0644) | ||
pyprojectFile := os.WriteFile(filepath.Join(botName, "pyproject.toml"), []byte(PyProjectContent(botName)), 0644) | ||
dockerFile := os.WriteFile(filepath.Join(botName, "Dockerfile"), []byte(dockerFileContent), 0644) | ||
resourcesFile := os.WriteFile(filepath.Join(botName, "resources.md"), []byte(python.Resources()), 0644) | ||
|
||
if mainFile != nil { | ||
log.Fatal(mainFile) | ||
} | ||
|
||
if pyprojectFile != nil { | ||
log.Fatal(pyprojectFile) | ||
} | ||
|
||
if dockerFile != nil { | ||
log.Fatal(dockerFile) | ||
} | ||
|
||
if resourcesFile != nil { | ||
log.Fatal(resourcesFile) | ||
} | ||
|
||
poetryAdd := poetry + " add python-telegram-bot botway.py pyyaml cryptography PySocks ujson" | ||
|
||
cmd := exec.Command("bash", "-c", poetryAdd) | ||
|
||
if runtime.GOOS == "windows" { | ||
cmd = exec.Command("powershell.exe", poetryAdd) | ||
} | ||
|
||
cmd.Dir = botName | ||
cmd.Stdin = os.Stdin | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
err = cmd.Run() | ||
|
||
if err != nil { | ||
log.Printf("error: %v\n", err) | ||
} | ||
|
||
templates.CheckProject(botName, "discord") | ||
} | ||
} |