filters, for images: start with untagged/tagged boolean

This is a new feature and flag. (replaces the suggestion of a flag for
--untagged images).
The concept is to have a syntax to filter. This begins with this
filtering for the 'images' subcommand, and at that only filtering for
whether images are untagged.
  example like: docker rmi $(docker images -q --filter 'untagged=true')

Docker-DCO-1.1-Signed-off-by: Vincent Batts <vbatts@redhat.com> (github: vbatts)
This commit is contained in:
Vincent Batts
2014-06-02 16:33:50 -04:00
parent afb2d5de3d
commit 5f3812ec97
6 changed files with 1678 additions and 20 deletions
+31 -12
View File
@@ -55,6 +55,7 @@ import (
"github.com/dotcloud/docker/registry"
"github.com/dotcloud/docker/runconfig"
"github.com/dotcloud/docker/utils"
"github.com/dotcloud/docker/utils/filters"
)
func (srv *Server) handlerWrap(h engine.Handler) engine.Handler {
@@ -694,10 +695,23 @@ func (srv *Server) ImagesViz(job *engine.Job) engine.Status {
func (srv *Server) Images(job *engine.Job) engine.Status {
var (
allImages map[string]*image.Image
err error
allImages map[string]*image.Image
err error
filt_tagged = true
)
if job.GetenvBool("all") {
imageFilters, err := filters.ParseFlag(job.Getenv("filters"), nil)
if err != nil {
return job.Error(err)
}
if i, ok := imageFilters["untagged"]; ok && strings.ToLower(i) == "true" {
filt_tagged = false
}
if i, ok := imageFilters["tagged"]; ok && strings.ToLower(i) == "false" {
filt_tagged = false
}
if job.GetenvBool("all") && !filt_tagged {
allImages, err = srv.daemon.Graph().Map()
} else {
allImages, err = srv.daemon.Graph().Heads()
@@ -721,17 +735,22 @@ func (srv *Server) Images(job *engine.Job) engine.Status {
}
if out, exists := lookup[id]; exists {
out.SetList("RepoTags", append(out.GetList("RepoTags"), fmt.Sprintf("%s:%s", name, tag)))
if filt_tagged {
out.SetList("RepoTags", append(out.GetList("RepoTags"), fmt.Sprintf("%s:%s", name, tag)))
}
} else {
out := &engine.Env{}
// get the boolean list for if only the untagged images are requested
delete(allImages, id)
out.Set("ParentId", image.Parent)
out.SetList("RepoTags", []string{fmt.Sprintf("%s:%s", name, tag)})
out.Set("Id", image.ID)
out.SetInt64("Created", image.Created.Unix())
out.SetInt64("Size", image.Size)
out.SetInt64("VirtualSize", image.GetParentsSize(0)+image.Size)
lookup[id] = out
if filt_tagged {
out := &engine.Env{}
out.Set("ParentId", image.Parent)
out.SetList("RepoTags", []string{fmt.Sprintf("%s:%s", name, tag)})
out.Set("Id", image.ID)
out.SetInt64("Created", image.Created.Unix())
out.SetInt64("Size", image.Size)
out.SetInt64("VirtualSize", image.GetParentsSize(0)+image.Size)
lookup[id] = out
}
}
}