aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordvs12024-10-23 19:16:01 +1000
committerdvs12024-10-23 19:16:01 +1000
commit8e7c1c219589120f2088ce9924907c7d66492312 (patch)
tree3717fd388e2402db471d43a64c2c6532ac48e075
parentRearrange those logging globals and a few other things in _. (diff)
downloadJackOnAllDevices-8e7c1c219589120f2088ce9924907c7d66492312.zip
JackOnAllDevices-8e7c1c219589120f2088ce9924907c7d66492312.tar.gz
JackOnAllDevices-8e7c1c219589120f2088ce9924907c7d66492312.tar.bz2
JackOnAllDevices-8e7c1c219589120f2088ce9924907c7d66492312.tar.xz
New options parsing stuff.
-rwxr-xr-x_.lua45
-rwxr-xr-xtest_.lua108
2 files changed, 103 insertions, 50 deletions
diff --git a/_.lua b/_.lua
index 19b73b4..12d7461 100755
--- a/_.lua
+++ b/_.lua
@@ -6,13 +6,38 @@ local _ = {}
6_.version = '0.0 crap' 6_.version = '0.0 crap'
7 7
8 8
9D = function(s) print('DEBUG ' .. s) end 9D = function(s) print('DEBUG ' .. s); io.flush() end
10I = function(s) print('INFO ' .. s) end 10I = function(s) print('INFO ' .. s); io.flush() end
11T = function(s) print('TIMEOUT ' .. s) end 11T = function(s) print('TIMEOUT ' .. s); io.flush() end
12W = function(s) print('WARNING ' .. s) end 12W = function(s) print('WARNING ' .. s); io.flush() end
13E = function(s) print('ERROR ' .. s) end 13E = function(s) print('ERROR ' .. s); io.flush() end
14C = function(s) print('CRITICAL ' .. s) end 14C = function(s) print('CRITICAL ' .. s); io.flush() end
15
16
17_.parseArgs = function(options, args)
18 local o = nil
19 if 0 ~= #args then
20 for i,a in pairs(args) do
21 local s, e = a:find("=")
22 if nil == s then e = 0 end
23 opt = a:sub(1, e - 1)
24 o = options[opt]
25 D('Argument ' .. i .. ' = ' .. a)
26 if nil ~= o then
27 o:func(a, args, i)
28 end
29 end
30 end
15 31
32 if nil == o then
33 local h = ''
34 for k, v in pairs(options) do
35 h = h .. k .. '|'
36 end
37 print('Usage: aataaj.lua {' .. string.sub(h, 1, -2) .. '}')
38 os.exit(0)
39 end
40end
16 41
17_.runnable = function(c) 42_.runnable = function(c)
18 return ( 0 == __('which ' .. c):Do().status ) 43 return ( 0 == __('which ' .. c):Do().status )
@@ -66,8 +91,12 @@ __ = function(c)
66 elseif 'string' == type(c) then 91 elseif 'string' == type(c) then
67 for l in string.gmatch(c, "\n*([^\n]+)\n*") do 92 for l in string.gmatch(c, "\n*([^\n]+)\n*") do
68 if '' ~= l then 93 if '' ~= l then
69 n = n + 1 94 if ('#!' == l:sub(1,2)) and (n == 0) then
70 exe.cmd = exe.cmd .. l .. ' ; ' 95 -- TODO - should do something with this, not just run it as shell stuff.
96 else
97 n = n + 1
98 exe.cmd = exe.cmd .. l .. ' ; '
99 end
71 end 100 end
72 end 101 end
73 end 102 end
diff --git a/test_.lua b/test_.lua
index c9884ea..6784039 100755
--- a/test_.lua
+++ b/test_.lua
@@ -11,31 +11,59 @@ This is part of the blah blah blah...
11]] 11]]
12 12
13 13
14 14local options =
15local args = {...} 15{
16if 0 ~= #args then 16 start =
17-- for i,a in pairs(args) do 17 {
18-- print('Argument ' .. i .. ' = ' .. a) 18 help = 'Command to start the scanning process, for Sys V init.',
19-- end 19 value = false,
20 20 func = function(a, args, i)
21 if 'start' == args[1] then 21 end
22 elseif 'stop' == args[1] then 22 },
23 restart = {start},
24 ['force-reload'] = {start},
25 status =
26 {
27 help = 'Command to check the status of the scanning process, for Sys V init.',
28 value = false,
29 func = function(a, args, i)
30 end
31 },
32 stop =
33 {
34 help = 'Command to stop the scanning process, for Sys V init.',
35 value = false,
36 func = function(a, args, i)
37 end
38 },
39 JACK =
40 {
41 help = 'Command to start the JACK stuff, for users.',
42 value = false,
43 func = function(a, args, i)
44 end
45 },
46 STOP =
47 {
48 help = 'Command to stop the JACK stuff, for users.',
49 value = false,
50 func = function(a, args, i)
23--[=[ 51--[=[
24 _.killEmAll{'qsynth'} 52 _.killEmAll{'qsynth'}
25 __[[ 53 __[[
26a2j_control --stop 54 a2j_control --stop
27sleep 2 55 sleep 2
28a2j_control --exit 56 a2j_control --exit
29sleep 2 57 sleep 2
30]]:Do() 58 ]]:Do()
31 _.killEmAll{'alsa_in', 'alsa_out', 'zita-a2j', 'zita-j2a', 'aseqjoy', 'jack-plumbing'} 59 _.killEmAll{'alsa_in', 'alsa_out', 'zita-a2j', 'zita-j2a', 'aseqjoy', 'jack-plumbing'}
32 __[[ 60 __[[
33sleep 2 61 sleep 2
34jack_control stop 62 jack_control stop
35sleep 2 63 sleep 2
36jack_control exit 64 jack_control exit
37sleep 2 65 sleep 2
38]]:Do() 66 ]]:Do()
39 _.killEmAll{'jmcore', 'qjackctl'} 67 _.killEmAll{'jmcore', 'qjackctl'}
40 -- Catia is python, and no easy way to kill it. 68 -- Catia is python, and no easy way to kill it.
41 -- Also it keeps jackdbus alive, no matter how hard you kill it. 69 -- Also it keeps jackdbus alive, no matter how hard you kill it.
@@ -43,26 +71,22 @@ sleep 2
43 __"sleep 2":Do() 71 __"sleep 2":Do()
44 _.killEmAll{'jackdbus', 'a2jmidid'} 72 _.killEmAll{'jackdbus', 'a2jmidid'}
45]=] 73]=]
46 return(0) 74 end
47 elseif 'JACK' == args[1] then 75 },
48 elseif 'restart' == args[1] then args[1] = 'start' 76 help =
49 elseif 'force-reload' == args[1] then args[1] = 'start' 77 {
50 elseif 'status' == args[1] then 78 help = 'Print help.',
51 return(0) 79 value = false,
52 elseif 'help' == args[1] then 80 func = function(a, args, i)
53 print(Help) 81 print(Help)
54 return(0) 82 os.exit(0)
55 elseif '--help' == args[1] then 83 end
56 print(Help) 84 },
57 return(0) 85 ['--help'] = {help},
58 else 86}
59 print("Usage: /etc/init.d/aataaj.lua {start|stop|restart|force-reload|status}") 87
60 return(1) 88local args = {...}
61 end 89_.parseArgs(options, args)
62else
63 print("Usage: /etc/init.d/aataaj.lua {help|start|stop|restart|force-reload|status|JACK}")
64 return(1)
65end
66 90
67 91
68 92
@@ -87,7 +111,7 @@ for i,l in ipairs(__'df -h\nfree -h':log():Do().lines) do
87end 111end
88print('') 112print('')
89 113
90__[[ 114__[[#!/bin/bash
91 df -h 115 df -h
92 free -h 116 free -h
93]]:log():show():Do() 117]]:log():show():Do()
@@ -112,4 +136,4 @@ print(__'command NoSuchCommand':log():show():Do().status)
112 136
113 137
114D('debug?') 138D('debug?')
115I('info?') \ No newline at end of file 139I('info?')