// Import imports file from the filesystem.
491842
func (importer *FileImporter) Import(importedFrom, importedPath string) (contents Contents, foundAt string, err error) {
	dir, _ := path.Split(importedFrom)
	found, content, foundHere, err := importer.tryPath(dir, importedPath)
	if err != nil {
		return Contents{}, "", err
	}

	for i := len(importer.JPaths) - 1; !found && i >= 0; i-- {
		found, content, foundHere, err = importer.tryPath(importer.JPaths[i], importedPath)
		if err != nil {
			return Contents{}, "", err
		}
	}

	if !found {
		return Contents{}, "", fmt.Errorf("couldn't open import %#v: no match locally or in the Jsonnet library paths", importedPath)
	}
	return content, foundHere, nil
}
691769
func (api *API) Import(serialized params.SerializedModel) error {
	controller := state.NewController(api.pool)
	_, st, err := migration.ImportModel(controller, api.getClaimer, serialized.Bytes)
	if err != nil {
		return err
	}
	defer st.Close()
	// TODO(mjs) - post import checks
	// NOTE(fwereade) - checks here would be sensible, but we will
	// also need to check after the binaries are imported too.
	return err
}
987918
func (s service) Imports() []string {
	if !s.UnmarshallResponse {
		return nil
	}

	ipMap := map[string]struct{}{
		"from .unmarshall_error import UnmarshallError":      struct{}{},
		"from .unhandled_api_error import UnhandledAPIError": struct{}{},
	}
	for _, m := range s.Methods {
		for _, importLine := range m.imports() {
			ipMap[importLine] = struct{}{}
		}
	}
	return commons.MapToSortedStrings(ipMap)
}
770146
func (l *LiteBackend) Imported(ctx context.Context) (imported bool, err error) {
	err = l.inTransaction(ctx, func(tx *sql.Tx) error {
		q, err := tx.PrepareContext(ctx,
			"SELECT imported from meta LIMIT 1")
		if err != nil {
			return trace.Wrap(err)
		}
		row := q.QueryRowContext(ctx)
		if err := row.Scan(&imported); err != nil {
			if err != sql.ErrNoRows {
				return trace.Wrap(err)
			}
		}
		return nil
	})
	return imported, err
}
524787
func (si *shareImporter) importAll(ctx context.Context) error {
	src, shared, err := client.NewFromShareRoot(ctx, si.shareURL, client.OptionNoExternalConfig())
	if err != nil {
		return err
	}
	si.src = src
	si.br = shared
	si.workc = make(chan work, 2*numWorkers)
	defer close(si.workc)

	// fan out over a pool of numWorkers workers overall
	for i := 0; i < numWorkers; i++ {
		go func() {
			for wi := range si.workc {
				wi.errc <- si.imprt(ctx, wi.br)
			}
		}()
	}
	// work assignment is done asynchronously, so imprt returns before all the work is finished.
	err = si.imprt(ctx, shared)
	si.wg.Wait()
	if err == nil {
		si.mu.RLock()
		err = si.err
		si.mu.RUnlock()
	}
	log.Print("share importer: all workers done")
	if err != nil {
		return err
	}
	return nil
}
270378
func (_class VMClass) Import(sessionID SessionRef, url string, sr SRRef, fullRestore bool, force bool) (_retval []VMRef, _err error) {
	_method := "VM.import"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_urlArg, _err := convertStringToXen(fmt.Sprintf("%s(%s)", _method, "url"), url)
	if _err != nil {
		return
	}
	_srArg, _err := convertSRRefToXen(fmt.Sprintf("%s(%s)", _method, "sr"), sr)
	if _err != nil {
		return
	}
	_fullRestoreArg, _err := convertBoolToXen(fmt.Sprintf("%s(%s)", _method, "full_restore"), fullRestore)
	if _err != nil {
		return
	}
	_forceArg, _err := convertBoolToXen(fmt.Sprintf("%s(%s)", _method, "force"), force)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _urlArg, _srArg, _fullRestoreArg, _forceArg)
	if _err != nil {
		return
	}
	_retval, _err = convertVMRefSetToGo(_method + " -> ", _result.Value)
	return
}
1371877
func (d *Parallels9Driver) Import(name, srcPath, dstDir string, reassignMAC bool) error {
	err := d.Prlctl("register", srcPath, "--preserve-uuid")
	if err != nil {
		return err
	}

	srcID, err := getVMID(srcPath)
	if err != nil {
		return err
	}

	srcMAC := "auto"
	if !reassignMAC {
		srcMAC, err = getFirstMACAddress(srcPath)
		if err != nil {
			return err
		}
	}

	err = d.Prlctl("clone", srcID, "--name", name, "--dst", dstDir)
	if err != nil {
		return err
	}

	err = d.Prlctl("unregister", srcID)
	if err != nil {
		return err
	}

	err = d.Prlctl("set", name, "--device-set", "net0", "--mac", srcMAC)
	if err != nil {
		return err
	}
	return nil
}
183457
func (c *Client) Import(ctx context.Context, reader io.Reader, opts ...ImportOpt) ([]images.Image, error) {
	var iopts importOpts
	for _, o := range opts {
		if err := o(&iopts); err != nil {
			return nil, err
		}
	}

	ctx, done, err := c.WithLease(ctx)
	if err != nil {
		return nil, err
	}
	defer done(ctx)

	index, err := archive.ImportIndex(ctx, c.ContentStore(), reader)
	if err != nil {
		return nil, err
	}

	var (
		imgs []images.Image
		cs   = c.ContentStore()
		is   = c.ImageService()
	)

	if iopts.indexName != "" {
		imgs = append(imgs, images.Image{
			Name:   iopts.indexName,
			Target: index,
		})
	}
	var platformMatcher = platforms.All
	if !iopts.allPlatforms {
		platformMatcher = platforms.Default()
	}

	var handler images.HandlerFunc = func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
		// Only save images at top level
		if desc.Digest != index.Digest {
			return images.Children(ctx, cs, desc)
		}

		p, err := content.ReadBlob(ctx, cs, desc)
		if err != nil {
			return nil, err
		}

		var idx ocispec.Index
		if err := json.Unmarshal(p, &idx); err != nil {
			return nil, err
		}

		for _, m := range idx.Manifests {
			if ref := m.Annotations[ocispec.AnnotationRefName]; ref != "" {
				if iopts.imageRefT != nil {
					ref = iopts.imageRefT(ref)
				}
				if ref != "" {
					imgs = append(imgs, images.Image{
						Name:   ref,
						Target: m,
					})
				}
			}
			if iopts.dgstRefT != nil {
				ref := iopts.dgstRefT(m.Digest)
				if ref != "" {
					imgs = append(imgs, images.Image{
						Name:   ref,
						Target: m,
					})
				}
			}
		}

		return idx.Manifests, nil
	}

	handler = images.FilterPlatforms(handler, platformMatcher)
	handler = images.SetChildrenLabels(cs, handler)
	if err := images.Walk(ctx, handler, index); err != nil {
		return nil, err
	}

	for i := range imgs {
		img, err := is.Update(ctx, imgs[i], "target")
		if err != nil {
			if !errdefs.IsNotFound(err) {
				return nil, err
			}

			img, err = is.Create(ctx, imgs[i])
			if err != nil {
				return nil, err
			}
		}
		imgs[i] = img
	}

	return imgs, nil
}
784216
func (a *API) ImportPath() string {
	return path.Join(a.BaseImportPath, a.PackageName())
}
116128
func LoadFile(path string) (*Config, error) {
	importTree, err := loadTree(path)
	if err != nil {
		return nil, err
	}

	configTree, err := importTree.ConfigTree()

	// Close the importTree now so that we can clear resources as quickly
	// as possible.
	importTree.Close()

	if err != nil {
		return nil, err
	}

	return configTree.Flatten()
}
543685
func (si *shareImporter) importAssembled(ctx context.Context) {
	res, err := http.Get(si.shareURL)
	if err != nil {
		return
	}
	defer res.Body.Close()
	br, err := schema.WriteFileFromReader(ctx, si.dest, "", res.Body)
	if err != nil {
		return
	}
	si.mu.Lock()
	si.br = br
	si.mu.Unlock()
	return
}
337292
func (res *Resource) Import(container Container, context *qor.Context, callbacks ...func(Progress) error) error {
	rows, err := container.NewReader(res, context)
	if err == nil {
		var hasError bool
		var current uint
		var total = rows.Total()

		if db := context.GetDB(); db != nil && !res.Config.DisableTransaction {
			tx := db.Begin()
			context.SetDB(tx)
			defer func() {
				if hasError {
					tx.Rollback()
				} else {
					tx.Commit()
				}
			}()
		}

		for rows.Next() {
			current++
			progress := Progress{Total: total, Current: current}

			var metaValues *resource.MetaValues
			var handleError func(err error)

			if metaValues, err = rows.ReadRow(); err == nil {
				for _, metaValue := range metaValues.Values {
					progress.Cells = append(progress.Cells, Cell{
						Header: metaValue.Name,
						Value:  metaValue.Value,
					})
				}

				handleError = func(err error) {
					hasError = true
					progress.Errors.AddError(err)

					if errors, ok := err.(errorsInterface); ok {
						for _, err := range errors.GetErrors() {
							handleError(err)
						}
					} else if err, ok := err.(*validations.Error); ok {
						for idx, cell := range progress.Cells {
							if cell.Header == err.Column {
								cell.Error = err
								progress.Cells[idx] = cell
								break
							}
						}
					} else if len(progress.Cells) > 0 {
						var err error = err
						cell := progress.Cells[0]
						if cell.Error != nil {
							var errors qor.Errors
							errors.AddError(cell.Error)
							errors.AddError(err)
							err = errors
						}
						cell.Error = err
					}
				}

				result := res.NewStruct()
				progress.Value = result

				if err = res.FindOneHandler(result, metaValues, context); err == nil || err == gorm.ErrRecordNotFound {
					if err = resource.DecodeToResource(res, result, metaValues, context).Start(); err == nil {
						if err = res.CallSave(result, context); err != nil {
							handleError(err)
						}
					} else {
						handleError(err)
					}
				} else {
					handleError(err)
				}
			}

			for _, callback := range callbacks {
				if err := callback(progress); err != nil {
					return err
				}
			}
		}
	}
	return err
}
1250706
func ImportFrom(path string) ([]Config, error) {
	var cfgs []Config
	fmt.Println("walking:", path)
	walk := func(filename string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		if info.IsDir() {
			return nil
		}
		id := filepath.Base(filepath.Dir(filename))
		base := filepath.Base(filename)
		if !strings.HasSuffix(base, ".json") {
			return nil
		}
		var tmp []Config
		// eat all these errors since we're searching for matching json
		file, _ := os.Open(filename)
		blob, _ := ioutil.ReadAll(file)
		_ = file.Close()
		_ = json.Unmarshal(blob, &tmp)
		for _, c := range tmp {
			if c.LoginURL == "" || c.Username == "" {
				continue
			}
			c.ID = fmt.Sprintf("%s:%s", id, c.Username)
			fmt.Println("importing...", c.ID)
			cfgs = append(cfgs, c)
		}
		return nil
	}
	err := filepath.Walk(path, walk)
	fmt.Printf("loaded %d configs\n", len(cfgs))
	return cfgs, err
}
1266361
func (v *BtrfsVolume) Import(label string, reader io.Reader) error {
	if exists, err := v.snapshotExists(label); err != nil {
		return err
	} else if exists {
		return volume.ErrSnapshotExists
	}
	importdir := filepath.Join(v.path, fmt.Sprintf("import-%s", label))
	if _, err := volume.RunBtrFSCmd(v.sudoer, "subvolume", "create", importdir); err != nil {
		glog.Errorf("Could not create import path for snapshot %s: %s", label, err)
		return err
	}
	defer volume.RunBtrFSCmd(v.sudoer, "subvolume", "delete", importdir)
	if err := runBtrfsRecv(reader, v.sudoer, importdir); err != nil {
		glog.Errorf("Could not import snapshot %s: %s", label, err)
		return err
	}
	defer volume.RunBtrFSCmd(v.sudoer, "subvolume", "delete", filepath.Join(importdir, label))
	if _, err := volume.RunBtrFSCmd(v.sudoer, "subvolume", "snapshot", "-r", filepath.Join(importdir, label), v.Driver().Root()); err != nil {
		return err
	}
	return nil
}
40181
func (imp *Import) Copy() *Import {
	cpy := *imp
	cpy.Path = imp.Path.Copy()
	return &cpy
}
531229
func (p *Pubring) Import(buf []byte) error {
	pk := &xcpb.PublicKey{}
	if err := proto.Unmarshal(buf, pk); err != nil {
		return err
	}

	p.insert(pk)
	return nil
}
811786
func Import(env *vm.Env) *vm.Env {
	env.Define("keys", func(v interface{}) []interface{} {
		rv := reflect.ValueOf(v)
		if rv.Kind() == reflect.Interface {
			rv = rv.Elem()
		}
		mapKeysValue := rv.MapKeys()
		mapKeys := make([]interface{}, len(mapKeysValue))
		for i := 0; i < len(mapKeysValue); i++ {
			mapKeys[i] = mapKeysValue[i].Interface()
		}
		return mapKeys
	})

	env.Define("range", func(args ...int64) []int64 {
		var start, stop int64
		var step int64 = 1

		switch len(args) {
		case 0:
			panic("range expected at least 1 argument, got 0")
		case 1:
			stop = args[0]
		case 2:
			start = args[0]
			stop = args[1]
		case 3:
			start = args[0]
			stop = args[1]
			step = args[2]
			if step == 0 {
				panic("range argument 3 must not be zero")
			}
		default:
			panic(fmt.Sprintf("range expected at most 3 arguments, got %d", len(args)))
		}

		arr := []int64{}
		for i := start; (step > 0 && i < stop) || (step < 0 && i > stop); i += step {
			arr = append(arr, i)
		}
		return arr
	})

	env.Define("typeOf", func(v interface{}) string {
		return reflect.TypeOf(v).String()
	})

	env.Define("kindOf", func(v interface{}) string {
		typeOf := reflect.TypeOf(v)
		if typeOf == nil {
			return "nil"
		}
		return typeOf.Kind().String()
	})

	env.Define("chanOf", func(t reflect.Type) reflect.Value {
		return reflect.MakeChan(t, 1)
	})

	env.Define("defined", func(s string) bool {
		_, err := env.Get(s)
		return err == nil
	})

	env.Define("load", func(s string) interface{} {
		body, err := ioutil.ReadFile(s)
		if err != nil {
			panic(err)
		}
		scanner := new(parser.Scanner)
		scanner.Init(string(body))
		stmts, err := parser.Parse(scanner)
		if err != nil {
			if pe, ok := err.(*parser.Error); ok {
				pe.Filename = s
				panic(pe)
			}
			panic(err)
		}
		rv, err := vm.Run(stmts, env)
		if err != nil {
			panic(err)
		}
		return rv
	})

	env.Define("panic", func(e interface{}) {
		os.Setenv("ANKO_DEBUG", "1")
		panic(e)
	})

	env.Define("print", fmt.Print)
	env.Define("println", fmt.Println)
	env.Define("printf", fmt.Printf)

	ImportToX(env)

	return env
}