Files
mixer-tools/builder/bundle_validate.go
Ashlesha Atrey f6dcd44f21 Implement logging for mixer
Implement the logging package for mixer.

A common log file can be set for all the mixer commands in the
builder.conf. E.g. `mixer config set Mixer.LOG <filepath>`

The log file and level can also be set for individual mixer
commands using the `--log` and `--log-level` flags respectively.

The various log levels are:
ERROR (1), WARNING (2), INFO (3), DEBUG (4) and VERBOSE (5).
Default log level is 4.

Fixes #666

Signed-off-by: Ashlesha Atrey ashlesha.atrey@intel.com
2020-04-30 13:57:58 -07:00

55 lines
1.6 KiB
Go

// Copyright © 2018 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package builder
import (
"github.com/clearlinux/mixer-tools/log"
"path/filepath"
"github.com/clearlinux/mixer-tools/helpers"
"github.com/pkg/errors"
)
// ValidateLocalBundles runs bundle parsing validation on all local bundles.
func (b *Builder) ValidateLocalBundles(lvl ValidationLevel) error {
files, err := helpers.ListVisibleFiles(b.Config.Mixer.LocalBundleDir)
if err != nil {
return errors.Wrap(err, "Failed to read local-bundles")
}
return b.ValidateBundles(files, lvl)
}
// ValidateBundles runs bundle parsing validation on a list of local bundles. In
// addition to parsing errors, errors are generated if the bundle is not found
// in local-bundles.
func (b *Builder) ValidateBundles(bundles []string, lvl ValidationLevel) error {
invalid := false
for _, bundle := range bundles {
path := filepath.Join(b.Config.Mixer.LocalBundleDir, bundle)
if err := validateBundleFile(path, lvl); err != nil {
invalid = true
log.Error(log.Mca, "Invalid: %q:\n%s\n", bundle, err)
}
}
if invalid {
return errors.New("Invalid bundles found")
}
return nil
}