Skip to content

Commit 78da785

Browse files
idorucf-buildpacks-eng
authored andcommitted
Filter collectstatic output
[#150823743] Signed-off-by: Victoria Henry <[email protected]>
1 parent 356e5c8 commit 78da785

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/python/finalize/finalize.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package finalize
22

33
import (
4+
"bytes"
45
"fmt"
56
"io"
67
"io/ioutil"
78
"os"
89
"path/filepath"
10+
"regexp"
911
"strings"
1012

1113
"github.com/cloudfoundry/libbuildpack"
14+
"github.com/kr/text"
1215
)
1316

1417
type Manifest interface {
@@ -76,8 +79,8 @@ func (f *Finalizer) HandleCollectstatic() error {
7679
}
7780

7881
f.Log.Info("Running python %s collectstatic --noinput --traceback", managePyPath)
79-
//TODO: should filter out empty lines or those starting with Post-processed --OR-- Copying
80-
if err = f.Command.Execute(f.Stager.BuildDir(), os.Stdout, os.Stderr, "python", managePyPath, "collectstatic", "--noinput", "--traceback"); err != nil {
82+
output := new(bytes.Buffer)
83+
if err = f.Command.Execute(f.Stager.BuildDir(), output, text.NewIndentWriter(os.Stderr, []byte(" ")), "python", managePyPath, "collectstatic", "--noinput", "--traceback"); err != nil {
8184
f.Log.Error(fmt.Sprintf(` ! Error while running '$ python %s collectstatic --noinput'.
8285
See traceback above for details.
8386
@@ -90,9 +93,24 @@ func (f *Finalizer) HandleCollectstatic() error {
9093
return err
9194
}
9295

96+
writeFilteredCollectstaticOutput(output)
97+
9398
return nil
9499
}
95100

101+
func writeFilteredCollectstaticOutput(output *bytes.Buffer) {
102+
buffer := new(bytes.Buffer)
103+
r := regexp.MustCompile("^(Copying |Post-processed ).*$")
104+
lines := strings.Split(output.String(), "\n")
105+
for _, line := range lines {
106+
if len(line) > 0 && !r.MatchString(line) {
107+
buffer.WriteString(line)
108+
buffer.WriteString("\n")
109+
}
110+
}
111+
os.Stdout.Write(buffer.Bytes())
112+
}
113+
96114
func (f *Finalizer) ReplaceDepsDirWithLiteral() error {
97115
dirs, err := filepath.Glob(filepath.Join(f.Stager.DepDir(), "python", "lib", "python*"))
98116
if err != nil {

src/python/integration/deploy_a_python_app_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ var _ = Describe("CF Python Buildpack", func() {
9595
Expect(app.Stdout.String()).To(ContainSubstring("Installing python 3.5"))
9696
Expect(app.Stdout.String()).To(ContainSubstring("collectstatic --noinput"))
9797
Expect(app.Stdout.String()).NotTo(ContainSubstring("Error while running"))
98+
Expect(app.Stdout.String()).NotTo(ContainSubstring("Copying "))
9899
})
99100
})
100101
})

0 commit comments

Comments
 (0)