本文整理汇总了Golang中github.com/ubuntu-core/snappy/progress.Meter.Notify方法的典型用法代码示例。如果您正苦于以下问题:Golang Meter.Notify方法的具体用法?Golang Meter.Notify怎么用?Golang Meter.Notify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ubuntu-core/snappy/progress.Meter
的用法示例。
在下文中一共展示了Meter.Notify方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RemoveSnapFiles
func (f *fakeSnappyBackend) RemoveSnapFiles(s snap.PlaceInfo, meter progress.Meter) error {
meter.Notify("remove-snap-files")
f.ops = append(f.ops, fakeOp{
op: "remove-snap-files",
name: s.MountDir(),
})
return nil
}
示例2: UnlinkSnap
func (f *fakeSnappyBackend) UnlinkSnap(info *snap.Info, meter progress.Meter) error {
meter.Notify("unlink")
f.ops = append(f.ops, fakeOp{
op: "unlink-snap",
name: info.MountDir(),
})
return nil
}
示例3: UpdateAll
// UpdateAll the installed snappy packages, it returns the updated Parts
// if updates where available and an error and nil if any of the updates
// fail to apply.
func UpdateAll(flags InstallFlags, meter progress.Meter) ([]Part, error) {
updates, err := ListUpdates()
if err != nil {
return nil, err
}
for _, part := range updates {
meter.Notify(fmt.Sprintf("Updating %s (%s)", part.Name(), part.Version()))
if err := doUpdate(part, flags, meter); err != nil {
return nil, err
}
}
return updates, nil
}
示例4: parseSIProgress
func parseSIProgress(pb progress.Meter, stdout io.Reader) error {
if pb == nil {
pb = &progress.NullProgress{}
}
scanner := bufio.NewScanner(stdout)
// s-i is funny, total changes during the runs
total := 0.0
pb.Start("ubuntu-core", 100)
for scanner.Scan() {
if os.Getenv("SNAPPY_DEBUG") != "" {
fmt.Println(scanner.Text())
}
jsonStream := strings.NewReader(scanner.Text())
dec := json.NewDecoder(jsonStream)
var genericData genericJSON
if err := dec.Decode(&genericData); err != nil {
// we ignore invalid json here and continue
// the parsing if s-i-cli or ubuntu-core-upgrader
// output something unexpected (like stray debug
// output or whatnot)
continue
}
switch {
case genericData.Type == "spinner":
pb.Spin(genericData.Message)
case genericData.Type == "error":
return fmt.Errorf("error from %s: %s", systemImageCli, genericData.Message)
case genericData.Type == "progress":
if total != genericData.Total {
total = genericData.Total
pb.SetTotal(total)
}
pb.Set(genericData.Now)
}
}
// ugly: avoid Spin() artifacts
pb.Notify("\nApply done")
if err := scanner.Err(); err != nil {
return err
}
return nil
}
示例5: Purge
// Purge a part by a partSpec string, name[.origin][=version]
func Purge(partSpec string, flags PurgeFlags, meter progress.Meter) error {
var e error
datadirs := DataDirs(partSpec)
if len(datadirs) == 0 {
return ErrPackageNotFound
}
purgeActive := flags&DoPurgeActive != 0
var active []*SnapPart
// There can be a number of datadirs, such as for multiple versions, the
// .snap being installed for multiple users, or the .snap using both the
// snap data path as well as the user data path. They all need to be purged.
for _, datadir := range datadirs {
yamlPath := filepath.Join(dirs.SnapSnapsDir, datadir.QualifiedName(), datadir.Version, "meta", "package.yaml")
part, err := NewInstalledSnapPart(yamlPath, datadir.Origin)
if err != nil {
// no such part installed
continue
}
if part.IsActive() {
if !purgeActive {
return ErrStillActive
}
// We've been asked to purge a currently-active part. We don't want
// to blow away data out from under an active part, so we'll
// temporarily deactivate it here and keep track of it so we can
// reactivate it later.
err = part.deactivate(false, meter)
if err == nil {
active = append(active, part)
} else {
meter.Notify(fmt.Sprintf("Unable to deactivate %s: %s", part.Name(), err))
meter.Notify("Purge continues.")
}
}
}
// Conduct the purge.
for _, datadir := range datadirs {
if err := remove(datadir.QualifiedName(), datadir.Version); err != nil {
e = err
meter.Notify(fmt.Sprintf("unable to purge %s version %s: %s", datadir.QualifiedName(), datadir.Version, err.Error()))
}
}
// Reactivate the temporarily deactivated parts.
for _, part := range active {
if err := part.activate(false, meter); err != nil {
meter.Notify(fmt.Sprintf("Unable to reactivate %s: %s", part.Name(), err))
}
}
return e
}
示例6: UpdateAll
// UpdateAll the installed snappy packages, it returns the updated Parts
// if updates where available and an error and nil if any of the updates
// fail to apply.
func UpdateAll(flags InstallFlags, meter progress.Meter) ([]Part, error) {
mStore := NewUbuntuStoreSnapRepository()
updates, err := mStore.Updates()
if err != nil {
return nil, err
}
for _, part := range updates {
meter.Notify(fmt.Sprintf("Updating %s (%s)", part.Name(), part.Version()))
if err := doUpdate(mStore, part, flags, meter); err != nil {
return nil, err
}
}
installedUpdates, err := convertToInstalledSnaps(updates)
if err != nil {
return nil, err
}
return installedUpdates, nil
}
示例7: UpdateAll
// UpdateAll the installed snappy packages, it returns the updated Snaps
// if updates where available and an error and nil if any of the updates
// fail to apply.
func UpdateAll(flags InstallFlags, meter progress.Meter) ([]*Snap, error) {
mStore := NewConfiguredUbuntuStoreSnapRepository()
updates, err := snapUpdates(mStore)
if err != nil {
return nil, err
}
for _, snap := range updates {
meter.Notify(fmt.Sprintf("Updating %s (%s)", snap.Name(), snap.Version))
if err := doUpdate(mStore, snap, flags, meter); err != nil {
return nil, err
}
}
installedUpdates, err := convertToInstalledSnaps(updates)
if err != nil {
return nil, err
}
return installedUpdates, nil
}
示例8: Download
func (f *fakeSnappyBackend) Download(name, channel string, checker func(*snap.Info) error, p progress.Meter, auther store.Authenticator) (*snap.Info, string, error) {
p.Notify("download")
var macaroon string
if auther != nil {
macaroon = auther.(*auth.MacaroonAuthenticator).Macaroon
}
f.ops = append(f.ops, fakeOp{
op: "download",
macaroon: macaroon,
name: name,
channel: channel,
})
p.SetTotal(float64(f.fakeTotalProgress))
p.Set(float64(f.fakeCurrentProgress))
revno := 11
if channel == "channel-for-7" {
revno = 7
}
info := &snap.Info{
SideInfo: snap.SideInfo{
OfficialName: strings.Split(name, ".")[0],
Channel: channel,
SnapID: "snapIDsnapidsnapidsnapidsnapidsn",
Revision: revno,
},
Version: name,
}
err := checker(info)
if err != nil {
return nil, "", err
}
return info, "downloaded-snap-path", nil
}
示例9: Install
//.........这里部分代码省略.........
defer func() {
if err != nil {
if cerr := oldPart.activate(inhibitHooks, inter); cerr != nil {
logger.Noticef("Setting old version back to active failed: %v", cerr)
}
}
}()
if err != nil {
return "", err
}
err = copySnapData(fullName, oldPart.Version(), s.Version())
} else {
err = os.MkdirAll(dataDir, 0755)
}
defer func() {
if err != nil {
if cerr := removeSnapData(fullName, s.Version()); cerr != nil {
logger.Noticef("When cleaning up data for %s %s: %v", s.Name(), s.Version(), cerr)
}
}
}()
if err != nil {
return "", err
}
// and finally make active
err = s.activate(inhibitHooks, inter)
defer func() {
if err != nil && oldPart != nil {
if cerr := oldPart.activate(inhibitHooks, inter); cerr != nil {
logger.Noticef("When setting old %s version back to active: %v", s.Name(), cerr)
}
}
}()
if err != nil {
return "", err
}
// oh, one more thing: refresh the security bits
if !inhibitHooks {
deps, err := s.Dependents()
if err != nil {
return "", err
}
sysd := systemd.New(dirs.GlobalRootDir, inter)
stopped := make(map[string]time.Duration)
defer func() {
if err != nil {
for serviceName := range stopped {
if e := sysd.Start(serviceName); e != nil {
inter.Notify(fmt.Sprintf("unable to restart %s with the old %s: %s", serviceName, s.Name(), e))
}
}
}
}()
for _, dep := range deps {
if !dep.IsActive() {
continue
}
for _, svc := range dep.ServiceYamls() {
serviceName := filepath.Base(generateServiceFileName(dep.m, svc))
timeout := time.Duration(svc.StopTimeout)
if err = sysd.Stop(serviceName, timeout); err != nil {
inter.Notify(fmt.Sprintf("unable to stop %s; aborting install: %s", serviceName, err))
return "", err
}
stopped[serviceName] = timeout
}
}
if err := s.RefreshDependentsSecurity(oldPart, inter); err != nil {
return "", err
}
started := make(map[string]time.Duration)
defer func() {
if err != nil {
for serviceName, timeout := range started {
if e := sysd.Stop(serviceName, timeout); e != nil {
inter.Notify(fmt.Sprintf("unable to stop %s with the old %s: %s", serviceName, s.Name(), e))
}
}
}
}()
for serviceName, timeout := range stopped {
if err = sysd.Start(serviceName); err != nil {
inter.Notify(fmt.Sprintf("unable to restart %s; aborting install: %s", serviceName, err))
return "", err
}
started[serviceName] = timeout
}
}
return s.Name(), nil
}
示例10: Install
// Install installs the snap
func (s *SystemImagePart) Install(pb progress.Meter, flags InstallFlags) (name string, err error) {
if provisioning.IsSideLoaded(bootloaderDir()) {
return "", ErrSideLoaded
}
if pb != nil {
// ensure the progress finishes when we are done
defer func() {
pb.Finished()
}()
}
// Ensure there is always a kernel + initrd to boot with, even
// if the update does not provide new versions.
if s.needsBootAssetSync() {
if pb != nil {
pb.Notify("Syncing boot files")
}
err = s.partition.SyncBootloaderFiles(bootAssetFilePaths())
if err != nil {
return "", err
}
}
// find out what config file to use, the other partition may be
// empty so we need to fallback to the current one if it is
configFile := systemImageClientConfig
err = s.partition.RunWithOther(partition.RO, func(otherRoot string) (err error) {
// XXX: Note that systemImageDownloadUpdate() requires
// the s-i _client_ config file whereas otherIsEmpty()
// checks the s-i _channel_ config file.
otherConfigFile := filepath.Join(dirs.GlobalRootDir, otherRoot, systemImageClientConfig)
if !otherIsEmpty(otherRoot) && helpers.FileExists(otherConfigFile) {
configFile = otherConfigFile
}
// NOTE: we need to pass the config dir here
configDir := filepath.Dir(configFile)
return systemImageDownloadUpdate(configDir, pb)
})
if err != nil {
return "", err
}
// Check that the final system state is as expected.
if err = s.verifyUpgradeWasApplied(); err != nil {
return "", err
}
// XXX: ToggleNextBoot() calls handleAssets() (but not SyncBootloader
// files :/) - handleAssets() may copy kernel/initramfs to the
// sync mounted /boot/uboot, so its very slow, tell the user
// at least that something is going on
if pb != nil {
pb.Notify("Updating boot files")
}
if err = s.partition.ToggleNextBoot(); err != nil {
return "", err
}
return SystemImagePartName, nil
}
示例11: Install
//.........这里部分代码省略.........
}
}()
if err != nil {
return "", err
}
err = copySnapData(fullName, oldPart.Version(), s.Version())
} else {
err = os.MkdirAll(dataDir, 0755)
}
defer func() {
if err != nil {
if cerr := removeSnapData(fullName, s.Version()); cerr != nil {
logger.Noticef("When cleaning up data for %s %s: %v", s.Name(), s.Version(), cerr)
}
}
}()
if err != nil {
return "", err
}
if !inhibitHooks {
newPart, err := newSnapPartFromYaml(filepath.Join(s.instdir, "meta", "package.yaml"), s.origin, s.m)
if err != nil {
return "", err
}
// and finally make active
err = newPart.activate(inhibitHooks, inter)
defer func() {
if err != nil && oldPart != nil {
if cerr := oldPart.activate(inhibitHooks, inter); cerr != nil {
logger.Noticef("When setting old %s version back to active: %v", s.Name(), cerr)
}
}
}()
if err != nil {
return "", err
}
// oh, one more thing: refresh the security bits
deps, err := newPart.Dependents()
if err != nil {
return "", err
}
sysd := systemd.New(dirs.GlobalRootDir, inter)
stopped := make(map[string]time.Duration)
defer func() {
if err != nil {
for serviceName := range stopped {
if e := sysd.Start(serviceName); e != nil {
inter.Notify(fmt.Sprintf("unable to restart %s with the old %s: %s", serviceName, s.Name(), e))
}
}
}
}()
for _, dep := range deps {
if !dep.IsActive() {
continue
}
for _, svc := range dep.ServiceYamls() {
serviceName := filepath.Base(generateServiceFileName(dep.m, svc))
timeout := time.Duration(svc.StopTimeout)
if err = sysd.Stop(serviceName, timeout); err != nil {
inter.Notify(fmt.Sprintf("unable to stop %s; aborting install: %s", serviceName, err))
return "", err
}
stopped[serviceName] = timeout
}
}
if err := newPart.RefreshDependentsSecurity(oldPart, inter); err != nil {
return "", err
}
started := make(map[string]time.Duration)
defer func() {
if err != nil {
for serviceName, timeout := range started {
if e := sysd.Stop(serviceName, timeout); e != nil {
inter.Notify(fmt.Sprintf("unable to stop %s with the old %s: %s", serviceName, s.Name(), e))
}
}
}
}()
for serviceName, timeout := range stopped {
if err = sysd.Start(serviceName); err != nil {
inter.Notify(fmt.Sprintf("unable to restart %s; aborting install: %s", serviceName, err))
return "", err
}
started[serviceName] = timeout
}
}
return s.Name(), nil
}