• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang progress.Meter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/ubuntu-core/snappy/progress.Meter的典型用法代码示例。如果您正苦于以下问题:Golang Meter类的具体用法?Golang Meter怎么用?Golang Meter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Meter类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:dholbach,项目名称:snappy,代码行数:8,代码来源:backend_test.go


示例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
}
开发者ID:dholbach,项目名称:snappy,代码行数:8,代码来源:backend_test.go


示例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
}
开发者ID:General-Beck,项目名称:snappy,代码行数:18,代码来源:install.go


示例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
}
开发者ID:General-Beck,项目名称:snappy,代码行数:48,代码来源:systemimage_native.go


示例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
}
开发者ID:robert-ancell,项目名称:snapd,代码行数:58,代码来源:purge.go


示例6: downloadFile

func downloadFile(url string, pbar progress.Meter) (fn string, err error) {
	name := "classic"

	w, err := ioutil.TempFile("", name)
	if err != nil {
		return "", err
	}
	defer func() {
		if err != nil {
			os.Remove(w.Name())
		}
	}()
	defer w.Close()

	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return "", err
	}

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()

	if resp.StatusCode != 200 {
		return "", fmt.Errorf("failed to download %s: %v", url, resp.StatusCode)
	}

	if pbar != nil {
		pbar.Start(name, float64(resp.ContentLength))
		mw := io.MultiWriter(w, pbar)
		_, err = io.Copy(mw, resp.Body)
		pbar.Finished()
	} else {
		_, err = io.Copy(w, resp.Body)
	}

	return w.Name(), err
}
开发者ID:robert-ancell,项目名称:snapd,代码行数:41,代码来源:create.go


示例7: 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
}
开发者ID:alecu,项目名称:snappy,代码行数:24,代码来源:install.go


示例8: 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
}
开发者ID:dholbach,项目名称:snappy,代码行数:24,代码来源:install.go


示例9: download

// download writes an http.Request showing a progress.Meter
func download(name string, w io.Writer, req *http.Request, pbar progress.Meter) error {
	client := &http.Client{}

	resp, err := client.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	if resp.StatusCode != 200 {
		return &ErrDownload{Code: resp.StatusCode, URL: req.URL}
	}

	if pbar != nil {
		pbar.Start(name, float64(resp.ContentLength))
		mw := io.MultiWriter(w, pbar)
		_, err = io.Copy(mw, resp.Body)
		pbar.Finished()
	} else {
		_, err = io.Copy(w, resp.Body)
	}

	return err
}
开发者ID:strukturag,项目名称:snappy,代码行数:25,代码来源:snapp.go


示例10: 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
}
开发者ID:dholbach,项目名称:snappy,代码行数:37,代码来源:backend_test.go


示例11: Install

// Install installs the snap
func (s *SnapPart) Install(inter progress.Meter, flags InstallFlags) (name string, err error) {
	allowOEM := (flags & AllowOEM) != 0
	inhibitHooks := (flags & InhibitHooks) != 0

	if s.IsInstalled() {
		return "", ErrAlreadyInstalled
	}

	if err := s.CanInstall(allowOEM, inter); err != nil {
		return "", err
	}

	manifestData, err := s.deb.ControlMember("manifest")
	if err != nil {
		logger.Noticef("Snap inspect failed for %q: %v", s.Name(), err)
		return "", err
	}

	// the "oem" parts are special
	if s.Type() == pkg.TypeOem {
		if err := installOemHardwareUdevRules(s.m); err != nil {
			return "", err
		}
	}

	fullName := QualifiedName(s)
	dataDir := filepath.Join(dirs.SnapDataDir, fullName, s.Version())

	var oldPart *SnapPart
	if currentActiveDir, _ := filepath.EvalSymlinks(filepath.Join(s.basedir, "..", "current")); currentActiveDir != "" {
		oldPart, err = NewInstalledSnapPart(filepath.Join(currentActiveDir, "meta", "package.yaml"), s.origin)
		if err != nil {
			return "", err
		}
	}

	if err := os.MkdirAll(s.basedir, 0755); err != nil {
		logger.Noticef("Can not create %q: %v", s.basedir, err)
		return "", err
	}

	// if anything goes wrong here we cleanup
	defer func() {
		if err != nil {
			if e := os.RemoveAll(s.basedir); e != nil && !os.IsNotExist(e) {
				logger.Noticef("Failed to remove %q: %v", s.basedir, e)
			}
		}
	}()

	// we need to call the external helper so that we can reliable drop
	// privs
	if err := s.deb.UnpackWithDropPrivs(s.basedir, dirs.GlobalRootDir); err != nil {
		return "", err
	}

	// legacy, the hooks (e.g. apparmor) need this. Once we converted
	// all hooks this can go away
	clickMetaDir := filepath.Join(s.basedir, ".click", "info")
	if err := os.MkdirAll(clickMetaDir, 0755); err != nil {
		return "", err
	}
	if err := writeCompatManifestJSON(clickMetaDir, manifestData, s.origin); err != nil {
		return "", err
	}

	// write the hashes now
	if err := s.deb.ExtractHashes(filepath.Join(s.basedir, "meta")); err != nil {
		return "", err
	}

	// deal with the data:
	//
	// if there was a previous version, stop it
	// from being active so that it stops running and can no longer be
	// started then copy the data
	//
	// otherwise just create a empty data dir
	if oldPart != nil {
		// we need to stop making it active
		err = oldPart.deactivate(inhibitHooks, inter)
		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 {
//.........这里部分代码省略.........
开发者ID:strukturag,项目名称:snappy,代码行数:101,代码来源:snapp.go


示例12: 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
}
开发者ID:pombredanne,项目名称:snappy-1,代码行数:62,代码来源:systemimage.go


示例13: Install

// Install installs the snap
func (s *SnapFile) Install(inter progress.Meter, flags InstallFlags) (name string, err error) {
	allowGadget := (flags & AllowGadget) != 0
	inhibitHooks := (flags & InhibitHooks) != 0

	// we do not Verify() the package here. This is done earlier in
	// NewSnapFile() to ensure that we do not mount/inspect
	// potentially dangerous snaps

	if err := s.CanInstall(allowGadget, inter); err != nil {
		return "", err
	}

	// the "gadget" parts are special
	if s.Type() == snap.TypeGadget {
		if err := installGadgetHardwareUdevRules(s.m); err != nil {
			return "", err
		}
	}

	fullName := QualifiedName(s)
	dataDir := filepath.Join(dirs.SnapDataDir, fullName, s.Version())

	var oldPart *SnapPart
	if currentActiveDir, _ := filepath.EvalSymlinks(filepath.Join(s.instdir, "..", "current")); currentActiveDir != "" {
		oldPart, err = NewInstalledSnapPart(filepath.Join(currentActiveDir, "meta", "package.yaml"), s.origin)
		if err != nil {
			return "", err
		}
	}

	if err := os.MkdirAll(s.instdir, 0755); err != nil {
		logger.Noticef("Can not create %q: %v", s.instdir, err)
		return "", err
	}

	// if anything goes wrong here we cleanup
	defer func() {
		if err != nil {
			if e := os.RemoveAll(s.instdir); e != nil && !os.IsNotExist(e) {
				logger.Noticef("Failed to remove %q: %v", s.instdir, e)
			}
		}
	}()

	// we need to call the external helper so that we can reliable drop
	// privs
	if err := s.deb.Install(s.instdir); err != nil {
		return "", err
	}

	// generate the mount unit for the squashfs
	if err := s.m.addSquashfsMount(s.instdir, inhibitHooks, inter); err != nil {
		return "", err
	}
	// if anything goes wrong we ensure we stop
	defer func() {
		if err != nil {
			if e := s.m.removeSquashfsMount(s.instdir, inter); e != nil {
				logger.Noticef("Failed to remove mount unit for  %s: %s", fullName, e)
			}
		}
	}()

	// FIXME: special handling is bad 'mkay
	if s.m.Type == snap.TypeKernel {
		if err := extractKernelAssets(s, inter, flags); err != nil {
			return "", fmt.Errorf("failed to install kernel %s", err)
		}
	}

	// deal with the data:
	//
	// if there was a previous version, stop it
	// from being active so that it stops running and can no longer be
	// started then copy the data
	//
	// otherwise just create a empty data dir
	if oldPart != nil {
		// we need to stop making it active
		err = oldPart.deactivate(inhibitHooks, inter)
		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 {
//.........这里部分代码省略.........
开发者ID:robert-ancell,项目名称:snapd,代码行数:101,代码来源:snap_file.go



注:本文中的github.com/ubuntu-core/snappy/progress.Meter类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang snap.InfoFromSnapYaml函数代码示例发布时间:2022-05-28
下一篇:
Golang state.Task类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap