Ejemplo n.º 1
0
func targz(app *peony.App) {

	n := filepath.Base(app.ImportPath)
	n = app.GetStringConfig("app.name", n)
	destFilename := filepath.Join(".", fmt.Sprintf("%s.tar.gz", n))
	srcDir := app.BasePath
	os.Remove(destFilename)

	zipFile, err := os.Create(destFilename)
	panicOnError(err, "Failed to create archive")
	defer zipFile.Close()

	gzipWriter := gzip.NewWriter(zipFile)
	defer gzipWriter.Close()

	tarWriter := tar.NewWriter(gzipWriter)
	defer tarWriter.Close()

	tarapp(srcDir, app.AppName, tarWriter)

	var binPath string
	binPath, err = mole.GetBinPath(app)
	panicOnError(err, "get binary path error")
	_, binName := filepath.Split(binPath)
	tarbin(binPath, binName, app.AppName, tarWriter)

	tarshell(binName, app.AppName, tarWriter)

	tryTarErrors(srcDir, app.AppName, tarWriter)
	return
}
Ejemplo n.º 2
0
func convInner(url string, app *peony.App, f string) peony.Renderer {
	if url == "" {
		return peony.NotFound("No such file")
	}
	savePath := app.GetStringConfig("savepath", "/tmp")

	hash := md5.New()
	io.WriteString(hash, url)
	sum := hash.Sum(nil)
	destPath := path.Join(savePath, fmt.Sprintf("%x.%s", sum, f))

	if info, err := os.Stat(destPath); err == nil && !info.IsDir() {
		return peony.RenderFile(destPath)
	}
	transport := http.Transport{
		Dial: dialTimeout,
	}
	client := http.Client{
		Transport: &transport,
	}
	workPath := app.GetStringConfig("workpath", "/tmp")
	resp, err := client.Get(url)
	if err != nil || resp.StatusCode != http.StatusOK {
		return peony.NotFound("Get file from [%s] error.", url)
	}
	amrPath := path.Join(workPath, fmt.Sprintf("%x.amr", sum))
	amrFile, err := os.OpenFile(amrPath, os.O_WRONLY|os.O_CREATE, 0666)
	if err != nil {
		return peony.NotFound("Save file[%s] error, detial: %s ", url, err.Error())
	}
	defer resp.Body.Close()
	defer func() {
		amrFile.Close()
		os.Remove(amrPath)
	}()
	io.Copy(amrFile, resp.Body)
	convter[f](amrPath, destPath)
	return peony.RenderFile(destPath)
}