From f3bcaa6cfb9f2c95f5ae501ae37967650c707d32 Mon Sep 17 00:00:00 2001 From: "Zhang, Guodong" Date: Fri, 24 Apr 2015 11:11:12 +0800 Subject: [PATCH 1/3] aptly graph specific output filename MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/smira/aptly/issues/241 modify: cmd/graph.go Signed-off-by: Zhang, Guodong --- cmd/graph.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/graph.go b/cmd/graph.go index e1360756..e09abe9f 100644 --- a/cmd/graph.go +++ b/cmd/graph.go @@ -35,8 +35,13 @@ func aptlyGraph(cmd *commander.Command, args []string) error { os.Remove(tempfile.Name()) format := context.Flags().Lookup("format").Value.String() + output := context.Flags().Lookup("output").Value.String() tempfilename := tempfile.Name() + "." + format + if output != "" { + fmt.Printf("set file name option as %s . will output as %s.%s .\n", output, output, format) + tempfilename = output + "." + format + } command := exec.Command("dot", "-T"+format, "-o"+tempfilename) command.Stderr = os.Stderr @@ -66,6 +71,7 @@ func aptlyGraph(cmd *commander.Command, args []string) error { return err } + fmt.Printf("Rendered to %s file: %s, trying to open it...\n", format, tempfilename) _ = exec.Command("open", tempfilename).Run() @@ -90,6 +96,7 @@ Example: } cmd.Flag.String("format", "png", "render graph to specified format (png, svg, pdf, etc.)") + cmd.Flag.String("output", "", "specically output filename , default is output /tmp/aptlyxxxx.png") return cmd } From 2bf11a556c80824bfe5f7eb976024ea83fd820f9 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Mon, 18 May 2015 00:38:15 +0300 Subject: [PATCH 2/3] Update custom output filename generation. #242 --- cmd/graph.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/cmd/graph.go b/cmd/graph.go index e09abe9f..eb35559f 100644 --- a/cmd/graph.go +++ b/cmd/graph.go @@ -4,11 +4,13 @@ import ( "bytes" "fmt" "github.com/smira/aptly/deb" + "github.com/smira/aptly/utils" "github.com/smira/commander" "io" "io/ioutil" "os" "os/exec" + "path/filepath" ) func aptlyGraph(cmd *commander.Command, args []string) error { @@ -37,12 +39,12 @@ func aptlyGraph(cmd *commander.Command, args []string) error { format := context.Flags().Lookup("format").Value.String() output := context.Flags().Lookup("output").Value.String() - tempfilename := tempfile.Name() + "." + format - if output != "" { - fmt.Printf("set file name option as %s . will output as %s.%s .\n", output, output, format) - tempfilename = output + "." + format + if filepath.Ext(output) != "" { + format = filepath.Ext(output)[1:] } + tempfilename := tempfile.Name() + "." + format + command := exec.Command("dot", "-T"+format, "-o"+tempfilename) command.Stderr = os.Stderr @@ -71,10 +73,19 @@ func aptlyGraph(cmd *commander.Command, args []string) error { return err } + if output != "" { + err = utils.CopyFile(tempfilename, output) + if err != nil { + return fmt.Errorf("unable to copy %s -> %s: %s", tempfilename, output, err) + } + _ = os.Remove(tempfilename) - fmt.Printf("Rendered to %s file: %s, trying to open it...\n", format, tempfilename) + fmt.Printf("Output saved to %s\n", output) + } else { + fmt.Printf("Rendered to %s file: %s, trying to open it...\n", format, tempfilename) - _ = exec.Command("open", tempfilename).Run() + _ = exec.Command("open", tempfilename).Run() + } return err } @@ -96,7 +107,7 @@ Example: } cmd.Flag.String("format", "png", "render graph to specified format (png, svg, pdf, etc.)") - cmd.Flag.String("output", "", "specically output filename , default is output /tmp/aptlyxxxx.png") + cmd.Flag.String("output", "", "specify output filename, default is to open result in viewer") return cmd } From 82e6e8242e51a63e5d312267c2ec08fb6d8f9cb9 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Mon, 18 May 2015 00:39:01 +0300 Subject: [PATCH 3/3] Update man page. #242 --- man/aptly.1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/man/aptly.1 b/man/aptly.1 index 8c2f9996..0e74e8ca 100644 --- a/man/aptly.1 +++ b/man/aptly.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "APTLY" "1" "April 2015" "" "" +.TH "APTLY" "1" "May 2015" "" "" . .SH "NAME" \fBaptly\fR \- Debian repository management tool @@ -180,7 +180,7 @@ bucket name . .TP \fBdisableMultiDel\fR -for S3\-compatible cloud storages which do not support \fBMultiDel\fR S3 API, enable this setting (file deletion would be slower with this setting enabled) +(optional) for S3\-compatible cloud storages which do not support \fBMultiDel\fR S3 API, enable this setting (file deletion would be slower with this setting enabled) . .P In order to publish to S3, specify endpoint as \fBs3:endpoint\-name:\fR before publishing prefix on the command line, e\.g\.: @@ -1640,6 +1640,10 @@ Options: \-\fBformat\fR=png render graph to specified format (png, svg, pdf, etc\.) . +.TP +\-\fBoutput\fR= +specify output filename, default is to open result in viewer +. .SH "SHOW CURRENT APTLY\(cqS CONFIG" \fBaptly\fR \fBconfig\fR \fBshow\fR .