mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-11 03:11:50 +00:00
graph: do not remove tempfile when opening in viewer
This commit is contained in:
18
cmd/graph.go
18
cmd/graph.go
@@ -9,7 +9,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/aptly-dev/aptly/deb"
|
"github.com/aptly-dev/aptly/deb"
|
||||||
"github.com/aptly-dev/aptly/utils"
|
"github.com/aptly-dev/aptly/utils"
|
||||||
@@ -79,10 +78,6 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
|
||||||
_ = os.Remove(tempfilename)
|
|
||||||
}()
|
|
||||||
|
|
||||||
if output != "" {
|
if output != "" {
|
||||||
err = utils.CopyFile(tempfilename, output)
|
err = utils.CopyFile(tempfilename, output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -90,23 +85,16 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Output saved to %s\n", output)
|
fmt.Printf("Output saved to %s\n", output)
|
||||||
|
_ = os.Remove(tempfilename)
|
||||||
} else {
|
} else {
|
||||||
command := getOpenCommand()
|
command := getOpenCommand()
|
||||||
fmt.Printf("Rendered to %s file: %s, trying to open it with: %s %s...\n", format, tempfilename, command, tempfilename)
|
fmt.Printf("Displaying %s file: %s %s\n", format, command, tempfilename)
|
||||||
|
|
||||||
args := strings.Split(command, " ")
|
args := strings.Split(command, " ")
|
||||||
|
|
||||||
viewer := exec.Command(args[0], append(args[1:], tempfilename)...)
|
viewer := exec.Command(args[0], append(args[1:], tempfilename)...)
|
||||||
viewer.Stderr = os.Stderr
|
viewer.Stderr = os.Stderr
|
||||||
if err = viewer.Start(); err == nil {
|
err = viewer.Start()
|
||||||
// Wait for a second so that the visualizer has a chance to
|
|
||||||
// open the input file. This needs to be done even if we're
|
|
||||||
// waiting for the visualizer as it can be just a wrapper that
|
|
||||||
// spawns a browser tab and returns right away.
|
|
||||||
defer func(t <-chan time.Time) {
|
|
||||||
<-t
|
|
||||||
}(time.After(time.Second))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|||||||
2
system/t14_graph/CreateGraphOutputTest_gold
Normal file
2
system/t14_graph/CreateGraphOutputTest_gold
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
Generating graph...
|
||||||
|
Output saved to /tmp/aptly-graph.png
|
||||||
2
system/t14_graph/CreateGraphTest_gold
Normal file
2
system/t14_graph/CreateGraphTest_gold
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
Generating graph...
|
||||||
|
Displaying png file: xdg-open /tmp/aptly-graph1173098610.png
|
||||||
33
system/t14_graph/graph.py
Normal file
33
system/t14_graph/graph.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
"""
|
||||||
|
Test aptly graph
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
|
from lib import BaseTest
|
||||||
|
|
||||||
|
|
||||||
|
class CreateGraphTest(BaseTest):
|
||||||
|
"""
|
||||||
|
open graph in viewer
|
||||||
|
"""
|
||||||
|
fixtureCmds = ["mkdir -p ../build", "ln -fs /bin/true ../build/xdg-open"]
|
||||||
|
environmentOverride = {"PATH": os.environ["PATH"] + ":../build"}
|
||||||
|
runCmd = "aptly graph"
|
||||||
|
|
||||||
|
def outputMatchPrepare(self, s):
|
||||||
|
return re.sub(r"[0-9]", "", s)
|
||||||
|
|
||||||
|
def teardown(self):
|
||||||
|
self.run_cmd(["rm", "-f", "../build/xdg-open"])
|
||||||
|
|
||||||
|
|
||||||
|
class CreateGraphOutputTest(BaseTest):
|
||||||
|
"""
|
||||||
|
open graph in viewer
|
||||||
|
"""
|
||||||
|
runCmd = "aptly graph -output /tmp/aptly-graph.png"
|
||||||
|
|
||||||
|
def teardown(self):
|
||||||
|
self.run_cmd(["rm", "-f", "/tmp/aptly-graph.png"])
|
||||||
Reference in New Issue
Block a user