本文整理汇总了Golang中v/io/jiri.X类的典型用法代码示例。如果您正苦于以下问题:Golang X类的具体用法?Golang X怎么用?Golang X使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了X类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: MissingOSPackages
// MissingOSPackages returns the subset of the supplied packages that are
// missing from the underlying operating system and hence will need to
// be installed.
func MissingOSPackages(jirix *jiri.X, pkgs []string) ([]string, error) {
installedPkgs := map[string]bool{}
switch runtime.GOOS {
case "linux":
if IsFNLHost() {
fmt.Fprintf(jirix.Stdout(), "skipping %v on FNL host\n", pkgs)
break
}
var err error
installedPkgs, err = linuxList(jirix, pkgs)
if err != nil {
return nil, err
}
case "darwin":
var err error
installedPkgs, err = brewList(jirix)
if err != nil {
return nil, err
}
}
missing := []string{}
for _, pkg := range pkgs {
if !installedPkgs[pkg] {
missing = append(missing, pkg)
}
}
return missing, nil
}
示例2: packagesImpl
func packagesImpl(jirix *jiri.X, cl *packagesFlagValues, args []string) error {
mgrs, _, err := availableProfileManagers(jirix, cl.dbPath, args)
if err != nil {
return err
}
cl.target.UseCommandLineEnv()
root := jiri.NewRelPath(cl.root).Join(profileInstaller)
s := jirix.NewSeq()
installPackages := cl.installPackages
// Never ask a subcommand to install packages.
cl.installPackages = false
for _, mgr := range mgrs {
cmds, err := mgr.packageCmds(jirix, cl, root)
if err != nil {
return err
}
for _, cmd := range cmds {
if installPackages {
if err := s.Verbose(true).Last(cmd[0], cmd[1:]...); err != nil {
return err
}
} else {
fmt.Fprintf(jirix.Stdout(), "%s\n", strings.TrimSpace(strings.Join(cmd, " ")))
}
}
}
return nil
}
示例3: runUpdate
func runUpdate(jirix *jiri.X, _ []string) error {
seq := jirix.NewSeq()
// Create the $JIRI_ROOT/.jiri_root directory if it doesn't already exist.
//
// TODO(toddw): Remove this logic after the transition to .jiri_root is done.
// The bootstrapping logic should create this directory, and jiri should fail
// if the directory doesn't exist.
if err := seq.MkdirAll(jirix.RootMetaDir(), 0755).Done(); err != nil {
return err
}
// Update all projects to their latest version.
// Attempt <attemptsFlag> times before failing.
updateFn := func() error { return project.UpdateUniverse(jirix, gcFlag) }
if err := retry.Function(jirix.Context, updateFn, retry.AttemptsOpt(attemptsFlag)); err != nil {
return err
}
if err := project.WriteUpdateHistorySnapshot(jirix, ""); err != nil {
return err
}
// Only attempt the bin dir transition after the update has succeeded, to
// avoid messy partial states.
return project.TransitionBinDir(jirix)
}
示例4: linuxList
func linuxList(jirix *jiri.X, pkgs []string) (map[string]bool, error) {
aptitude, yum, pacman := UsingAptitude(jirix), UsingYum(jirix), UsingPacman(jirix)
cmd := ""
opt := ""
switch {
case aptitude:
cmd = "dpkg"
opt = "-L"
case yum:
cmd = "yum"
opt = "list"
case pacman:
cmd = "pacman"
opt = "-Q"
default:
return nil, fmt.Errorf("no usable package manager found, tested for aptitude, yum and pacman")
}
s := jirix.NewSeq()
installedPkgs := map[string]bool{}
for _, pkg := range pkgs {
if err := s.Capture(ioutil.Discard, ioutil.Discard).Last(cmd, opt, pkg); err == nil {
installedPkgs[pkg] = true
}
}
return installedPkgs, nil
}
示例5: uninstall
func (ip *inproc) uninstall(jirix *jiri.X, cl *uninstallFlagValues, root jiri.RelPath) error {
profile := ip.db.LookupProfile(ip.installer, ip.name)
if profile == nil {
fmt.Fprintf(jirix.Stdout(), "%s is not installed\n", ip.qname)
return nil
}
mgr := profilesmanager.LookupManager(ip.qname)
var targets []*profiles.Target
if cl.allTargets {
targets = profile.Targets()
} else {
def, err := targetAtDefaultVersion(mgr, cl.target)
if err != nil {
return err
}
targets = []*profiles.Target{&def}
}
for _, target := range targets {
if err := mgr.Uninstall(jirix, ip.db, root, *target); err != nil {
logResult(jirix, "Uninstall", mgr, *target, err)
return err
}
logResult(jirix, "Uninstall", mgr, *target, nil)
}
return nil
}
示例6: runRebuild
func runRebuild(jirix *jiri.X, args []string) (e error) {
projects, tools, err := project.LoadManifest(jirix)
if err != nil {
return err
}
// Create a temporary directory in which tools will be built.
tmpDir, err := jirix.NewSeq().TempDir("", "tmp-jiri-rebuild")
if err != nil {
return fmt.Errorf("TempDir() failed: %v", err)
}
// Make sure we cleanup the temp directory.
defer collect.Error(func() error { return jirix.NewSeq().RemoveAll(tmpDir).Done() }, &e)
// Paranoid sanity checking.
if _, ok := tools[project.JiriName]; !ok {
return fmt.Errorf("tool %q not found", project.JiriName)
}
// Build and install tools.
if err := project.BuildTools(jirix, projects, tools, tmpDir); err != nil {
return err
}
return project.InstallTools(jirix, tmpDir)
}
示例7: update
func (ip *inproc) update(jirix *jiri.X, cl *updateFlagValues, root jiri.RelPath) error {
profile := ip.db.LookupProfile(ip.installer, ip.name)
if profile == nil {
// silently ignore uninstalled profile.
return nil
}
mgr := profilesmanager.LookupManager(ip.qname)
vi := mgr.VersionInfo()
for _, target := range profile.Targets() {
if vi.IsTargetOlderThanDefault(target.Version()) {
// Check if default target is already installed.
defTarget := *target
defTarget.SetVersion(vi.Default())
if profiles.FindTarget(profile.Targets(), &defTarget) != nil {
// Default target is already installed. Skip.
continue
}
if cl.verbose {
fmt.Fprintf(jirix.Stdout(), "Updating %s %s from %q to %s\n", ip.qname, target, target.Version(), vi)
}
err := mgr.Install(jirix, ip.db, root, defTarget)
logResult(jirix, "Update", mgr, defTarget, err)
if err != nil {
return err
}
} else {
if cl.verbose {
fmt.Fprintf(jirix.Stdout(), "%s %s at %q is up to date(%s)\n", ip.qname, target, target.Version(), vi)
}
}
}
return nil
}
示例8: getCommitMessageFileName
func getCommitMessageFileName(jirix *jiri.X, branch string) (string, error) {
topLevel, err := gitutil.New(jirix.NewSeq()).TopLevel()
if err != nil {
return "", err
}
return filepath.Join(topLevel, jiri.ProjectMetaDir, branch, commitMessageFileName), nil
}
示例9: checkDependents
// checkDependents makes sure that all CLs in the sequence of
// dependent CLs leading to (but not including) the current branch
// have been exported to Gerrit.
func checkDependents(jirix *jiri.X) (e error) {
originalBranch, err := gitutil.New(jirix.NewSeq()).CurrentBranchName()
if err != nil {
return err
}
branches, err := getDependentCLs(jirix, originalBranch)
if err != nil {
return err
}
for i := 1; i < len(branches); i++ {
file, err := getCommitMessageFileName(jirix, branches[i])
if err != nil {
return err
}
if _, err := jirix.NewSeq().Stat(file); err != nil {
if !runutil.IsNotExist(err) {
return err
}
return fmt.Errorf(`Failed to export the branch %q to Gerrit because its ancestor %q has not been exported to Gerrit yet.
The following steps are needed before the operation can be retried:
$ git checkout %v
$ jiri cl mail
$ git checkout %v
# retry the original command
`, originalBranch, branches[i], branches[i], originalBranch)
}
}
return nil
}
示例10: findProfileSubcommands
func findProfileSubcommands(jirix *jiri.X) []string {
if !runSubcommands {
return nil
}
cmds, _ := lookpath.LookPrefix(jirix.Env(), "jiri-profile-", nil)
return cmds
}
示例11: installImpl
func installImpl(jirix *jiri.X, cl *installFlagValues, args []string) error {
mgrs, db, err := availableProfileManagers(jirix, cl.dbPath, args)
if err != nil {
return err
}
cl.target.UseCommandLineEnv()
newMgrs := []profileManager{}
for _, mgr := range mgrs {
name := mgr.mgrName()
if !cl.force {
installer, profile := profiles.SplitProfileName(name)
if p := db.LookupProfileTarget(installer, profile, cl.target); p != nil {
fmt.Fprintf(jirix.Stdout(), "%v %v is already installed as %v\n", name, cl.target, p)
continue
}
}
newMgrs = append(newMgrs, mgr)
}
root := jiri.NewRelPath(cl.root).Join(profileInstaller)
for _, mgr := range newMgrs {
if err := mgr.install(jirix, cl, root); err != nil {
return err
}
}
return writeDB(jirix, db, profileInstaller, cl.dbPath)
}
示例12: assertFilesNotCommitted
// assertFilesNotCommitted asserts that the files exist and are *not*
// committed in the current branch.
func assertFilesNotCommitted(t *testing.T, jirix *jiri.X, files []string) {
assertFilesExist(t, jirix, files)
for _, file := range files {
if gitutil.New(jirix.NewSeq()).IsFileCommitted(file) {
t.Fatalf("expected file %v not to be committed but it is", file)
}
}
}
示例13: newmapInput
func newmapInput(jirix *jiri.X, state *project.ProjectState, key project.ProjectKey, index, total int) *mapInput {
return &mapInput{
ProjectState: state,
key: key,
jirix: jirix.Clone(tool.ContextOpts{}),
index: index,
total: total,
}
}
示例14: Untar
// Untar untars the file in srcFile and puts resulting files in directory dstDir.
func Untar(jirix *jiri.X, srcFile, dstDir string) error {
s := jirix.NewSeq()
if err := s.MkdirAll(dstDir, 0755).Done(); err != nil {
return err
}
return s.Output([]string{"untarring " + srcFile + " into " + dstDir}).
Pushd(dstDir).
Last("tar", "xvf", srcFile)
}
示例15: assertFileContent
// assertFileContent asserts that the content of the given file
// matches the expected content.
func assertFileContent(t *testing.T, jirix *jiri.X, file, want string) {
got, err := jirix.NewSeq().ReadFile(file)
if err != nil {
t.Fatalf("%v\n", err)
}
if string(got) != want {
t.Fatalf("unexpected content of file %v: got %v, want %v", file, got, want)
}
}