Skip to content

Commit

Permalink
Rename for consistency: Param -> Params
Browse files Browse the repository at this point in the history
  • Loading branch information
samuell committed Apr 24, 2019
1 parent 6155cdb commit 24579ab
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 55 deletions.
2 changes: 1 addition & 1 deletion components/concatenator.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (p *Concatenator) Run() {
outIP := scipipe.NewFileIP(p.OutPath)
outFh := outIP.OpenWriteTemp()
for inIP := range p.In().Chan {
fr := NewFileToParamReader(p.Workflow(), p.Name()+"_filereader_"+getRandString(7), inIP.Path())
fr := NewFileToParamsReader(p.Workflow(), p.Name()+"_filereader_"+getRandString(7), inIP.Path())

pip := scipipe.NewInParamPort(p.Name() + "temp_line_reader")
pip.SetProcess(p)
Expand Down
52 changes: 0 additions & 52 deletions components/file_to_param_reader.go

This file was deleted.

52 changes: 52 additions & 0 deletions components/file_to_params_reader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package components

import (
"bufio"
"log"
"os"

"github.com/scipipe/scipipe"
)

// FileToParamsReader takes a file path on its FilePath in-port, and returns the file
// content as []byte on its out-port Out
type FileToParamsReader struct {
scipipe.BaseProcess
filePath string
}

// NewFileToParamsReader returns an initialized new FileToParamsReader
func NewFileToParamsReader(wf *scipipe.Workflow, name string, filePath string) *FileToParamsReader {
p := &FileToParamsReader{
BaseProcess: scipipe.NewBaseProcess(wf, name),
filePath: filePath,
}
p.InitOutParamPort(p, "line")
wf.AddProc(p)
return p
}

// OutLine returns an parameter out-port with lines of the files being read
func (p *FileToParamsReader) OutLine() *scipipe.OutParamPort { return p.OutParamPort("line") }

// Run the FileToParamsReader
func (p *FileToParamsReader) Run() {
defer p.CloseAllOutPorts()

file, err := os.Open(p.filePath)
if err != nil {
err = errWrapf(err, "[FileToParamsReader] Could not open file %s", p.filePath)
log.Fatal(err)
}
defer file.Close()

scan := bufio.NewScanner(file)
for scan.Scan() {
strToSend := scan.Text()
p.OutLine().Send(strToSend)
}
if scan.Err() != nil {
err = errWrapf(scan.Err(), "[FileToParamsReader] Error when scanning input file %s", p.filePath)
log.Fatal(err)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/scipipe/scipipe"
)

func TestFileToParamReader(tt *testing.T) {
func TestFileToParamsReader(tt *testing.T) {
// Create file to read
filePath := "/tmp/filereader_testfile.txt"
f, err := os.Create("/tmp/filereader_testfile.txt")
Expand All @@ -22,7 +22,7 @@ func TestFileToParamReader(tt *testing.T) {
// Run test workflow and make sure that the parameter read from the file is
// always "abc"
wf := scipipe.NewWorkflow("wf", 4)
rd := NewFileToParamReader(wf, "reader", filePath)
rd := NewFileToParamsReader(wf, "reader", filePath)
checker := wf.NewProc("checker", "# {p:testparam}")
checker.InParam("testparam").From(rd.OutLine())
checker.CustomExecute = func(t *scipipe.Task) {
Expand Down

0 comments on commit 24579ab

Please sign in to comment.