Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Fix/create formula python #66

Merged
merged 17 commits into from
May 5, 2020
2 changes: 1 addition & 1 deletion cmd/single/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func buildCommands() *cobra.Command {
api.Single,
inputText,
inputPassword)

// level 1
autocompleteCmd := cmd.NewAutocompleteCmd()
addCmd := cmd.NewAddCmd()
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ func NewCleanCmd() *cobra.Command {
Short: "clean objects",
Long: descCleanLong,
}
}
}
4 changes: 2 additions & 2 deletions pkg/cmd/set_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func TestNewSetServerCmd(t *testing.T) {
}
}

type setServerMock struct {}
type setServerMock struct{}

func (setServerMock) Set(url string) error {
return nil
}
}
2 changes: 1 addition & 1 deletion pkg/cmd/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ func NewShowCmd() *cobra.Command {
Short: "Show objects",
Long: `Show objects like context, organization etc.`,
}
}
}
2 changes: 0 additions & 2 deletions pkg/cmd/single.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
package cmd

var CommonsRepoURL = ""


4 changes: 1 addition & 3 deletions pkg/file/fileutil/file_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func MoveFiles(oPath, nPath string, files []string) error {
for _, f := range files {
pwdOF := fmt.Sprintf("%s/%s", oPath, f)
pwdNF := fmt.Sprintf("%s/%s", nPath, f)
if err := os.Rename(pwdOF, pwdNF); err != nil {
if err := os.Rename(pwdOF, pwdNF); err != nil {
return err
}
}
Expand Down Expand Up @@ -278,5 +278,3 @@ func ListNewFiles(oPath, nPath string) ([]string, error) {
}
return new, nil
}


66 changes: 31 additions & 35 deletions pkg/formula/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,25 +184,24 @@ func createMakefileMain(dir, dirForm, name string) error {
if err != nil {
return err
}

return fileutil.WriteFile(dir+"/Makefile", []byte(tplFile))
return fileutil.WriteFile(fmt.Sprintf("%s/Makefile", dir), []byte(tplFile))
}

func createScripts(dir string) error {
tplFile := tpl_go.TemplateCopyBinConfig

err := fileutil.WriteFilePerm(dir+"/copy-bin-configs.sh", []byte(tplFile), 0755)
err := fileutil.WriteFilePerm(fmt.Sprintf("%s/copy-bin-configs.sh", dir), []byte(tplFile), 0755)
if err != nil {
return err
}

tplFile = tpl_go.TemplateUnzipBinConfigs

return fileutil.WriteFilePerm(dir+"/unzip-bin-configs.sh", []byte(tplFile), 0755)
return fileutil.WriteFilePerm(fmt.Sprintf("%s/unzip-bin-configs.sh", dir), []byte(tplFile), 0755)
}

func createSrcFiles(dir, pkg, lang string) error {
srcDir := dir + "/src"
srcDir := fmt.Sprintf("%s/src", dir)
err := fileutil.CreateDirIfNotExists(srcDir, os.ModePerm)
if err != nil {
return err
Expand All @@ -221,7 +220,7 @@ func createSrcFiles(dir, pkg, lang string) error {
if err != nil {
return err
}
pkgDir := srcDir + "/pkg/" + pkg
pkgDir := fmt.Sprintf("%s/pkg/%s", srcDir, pkg)
err = fileutil.CreateDirIfNotExists(pkgDir, os.ModePerm)
if err != nil {
return err
Expand Down Expand Up @@ -283,8 +282,7 @@ func createSrcFiles(dir, pkg, lang string) error {
if err != nil {
return err
}
pkgu := strings.Title(strings.ToLower(pkg))
pkgDir := fmt.Sprintf("%s/%s", srcDir, pkgu)
pkgDir := fmt.Sprintf("%s/%s", srcDir, pkg)
err = fileutil.CreateDirIfNotExists(pkgDir, os.ModePerm)
if err != nil {
return err
Expand Down Expand Up @@ -322,25 +320,24 @@ func createPkgFile(dir, pkg, lang string) error {
tfgo := tpl_go.TemplatePkg
tfgo = strings.ReplaceAll(tfgo, nameModule, pkg)

return fileutil.WriteFile(dir+"/"+pkg+".go", []byte(tfgo))
return fileutil.WriteFile(fmt.Sprintf("%s/%s.go", dir, pkg), []byte(tfgo))
case "Java":
tfj := tpl_java.TemplateFileJava
tfj = strings.ReplaceAll(tfj, nameBin, pkg)
fu := strings.Title(strings.ToLower(pkg))
tfj = strings.ReplaceAll(tfj, nameBinFirstUpper, fu)
return fileutil.WriteFile(dir+"/"+fu+".java", []byte(tfj))
return fileutil.WriteFile(fmt.Sprintf("%s/%s.java", dir, fu), []byte(tfj))
case "Node":
tfn := tpl_node.TemplateFileNode
tfn = strings.ReplaceAll(tfn, nameBin, pkg)
return fileutil.WriteFile(dir+"/"+pkg+".js", []byte(tfn))
return fileutil.WriteFile(fmt.Sprintf("%s/%s.js", dir, pkg), []byte(tfn))
case "Python":
tfp := tpl_python.TemplateFilePython
fu := strings.Title(strings.ToLower(pkg))
tfp = strings.ReplaceAll(tfp, nameBinFirstUpper, fu)
return fileutil.WriteFile(dir+"/"+fu+".py", []byte(tfp))
tfp = strings.ReplaceAll(tfp, nameBinFirstUpper, pkg)
return fileutil.WriteFile(fmt.Sprintf("%s/%s.py", dir, pkg), []byte(tfp))
default:
tfs := tpl_shell.TemplateFileShell
return fileutil.WriteFile(dir+"/"+pkg+".sh", []byte(tfs))
return fileutil.WriteFile(fmt.Sprintf("%s/%s.sh", dir, pkg), []byte(tfs))
}
}

Expand All @@ -350,10 +347,10 @@ func createRunTemplate(dir, lang string) error {
return nil
case "Java":
tj := tpl_java.TemplateRunTemplate
return fileutil.WriteFilePerm(dir+"/run_template", []byte(tj), 0777)
return fileutil.WriteFilePerm(fmt.Sprintf("%s/run_template", dir), []byte(tj), 0777)
case "Node":
tn := tpl_node.TemplateRunTemplate
return fileutil.WriteFilePerm(dir+"/run_template", []byte(tn), 0777)
return fileutil.WriteFilePerm(fmt.Sprintf("%s/run_template", dir), []byte(tn), 0777)
case "Python":
default:

Expand All @@ -368,73 +365,72 @@ func createMakefileForm(dir string, name, pathName, lang string) error {
tplFile = strings.ReplaceAll(tplFile, "{{name}}", name)
tplFile = strings.ReplaceAll(tplFile, "{{form-path}}", pathName)

return fileutil.WriteFile(dir+"/Makefile", []byte(tplFile))
return fileutil.WriteFile(fmt.Sprintf("%s/Makefile", dir), []byte(tplFile))
case "Java":
tfj := tpl_java.TemplateMakefile
tfj = strings.ReplaceAll(tfj, nameBin, name)
fu := strings.Title(strings.ToLower(name))
tfj = strings.ReplaceAll(tfj, nameBinFirstUpper, fu)
return fileutil.WriteFile(dir+"/Makefile", []byte(tfj))
return fileutil.WriteFile(fmt.Sprintf("%s/Makefile", dir), []byte(tfj))
case "Node":
tfn := tpl_node.TemplateMakefile
tfn = strings.ReplaceAll(tfn, nameBin, name)

err := fileutil.WriteFile(dir+"/Makefile", []byte(tfn))
err := fileutil.WriteFile(fmt.Sprintf("%s/Makefile", dir), []byte(tfn))
if err != nil {
return err
}
tfpj := tpl_node.TemplatePackageJson
return fileutil.WriteFile(dir+"/package.json", []byte(tfpj))
return fileutil.WriteFile(fmt.Sprintf("%s/package.json", dir), []byte(tfpj))
case "Python":
tfp := tpl_python.TemplateMakefile
tfp = strings.ReplaceAll(tfp, nameBin, name)
fu := strings.Title(strings.ToLower(name))
tfp = strings.ReplaceAll(tfp, nameBinFirstUpper, fu)
return fileutil.WriteFile(dir+"/Makefile", []byte(tfp))
return fileutil.WriteFile(fmt.Sprintf("%s/Makefile", dir), []byte(tfp))
default:
tfs := tpl_shell.TemplateMakefile
tfs = strings.ReplaceAll(tfs, nameBin, name)
return fileutil.WriteFile(dir+"/Makefile", []byte(tfs))
return fileutil.WriteFile(fmt.Sprintf("%s/Makefile", dir), []byte(tfs))
}
}

func createGoModFile(dir, pkg string) error {
tplFile := tpl_go.TemplateGoMod
tplFile = strings.ReplaceAll(tplFile, nameModule, pkg)
return fileutil.WriteFile(dir+"/go.mod", []byte(tplFile))
return fileutil.WriteFile(fmt.Sprintf("%s/go.mod", dir), []byte(tplFile))
}

func createMainFile(dir, pkg, lang string) error {
switch lang {
case "Go":
tfgo := tpl_go.TemplateMain
tfgo = strings.ReplaceAll(tfgo, nameModule, pkg)
return fileutil.WriteFile(dir+"/main.go", []byte(tfgo))
return fileutil.WriteFile(fmt.Sprintf("%s/main.go", dir), []byte(tfgo))
case "Java":
tfj := tpl_java.TemplateMain
tfj = strings.ReplaceAll(tfj, nameBin, pkg)
fu := strings.Title(strings.ToLower(pkg))
tfj = strings.ReplaceAll(tfj, nameBinFirstUpper, fu)
return fileutil.WriteFile(dir+"/Main.java", []byte(tfj))
return fileutil.WriteFile(fmt.Sprintf("%s/Main.java", dir), []byte(tfj))
case "Node":
tfn := tpl_node.TemplateIndex
tfn = strings.ReplaceAll(tfn, nameBin, pkg)
return fileutil.WriteFile(dir+"/index.js", []byte(tfn))
return fileutil.WriteFile(fmt.Sprintf("%s/index.java", dir), []byte(tfn))
case "Python":
tfp := tpl_python.TemplateMain
fu := strings.Title(strings.ToLower(pkg))
tfp = strings.ReplaceAll(tfp, nameBinFirstUpper, fu)
return fileutil.WriteFile(dir+"/main.py", []byte(tfp))
tfp = strings.ReplaceAll(tfp, nameBin, pkg)
return fileutil.WriteFile(fmt.Sprintf("%s/main.py", dir), []byte(tfp))
default:
tfs := tpl_shell.TemplateMain
tfs = strings.ReplaceAll(tfs, nameBin, pkg)
return fileutil.WriteFile(dir+"/main.sh", []byte(tfs))
return fileutil.WriteFile(fmt.Sprintf("%s/main.sh", dir), []byte(tfs))
}
}

func createConfigFile(dir string) error {
tplFile := tpl_go.TemplateConfig
return fileutil.WriteFile(dir+"/config.json", []byte(tplFile))
return fileutil.WriteFile(fmt.Sprintf("%s/config.json", dir), []byte(tplFile))
}

func updateTree(fCmd string, t Tree, lang string, i int) (Tree, error) {
Expand All @@ -456,9 +452,9 @@ func updateTree(fCmd string, t Tree, lang string, i int) (Tree, error) {
Help: fmt.Sprintf("%s %s", fc[i-1], fc[i]),
Formula: api.Formula{
Path: pathValue,
Bin: fn + ".py",
LBin: fn + ".py",
MBin: fn + ".py",
Bin: "main.py",
LBin: "main.py",
MBin: "main.py",
WBin: fn + ".bat",
Bundle: "${so}.zip",
Config: "config.json",
Expand Down
2 changes: 0 additions & 2 deletions pkg/formula/default_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type RepoManager struct {
httpClient *http.Client
sessionManager session.Manager
serverFinder server.Finder

}

// ByPriority implements sort.Interface for []Repository based on
Expand All @@ -62,7 +61,6 @@ func NewSingleRepoManager(homePath string, hc *http.Client, sm session.Manager)
}
}


func NewTeamRepoManager(homePath string, serverFinder server.Finder, hc *http.Client, sm session.Manager) RepoManager {
return RepoManager{

Expand Down
10 changes: 5 additions & 5 deletions pkg/formula/tpl/tpl_python/tpl_python.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const (
TemplateMain = `#!/usr/bin/python3
import os

from {{bin-name-first-upper}} import {{bin-name-first-upper}}
from {{bin-name}} import {{bin-name}}

input1 = os.environ.get('SAMPLE_TEXT')
input2 = os.environ.get('SAMPLE_LIST')
input3 = os.environ.get('SAMPLE_BOOL')
{{bin-name-first-upper}}.Run(input1, input2, input3)
{{bin-name}}.Run(input1, input2, input3)
`

TemplateMakefile = `# Make Run Python
Expand All @@ -19,9 +19,9 @@ DIST=../dist
DIST_DIR=$(DIST)/commons/bin
build:
mkdir -p $(DIST_DIR)
cp main.py $(DIST_DIR)/$(BINARY_NAME) && cp -r {{bin-name-first-upper}} $(DIST_DIR)
chmod +x $(DIST_DIR)/$(BINARY_NAME)
echo 'python {{bin-name}}.py' >> $(DIST_DIR)/$(BINARY_NAME_WINDOWS)`
cp main.py $(DIST_DIR) && cp -r {{bin-name}} $(DIST_DIR)
chmod +x $(DIST_DIR)/main.py
echo 'python main.py' >> $(DIST_DIR)/$(BINARY_NAME_WINDOWS)`

TemplateFilePython = `#!/usr/bin/python3
import time
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ type Setter interface {

type Finder interface {
Find() (string, error)
}
}
4 changes: 2 additions & 2 deletions pkg/server/setter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

const (
serverFilePattern = "%s/server"
serverDown = "please, check your server. It doesn't seem to be UP"
serverDown = "please, check your server. It doesn't seem to be UP"
)

type SetterManager struct {
Expand All @@ -32,7 +32,7 @@ func (s SetterManager) Set(url string) error {
if (err != nil) || (resp.StatusCode != http.StatusOK) {
return fmt.Errorf(
"%v: %w",
"HttpStatus returned: " + resp.Status + " for URL: " + url,
"HttpStatus returned: "+resp.Status+" for URL: "+url,
errors.New(serverDown))
}
if err := fileutil.WriteFile(s.serverFile, []byte(url)); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/setter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ func TestSet(t *testing.T) {
{
name: "empty serverURL",
in: "",
out: out {
out: out{
err: validator.ErrInvalidServerURL,
},
},
{
name: "existing serverURL",
in: "http://localhost/mocked",
out: out {
out: out{
status: 200,
},
},
Expand Down