[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 05/10] dtas-sourcedit: allow loading YAML from stdin
From: |
Eric Wong |
Subject: |
[PATCH 05/10] dtas-sourcedit: allow loading YAML from stdin |
Date: |
Sun, 1 Sep 2013 01:22:05 +0000 |
This should make it easy to save/load sink profiles depending on
the users mood. One could easily create different profiles
depending on different listening criteria.
dtas-ctl source cat sox > casual.yml
dtas-sourceedit sox < critical.yml
---
Documentation/dtas-sourceedit.txt | 10 +++++++++-
bin/dtas-sourceedit | 31 +++++++++++++++++++++++--------
2 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/Documentation/dtas-sourceedit.txt
b/Documentation/dtas-sourceedit.txt
index 4a47107..9b9fe14 100644
--- a/Documentation/dtas-sourceedit.txt
+++ b/Documentation/dtas-sourceedit.txt
@@ -12,7 +12,10 @@ dtas-sourceedit {sox | av | ff}
# DESCRIPTION
dtas-sourceedit spawns an editor to allow editing of a source as a YAML file.
-See dtas-player_protocol(7) for details on SOURCEARGS.
+See dtas-player_protocol(7) for details on SOURCEARGS. If standard input is
+a pipe or file, it is parsed as YAML and fed to the dtas-player(1) instance
+non-interactively. This is useful for loading various profiles from the
+filesystem.
# EXAMPLES
@@ -20,6 +23,11 @@ Invoking dtas-sourceedit will spawn your favorite text
editor on "sox":
$ dtas-sourceedit sox
+To load an existing YAML profile for sox. saved.yml could be the output
+of a previous "dtas-ctl source cat sox" invocation:
+
+ $ dtas-sourceedit sox < saved.yml
+
To change the way dtas-player calls avconv (part of libav):
$ dtas-sourceedit av
diff --git a/bin/dtas-sourceedit b/bin/dtas-sourceedit
index a511793..0c8aeb5 100755
--- a/bin/dtas-sourceedit
+++ b/bin/dtas-sourceedit
@@ -5,22 +5,33 @@ require 'dtas/edit_client'
include DTAS::EditClient
c = client_socket
sources = c.req('source ls') || "(unknown)"
-usage = "Usage: #{DTAS_PROGNAME} SOURCENAME\n" \
+usage = "Usage: #{DTAS_PROGNAME} [-n|--dry-run][-V|--verbose] SOURCENAME\n" \
"available SOURCENAME values: #{sources}"
+
+# use a real option parser if we have anything more complex
+dry_run = !!(ARGV.delete('-n') || ARGV.delete('--dry-run'))
+verbose = !!(ARGV.delete('-V') || ARGV.delete('--verbose'))
+
ARGV.size <= 1 or abort usage
name = ARGV[0] || "sox"
-tmp = tmpyaml
+st_in = $stdin.stat
+
buf = c.req(%W(source cat #{name}))
abort(buf) if buf =~ /\AERR/
orig = YAML.load(buf)
-tmp.write(buf << DTAS_DISCLAIMER)
-cmd = "#{editor} #{tmp.path}"
-system(cmd) or abort "#{cmd} failed: #$?"
-tmp.rewind
-source = YAML.load(tmp.read)
+if st_in.file? || st_in.pipe?
+ tmp = $stdin
+else
+ tmp = tmpyaml
+ tmp.write(buf << DTAS_DISCLAIMER)
+ cmd = "#{editor} #{tmp.path}"
+ system(cmd) or abort "#{cmd} failed: #$?"
+ tmp.rewind
+end
+source = YAML.load(tmp.read)
cmd = %W(source ed #{name})
update_cmd_env(cmd, orig, source)
@@ -29,4 +40,8 @@ update_cmd_env(cmd, orig, source)
cmd << "#{field}=#{source[field]}"
end
-c.req_ok(cmd)
+if verbose || dry_run
+ warn Shellwords.join(cmd)
+end
+
+c.req_ok(cmd) unless dry_run
--
1.8.4
- [PATCH 0/10] misc updates to master, Eric Wong, 2013/08/31
- [PATCH 02/10] GNUmakefile: combine with pkg.mk, Eric Wong, 2013/08/31
- [PATCH 08/10] doc: reorganize sections around dtas-player, Eric Wong, 2013/08/31
- [PATCH 10/10] doc: add contact info to all documentation, Eric Wong, 2013/08/31
- [PATCH 09/10] doc: sink_examples: reference dtas-xdelay and friends, Eric Wong, 2013/08/31
- [PATCH 04/10] Rakefile: wrap long line, Eric Wong, 2013/08/31
- [PATCH 07/10] source/{av, ff}: probe harder for audio in weird containers, Eric Wong, 2013/08/31
- [PATCH 03/10] Rakefile: additional pointer to git-set-file-times, Eric Wong, 2013/08/31
- [PATCH 05/10] dtas-sourcedit: allow loading YAML from stdin,
Eric Wong <=
- [PATCH 06/10] test_source_av: fix test to actually run, Eric Wong, 2013/08/31
- [PATCH 01/10] disclaimer: disambiguate between dtas/$PROGNAME, Eric Wong, 2013/08/31