Exemple #1
0
func importFiles(csvfile, newdir string) error {
	var err error

	csvFile, err := os.Open(csvfile)
	if err != nil {
		return fmt.Errorf("error opening csv file: %v\n", err)
	}
	defer csvFile.Close()

	reader := csv.NewReader(csvFile)
	rawCSVdata, err := reader.ReadAll()
	if err != nil {
		return fmt.Errorf("error reading csv file: %v\n", err)
	}

	for _, each := range rawCSVdata {
		if logger.Level > 0 {
			err = ipfs.GetFromIPFS(each[0], each[1], newdir, logger.Writer)
		} else {
			err = ipfs.GetFromIPFS(each[0], each[1], newdir, bytes.NewBuffer([]byte{}))
		}
		if err != nil {
			return err
		}
	}
	return nil
}
Exemple #2
0
func ImportService(do *definitions.Do) error {
	fileName := filepath.Join(ServicesPath, do.Name)
	if filepath.Ext(fileName) == "" {
		fileName = fileName + ".toml"
	}

	var err error
	if logger.Level > 0 {
		err = ipfs.GetFromIPFS(do.Hash, fileName, "", logger.Writer)
	} else {
		err = ipfs.GetFromIPFS(do.Hash, fileName, "", bytes.NewBuffer([]byte{}))
	}

	if err != nil {
		return err
		//return fmt.Errorf("I do not know how to get that file. Sorry. %v\n", err)
	}

	_, err = loaders.LoadServiceDefinition(do.Name, false, 0)
	//XXX add protections?
	if err != nil {
		return fmt.Errorf("Your service defintion file looks improperly formatted and will not marshal.")
	}

	do.Result = "success"
	return nil
}
Exemple #3
0
func ImportService(do *definitions.Do) error {
	fileName := filepath.Join(ServicesPath, do.Name)
	if filepath.Ext(fileName) == "" {
		fileName = fileName + ".toml"
	}

	s := strings.Split(do.Path, ":")
	if s[0] == "ipfs" {

		var err error
		if logger.Level > 0 {
			err = ipfs.GetFromIPFS(s[1], fileName, "", logger.Writer)
		} else {
			err = ipfs.GetFromIPFS(s[1], fileName, "", bytes.NewBuffer([]byte{}))
		}

		if err != nil {
			return err
		}
		return nil
	}

	if strings.Contains(s[0], "github") {
		logger.Errorln("https://twitter.com/ryaneshea/status/595957712040628224")
		return nil
	}
	do.Result = "success"
	return fmt.Errorf("I do not know how to get that file. Sorry.")
}
Exemple #4
0
func ImportService(do *definitions.Do) error {
	fileName := filepath.Join(ServicesPath, do.Name)
	if filepath.Ext(fileName) == "" {
		fileName = fileName + ".toml"
	}

	var err error
	if log.GetLevel() > 0 {
		err = ipfs.GetFromIPFS(do.Hash, fileName, "", os.Stdout)
	} else {
		err = ipfs.GetFromIPFS(do.Hash, fileName, "", bytes.NewBuffer([]byte{}))
	}

	if err != nil {
		return err
	}

	_, err = loaders.LoadServiceDefinition(do.Name, false, 0)
	//XXX add protections?
	if err != nil {
		return fmt.Errorf("Your service definition file looks improperly formatted and will not marshal.")
	}

	do.Result = "success"
	return nil
}
Exemple #5
0
func importFile(hash, fileName string) error {
	var err error

	if logger.Level > 0 {
		err = ipfs.GetFromIPFS(hash, fileName, "", logger.Writer)
	} else {
		err = ipfs.GetFromIPFS(hash, fileName, "", bytes.NewBuffer([]byte{}))
	}
	if err != nil {
		return err
	}
	return nil
}
Exemple #6
0
func importFile(hash, fileName string) error {
	var err error

	if log.GetLevel() > 0 {
		err = ipfs.GetFromIPFS(hash, fileName, "", os.Stdout)
	} else {
		err = ipfs.GetFromIPFS(hash, fileName, "", bytes.NewBuffer([]byte{}))
	}
	if err != nil {
		return err
	}
	return nil
}
Exemple #7
0
func ImportAction(do *definitions.Do) error {
	if do.Name == "" {
		do.Name = strings.Join(do.Operations.Args, "_")
	}
	fileName := filepath.Join(ActionsPath, strings.Join(do.Operations.Args, " "))
	if filepath.Ext(fileName) == "" {
		fileName = fileName + ".toml"
	}

	s := strings.Split(do.Path, ":")
	if s[0] == "ipfs" {

		var err error
		//unset 1 as default ContainerNumber, let it take flag?
		ipfsService, err := loaders.LoadServiceDefinition("ipfs", false, 1)
		if err != nil {
			return err
		}

		ipfsService.Operations.ContainerType = definitions.TypeService
		err = perform.DockerRunService(ipfsService.Service, ipfsService.Operations)
		if err != nil {
			return err
		}

		if log.GetLevel() > 0 {
			err = ipfs.GetFromIPFS(s[1], fileName, "", os.Stdout)
		} else {
			err = ipfs.GetFromIPFS(s[1], fileName, "", bytes.NewBuffer([]byte{}))
		}

		if err != nil {
			return err
		}
		return nil
	}

	if strings.Contains(s[0], "github") {
		log.Warn("https://twitter.com/ryaneshea/status/595957712040628224")
		return nil
	}

	log.Warn("Failed to get that file. Sorry")
	return nil
}