everything related to duct tape audio suite (dtas)
 help / color / mirror / code / Atom feed
3a4bda84a0a729f358b2c63bf326508eeb29e3c3 blob 2525 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
 
#!/usr/bin/env ruby
# Copyright (C) 2013-2015 all contributors <dtas-all@nongnu.org>
# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
require 'optparse'
require 'dtas/edit_client'
require 'dtas/sigevent'
require 'dtas/watchable'
include DTAS::EditClient
c = client_socket
sinks = c.req('sink ls') || "(unknown)"
usage = "Usage: #{DTAS_PROGNAME} [OPTIONS] SINKNAME\n" \
        "available SINKNAME values: #{sinks}"
dry_run = verbose = false
watch = defined?(DTAS::Watchable)

OptionParser.new('', 24, '  ') do |op|
  op.banner = usage
  watch and
    op.on('-N', '--no-watch', 'disable inotify support') { watch = false }

  op.on('-n', '--dry-run', 'only print commands, do not run them') {
    dry_run = true
  }
  op.on('-V', '--verbose', 'print out commands sent to change the sink') {
    verbose = true
  }
  op.on('-h', '--help') { puts(op.to_s); exit }
  op.parse!(ARGV)
end

ARGV.size == 1 or abort usage
name = ARGV[0]

st_in = $stdin.stat

buf = c.req(%W(sink cat #{name}))
abort(buf) if buf =~ /\AERR/
orig = YAML.load(buf)

commit_update = lambda do |buf|
  sink = YAML.load(buf)
  cmd = %W(sink ed #{name})
  update_cmd_env(cmd, orig, sink)

  # both of these default to false
  %w(nonblock active).each do |field|
    cmd << "#{field}=#{sink[field] ? 'true' : 'false'}"
  end

  %w(prio).each do |field|
    value = sink[field] and cmd << "#{field}=#{value}"
  end

  %w(pipe_size).each { |field| cmd << "#{field}=#{sink[field]}" }

  # nil OK
  %w(command).each do |field|
    cmd << "#{field}=#{sink[field]}"
  end

  warn(Shellwords.join(cmd)) if verbose || dry_run
  c.req_ok(cmd) unless dry_run
  orig = sink
end

if st_in.file? || st_in.pipe?
  buf = $stdin.read
  commit_update.call(buf)
else
  include DTAS::SpawnFix
  tmp = tmpyaml
  tmp_path = tmp.path
  do_update = lambda { commit_update.call(File.read(tmp_path)) }
  tmp.write(buf << DTAS_DISCLAIMER)
  cmd = "#{editor} #{tmp_path}"

  sev = DTAS::Sigevent.new
  rset = [ sev ]
  if watch
    ino = DTAS::Watchable::InotifyReadableIter.new
    ino.watch_file(tmp_path, do_update)
    rset << ino
  end

  trap(:CHLD) { sev.signal }
  pid = spawn(cmd)
  begin
    r = IO.select(rset) or next
    r[0].each do |io|
      case io
      when sev
        _, status = Process.waitpid2(pid, Process::WNOHANG)
        status or next
        status.success? or abort "#{cmd} failed: #{status.inspect}"
        do_update.call
        exit
      when ino
        ino.readable_iter # calls do_update
      end
    end
  end while true
end
debug log:

solving 3a4bda8 ...
found 3a4bda8 in dtas.git

everything related to duct tape audio suite (dtas)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://80x24.org/dtas-all
	git clone --mirror http://ou63pmih66umazou.onion/dtas-all

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 dtas-all dtas-all/ https://80x24.org/dtas-all \
		dtas-all@nongnu.org
	public-inbox-index dtas-all

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.audio.dtas
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.audio.dtas
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	../../../dtas.git

AGPL code for this site: git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inbox.git