Skip to content

Commit

Permalink
Add ability to get progress bar instead of file log
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Shishkin <me@teran.ru>
  • Loading branch information
teran committed Feb 28, 2018
1 parent ae00056 commit 94b7d71
Show file tree
Hide file tree
Showing 24 changed files with 2,721 additions and 4 deletions.
40 changes: 36 additions & 4 deletions src/checksum/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/fatih/color"
"gopkg.in/cheggaaa/pb.v1"

"checksum/database"
)
Expand All @@ -26,10 +27,12 @@ var db *database.Database

var filePattern *regexp.Regexp

var cntAdded uint64
var cntFailed uint64
var cntMissed uint64
var cntPassed uint64
var (
cntAdded uint64
cntFailed uint64
cntMissed uint64
cntPassed uint64
)

func main() {
flag.Usage = func() {
Expand All @@ -43,6 +46,8 @@ func main() {
fmt.Printf(" Specify data directory\n")
fmt.Printf(" -pattern <string>\n")
fmt.Printf(" Pattern to match filenames which checking for new files(default is `.(3fr|ari|arw|bay|crw|cr2|cap|data|dcs|dcr|drf|eip|erf|fff|gpr|iiq|k25|kdc|mdc|mef|mos|mrw|nef|nrw|obm|orf|pef|ptx|pxn|r3d|raf|raw|rwl|rw2|rwz|sr2|srf|srw|x3f)$`)\n")
fmt.Printf(" -progressbar\n")
fmt.Printf(" Show progress bar instead of printing handled files(the same as `-skipfailed`, `-skipmissed`, `-skipok` but with pretty progress bar)")
fmt.Printf(" -skipfailed\n")
fmt.Printf(" Skip FAIL verification results from output\n")
fmt.Printf(" -skipmissed\n")
Expand All @@ -63,6 +68,7 @@ func main() {
skipfailed := flag.Bool("skipfailed", false, "")
skipmissed := flag.Bool("skipmissed", false, "")
skipok := flag.Bool("skipok", false, "")
progressbar := flag.Bool("progressbar", false, "")

flag.Parse()

Expand All @@ -76,6 +82,12 @@ func main() {
return
}

if *progressbar == true {
*skipfailed = true
*skipmissed = true
*skipok = true
}

var err error

db = database.NewDatabase(*dbPath)
Expand All @@ -84,11 +96,27 @@ func main() {
log.Fatalf("Error compiling pattern: %s", err)
}
sem := make(chan bool, *concurrency)
var bar *pb.ProgressBar
if *progressbar {
bar = pb.New(db.Count())
bar.ShowCounters = true
bar.SetRefreshRate(time.Second)
bar.ShowPercent = true
bar.ShowBar = true
bar.ShowTimeLeft = true
bar.ShowSpeed = true
bar.Start()
}

for file, obj := range db.MapObjects() {
sem <- true
wg.Add(1)
go func(file string, obj database.Data) {
if *progressbar {
defer func() {
bar.Increment()
}()
}
defer func() {
<-sem
}()
Expand Down Expand Up @@ -123,6 +151,10 @@ func main() {
}
wg.Wait()

if *progressbar {
bar.Finish()
}

fmt.Printf("%s Verification step complete. Checking for new files on %s\n", color.CyanString("[INFO]"), *datadir)

err = filepath.Walk(*datadir, func(path string, info os.FileInfo, err error) error {
Expand Down
2 changes: 2 additions & 0 deletions src/vendor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ github.com/fatih/color v1.5.0-8-g5df930a
github.com/mattn/go-colorable v0.0.9-10-g586e6dc
github.com/mattn/go-isatty v0.0.3-7-g6ca4dbf
golang.org/x/sys 8380141
gopkg.in/cheggaaa/pb.v1 v1.0.22
github.com/mattn/go-runewidth 97311d9
8 changes: 8 additions & 0 deletions src/vendor/github.com/mattn/go-runewidth/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions src/vendor/github.com/mattn/go-runewidth/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions src/vendor/github.com/mattn/go-runewidth/README.mkd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 94b7d71

Please sign in to comment.