Top Level Namespace

Defined Under Namespace

Modules: Nite Classes: Fixnum

Instance Method Summary collapse

Instance Method Details

#actionObject



30
31
32
# File 'lib/nite/owl/niteowl.rb', line 30

def action
  Nite::Owl::NiteOwl.instance.current_action()
end

#cancelObject



38
39
40
# File 'lib/nite/owl/niteowl.rb', line 38

def cancel
  action.cancel
end

#cd(dir) ⇒ Object



12
13
14
15
# File 'lib/nite/owl/niteowl.rb', line 12

def cd(dir)
  Dir.chdir quote(dir)
  puts "cd #{dir}"
end

#delay(time) ⇒ Object



34
35
36
# File 'lib/nite/owl/niteowl.rb', line 34

def delay(time)
  action.delay(time)
end

#kill(pids, signal = 15) ⇒ Object

kill process



157
158
159
160
161
162
163
164
165
# File 'lib/nite/owl/niteowl.rb', line 157

def kill(pids,signal=15)
  if pids.is_a?(Array)
    pids.each do |pid|
      Process.kill(signal,pid)
    end
  else
    Process.kill(signal,pids)
  end
end

#process(name, full = true) ⇒ Object

get process pid(s)



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/nite/owl/niteowl.rb', line 134

def process(name,full=true)
  if full
    full = '-f '
  else
    full = ''
  end
  out,_ = Open3.capture2("/usr/bin/pgrep #{full}#{name}")
  if out == ''
    nil
  else
    pids = []
    out.lines.each do |pid|
      pids << pid.to_i
    end
    if pids.size == 1
      pids[0]
    else
      pids
    end
  end
end

#pwdObject



17
18
19
20
21
# File 'lib/nite/owl/niteowl.rb', line 17

def pwd
  d = Dir.pwd
  puts "pwd: #{d}"
  d
end

#quote(path) ⇒ Object

Nite Owl DSL



4
5
6
7
8
9
10
# File 'lib/nite/owl/niteowl.rb', line 4

def quote(path)
  if path.include? " "
    "\"#{path}\""
  else
    path
  end
end

#shell(command, options = {:verbose => false,:silent => false,:stdin => nil}) ⇒ Object

Run command in shell and redirect it’s output to stdout and stderr



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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/nite/owl/niteowl.rb', line 43

def shell(command,options={:verbose => false,:silent => false,:stdin => nil})
  stdout = ""
  stderr = ""
  verbose = options[:verbose]
  silent = options[:silent]
  stdin = options[:stdin]
  if verbose
    puts "Executing: #{command}"
  end
  Open3.popen3(command) do |i,o,e,t|
    stdin_i = 0
    stdin_open = stdin != nil
    stdout_buffer = ""
    stderr_buffer = ""
    stdout_open = true
    stderr_open = true
    stdout_ch = nil
    stderr_ch = nil
    while stdout_open or stderr_open or stdin_open
      if stdin_open
        begin
          p stdin
          i.write(stdin)
          i.close_write
          stdin_open = false
          #c = i.write_nonblock(stdin[stdin_i])
          #if c > 0
          #  stdin_i += 1
          #  if stdin_i == stdin.size
          #    i.close_write
          #    stdin_open = false
          #  end
          #end
        rescue IO::WaitWritable
          IO.select([i])
          puts "retry writeable"
          retry
        rescue EOFError
          stdin_open = false
        end
      end
      if stdout_open
        begin
          stdout_ch = o.read_nonblock(1)
        rescue IO::WaitReadable
          IO.select([o])
          retry
        rescue EOFError
          stdout_open = false
        end
      end
      if stderr_open
        begin
          stderr_ch = e.read_nonblock(1)
        rescue IO::WaitReadable
          IO.select([e])
          retry
        rescue EOFError
          stderr_open = false
        end
      end
      if stdout_ch == "\n" then
        stdout += stdout_buffer+"\n"
        unless silent
          puts stdout_buffer
        end
        stdout_buffer = ""
      elsif stdout_ch != nil
        stdout_buffer << stdout_ch
      end
      stdout_ch = nil
      if stderr_ch == "\n" then
        stderr += stderr_buffer+"\n"
        unless silent
          STDERR.puts stderr_buffer
        end
        stderr_buffer = ""
      elsif stderr_ch != nil
        stderr_buffer << stderr_ch
      end
      stderr_ch = nil
    end
  end
  if stderr != ""
    return stdout, stderr
  else
    return stdout
  end
end

#whenever(files) ⇒ Object



23
24
25
26
27
28
# File 'lib/nite/owl/niteowl.rb', line 23

def whenever(files)
  if files.is_a?(String) or files.is_a?(Regexp)
    files = [files]
  end
  Nite::Owl::NiteOwl.instance.whenever(files)
end