From 07ca6267d1b30f4e2b590126b7ac714f4e8a28ca Mon Sep 17 00:00:00 2001 From: Harishankar Date: Wed, 24 Oct 2018 15:02:56 +0530 Subject: [PATCH] Made resource management Instead of loading from file, now initialized go-bindata and using resource instead of file. --- bindata.go | 237 ++++++++++++++++++ .../resumebuilder.glade | 0 resumebuilder.go | 8 +- 3 files changed, 244 insertions(+), 1 deletion(-) create mode 100644 bindata.go rename resumebuilder.glade => resources/resumebuilder.glade (100%) diff --git a/bindata.go b/bindata.go new file mode 100644 index 0000000..00b9946 --- /dev/null +++ b/bindata.go @@ -0,0 +1,237 @@ +// Code generated by go-bindata. +// sources: +// resources/resumebuilder.glade +// DO NOT EDIT! + +package main + +import ( + "bytes" + "compress/gzip" + "fmt" + "io" + "io/ioutil" + "os" + "path/filepath" + "strings" + "time" +) + +func bindataRead(data []byte, name string) ([]byte, error) { + gz, err := gzip.NewReader(bytes.NewBuffer(data)) + if err != nil { + return nil, fmt.Errorf("Read %q: %v", name, err) + } + + var buf bytes.Buffer + _, err = io.Copy(&buf, gz) + clErr := gz.Close() + + if err != nil { + return nil, fmt.Errorf("Read %q: %v", name, err) + } + if clErr != nil { + return nil, err + } + + return buf.Bytes(), nil +} + +type asset struct { + bytes []byte + info os.FileInfo +} + +type bindataFileInfo struct { + name string + size int64 + mode os.FileMode + modTime time.Time +} + +func (fi bindataFileInfo) Name() string { + return fi.name +} +func (fi bindataFileInfo) Size() int64 { + return fi.size +} +func (fi bindataFileInfo) Mode() os.FileMode { + return fi.mode +} +func (fi bindataFileInfo) ModTime() time.Time { + return fi.modTime +} +func (fi bindataFileInfo) IsDir() bool { + return false +} +func (fi bindataFileInfo) Sys() interface{} { + return nil +} + +var _resourcesResumebuilderGlade = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x5a\xc9\x6e\xe3\x38\x10\xbd\xe7\x2b\x38\xbc\x0e\xbc\x6a\x9c\x05\x90\x15\x24\x98\x38\x97\x4c\x06\x98\x64\xd0\x47\x83\x16\xcb\x32\xdb\x0c\xa9\x26\x29\x2f\x7f\xdf\xa0\x9d\xb4\x17\x2d\x96\xe4\x25\x0a\xda\x97\x20\x91\xab\x4a\xc5\x7a\xf5\x6a\x09\xed\xde\xce\xde\x38\x9a\x80\xd2\x4c\x8a\x2e\x6e\xd5\x9b\x18\x81\xf0\x25\x65\x22\xe8\xe2\xff\x5f\x7b\xb5\x6b\x7c\xeb\x5d\xb8\x7f\xd4\x6a\xe8\x11\x04\x28\x62\x80\xa2\x29\x33\x23\x14\x70\x42\x01\x39\xf5\x76\xbb\xde\x42\xb5\x9a\x77\xe1\x32\x61\x40\x0d\x89\x0f\xde\x05\x42\xae\x82\x1f\x11\x53\xa0\x11\x67\x83\x2e\x0e\xcc\xf8\x4f\xbc\x7a\x91\x53\x6f\x37\x71\x63\x21\x27\x07\xdf\xc1\x37\xc8\xe7\x44\xeb\x2e\x7e\x34\xe3\x6f\x4c\x50\x39\xc5\x88\xd1\x2e\xfe\x87\x30\xf1\xfe\xb7\x15\x46\xc8\x0d\x95\x0c\x41\x99\x39\x12\xe4\x0d\xba\xd8\xfe\xc4\xde\x4a\xcc\x6d\x7c\x08\x24\xcb\xfb\x44\xf4\x87\xd2\x8f\x34\xf6\x7a\x84\x6b\xd8\x25\x3f\x5d\x58\xed\x87\x52\x33\xc3\xa4\xc0\x9e\x0f\xf6\x94\x35\x29\x6a\x21\x51\x20\x4c\xcc\x80\x3f\x62\x9c\x2e\x7f\xb7\xe6\x38\xf1\x61\x24\x39\x05\xd5\x78\x17\x68\xac\x49\x6c\x49\xc7\x62\xf1\x2c\x0d\x0c\xa4\x1c\xe3\x0f\x91\xb8\x87\x13\xa6\xd9\x80\x03\xf6\x5e\x55\x14\x3b\xce\x8e\x10\xa4\xaa\x6c\xb8\x95\xec\x5a\x8f\xcd\x80\xe2\x75\x99\x12\xbe\x95\x81\x28\xdd\xc9\x64\x47\x1f\x84\x51\xf3\x65\x3a\xf5\x98\xd2\xe6\x79\x91\x32\x5b\x6a\x49\xc8\x53\x33\xea\xdb\x2c\x06\x6d\xb0\xd7\x6e\x77\xd2\x1c\x29\x7d\xf2\x92\xe8\xa4\xa9\x32\x11\x46\xa6\x1f\x46\x2a\x94\x1a\xb0\x67\x1f\xa6\xab\xbb\x8d\x65\xa0\x62\xcf\x43\xe2\x8f\x99\x08\x76\xbf\x6e\x66\x83\xd2\x2a\xe2\xe0\x1c\x7b\xad\x0c\x05\xb7\x91\xf8\xee\x0d\xc2\xfc\x7a\x98\x13\xfc\x27\x32\x00\x9e\x03\xed\x43\xe0\x95\x99\xad\x49\xba\x7c\xe1\x1c\x32\x8a\x08\xcd\x89\x21\x03\x6e\x83\x04\xd6\x94\x4d\x54\x74\x02\x04\x9d\xab\xa2\x00\x5e\x9f\x01\xcc\x01\xe0\x13\xa9\x28\x7e\x9d\x0c\x85\x63\xe0\xb7\x56\x7d\x6d\x4c\xce\xc5\x17\x7d\x5e\xf1\xed\x34\xcf\xdc\xcd\xc1\xdd\x17\x98\x55\x8d\xb5\x2d\xa7\x7d\x5a\xe8\xfe\x23\x94\xc9\xfb\xc8\x18\x29\x3e\x26\x71\x9e\x87\xb8\xe9\x51\xb5\x06\x8a\x9c\x7a\xab\x04\x74\x6e\x8a\x28\x8f\x80\x05\x23\xb3\x56\x40\xfe\xaa\x7a\xfd\x50\xe0\x03\x9b\x80\xee\x53\x18\x92\x88\x9b\x12\x19\x4d\x7c\xc3\x26\x25\xbc\xa6\x8a\x4c\xfb\x4c\x50\xe6\x13\x23\xd5\x2e\xfd\x83\x10\xa0\xd5\x29\x3c\x38\x3a\x27\x9e\x1c\x63\x0c\xe8\xc1\xdb\xbe\x1c\x58\x9a\xd8\x83\x05\x57\x85\xfa\xe0\x99\x05\x47\x63\x41\x5c\x3f\x50\x32\x0a\x77\x95\xb9\x03\x35\xfe\x8c\x66\x50\x3d\xf2\xec\x43\x98\x7f\xcd\x08\xd4\x1e\x7c\xb9\xdc\x8f\x2f\x95\x9f\x3a\xcf\x7c\xd9\xf5\x1a\x3b\x6d\x35\x9d\xaa\xf3\xe5\x8b\x4e\xca\x77\x41\xe5\xf6\xdb\x9b\xcf\xdb\x6f\xef\x82\x12\xab\x6d\xd6\x4e\x56\x8d\x1a\xb3\xb5\xd9\x52\x16\x30\xa3\x8f\xde\xe2\x0a\x85\x65\x8e\xbd\xeb\x8c\xfd\xe0\x18\xb8\xaf\x4f\x86\x2f\x64\x02\x07\x68\x76\xd6\xcc\x1e\xbd\xae\xe5\x14\x8a\xd9\x76\xb3\x73\xbe\xe0\x70\x78\x82\x4d\xc5\x69\x16\xde\xd5\x2f\x0f\xf2\x2f\xd2\x24\xef\x93\x3d\xdf\xf6\xc1\x90\x41\x7f\xc8\x38\xcf\x2c\xf5\x09\x8e\xc4\x9c\x58\x72\x01\x99\x79\xb8\xb4\xba\x91\xdd\xf9\x9a\xd8\x69\x6f\x84\x72\x53\xed\x9e\x68\xe6\xa3\xbf\xc1\x10\xc6\x53\x6a\x59\x65\xe2\x9f\x1d\xf4\x4f\xbe\x86\x2b\x1f\xa5\xd5\x95\x6a\xca\xac\xf5\x7b\x67\xe8\x03\x8d\x7c\x62\xe3\x73\xf2\xb8\x9f\x36\xa1\xe3\x17\xe4\x25\x80\xce\x65\x64\x33\x64\x6b\x1f\xae\x3e\x70\x1b\x6b\xdf\x61\xf8\x19\x00\x00\xff\xff\xcc\x33\xb3\xcd\x1c\x21\x00\x00") + +func resourcesResumebuilderGladeBytes() ([]byte, error) { + return bindataRead( + _resourcesResumebuilderGlade, + "resources/resumebuilder.glade", + ) +} + +func resourcesResumebuilderGlade() (*asset, error) { + bytes, err := resourcesResumebuilderGladeBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "resources/resumebuilder.glade", size: 8476, mode: os.FileMode(436), modTime: time.Unix(1540310475, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + +// Asset loads and returns the asset for the given name. +// It returns an error if the asset could not be found or +// could not be loaded. +func Asset(name string) ([]byte, error) { + cannonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[cannonicalName]; ok { + a, err := f() + if err != nil { + return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) + } + return a.bytes, nil + } + return nil, fmt.Errorf("Asset %s not found", name) +} + +// MustAsset is like Asset but panics when Asset would return an error. +// It simplifies safe initialization of global variables. +func MustAsset(name string) []byte { + a, err := Asset(name) + if err != nil { + panic("asset: Asset(" + name + "): " + err.Error()) + } + + return a +} + +// AssetInfo loads and returns the asset info for the given name. +// It returns an error if the asset could not be found or +// could not be loaded. +func AssetInfo(name string) (os.FileInfo, error) { + cannonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[cannonicalName]; ok { + a, err := f() + if err != nil { + return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) + } + return a.info, nil + } + return nil, fmt.Errorf("AssetInfo %s not found", name) +} + +// AssetNames returns the names of the assets. +func AssetNames() []string { + names := make([]string, 0, len(_bindata)) + for name := range _bindata { + names = append(names, name) + } + return names +} + +// _bindata is a table, holding each asset generator, mapped to its name. +var _bindata = map[string]func() (*asset, error){ + "resources/resumebuilder.glade": resourcesResumebuilderGlade, +} + +// AssetDir returns the file names below a certain +// directory embedded in the file by go-bindata. +// For example if you run go-bindata on data/... and data contains the +// following hierarchy: +// data/ +// foo.txt +// img/ +// a.png +// b.png +// then AssetDir("data") would return []string{"foo.txt", "img"} +// AssetDir("data/img") would return []string{"a.png", "b.png"} +// AssetDir("foo.txt") and AssetDir("notexist") would return an error +// AssetDir("") will return []string{"data"}. +func AssetDir(name string) ([]string, error) { + node := _bintree + if len(name) != 0 { + cannonicalName := strings.Replace(name, "\\", "/", -1) + pathList := strings.Split(cannonicalName, "/") + for _, p := range pathList { + node = node.Children[p] + if node == nil { + return nil, fmt.Errorf("Asset %s not found", name) + } + } + } + if node.Func != nil { + return nil, fmt.Errorf("Asset %s not found", name) + } + rv := make([]string, 0, len(node.Children)) + for childName := range node.Children { + rv = append(rv, childName) + } + return rv, nil +} + +type bintree struct { + Func func() (*asset, error) + Children map[string]*bintree +} +var _bintree = &bintree{nil, map[string]*bintree{ + "resources": &bintree{nil, map[string]*bintree{ + "resumebuilder.glade": &bintree{resourcesResumebuilderGlade, map[string]*bintree{}}, + }}, +}} + +// RestoreAsset restores an asset under the given directory +func RestoreAsset(dir, name string) error { + data, err := Asset(name) + if err != nil { + return err + } + info, err := AssetInfo(name) + if err != nil { + return err + } + err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755)) + if err != nil { + return err + } + err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode()) + if err != nil { + return err + } + err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) + if err != nil { + return err + } + return nil +} + +// RestoreAssets restores an asset under the given directory recursively +func RestoreAssets(dir, name string) error { + children, err := AssetDir(name) + // File + if err != nil { + return RestoreAsset(dir, name) + } + // Dir + for _, child := range children { + err = RestoreAssets(dir, filepath.Join(name, child)) + if err != nil { + return err + } + } + return nil +} + +func _filePath(dir, name string) string { + cannonicalName := strings.Replace(name, "\\", "/", -1) + return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) +} + diff --git a/resumebuilder.glade b/resources/resumebuilder.glade similarity index 100% rename from resumebuilder.glade rename to resources/resumebuilder.glade diff --git a/resumebuilder.go b/resumebuilder.go index 82186cc..88fe6a6 100644 --- a/resumebuilder.go +++ b/resumebuilder.go @@ -108,11 +108,17 @@ func getSaveButton() (*gtk.Button, error) { func LoadMain() { gtk.Init(nil) var err error - ui, err = gtk.BuilderNewFromFile("resumebuilder.glade") + ui, err = gtk.BuilderNew() if err != nil { fmt.Println(err.Error()) os.Exit(1) } + asset, err := Asset("resources/resumebuilder.glade") + if err != nil { + fmt.Println(err.Error()) + os.Exit(1) + } + ui.AddFromString(string(asset)) wnd, err := getWindow() if err != nil { -- 2.20.1