11package finalize
22
33import (
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
1417type 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+
96114func (f * Finalizer ) ReplaceDepsDirWithLiteral () error {
97115 dirs , err := filepath .Glob (filepath .Join (f .Stager .DepDir (), "python" , "lib" , "python*" ))
98116 if err != nil {
0 commit comments