Ejemplo n.º 1
0
func LoadSchema(uri string, localCopy bool) (sd *Schema, err error) {
	var protocol, localPath string
	var rc io.ReadCloser

	if pos := strings.Index(uri, protSep); pos < 0 {
		protocol = "http" + protSep
	} else {
		protocol = uri[:pos+len(protSep)]
		uri = uri[pos+len(protSep):]
	}
	if localCopy {
		if localPath = filepath.Join(PkgGen.BaseCodePath, uri); !uio.FileExists(localPath) {
			if err = uio.EnsureDirExists(filepath.Dir(localPath)); err == nil {
				err = unet.DownloadFile(protocol+uri, localPath)
			}
		}
		if err == nil {
			if sd, err = loadSchemaFile(localPath, uri); sd != nil {
				sd.loadLocalPath = localPath
			}
		}
	} else if rc, err = unet.OpenRemoteFile(protocol + uri); err == nil {
		defer rc.Close()
		sd, err = loadSchema(rc, uri, "")
	}
	return
}
Ejemplo n.º 2
0
func processFile(srcFilePath string) (keepWalking bool) {
	if strings.HasSuffix(srcFilePath, ".tga") {
		var (
			outFilePath      = strings.Replace(strings.Replace(srcFilePath, *fSrcDirPath, *fOutDirPath, -1), ".tga", ".png", -1)
			dirPath          = filepath.Dir(outFilePath)
			tgaFile, pngFile *os.File
			img              image.Image
			err              error
		)
		if err = uio.EnsureDirExists(dirPath); err != nil {
			log.Printf("ERR MkDir %v: %v\n", dirPath, err)
		} else if uio.DirExists(dirPath) {
			if tgaFile, err = os.OpenFile(srcFilePath, os.O_RDONLY, os.ModePerm); err != nil {
				log.Printf("ERR OpenFile %v: %v\n", srcFilePath, err)
			} else {
				defer tgaFile.Close()
				if img, err = tga.Decode(tgaFile); err != nil {
					log.Printf("ERR Decode %v: %v\n", srcFilePath, err)
				} else {
					if pngFile, err = os.Create(outFilePath); err != nil {
						log.Printf("ERR CreateFile %v: %v\n", outFilePath, err)
					} else {
						defer pngFile.Close()
						if err = png.Encode(pngFile, img); err != nil {
							log.Printf("ERR Encode %v: %v\n", outFilePath, err)
						} else {
							log.Printf("DONE %v\n", outFilePath)
						}
					}
				}
			}
		}
	}
	return true
}
Ejemplo n.º 3
0
func (me *Schema) MakeGoPkgSrcFile() (goOutFilePath string, err error) {
	var goOutDirPath = filepath.Join(filepath.Dir(me.loadLocalPath), goPkgPrefix+filepath.Base(me.loadLocalPath)+goPkgSuffix)
	goOutFilePath = filepath.Join(goOutDirPath, path.Base(me.loadUri)+".go")
	var bag = newPkgBag(me)
	for _, inc := range me.XMLIncludedSchemas {
		bag.Schema = inc
		inc.makePkg(bag)
	}
	bag.Schema = me
	me.hasElemAnnotation.makePkg(bag)
	bag.appendFmt(true, "")
	me.makePkg(bag)
	if err = uio.EnsureDirExists(filepath.Dir(goOutFilePath)); err == nil {
		err = uio.WriteTextFile(goOutFilePath, bag.assembleSource())
	}
	return
}