From f3145c6678f4bb610b832327b84a8c12b2c19f59 Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Wed, 17 Jan 2018 01:20:12 +0530 Subject: [PATCH 01/10] Create .private --- .private | 1 + 1 file changed, 1 insertion(+) create mode 100644 .private diff --git a/.private b/.private new file mode 100644 index 0000000..1b02325 --- /dev/null +++ b/.private @@ -0,0 +1 @@ +bea494ba492727728f9f2518e45d0e43a62d2237 From 7bc6d61e5dc94fbddecbd93f7ba6eacfbb199a76 Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Wed, 17 Jan 2018 01:35:31 +0530 Subject: [PATCH 02/10] wip/push file --- cmd/push.go | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/cmd/push.go b/cmd/push.go index c47b813..8a0a5c3 100644 --- a/cmd/push.go +++ b/cmd/push.go @@ -15,9 +15,18 @@ package cmd import ( + "crypto/sha256" + "encoding/hex" "fmt" - + "io" + "io/ioutil" + "log" + "os" + //"github.com/FourtekIT/devnagri-cli/utils" + "github.com/FourtekIT/devnagri-cli/config" + "github.com/Jeffail/gabs" "github.com/spf13/cobra" + "gopkg.in/resty.v1" ) // pushCmd represents the push command @@ -43,3 +52,84 @@ func init() { // is called directly, e.g.: // pushCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } + +func listAllFilesAndPush() { + var ClientID = config.FetchAndValidate("ClientID") // returns string + + var ClientSecret = config.FetchAndValidate("ClientSecret") // returns string + + var ProjectKey = config.FetchAndValidate("ProjectKey") // returns string + + var AccessToken = config.FetchAndValidate("AccessToken") // returns string + + filename := "./en/CallingPapaPro2.xml" + + resp, err := resty.R(). + SetHeader("Accept", "application/json"). + SetHeader("Content-Type", "multipart/form-data"). + SetAuthToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjE0MmI1YjlkOTI3ZGQ2ZjI3ODcyZDJmNDFmNWQzNjhkOGU3MmVhZjk2YzE2YTdmMTZjM2ZkM2I5ZmVmNjJiMDFmMTBiOWQwMTMxNzJjYTIyIn0.eyJhdWQiOiIxIiwianRpIjoiMTQyYjViOWQ5MjdkZDZmMjc4NzJkMmY0MWY1ZDM2OGQ4ZTcyZWFmOTZjMTZhN2YxNmMzZmQzYjlmZWY2MmIwMWYxMGI5ZDAxMzE3MmNhMjIiLCJpYXQiOjE1MTU1OTA4NDksIm5iZiI6MTUxNTU5MDg0OSwiZXhwIjoxNTQ3MTI2ODQ5LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.inJAzB_9Vjx9YXHQgZYCy3HxbTaSV2VSjKYgtB_s4ZrrS9vucEnEF4Ijh8wPMylxDLI7e8iGfRObK0rGTBqnCw94ElcmeYPM7GfWRqWW5Bz8ctJhXH7-VGml22fT6ahFVHssbVcx636xwPlydhN4fBay0TElXgC5QkSmzINFPMF3FRJ54WaAsTAvwpsnAIUfigZdNggSjMnROp-i7dtF5M9Ty3utLM2kmlEZVC9lhhLUvJujvbWJwCGDOStrBv4iapWQ4qPZ8AuaVTmigW_hVinkZ6GGTp8GT07GGF9iwDjPnSyCzEx7Ta4S0U3nSeJVogxmsO7N1hZrmCuZmUtEkSPMSP0wIhrMrranpzqFRqvsYve6hp8BBE9qxbuiEwc3F-2xFm-R6esmUu5mpWcRlM1imenuvb9C-lotKf0znM9neVimWhMe7OqENcGXTx7puTyZoK0wUmrn-2_vIxfwtU5s9aBomlw6qGQt6k14pgKA69bp2C51C46HyKa_QrEvol-_3YvccjvR3hO-jcAj_SLALYk6HJp1eSqy_tGZZ5QW4-4QvUcPaa3E4sXA4Ye_4OB2dGRcKVuhR5jzpaYJC-_qGRY0dhfYdpKjEgc1o3pitzpNW0iWzImN9iidRThu_YFP_RwPk2Qragch55f086JNdM7jGPkjcEUcgGIs3PE"). + SetFile("file[0][file]", filename). + SetFormData(map[string]string{ + "client_id": ClientID, + "client_secret": ClientSecret, + "project_key": ProjectKey, + "file[0][hash]": sha256Hash(filename), + "file[0][extension]": "xml", + "file[0][file_type]": "xml", + "file[0][location]": filename, + }). + Post("http://dev.devnagri.co.in/api/project/push") + + if err != nil { + panic(err) + } + + fmt.Println(resp) + fmt.Println("\n\n") + + resJson, _ := gabs.ParseJSON([]byte(resp.String())) + children, _ := resJson.S("file_content").Children() + child := children[0] + + fmt.Println(child.String()) + + //TODO: Iterate this over all the file names recieved from the remote + file, err := os.Create("temp.txt") + if err != nil { + log.Fatal("Cannot create file", err) + } + defer file.Close() + + _, err = file.WriteString(child.String()) + + // This works perfectly + //fmt.Println("Decoding the string manually") + //x := "PCEtLSBUcmFuc2xhdGVkIEJ5IERldm5hZ3JpIC0tPgo8IS0tIGh0dHA6Ly9kZXZuYWdyaS5jb20gLS0+CjxyZXNvdXJjZXMgdG9vbHM6aWdub3JlPSJFeHRyYVRyYW5zbGF0aW9uIiB4bWxuczp0b29scz0iaHR0cDovL3NjaGVtYXMuYW5kcm9pZC5jb20vdG9vbHMiPgogICAgPHN0cmluZyBuYW1lPSJhcHBfbmFtZSI+PC9zdHJpbmc+CiAgICA8c3RyaW5nIG5hbWU9ImhpbnRfYWN0dWFsIj48L3N0cmluZz4KIDwvcmVzb3VyY2VzPg==" + //decodeBase64(x) + + dat, _ := ioutil.ReadFile("temp.txt") + //fmt.Println("Reading content.txt") + fileContent := decodeBase64(string(dat)) + fmt.Println(fileContent) + +} + +func sha256Hash(fileName string) string { + + f, err := os.Open(fileName) + if err != nil { + log.Fatal(err) + } + defer f.Close() + + h := sha256.New() + if _, err := io.Copy(h, f); err != nil { + log.Fatal(err) + } + + //fmt.Printf("%x", h.Sum(nil)) + //return h.Sum(nil) + + hashString := hex.EncodeToString(h.Sum(nil)) + return hashString +} From e8fc5bd1fc19250325eb4361bfa8eb79d5b42788 Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Wed, 17 Jan 2018 01:38:21 +0530 Subject: [PATCH 03/10] minor tweak --- cmd/push.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/push.go b/cmd/push.go index 8a0a5c3..605ca43 100644 --- a/cmd/push.go +++ b/cmd/push.go @@ -60,7 +60,7 @@ func listAllFilesAndPush() { var ProjectKey = config.FetchAndValidate("ProjectKey") // returns string - var AccessToken = config.FetchAndValidate("AccessToken") // returns string + //var AccessToken = config.FetchAndValidate("AccessToken") // returns string filename := "./en/CallingPapaPro2.xml" From b5b28414b645eb5e14507a77d03e57754c3def99 Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Wed, 17 Jan 2018 16:45:46 +0530 Subject: [PATCH 04/10] the pull_dev is almost complete now --- _dev/content.txt | 1 - _dev/decodeFile.go | 30 ++++++++++++++++ _dev/en/CallingPapaPro1.xml | 4 +++ _dev/pull_dev.go | 68 ++++++++++++++++++++++++++----------- _dev/responseFile.txt | 6 ++++ _dev/temp.txt | 1 + cmd/push.go | 34 ++----------------- 7 files changed, 93 insertions(+), 51 deletions(-) delete mode 100644 _dev/content.txt create mode 100644 _dev/decodeFile.go create mode 100644 _dev/en/CallingPapaPro1.xml create mode 100644 _dev/responseFile.txt create mode 100644 _dev/temp.txt diff --git a/_dev/content.txt b/_dev/content.txt deleted file mode 100644 index 67f03ee..0000000 --- a/_dev/content.txt +++ /dev/null @@ -1 +0,0 @@ -PCEtLSBUcmFuc2xhdGVkIEJ5IERldm5hZ3JpIC0tPgo8IS0tIGh0dHA6Ly9kZXZuYWdyaS5jb20gLS0+CjxyZXNvdXJjZXMgdG9vbHM6aWdub3JlPSJFeHRyYVRyYW5zbGF0aW9uIiB4bWxuczp0b29scz0iaHR0cDovL3NjaGVtYXMuYW5kcm9pZC5jb20vdG9vbHMiPgogICAgPHN0cmluZyBuYW1lPSJhcHBfbmFtZSI+PC9zdHJpbmc+CiAgICA8c3RyaW5nIG5hbWU9ImhpbnRfYWN0dWFsIj48L3N0cmluZz4KIDwvcmVzb3VyY2VzPg== diff --git a/_dev/decodeFile.go b/_dev/decodeFile.go new file mode 100644 index 0000000..c65e06e --- /dev/null +++ b/_dev/decodeFile.go @@ -0,0 +1,30 @@ +package main + +import ( + "encoding/base64" + "fmt" + "io/ioutil" +) + +func main() { + + dat, _ := ioutil.ReadFile("temp.txt") + datString := string(dat) + //fmt.Println("String Length : ", len(datString)) + content := datString[1:(len(datString) - 1)] + //fmt.Println(content) + fileContent := decodeBase64(content) + //fmt.Println(fileContent) + //fmt.Println("<<< Reading temp file now >>>") + //fileContent := decodeBase64(string(dat)) + fmt.Println(fileContent) +} + +func decodeBase64(cypher string) string { + + data, _ := base64.StdEncoding.DecodeString(cypher) + + stringData := string(data) + + return stringData +} diff --git a/_dev/en/CallingPapaPro1.xml b/_dev/en/CallingPapaPro1.xml new file mode 100644 index 0000000..5a71912 --- /dev/null +++ b/_dev/en/CallingPapaPro1.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/_dev/pull_dev.go b/_dev/pull_dev.go index e68ebe1..6cdd519 100644 --- a/_dev/pull_dev.go +++ b/_dev/pull_dev.go @@ -4,10 +4,11 @@ import ( "encoding/base64" "fmt" "io/ioutil" - // "os" + "log" + "os" // "reflect" - // "github.com/Jeffail/gabs" + "github.com/Jeffail/gabs" "gopkg.in/resty.v1" ) @@ -23,7 +24,7 @@ func decodeBase64(cypher string) string { //fmt.Println(string(data)) - println("Text after decoding") + println("<<< Text after decoding >>>") //fmt.Println(data) //fmt.Println(string(data)) @@ -32,15 +33,15 @@ func decodeBase64(cypher string) string { } -func saveResponseAndConvert() string { +func saveResponseAndConvert() { resp, err := resty.R(). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "multipart/form-data"). - SetAuthToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjE0MmI1YjlkOTI3ZGQ2ZjI3ODcyZDJmNDFmNWQzNjhkOGU3MmVhZjk2YzE2YTdmMTZjM2ZkM2I5ZmVmNjJiMDFmMTBiOWQwMTMxNzJjYTIyIn0.eyJhdWQiOiIxIiwianRpIjoiMTQyYjViOWQ5MjdkZDZmMjc4NzJkMmY0MWY1ZDM2OGQ4ZTcyZWFmOTZjMTZhN2YxNmMzZmQzYjlmZWY2MmIwMWYxMGI5ZDAxMzE3MmNhMjIiLCJpYXQiOjE1MTU1OTA4NDksIm5iZiI6MTUxNTU5MDg0OSwiZXhwIjoxNTQ3MTI2ODQ5LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.inJAzB_9Vjx9YXHQgZYCy3HxbTaSV2VSjKYgtB_s4ZrrS9vucEnEF4Ijh8wPMylxDLI7e8iGfRObK0rGTBqnCw94ElcmeYPM7GfWRqWW5Bz8ctJhXH7-VGml22fT6ahFVHssbVcx636xwPlydhN4fBay0TElXgC5QkSmzINFPMF3FRJ54WaAsTAvwpsnAIUfigZdNggSjMnROp-i7dtF5M9Ty3utLM2kmlEZVC9lhhLUvJujvbWJwCGDOStrBv4iapWQ4qPZ8AuaVTmigW_hVinkZ6GGTp8GT07GGF9iwDjPnSyCzEx7Ta4S0U3nSeJVogxmsO7N1hZrmCuZmUtEkSPMSP0wIhrMrranpzqFRqvsYve6hp8BBE9qxbuiEwc3F-2xFm-R6esmUu5mpWcRlM1imenuvb9C-lotKf0znM9neVimWhMe7OqENcGXTx7puTyZoK0wUmrn-2_vIxfwtU5s9aBomlw6qGQt6k14pgKA69bp2C51C46HyKa_QrEvol-_3YvccjvR3hO-jcAj_SLALYk6HJp1eSqy_tGZZ5QW4-4QvUcPaa3E4sXA4Ye_4OB2dGRcKVuhR5jzpaYJC-_qGRY0dhfYdpKjEgc1o3pitzpNW0iWzImN9iidRThu_YFP_RwPk2Qragch55f086JNdM7jGPkjcEUcgGIs3PE"). + SetAuthToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjY2MTY0MzEzNGYyNDRlNjEyMWE1MzAwMjAyZDFhMDVkYmY3MTFjYjQxZDg2NjUxNmU5ZjRiNDI4OTBkNGE0NDk5NDU5ODc2M2M4ZGNjYTI5In0.eyJhdWQiOiIzIiwianRpIjoiNjYxNjQzMTM0ZjI0NGU2MTIxYTUzMDAyMDJkMWEwNWRiZjcxMWNiNDFkODY2NTE2ZTlmNGI0Mjg5MGQ0YTQ0OTk0NTk4NzYzYzhkY2NhMjkiLCJpYXQiOjE1MTYxNzIwNDQsIm5iZiI6MTUxNjE3MjA0NCwiZXhwIjoxNTQ3NzA4MDQ0LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.HqVfac3VEcTFT79WuQ_9CH1Q3KWeRO9i6IyQYT7iLqz7S6JmvY0mmLo34awViYN_7jssUZCOXo_esz7juzO3mPXMS9ej_rbUQUH3CHw-JRnBOJ8sPgsg43yF79omiZpxWjn5-Brlq7cyqu28mpXENqkIV_1mXE214hIK0ap0BZHrQ8iQmbYuKpWlZMJnmNzbD2FJ2GtcatkEtSjZsnglXpWHnYSuVcSaFc59KE4TOqFeNh4Xln7puWKB2MJrjSGFMvtKlh5u2RlWDVOwM1tAs9hrrE6nOq6ncoF6ur51P26_BjByjZtlhEXvKKHjLJkYdWipB-yjyjl8uS5JciINzZkj6AnnmRHWFNU0dOKYb8E8FJv9Z5yDBz4EitDqa-LSOoHfYidyrBpJU_c4n04Fjo2RbzyMdRphk1NT9CdgteR973DUBNRCkI0z-OlORRTz8mh62SlshanA4jtFme3qYXph-J5mzVyRInVB0HtJh8LF9yIPnlX3ge0jjvpZSgrP_r7XCtPlYeih6KFK3sQc24vo-wPKTE6-UBLZSxsH3mJeJGzsbR9F59vbAaJ518-WgbQfMeAo2lUz_ebsB24Lvrc7rVMqdA1yEdwPepcCYuGO7-Afb3XzOFjSVlRCtFTHLxWWvJ221g1a_lS0ifxxjbVetFYxqw8xaWnWMwoI2Vk"). SetFormData(map[string]string{ - "client_id": "3", - "client_secret": "3WnUqVSP7Vhs8DU7FInIrwHIVMg9twGshcpswlJW", - "project_key": "2e12635aca73c7d39ec76a514d7490a6"}). + "client_id": "2", + "client_secret": "y8umxMS54nUBc1ak7cxod6mjYiAbht2rCNAKsW7c", + "project_key": "ded491851ec93a79ee89460902aff582"}). Post("http://dev.devnagri.co.in/api/project/pull") if err != nil { panic(err) @@ -49,12 +50,10 @@ func saveResponseAndConvert() string { fmt.Println(resp) fmt.Println("\n\n") - /* - resJson, _ := gabs.ParseJSON([]byte(resp.String())) - children, _ := resJson.S("file_content").Children() - child := children[0] - */ - //fmt.Println(child.String()) + resJson, _ := gabs.ParseJSON([]byte(resp.String())) + children, _ := resJson.S("file_content").Children() + child := children[0] + fmt.Println(child.String()) //data, _ := base64.StdEncoding.Decode(child.String()) //encoded := child.String() @@ -68,9 +67,40 @@ func saveResponseAndConvert() string { //x := "PCEtLSBUcmFuc2xhdGVkIEJ5IERldm5hZ3JpIC0tPgo8IS0tIGh0dHA6Ly9kZXZuYWdyaS5jb20gLS0+CjxyZXNvdXJjZXMgdG9vbHM6aWdub3JlPSJFeHRyYVRyYW5zbGF0aW9uIiB4bWxuczp0b29scz0iaHR0cDovL3NjaGVtYXMuYW5kcm9pZC5jb20vdG9vbHMiPgogICAgPHN0cmluZyBuYW1lPSJhcHBfbmFtZSI+PC9zdHJpbmc+CiAgICA8c3RyaW5nIG5hbWU9ImhpbnRfYWN0dWFsIj48L3N0cmluZz4KIDwvcmVzb3VyY2VzPg==" //decodeBase64(x) - dat, _ := ioutil.ReadFile("./content.txt") - fmt.Println("reading content.txt") - x := decodeBase64(string(dat)) - fmt.Println(x) - return string(dat) + //TODO: Iterate this over all the file names recieved from the remote + file, err := os.Create("temp.txt") + if err != nil { + log.Fatal("Cannot create file", err) + } + defer file.Close() + + _, err = file.WriteString(child.String()) + + // This works perfectly + //fmt.Println("Decoding the string manually") + //x := "PCEtLSBUcmFuc2xhdGVkIEJ5IERldm5hZ3JpIC0tPgo8IS0tIGh0dHA6Ly9kZXZuYWdyaS5jb20gLS0+CjxyZXNvdXJjZXMgdG9vbHM6aWdub3JlPSJFeHRyYVRyYW5zbGF0aW9uIiB4bWxuczp0b29scz0iaHR0cDovL3NjaGVtYXMuYW5kcm9pZC5jb20vdG9vbHMiPgogICAgPHN0cmluZyBuYW1lPSJhcHBfbmFtZSI+PC9zdHJpbmc+CiAgICA8c3RyaW5nIG5hbWU9ImhpbnRfYWN0dWFsIj48L3N0cmluZz4KIDwvcmVzb3VyY2VzPg==" + //decodeBase64(x) + + dat, _ := ioutil.ReadFile("temp.txt") + datString := string(dat) + //fmt.Println("String Length : ", len(datString)) + content := datString[1:(len(datString) - 1)] + //fmt.Println(content) + fileContent := decodeBase64(content) + //fmt.Println(fileContent) + //fmt.Println("<<< Reading temp file now >>>") + //fileContent := decodeBase64(string(dat)) + //fmt.Println(fileContent) + + //TODO: Store the content of temp into the actual file + responseFile, err := os.Create("responseFile.txt") + if err != nil { + log.Fatal("Cannot create file", err) + } + defer responseFile.Close() + + _, err = responseFile.WriteString(fileContent) + + //TODO: Delete the temp file + } diff --git a/_dev/responseFile.txt b/_dev/responseFile.txt new file mode 100644 index 0000000..bc9d843 --- /dev/null +++ b/_dev/responseFile.txt @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/_dev/temp.txt b/_dev/temp.txt new file mode 100644 index 0000000..4170a80 --- /dev/null +++ b/_dev/temp.txt @@ -0,0 +1 @@ +"PCEtLSBUcmFuc2xhdGVkIEJ5IERldm5hZ3JpIC0tPgo8IS0tIGh0dHA6Ly9kZXZuYWdyaS5jb20gLS0+CjxyZXNvdXJjZXMgdG9vbHM6aWdub3JlPSJFeHRyYVRyYW5zbGF0aW9uIiB4bWxuczp0b29scz0iaHR0cDovL3NjaGVtYXMuYW5kcm9pZC5jb20vdG9vbHMiPgogICAgPHN0cmluZyBuYW1lPSJhcHBfbmFtZSI+PC9zdHJpbmc+CiAgICA8c3RyaW5nIG5hbWU9ImhpbnRfYWN0dWFsIj48L3N0cmluZz4KIDwvcmVzb3VyY2VzPg==" \ No newline at end of file diff --git a/cmd/push.go b/cmd/push.go index 605ca43..325f7e0 100644 --- a/cmd/push.go +++ b/cmd/push.go @@ -19,12 +19,10 @@ import ( "encoding/hex" "fmt" "io" - "io/ioutil" "log" "os" //"github.com/FourtekIT/devnagri-cli/utils" "github.com/FourtekIT/devnagri-cli/config" - "github.com/Jeffail/gabs" "github.com/spf13/cobra" "gopkg.in/resty.v1" ) @@ -36,6 +34,7 @@ var pushCmd = &cobra.Command{ Long: `This command transfers all the untranslated local files to the Devnagri platform on a language basis.`, Run: func(cmd *cobra.Command, args []string) { fmt.Println("push called") + listAllFilesAndPush() }, } @@ -60,14 +59,14 @@ func listAllFilesAndPush() { var ProjectKey = config.FetchAndValidate("ProjectKey") // returns string - //var AccessToken = config.FetchAndValidate("AccessToken") // returns string + var AccessToken = config.FetchAndValidate("AccessToken") // returns string filename := "./en/CallingPapaPro2.xml" resp, err := resty.R(). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "multipart/form-data"). - SetAuthToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjE0MmI1YjlkOTI3ZGQ2ZjI3ODcyZDJmNDFmNWQzNjhkOGU3MmVhZjk2YzE2YTdmMTZjM2ZkM2I5ZmVmNjJiMDFmMTBiOWQwMTMxNzJjYTIyIn0.eyJhdWQiOiIxIiwianRpIjoiMTQyYjViOWQ5MjdkZDZmMjc4NzJkMmY0MWY1ZDM2OGQ4ZTcyZWFmOTZjMTZhN2YxNmMzZmQzYjlmZWY2MmIwMWYxMGI5ZDAxMzE3MmNhMjIiLCJpYXQiOjE1MTU1OTA4NDksIm5iZiI6MTUxNTU5MDg0OSwiZXhwIjoxNTQ3MTI2ODQ5LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.inJAzB_9Vjx9YXHQgZYCy3HxbTaSV2VSjKYgtB_s4ZrrS9vucEnEF4Ijh8wPMylxDLI7e8iGfRObK0rGTBqnCw94ElcmeYPM7GfWRqWW5Bz8ctJhXH7-VGml22fT6ahFVHssbVcx636xwPlydhN4fBay0TElXgC5QkSmzINFPMF3FRJ54WaAsTAvwpsnAIUfigZdNggSjMnROp-i7dtF5M9Ty3utLM2kmlEZVC9lhhLUvJujvbWJwCGDOStrBv4iapWQ4qPZ8AuaVTmigW_hVinkZ6GGTp8GT07GGF9iwDjPnSyCzEx7Ta4S0U3nSeJVogxmsO7N1hZrmCuZmUtEkSPMSP0wIhrMrranpzqFRqvsYve6hp8BBE9qxbuiEwc3F-2xFm-R6esmUu5mpWcRlM1imenuvb9C-lotKf0znM9neVimWhMe7OqENcGXTx7puTyZoK0wUmrn-2_vIxfwtU5s9aBomlw6qGQt6k14pgKA69bp2C51C46HyKa_QrEvol-_3YvccjvR3hO-jcAj_SLALYk6HJp1eSqy_tGZZ5QW4-4QvUcPaa3E4sXA4Ye_4OB2dGRcKVuhR5jzpaYJC-_qGRY0dhfYdpKjEgc1o3pitzpNW0iWzImN9iidRThu_YFP_RwPk2Qragch55f086JNdM7jGPkjcEUcgGIs3PE"). + SetAuthToken(AccessToken). SetFile("file[0][file]", filename). SetFormData(map[string]string{ "client_id": ClientID, @@ -85,33 +84,6 @@ func listAllFilesAndPush() { } fmt.Println(resp) - fmt.Println("\n\n") - - resJson, _ := gabs.ParseJSON([]byte(resp.String())) - children, _ := resJson.S("file_content").Children() - child := children[0] - - fmt.Println(child.String()) - - //TODO: Iterate this over all the file names recieved from the remote - file, err := os.Create("temp.txt") - if err != nil { - log.Fatal("Cannot create file", err) - } - defer file.Close() - - _, err = file.WriteString(child.String()) - - // This works perfectly - //fmt.Println("Decoding the string manually") - //x := "PCEtLSBUcmFuc2xhdGVkIEJ5IERldm5hZ3JpIC0tPgo8IS0tIGh0dHA6Ly9kZXZuYWdyaS5jb20gLS0+CjxyZXNvdXJjZXMgdG9vbHM6aWdub3JlPSJFeHRyYVRyYW5zbGF0aW9uIiB4bWxuczp0b29scz0iaHR0cDovL3NjaGVtYXMuYW5kcm9pZC5jb20vdG9vbHMiPgogICAgPHN0cmluZyBuYW1lPSJhcHBfbmFtZSI+PC9zdHJpbmc+CiAgICA8c3RyaW5nIG5hbWU9ImhpbnRfYWN0dWFsIj48L3N0cmluZz4KIDwvcmVzb3VyY2VzPg==" - //decodeBase64(x) - - dat, _ := ioutil.ReadFile("temp.txt") - //fmt.Println("Reading content.txt") - fileContent := decodeBase64(string(dat)) - fmt.Println(fileContent) - } func sha256Hash(fileName string) string { From b4621fe4b1e0191cbb23a508ccef923a9bc72c18 Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Wed, 17 Jan 2018 16:55:12 +0530 Subject: [PATCH 05/10] the pull is almost done now --- _dev/pull_dev.go | 8 +++----- cmd/pull.go | 22 +++++++++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/_dev/pull_dev.go b/_dev/pull_dev.go index 6cdd519..38b3dc7 100644 --- a/_dev/pull_dev.go +++ b/_dev/pull_dev.go @@ -2,7 +2,6 @@ package main import ( "encoding/base64" - "fmt" "io/ioutil" "log" "os" @@ -24,7 +23,7 @@ func decodeBase64(cypher string) string { //fmt.Println(string(data)) - println("<<< Text after decoding >>>") + //println("<<< Text after decoding >>>") //fmt.Println(data) //fmt.Println(string(data)) @@ -47,13 +46,12 @@ func saveResponseAndConvert() { panic(err) } - fmt.Println(resp) - fmt.Println("\n\n") + //fmt.Println(resp) resJson, _ := gabs.ParseJSON([]byte(resp.String())) children, _ := resJson.S("file_content").Children() child := children[0] - fmt.Println(child.String()) + //fmt.Println(child.String()) //data, _ := base64.StdEncoding.Decode(child.String()) //encoded := child.String() diff --git a/cmd/pull.go b/cmd/pull.go index 305104b..9d80e3b 100644 --- a/cmd/pull.go +++ b/cmd/pull.go @@ -73,8 +73,7 @@ func saveResponseAndConvert() { panic(err) } - fmt.Println(resp) - fmt.Println("\n\n") + // fmt.Println(resp) resJson, _ := gabs.ParseJSON([]byte(resp.String())) children, _ := resJson.S("file_content").Children() @@ -97,11 +96,24 @@ func saveResponseAndConvert() { //decodeBase64(x) dat, _ := ioutil.ReadFile("temp.txt") - //fmt.Println("Reading content.txt") - fileContent := decodeBase64(string(dat)) - fmt.Println(fileContent) + datString := string(dat) + //fmt.Println("String Length : ", len(datString)) + content := datString[1:(len(datString) - 1)] + //fmt.Println(content) + fileContent := decodeBase64(content) + //fmt.Println(fileContent) + //fmt.Println("<<< Reading temp file now >>>") + //fileContent := decodeBase64(string(dat)) + //fmt.Println(fileContent) //TODO: Store the content of temp into the actual file + responseFile, err := os.Create("responseFile.txt") + if err != nil { + log.Fatal("Cannot create file", err) + } + defer responseFile.Close() + + _, err = responseFile.WriteString(fileContent) //TODO: Delete the temp file } From 7c6d1e3c256ab9be30cf7806b15d00a1a60128b8 Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Wed, 17 Jan 2018 19:46:08 +0530 Subject: [PATCH 06/10] the beta build works --- _dev/.devnagri.yaml | 17 +++++++++-------- _dev/devnagri | 8 ++++++++ _dev/devnagri.yaml | 8 -------- _dev/validation_dev1.go | 2 +- cmd/pull.go | 3 +++ 5 files changed, 21 insertions(+), 17 deletions(-) create mode 100644 _dev/devnagri delete mode 100644 _dev/devnagri.yaml diff --git a/_dev/.devnagri.yaml b/_dev/.devnagri.yaml index 85052e9..2e02ccd 100644 --- a/_dev/.devnagri.yaml +++ b/_dev/.devnagri.yaml @@ -1,8 +1,9 @@ -ClientID: 1 -ClientSecret: CIo1QNTKcM4FMMpI7JlytrHt1p1Iux9EENSYzBHi -GlobalPreferenceInCaseOfMergeConflict: devnagri -ProjectKey: 5034b2cd56c8f3af0c711a9a437eb616 -RootDir: langs -SourceLanguage: en -TargetLanguages: -- hi +ClientID: 2 +ClientSecret: y8umxMS54nUBc1ak7cxod6mjYiAbht2rCNAKsW7c +GlobalPreferenceInCaseOfMergeConflict: devnagri +ProjectKey: 3c5724f8fe2d45e1dea65f8842cebd79 +RootDir: langs +SourceLanguage: en +TargetLanguages: +- hi +AccessToken: eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImJlYzgwMjA3MDdlYTdhNTU2MzZlNjBiNjVhOGYyNDFlY2RkZmYzM2ZjMmNlZjcwNzFlMWU3YjUzNDNiMDM0OTMwODdhNzc2ZDlhMTc2ZjA0In0.eyJhdWQiOiIzIiwianRpIjoiYmVjODAyMDcwN2VhN2E1NTYzNmU2MGI2NWE4ZjI0MWVjZGRmZjMzZmMyY2VmNzA3MWUxZTdiNTM0M2IwMzQ5MzA4N2E3NzZkOWExNzZmMDQiLCJpYXQiOjE1MTYxOTgzODgsIm5iZiI6MTUxNjE5ODM4OCwiZXhwIjoxNTQ3NzM0Mzg4LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.RcmkeUoAsaUBY_HtNt4LgOv02EyqINHTEgrkAj_Z9zo6J_7QKTbfv1TSTnY0a3jtW00TKnhYMkoP3SrgmmxKEAOuA8aGxHhgi9NaMr-aYPd-MGlEqUFUw4gu_6AUYsHpLkTB1j6Ftz3Vns_ZSGXXv6QmSZKy1I1TX05W8MPvVClkOaqRPPlRq5AJm4du_h-FaOmFOEhchwi9nnSnSN68jU0Pbn8zZcOQIfbF8sg9WL-BHiE15K04JmUOuGrh1HbaWQQQ1dspZrc0FInCdzlJx2rk1SPVOaLdrIkaP0ZRTZVpoMomgr0AkmZZnUu5Kg-9O9d2jofER_YE5r1jj5K6HrJJT7uhTIdNU8bIqGqwBTRWb7TxkeR4kfFIej9aiKzBLCdMPbmq1pZf7iWHrdJBNLtU0qc6-XBG5iLDU9RBK_F2pFcOKLGAy_w2tBvcyXcz6FJDb0z620jV3QJh0xbZrzjcIxFzJcxTd6xUOQIkUjnDCycGkT-gn8eK_ohaxIxkSTnETvhksUJ-Rv2UGjLdfB8wRItQsAXwjjUmDMse83ge_Uo-vaSrqUjTmxeFnW9qdnQ1-iQ5EoVaskN8ppnM5ks2vGipTcMzp42ONlDboBAFa9zoX3qKmQQZs_lUKXmik6J4YMdY4BIsEa30ykxaVjFqm8rl4idSmY8_K5OLDZg \ No newline at end of file diff --git a/_dev/devnagri b/_dev/devnagri new file mode 100644 index 0000000..85052e9 --- /dev/null +++ b/_dev/devnagri @@ -0,0 +1,8 @@ +ClientID: 1 +ClientSecret: CIo1QNTKcM4FMMpI7JlytrHt1p1Iux9EENSYzBHi +GlobalPreferenceInCaseOfMergeConflict: devnagri +ProjectKey: 5034b2cd56c8f3af0c711a9a437eb616 +RootDir: langs +SourceLanguage: en +TargetLanguages: +- hi diff --git a/_dev/devnagri.yaml b/_dev/devnagri.yaml deleted file mode 100644 index cbc56d1..0000000 --- a/_dev/devnagri.yaml +++ /dev/null @@ -1,8 +0,0 @@ -ClientID: 3 -ClientSecret: 3WnUqVSP7Vhs8DU7FInIrwHIVMg9twGshcpswlJW -GlobalPreferenceInCaseOfMergeConflict: devnagri -ProjectKey: 2e12635aca73c7d39ec76a514d7490a6 -RootDir: langs -SourceLanguage: en -TargetLanguages: -- hi diff --git a/_dev/validation_dev1.go b/_dev/validation_dev1.go index 81e8baf..e1a7345 100644 --- a/_dev/validation_dev1.go +++ b/_dev/validation_dev1.go @@ -30,7 +30,7 @@ func main() { SetFormData(map[string]string{ "client_id": "2", "client_secret": "y8umxMS54nUBc1ak7cxod6mjYiAbht2rCNAKsW7c", - "project_key": "3c5724f8fe2d45e1dea65f8842cebd79 "}). + "project_key": "3c5724f8fe2d45e1dea65f8842cebd79"}). Post("http://dev.devnagri.co.in/api/key/validations") // Post("http://192.168.60.10/api/key/validations") diff --git a/cmd/pull.go b/cmd/pull.go index 9d80e3b..f5a0f9c 100644 --- a/cmd/pull.go +++ b/cmd/pull.go @@ -61,8 +61,11 @@ func saveResponseAndConvert() { var ProjectKey = config.FetchAndValidate("ProjectKey") // returns string + var AccessToken = config.FetchAndValidate("AccessToken") // returns string + resp, err := resty.R(). SetHeader("Content-Type", "multipart/form-data"). + SetAuthToken(AccessToken). SetFormData(map[string]string{ "client_id": ClientID, "client_secret": ClientSecret, From ffd9cb5aa69a5509f4cc15e460ab0e3de433abc8 Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Wed, 17 Jan 2018 20:03:18 +0530 Subject: [PATCH 07/10] The pull has been done now --- _dev/pull_dev.go | 22 ---------------------- cmd/init.go | 5 +++-- cmd/pull.go | 10 +++++++--- cmd/push.go | 4 ++-- cmd/root.go | 2 +- cmd/status.go | 3 ++- cmd/validate.go | 1 + 7 files changed, 16 insertions(+), 31 deletions(-) diff --git a/_dev/pull_dev.go b/_dev/pull_dev.go index 38b3dc7..5da6d64 100644 --- a/_dev/pull_dev.go +++ b/_dev/pull_dev.go @@ -16,18 +16,9 @@ func main() { } func decodeBase64(cypher string) string { - //println("\n\nRecieved at decodeBase64 function\n\n") - // fmt.Println(cypher) data, _ := base64.StdEncoding.DecodeString(cypher) - //fmt.Println(string(data)) - - //println("<<< Text after decoding >>>") - - //fmt.Println(data) - //fmt.Println(string(data)) - return string(data) } @@ -51,19 +42,6 @@ func saveResponseAndConvert() { resJson, _ := gabs.ParseJSON([]byte(resp.String())) children, _ := resJson.S("file_content").Children() child := children[0] - //fmt.Println(child.String()) - - //data, _ := base64.StdEncoding.Decode(child.String()) - //encoded := child.String() - //fmt.Println(encoded) - //fmt.Println(reflect.TypeOf(encoded)) - //x := decodeBase64(encoded) - //fmt.Println(x) - - // This works perfectly - //fmt.Println("Decoding the string manually") - //x := "PCEtLSBUcmFuc2xhdGVkIEJ5IERldm5hZ3JpIC0tPgo8IS0tIGh0dHA6Ly9kZXZuYWdyaS5jb20gLS0+CjxyZXNvdXJjZXMgdG9vbHM6aWdub3JlPSJFeHRyYVRyYW5zbGF0aW9uIiB4bWxuczp0b29scz0iaHR0cDovL3NjaGVtYXMuYW5kcm9pZC5jb20vdG9vbHMiPgogICAgPHN0cmluZyBuYW1lPSJhcHBfbmFtZSI+PC9zdHJpbmc+CiAgICA8c3RyaW5nIG5hbWU9ImhpbnRfYWN0dWFsIj48L3N0cmluZz4KIDwvcmVzb3VyY2VzPg==" - //decodeBase64(x) //TODO: Iterate this over all the file names recieved from the remote file, err := os.Create("temp.txt") diff --git a/cmd/init.go b/cmd/init.go index 73df35e..2345020 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -45,9 +45,9 @@ var initCmd = &cobra.Command{ Short: "This command creates a .devnagri.yaml file in the repo.", Long: `A longer description of init command`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("init called") - + fmt.Println("Created the default .devnagri.yaml config in the current directory.") createConfigFile() + fmt.Println("Done!") }, } @@ -88,4 +88,5 @@ func createConfigFile() { defer file.Close() fmt.Fprintf(file, string(d)) + } diff --git a/cmd/pull.go b/cmd/pull.go index f5a0f9c..fe5e80c 100644 --- a/cmd/pull.go +++ b/cmd/pull.go @@ -34,7 +34,7 @@ var pullCmd = &cobra.Command{ Short: "This command pulls the translated files from Devnagri", Long: `When all the files for a language have been translated, they can be pulled from the Devnagri platform to the local filesystem using the CLI tool.`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("pull called") + fmt.Println("Pulling the files from Devnagri") saveResponseAndConvert() }, } @@ -64,6 +64,7 @@ func saveResponseAndConvert() { var AccessToken = config.FetchAndValidate("AccessToken") // returns string resp, err := resty.R(). + SetHeader("Accept", "application/json"). SetHeader("Content-Type", "multipart/form-data"). SetAuthToken(AccessToken). SetFormData(map[string]string{ @@ -76,13 +77,13 @@ func saveResponseAndConvert() { panic(err) } - // fmt.Println(resp) + //fmt.Println(resp) resJson, _ := gabs.ParseJSON([]byte(resp.String())) children, _ := resJson.S("file_content").Children() child := children[0] - fmt.Println(child.String()) + //fmt.Println(child.String()) //TODO: Iterate this over all the file names recieved from the remote file, err := os.Create("temp.txt") @@ -111,6 +112,7 @@ func saveResponseAndConvert() { //TODO: Store the content of temp into the actual file responseFile, err := os.Create("responseFile.txt") + if err != nil { log.Fatal("Cannot create file", err) } @@ -119,6 +121,8 @@ func saveResponseAndConvert() { _, err = responseFile.WriteString(fileContent) //TODO: Delete the temp file + + fmt.Println("Done!") } func decodeBase64(cypher string) string { diff --git a/cmd/push.go b/cmd/push.go index 325f7e0..7147cc3 100644 --- a/cmd/push.go +++ b/cmd/push.go @@ -30,10 +30,10 @@ import ( // pushCmd represents the push command var pushCmd = &cobra.Command{ Use: "push", - Short: "This command pushes the untranslated files from Devnagri", + Short: "This command pushes the untranslated files to Devnagri", Long: `This command transfers all the untranslated local files to the Devnagri platform on a language basis.`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("push called") + fmt.Println("Pushing the files from Devnagri") listAllFilesAndPush() }, } diff --git a/cmd/root.go b/cmd/root.go index 4300d28..f0f0970 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -31,7 +31,7 @@ var rootCmd = &cobra.Command{ Short: "The CLI client for the Devnagri platform API", Long: ` devnagri is the cross platform API client for Devnagri written in Go-lang. - + This CLI client has been developed to facilitate the integration of Devnagri platform with a Developer's workflow `, diff --git a/cmd/status.go b/cmd/status.go index eab422c..8fb1112 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -28,10 +28,11 @@ var statusCmd = &cobra.Command{ Short: "This command fetches the status of the current project.", Long: `A long description of status command.`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("status called") + fmt.Println("The current status of your projects from Devnagri") fetchStatus() + fmt.Println("Done!") }, } diff --git a/cmd/validate.go b/cmd/validate.go index 177216b..7dd19bd 100644 --- a/cmd/validate.go +++ b/cmd/validate.go @@ -32,6 +32,7 @@ var validateCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { fmt.Println("validate called") validate() + fmt.Println("Done!") }, } From f6c0107655f902c29e42e61997b325f658c51ccf Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Mon, 15 Jan 2018 21:57:42 +0530 Subject: [PATCH 08/10] removed the _dev folder from staging --- _dev/CallingPapaPro2.xml | 4 -- _dev/createYaml.go | 56 ------------------------- _dev/createYaml_dev.go | 77 ----------------------------------- _dev/en/CallingPapaPro2.xml | 4 -- _dev/listoffiles_dev.go | 57 -------------------------- _dev/push_dev.go | 79 ------------------------------------ _dev/wip:yaml/.devnagri.yaml | 10 ----- _dev/wip:yaml/devnagri.yaml | 19 --------- _dev/wip:yaml/test.go | 20 --------- 9 files changed, 326 deletions(-) delete mode 100644 _dev/CallingPapaPro2.xml delete mode 100644 _dev/createYaml.go delete mode 100644 _dev/createYaml_dev.go delete mode 100644 _dev/en/CallingPapaPro2.xml delete mode 100644 _dev/listoffiles_dev.go delete mode 100644 _dev/push_dev.go delete mode 100644 _dev/wip:yaml/.devnagri.yaml delete mode 100644 _dev/wip:yaml/devnagri.yaml delete mode 100644 _dev/wip:yaml/test.go diff --git a/_dev/CallingPapaPro2.xml b/_dev/CallingPapaPro2.xml deleted file mode 100644 index 5a71912..0000000 --- a/_dev/CallingPapaPro2.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/_dev/createYaml.go b/_dev/createYaml.go deleted file mode 100644 index 4653340..0000000 --- a/_dev/createYaml.go +++ /dev/null @@ -1,56 +0,0 @@ -package main - -import ( - "fmt" - "log" - - "gopkg.in/yaml.v2" -) - -var data = ` -a: Easy! -b: - c: 2 - d: [3, 4] -` - -// Note: struct fields must be public in order for unmarshal to -// correctly populate the data. -type T struct { - A string - B struct { - RenamedC int `yaml:"c"` - D []int `yaml:",flow"` - } -} - -func main() { - t := T{} - - err := yaml.Unmarshal([]byte(data), &t) - if err != nil { - log.Fatalf("error: %v", err) - } - fmt.Printf("--- t:\n%v\n\n", t) - - d, err := yaml.Marshal(&t) - if err != nil { - log.Fatalf("error: %v", err) - } - fmt.Printf("--- t dump:\n%s\n\n", string(d)) - - m := make(map[interface{}]interface{}) - - err = yaml.Unmarshal([]byte(data), &m) - if err != nil { - log.Fatalf("error: %v", err) - } - fmt.Printf("--- m:\n%v\n\n", m) - - d, err = yaml.Marshal(&m) - if err != nil { - log.Fatalf("error: %v", err) - } - fmt.Printf("--- m dump:\n%s\n\n", string(d)) - -} diff --git a/_dev/createYaml_dev.go b/_dev/createYaml_dev.go deleted file mode 100644 index bb7bcb3..0000000 --- a/_dev/createYaml_dev.go +++ /dev/null @@ -1,77 +0,0 @@ -package main - -import ( - "fmt" - "gopkg.in/yaml.v2" - "log" - "os" -) - -var data = ` -ClientID: "" - -ClientSecret: "" - -ProjectKey: "" - -RootDir: "" - -LocalizationFolder: "" - -SourceLanguage: "en" - -TargetLanguages: - - "pn" - - "hi" - -GlobalPreferenceInCaseOfMergeConflict: "" -` - -type T struct { - ClientID string `yaml:"ClientID"` - ClientSecret string `yaml:"ClientSecret"` - ProjectKey string `yaml:"ProjectKey"` - RootDir string `yaml:"RootDir"` - LocalizationFolder string `yaml:"LocalizationFolder"` - SourceLanguage string `yaml:"SourceLanguage"` - //TODO This needs to be changed as the target languages are multiple - TargetLanguages []string `yaml:"TargetLanguages"` - GlobalPreferenceInCaseOfMergeConflict string `yaml:"GlobalPreferenceInCaseOfMergeConflict"` -} - -func main() { - - /* - t := T{} - - d, err := yaml.Marshal(&t) - if err != nil { - log.Fatalf("error: %v", err) - } - fmt.Printf("--- t dump:\n%s\n\n", string(d)) - - - */ - - m := make(map[interface{}]interface{}) - - err := yaml.Unmarshal([]byte(data), &m) - if err != nil { - log.Fatalf("error: %v", err) - } - // fmt.Printf("--- m:\n%v\n\n", m) - - d, err := yaml.Marshal(&m) - if err != nil { - log.Fatalf("error: %v", err) - } - fmt.Printf("%s\n\n", string(d)) - - file, err := os.Create(".devnagri.yaml") - if err != nil { - log.Fatal("Cannot create file", err) - } - defer file.Close() - - fmt.Fprintf(file, string(d)) -} diff --git a/_dev/en/CallingPapaPro2.xml b/_dev/en/CallingPapaPro2.xml deleted file mode 100644 index 5a71912..0000000 --- a/_dev/en/CallingPapaPro2.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/_dev/listoffiles_dev.go b/_dev/listoffiles_dev.go deleted file mode 100644 index 1ccf225..0000000 --- a/_dev/listoffiles_dev.go +++ /dev/null @@ -1,57 +0,0 @@ -package main - -import ( - "fmt" - "log" - "os" - "path/filepath" - "regexp" - - "github.com/Jeffail/gabs" -) - -func main() { - var allFiles []string - - root := "./en" - extension := "pdf" - - err := filepath.Walk(root, visit(&allFiles)) - if err != nil { - panic(err) - } - - reqFiles := requiredExtensionFiles(allFiles, extension) - //fmt.Println(reqFiles) - - //TODO return the list of files as a json structure - jsonObj := gabs.New() - jsonObj.Set(reqFiles) - fmt.Println(jsonObj.String()) -} - -func requiredExtensionFiles(files []string, extension string) []string { - - extensionRegexp := ".*." + extension + "$" - - var reqFiles []string - for _, file := range files { - - matches, _ := regexp.MatchString(extensionRegexp, file) - if matches == true { - reqFiles = append(reqFiles, file) - - } - } - return reqFiles -} - -func visit(files *[]string) filepath.WalkFunc { - return func(path string, info os.FileInfo, err error) error { - if err != nil { - log.Fatal(err) - } - *files = append(*files, path) - return nil - } -} diff --git a/_dev/push_dev.go b/_dev/push_dev.go deleted file mode 100644 index 8135a3c..0000000 --- a/_dev/push_dev.go +++ /dev/null @@ -1,79 +0,0 @@ -package main - -import ( - "crypto/sha256" - "encoding/hex" - "fmt" - "io" - "log" - "os" - - "github.com/FourtekIT/devnagri-cli/config" - "gopkg.in/resty.v1" -) - -func main() { - - //fileBytes, _ := ioutil.ReadFile("CallingPapaPro2.xml") - //hash := BytesToString(sha256Hash("./CallingPapaPro2.xml")) - //hash := sha256Hash("./CallingPapaPro2.xml") - //hash := hex.EncodeToString(sha256Hash("./CallingPapaPro2.xml")) - //hash := sha256Hash("./CallingPapaPro2.xml") - - resp, err := resty.R(). - SetHeader("Accept", "application/json"). - SetHeader("Content-Type", "multipart/form-data"). - SetFile("file[0][file]", "./CallingPapaPro2.xml"). - SetAuthToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjE0MmI1YjlkOTI3ZGQ2ZjI3ODcyZDJmNDFmNWQzNjhkOGU3MmVhZjk2YzE2YTdmMTZjM2ZkM2I5ZmVmNjJiMDFmMTBiOWQwMTMxNzJjYTIyIn0.eyJhdWQiOiIxIiwianRpIjoiMTQyYjViOWQ5MjdkZDZmMjc4NzJkMmY0MWY1ZDM2OGQ4ZTcyZWFmOTZjMTZhN2YxNmMzZmQzYjlmZWY2MmIwMWYxMGI5ZDAxMzE3MmNhMjIiLCJpYXQiOjE1MTU1OTA4NDksIm5iZiI6MTUxNTU5MDg0OSwiZXhwIjoxNTQ3MTI2ODQ5LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.inJAzB_9Vjx9YXHQgZYCy3HxbTaSV2VSjKYgtB_s4ZrrS9vucEnEF4Ijh8wPMylxDLI7e8iGfRObK0rGTBqnCw94ElcmeYPM7GfWRqWW5Bz8ctJhXH7-VGml22fT6ahFVHssbVcx636xwPlydhN4fBay0TElXgC5QkSmzINFPMF3FRJ54WaAsTAvwpsnAIUfigZdNggSjMnROp-i7dtF5M9Ty3utLM2kmlEZVC9lhhLUvJujvbWJwCGDOStrBv4iapWQ4qPZ8AuaVTmigW_hVinkZ6GGTp8GT07GGF9iwDjPnSyCzEx7Ta4S0U3nSeJVogxmsO7N1hZrmCuZmUtEkSPMSP0wIhrMrranpzqFRqvsYve6hp8BBE9qxbuiEwc3F-2xFm-R6esmUu5mpWcRlM1imenuvb9C-lotKf0znM9neVimWhMe7OqENcGXTx7puTyZoK0wUmrn-2_vIxfwtU5s9aBomlw6qGQt6k14pgKA69bp2C51C46HyKa_QrEvol-_3YvccjvR3hO-jcAj_SLALYk6HJp1eSqy_tGZZ5QW4-4QvUcPaa3E4sXA4Ye_4OB2dGRcKVuhR5jzpaYJC-_qGRY0dhfYdpKjEgc1o3pitzpNW0iWzImN9iidRThu_YFP_RwPk2Qragch55f086JNdM7jGPkjcEUcgGIs3PE"). - SetFormData(map[string]string{ - "client_id": config.ClientID, - "client_secret": "3WnUqVSP7Vhs8DU7FInIrwHIVMg9twGshcpswlJW", - "project_key": "2e12635aca73c7d39ec76a514d7490a6", - //"file[0][hash]": "3221255c6aecb25c8f73472dcb7c99f42ade9112b8e3029a3e67070233fd101d", - //"file[0][hash]": hash, - "file[0][hash]": sha256Hash("./CallingPapaPro2.xml"), - //"file[0][name]": "CallingPapaPro2.xml", - "file[0][extension]": "xml", - "file[0][file_type]": "xml", - "file[0][location]": "./CallingPapaPro2.xml", - //"file[0][file]": - - }). - Post("http://dev.devnagri.co.in/api/project/push") - //Post("http://192.168.60.10/api/project/push") - //Post("https://requestb.in/pkfuyypk") - if err != nil { - panic(err) - } - - //fmt.Println(sha256Hash("push_test_file.xml")) - - fmt.Println(resp) -} - -func sha256Hash(fileName string) string { - - f, err := os.Open(fileName) - if err != nil { - log.Fatal(err) - } - defer f.Close() - - h := sha256.New() - if _, err := io.Copy(h, f); err != nil { - log.Fatal(err) - } - - //fmt.Printf("%x", h.Sum(nil)) - //return h.Sum(nil) - - hashString := hex.EncodeToString(h.Sum(nil)) - return hashString -} - -// NOTE: http://www.mrwaggel.be/post/golang-hash-sum-and-checksum-to-string-tutorial-and-examples/ -func BytesToString(data []byte) string { - return string(data[:]) -} - -// TODO: base64 diff --git a/_dev/wip:yaml/.devnagri.yaml b/_dev/wip:yaml/.devnagri.yaml deleted file mode 100644 index e0bc789..0000000 --- a/_dev/wip:yaml/.devnagri.yaml +++ /dev/null @@ -1,10 +0,0 @@ -ClientID: "" -ClientSecret: "" -GlobalPreferenceInCaseOfMergeConflict: "" -LocalizationFolder: "" -ProjectKey: "" -RootDir: "" -SourceLanguage: en -TargetLanguages: -- pn -- hi diff --git a/_dev/wip:yaml/devnagri.yaml b/_dev/wip:yaml/devnagri.yaml deleted file mode 100644 index e2ed37f..0000000 --- a/_dev/wip:yaml/devnagri.yaml +++ /dev/null @@ -1,19 +0,0 @@ -## sample content of the .devnagri.yaml - -ClientID: "3" - -ClientSecret: "3WnUqVSP7Vhs8DU7FInIrwHIVMg9twGshcpswlJW" - -ProjectKey: "211fd1d00f0cc01249bb8f7476152c28" - -RootDir: "./" - -Localizationfolder: "./languages" - -SourceLanguage: "en" - -LanguagesToBeTranslated: - - "hi" - -GlobalPreferenceInCaseOfMergeConflict: "Remote" -#GlobalPreferenceInCaseOfMergeConflict: "Local" diff --git a/_dev/wip:yaml/test.go b/_dev/wip:yaml/test.go deleted file mode 100644 index f1d9422..0000000 --- a/_dev/wip:yaml/test.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "fmt" - "github.com/FourtekIT/devnagri-cli/config" -) - -func main() { - - fmt.Println(config.ClientID) - - fmt.Println(config.ClientSecret) - - fmt.Println(config.ProjectKey) - - fmt.Println(config.SourceLanguage) - - // fmt.Println(config.LanguagesToBeTranslated) - -} From c2fb7ab434e78850c01a170fcc81ba8d3aae215a Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Wed, 17 Jan 2018 20:14:58 +0530 Subject: [PATCH 09/10] updated the message for the validate command --- cmd/validate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/validate.go b/cmd/validate.go index 7dd19bd..586ff4c 100644 --- a/cmd/validate.go +++ b/cmd/validate.go @@ -30,7 +30,7 @@ var validateCmd = &cobra.Command{ Short: "This command validates the credentials in the .devnagri file within the local folder.", Long: `The validate command is responsible for generating and storing the Access Token which will further enable the usage of pull and push.`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("validate called") + fmt.Println("Validating the configuration in .devnagri.yaml and generating the access token.") validate() fmt.Println("Done!") }, From 69b5ea6e3ca9cc3ac82e1b55bb0416229908cb25 Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Wed, 17 Jan 2018 20:16:33 +0530 Subject: [PATCH 10/10] nearing the v0.1.3 release now --- _dev/.devnagri.yaml | 9 ---- _dev/decodeFile.go | 30 -------------- _dev/devnagri | 8 ---- _dev/en/CallingPapaPro1.xml | 4 -- _dev/pull_dev.go | 82 ------------------------------------- _dev/responseFile.txt | 6 --- _dev/temp.txt | 1 - _dev/validation_dev1.go | 43 ------------------- 8 files changed, 183 deletions(-) delete mode 100644 _dev/.devnagri.yaml delete mode 100644 _dev/decodeFile.go delete mode 100644 _dev/devnagri delete mode 100644 _dev/en/CallingPapaPro1.xml delete mode 100644 _dev/pull_dev.go delete mode 100644 _dev/responseFile.txt delete mode 100644 _dev/temp.txt delete mode 100644 _dev/validation_dev1.go diff --git a/_dev/.devnagri.yaml b/_dev/.devnagri.yaml deleted file mode 100644 index 2e02ccd..0000000 --- a/_dev/.devnagri.yaml +++ /dev/null @@ -1,9 +0,0 @@ -ClientID: 2 -ClientSecret: y8umxMS54nUBc1ak7cxod6mjYiAbht2rCNAKsW7c -GlobalPreferenceInCaseOfMergeConflict: devnagri -ProjectKey: 3c5724f8fe2d45e1dea65f8842cebd79 -RootDir: langs -SourceLanguage: en -TargetLanguages: -- hi -AccessToken: eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImJlYzgwMjA3MDdlYTdhNTU2MzZlNjBiNjVhOGYyNDFlY2RkZmYzM2ZjMmNlZjcwNzFlMWU3YjUzNDNiMDM0OTMwODdhNzc2ZDlhMTc2ZjA0In0.eyJhdWQiOiIzIiwianRpIjoiYmVjODAyMDcwN2VhN2E1NTYzNmU2MGI2NWE4ZjI0MWVjZGRmZjMzZmMyY2VmNzA3MWUxZTdiNTM0M2IwMzQ5MzA4N2E3NzZkOWExNzZmMDQiLCJpYXQiOjE1MTYxOTgzODgsIm5iZiI6MTUxNjE5ODM4OCwiZXhwIjoxNTQ3NzM0Mzg4LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.RcmkeUoAsaUBY_HtNt4LgOv02EyqINHTEgrkAj_Z9zo6J_7QKTbfv1TSTnY0a3jtW00TKnhYMkoP3SrgmmxKEAOuA8aGxHhgi9NaMr-aYPd-MGlEqUFUw4gu_6AUYsHpLkTB1j6Ftz3Vns_ZSGXXv6QmSZKy1I1TX05W8MPvVClkOaqRPPlRq5AJm4du_h-FaOmFOEhchwi9nnSnSN68jU0Pbn8zZcOQIfbF8sg9WL-BHiE15K04JmUOuGrh1HbaWQQQ1dspZrc0FInCdzlJx2rk1SPVOaLdrIkaP0ZRTZVpoMomgr0AkmZZnUu5Kg-9O9d2jofER_YE5r1jj5K6HrJJT7uhTIdNU8bIqGqwBTRWb7TxkeR4kfFIej9aiKzBLCdMPbmq1pZf7iWHrdJBNLtU0qc6-XBG5iLDU9RBK_F2pFcOKLGAy_w2tBvcyXcz6FJDb0z620jV3QJh0xbZrzjcIxFzJcxTd6xUOQIkUjnDCycGkT-gn8eK_ohaxIxkSTnETvhksUJ-Rv2UGjLdfB8wRItQsAXwjjUmDMse83ge_Uo-vaSrqUjTmxeFnW9qdnQ1-iQ5EoVaskN8ppnM5ks2vGipTcMzp42ONlDboBAFa9zoX3qKmQQZs_lUKXmik6J4YMdY4BIsEa30ykxaVjFqm8rl4idSmY8_K5OLDZg \ No newline at end of file diff --git a/_dev/decodeFile.go b/_dev/decodeFile.go deleted file mode 100644 index c65e06e..0000000 --- a/_dev/decodeFile.go +++ /dev/null @@ -1,30 +0,0 @@ -package main - -import ( - "encoding/base64" - "fmt" - "io/ioutil" -) - -func main() { - - dat, _ := ioutil.ReadFile("temp.txt") - datString := string(dat) - //fmt.Println("String Length : ", len(datString)) - content := datString[1:(len(datString) - 1)] - //fmt.Println(content) - fileContent := decodeBase64(content) - //fmt.Println(fileContent) - //fmt.Println("<<< Reading temp file now >>>") - //fileContent := decodeBase64(string(dat)) - fmt.Println(fileContent) -} - -func decodeBase64(cypher string) string { - - data, _ := base64.StdEncoding.DecodeString(cypher) - - stringData := string(data) - - return stringData -} diff --git a/_dev/devnagri b/_dev/devnagri deleted file mode 100644 index 85052e9..0000000 --- a/_dev/devnagri +++ /dev/null @@ -1,8 +0,0 @@ -ClientID: 1 -ClientSecret: CIo1QNTKcM4FMMpI7JlytrHt1p1Iux9EENSYzBHi -GlobalPreferenceInCaseOfMergeConflict: devnagri -ProjectKey: 5034b2cd56c8f3af0c711a9a437eb616 -RootDir: langs -SourceLanguage: en -TargetLanguages: -- hi diff --git a/_dev/en/CallingPapaPro1.xml b/_dev/en/CallingPapaPro1.xml deleted file mode 100644 index 5a71912..0000000 --- a/_dev/en/CallingPapaPro1.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/_dev/pull_dev.go b/_dev/pull_dev.go deleted file mode 100644 index 5da6d64..0000000 --- a/_dev/pull_dev.go +++ /dev/null @@ -1,82 +0,0 @@ -package main - -import ( - "encoding/base64" - "io/ioutil" - "log" - "os" - // "reflect" - - "github.com/Jeffail/gabs" - "gopkg.in/resty.v1" -) - -func main() { - saveResponseAndConvert() -} - -func decodeBase64(cypher string) string { - - data, _ := base64.StdEncoding.DecodeString(cypher) - - return string(data) - -} - -func saveResponseAndConvert() { - resp, err := resty.R(). - SetHeader("Accept", "application/json"). - SetHeader("Content-Type", "multipart/form-data"). - SetAuthToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjY2MTY0MzEzNGYyNDRlNjEyMWE1MzAwMjAyZDFhMDVkYmY3MTFjYjQxZDg2NjUxNmU5ZjRiNDI4OTBkNGE0NDk5NDU5ODc2M2M4ZGNjYTI5In0.eyJhdWQiOiIzIiwianRpIjoiNjYxNjQzMTM0ZjI0NGU2MTIxYTUzMDAyMDJkMWEwNWRiZjcxMWNiNDFkODY2NTE2ZTlmNGI0Mjg5MGQ0YTQ0OTk0NTk4NzYzYzhkY2NhMjkiLCJpYXQiOjE1MTYxNzIwNDQsIm5iZiI6MTUxNjE3MjA0NCwiZXhwIjoxNTQ3NzA4MDQ0LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.HqVfac3VEcTFT79WuQ_9CH1Q3KWeRO9i6IyQYT7iLqz7S6JmvY0mmLo34awViYN_7jssUZCOXo_esz7juzO3mPXMS9ej_rbUQUH3CHw-JRnBOJ8sPgsg43yF79omiZpxWjn5-Brlq7cyqu28mpXENqkIV_1mXE214hIK0ap0BZHrQ8iQmbYuKpWlZMJnmNzbD2FJ2GtcatkEtSjZsnglXpWHnYSuVcSaFc59KE4TOqFeNh4Xln7puWKB2MJrjSGFMvtKlh5u2RlWDVOwM1tAs9hrrE6nOq6ncoF6ur51P26_BjByjZtlhEXvKKHjLJkYdWipB-yjyjl8uS5JciINzZkj6AnnmRHWFNU0dOKYb8E8FJv9Z5yDBz4EitDqa-LSOoHfYidyrBpJU_c4n04Fjo2RbzyMdRphk1NT9CdgteR973DUBNRCkI0z-OlORRTz8mh62SlshanA4jtFme3qYXph-J5mzVyRInVB0HtJh8LF9yIPnlX3ge0jjvpZSgrP_r7XCtPlYeih6KFK3sQc24vo-wPKTE6-UBLZSxsH3mJeJGzsbR9F59vbAaJ518-WgbQfMeAo2lUz_ebsB24Lvrc7rVMqdA1yEdwPepcCYuGO7-Afb3XzOFjSVlRCtFTHLxWWvJ221g1a_lS0ifxxjbVetFYxqw8xaWnWMwoI2Vk"). - SetFormData(map[string]string{ - "client_id": "2", - "client_secret": "y8umxMS54nUBc1ak7cxod6mjYiAbht2rCNAKsW7c", - "project_key": "ded491851ec93a79ee89460902aff582"}). - Post("http://dev.devnagri.co.in/api/project/pull") - if err != nil { - panic(err) - } - - //fmt.Println(resp) - - resJson, _ := gabs.ParseJSON([]byte(resp.String())) - children, _ := resJson.S("file_content").Children() - child := children[0] - - //TODO: Iterate this over all the file names recieved from the remote - file, err := os.Create("temp.txt") - if err != nil { - log.Fatal("Cannot create file", err) - } - defer file.Close() - - _, err = file.WriteString(child.String()) - - // This works perfectly - //fmt.Println("Decoding the string manually") - //x := "PCEtLSBUcmFuc2xhdGVkIEJ5IERldm5hZ3JpIC0tPgo8IS0tIGh0dHA6Ly9kZXZuYWdyaS5jb20gLS0+CjxyZXNvdXJjZXMgdG9vbHM6aWdub3JlPSJFeHRyYVRyYW5zbGF0aW9uIiB4bWxuczp0b29scz0iaHR0cDovL3NjaGVtYXMuYW5kcm9pZC5jb20vdG9vbHMiPgogICAgPHN0cmluZyBuYW1lPSJhcHBfbmFtZSI+PC9zdHJpbmc+CiAgICA8c3RyaW5nIG5hbWU9ImhpbnRfYWN0dWFsIj48L3N0cmluZz4KIDwvcmVzb3VyY2VzPg==" - //decodeBase64(x) - - dat, _ := ioutil.ReadFile("temp.txt") - datString := string(dat) - //fmt.Println("String Length : ", len(datString)) - content := datString[1:(len(datString) - 1)] - //fmt.Println(content) - fileContent := decodeBase64(content) - //fmt.Println(fileContent) - //fmt.Println("<<< Reading temp file now >>>") - //fileContent := decodeBase64(string(dat)) - //fmt.Println(fileContent) - - //TODO: Store the content of temp into the actual file - responseFile, err := os.Create("responseFile.txt") - if err != nil { - log.Fatal("Cannot create file", err) - } - defer responseFile.Close() - - _, err = responseFile.WriteString(fileContent) - - //TODO: Delete the temp file - -} diff --git a/_dev/responseFile.txt b/_dev/responseFile.txt deleted file mode 100644 index bc9d843..0000000 --- a/_dev/responseFile.txt +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/_dev/temp.txt b/_dev/temp.txt deleted file mode 100644 index 4170a80..0000000 --- a/_dev/temp.txt +++ /dev/null @@ -1 +0,0 @@ -"PCEtLSBUcmFuc2xhdGVkIEJ5IERldm5hZ3JpIC0tPgo8IS0tIGh0dHA6Ly9kZXZuYWdyaS5jb20gLS0+CjxyZXNvdXJjZXMgdG9vbHM6aWdub3JlPSJFeHRyYVRyYW5zbGF0aW9uIiB4bWxuczp0b29scz0iaHR0cDovL3NjaGVtYXMuYW5kcm9pZC5jb20vdG9vbHMiPgogICAgPHN0cmluZyBuYW1lPSJhcHBfbmFtZSI+PC9zdHJpbmc+CiAgICA8c3RyaW5nIG5hbWU9ImhpbnRfYWN0dWFsIj48L3N0cmluZz4KIDwvcmVzb3VyY2VzPg==" \ No newline at end of file diff --git a/_dev/validation_dev1.go b/_dev/validation_dev1.go deleted file mode 100644 index e1a7345..0000000 --- a/_dev/validation_dev1.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright © 2017 NAME HERE -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//TODO: change this package name -//package cmd - -package main - -import ( - "fmt" - - "gopkg.in/resty.v1" -) - -func main() { - - resp, err := resty.R(). - SetHeader("Content-Type", "multipart/form-data"). - SetFormData(map[string]string{ - "client_id": "2", - "client_secret": "y8umxMS54nUBc1ak7cxod6mjYiAbht2rCNAKsW7c", - "project_key": "3c5724f8fe2d45e1dea65f8842cebd79"}). - Post("http://dev.devnagri.co.in/api/key/validations") - // Post("http://192.168.60.10/api/key/validations") - - if err != nil { - panic(err) - } - - fmt.Println(resp) - //TODO: Save the returned access_token to the .devnagri.yaml -}