Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.

Commit

Permalink
pass subdir name to get
Browse files Browse the repository at this point in the history
  • Loading branch information
farthir committed Jun 20, 2019
1 parent 9701095 commit 2bb6035
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions cli/data/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
getCommitPath string
getBucket string
getFiles []string
getSubdir string
)

const (
Expand All @@ -52,7 +53,7 @@ var getCmd = &cobra.Command{
Example:
$ paddle data get -b experimental --bucket roo-pipeline trained-model/version1 dest/path
$ paddle data get -b experimental --bucket roo-pipeline --subdir extract trained-model/version1 dest/path
$ paddle data get -b experimental --bucket roo-pipeline --files file1.csv,file2.csv trained-model/version1 dest/path
`,
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -68,7 +69,7 @@ $ paddle data get -b experimental --bucket roo-pipeline --files file1.csv,file2.
path: fmt.Sprintf("%s/%s/%s", args[0], getBranch, getCommitPath),
}

copyPathToDestination(source, args[1], getFiles)
copyPathToDestination(source, args[1], getFiles, getSubdir)
},
}

Expand All @@ -77,9 +78,10 @@ func init() {
getCmd.Flags().StringVar(&getBucket, "bucket", "", "Bucket to use")
getCmd.Flags().StringVarP(&getCommitPath, "path", "p", "HEAD", "Path to fetch (instead of HEAD)")
getCmd.Flags().StringSliceVarP(&getFiles, "files", "f", []string{}, "A list of files to download separated by comma")
getCmd.Flags().StringVar(&getSubdir, "subdir", "", "Subdirectory for destination path")
}

func copyPathToDestination(source S3Path, destination string, files []string) {
func copyPathToDestination(source S3Path, destination string, files []string, subdir string) {
session := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
Expand All @@ -94,6 +96,9 @@ func copyPathToDestination(source S3Path, destination string, files []string) {
if !strings.HasSuffix(source.path, "/") {
source.path += "/"
}
if subdir != "" {
destination = parseDestination(destination, subdir)
}

fmt.Println("Copying " + source.path + " to " + destination)
copy(session, source, destination, files)
Expand All @@ -113,6 +118,15 @@ func readHEAD(session *session.Session, source S3Path) string {
return buf.String()
}

func parseDestination(destination string, subdir string) string {
if !strings.HasPrefix(destination, "/") {
destination += "/" + subdir
} else {
destination += subdir
}
return destination
}

func copy(session *session.Session, source S3Path, destination string, files []string) {
query := &s3.ListObjectsV2Input{
Bucket: aws.String(source.bucket),
Expand Down

0 comments on commit 2bb6035

Please sign in to comment.