Top Level Namespace

Includes:
Config, FileUtils, FileUtils::Verbose, Open4, WEBrick

Defined Under Namespace

Modules: CrazyIvan, Enumerable, GeneratorBenchmarkCommon, JSON, JSONGeneratorCommon, Kernel, Open4, ParserBenchmarkCommon Classes: AlreadyRunningError, Class, Date, DateTime, Dir, Exception, File, Fuzzer, GeneratorBenchmarkExt, GeneratorBenchmarkPure, GeneratorBenchmarkRails, JSONServlet, Lockfile, MyState, NFSStore, Object, ParserBenchmarkExt, ParserBenchmarkPure, ParserBenchmarkRails, ParserBenchmarkYAML, ProcessManager, Range, Regexp, ReportAssembler, String, Struct, Symbol, TC_JSON, TC_JSONAddition, TC_JSONFixtures, TC_JSONGenerate, TC_JSONRails, TC_JSONUnicode, TestRunner, Time

Constant Summary collapse

ISO_8859_1_TO_UTF8 =
Iconv.new('utf-8', 'iso-8859-15')
LIBDIR =
"lib"
LIBDIR_MODE =
0644
BINDIR =
"bin"
BINDIR_MODE =
0755
RUBY_PATH =
File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
RAKE_PATH =
File.join(Config::CONFIG['bindir'], 'rake')

Constants included from Open4

Open4::VERSION

Instance Method Summary collapse

Methods included from Open4

alive, alive?, background, bg, chdir, getopts, maim, new_thread, open4, popen4, relay, spawn, to, version

Instance Method Details

#create_server(err, dir, port) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/crazy_ivan/vendor/json-1.1.7/tools/server.rb', line 33

def create_server(err, dir, port)
  dir = File.expand_path(dir)
  err.puts "Surf to:", "http://#{Socket.gethostname}:#{port}"

  s = HTTPServer.new(
    :Port         => port,
    :DocumentRoot => dir,
    :Logger       => WEBrick::Log.new(err),
    :AccessLog    => [
      [ err, WEBrick::AccessLog::COMMON_LOG_FORMAT  ],
      [ err, WEBrick::AccessLog::REFERER_LOG_FORMAT ],
      [ err, WEBrick::AccessLog::AGENT_LOG_FORMAT   ]
    ]
  )
  s.mount("/json", JSONServlet)
  s
end

#go(s, args = ARGV) ⇒ Object

Parses the argument array args, according to the pattern s, to retrieve the single character command line options from it. If s is ‘xy:’ an option ‘-x’ without an option argument is searched, and an option ‘-y foo’ with an option argument (‘foo’).

An option hash is returned with all found options set to true or the found option argument.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/crazy_ivan/vendor/json-1.1.7/bin/prettify_json.rb', line 14

def go(s, args = ARGV)
  b, v = s.scan(/(.)(:?)/).inject([{},{}]) { |t,(o,a)|
    t[a.empty? ? 0 : 1][o] = a.empty? ? false : nil
    t
  }
  while a = args.shift
    a !~ /\A-(.+)/ and args.unshift a and break
    p = $1
    until p == ''
      o = p.slice!(0, 1)
      if v.key?(o)
        v[o] = if p == '' then args.shift or break 1 else p end
        break
      elsif b.key?(o)
        b[o] = true
      else
        args.unshift a
        break 1
      end
    end and break
  end
  b.merge(v)
end

#hostnameObject

}}}



24
25
26
27
28
# File 'lib/crazy_ivan/vendor/lockfile-1.4.3/samples/a.rb', line 24

def hostname
#{{{
  @__hostname__ ||= Socket::gethostname
#}}}
end

#install_rb(srcdir = nil, destdir = nil, mode = nil, bin = nil) ⇒ Object



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
# File 'lib/crazy_ivan/vendor/lockfile-1.4.3/install.rb', line 31

def install_rb(srcdir=nil, destdir=nil, mode=nil, bin=nil)
#{{{
  path   = []
  dir    = []
  Find.find(srcdir) do |f|
    next unless FileTest.file?(f)
    next if (f = f[srcdir.length+1..-1]) == nil
    next if (/CVS$/ =~ File.dirname(f))
    next if f =~ %r/\.lnk/
    path.push f
    dir |= [File.dirname(f)]
  end
  for f in dir
    next if f == "."
    next if f == "CVS"
    File::makedirs(File.join(destdir, f))
  end
  for f in path
    next if (/\~$/ =~ f)
    next if (/^\./ =~ File.basename(f))
    unless bin
      File::install(File.join(srcdir, f), File.join(destdir, f), mode, true)
    else
      from = File.join(srcdir, f)
      to = File.join(destdir, f)
      shebangify(from) do |sf|
        $deferr.print from, " -> ", File::catname(from, to), "\n"
        $deferr.printf "chmod %04o %s\n", mode, to 
        File::install(sf, to, mode, false)
      end
    end
  end
#}}}
end

#linkify(d, linked = []) ⇒ Object

}}}



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/crazy_ivan/vendor/lockfile-1.4.3/install.rb', line 109

def linkify d, linked = []
#--{{{
  if test ?d, d
    versioned = Dir[ File::join(d, "*-[0-9].[0-9].[0-9].rb") ]
    versioned.each do |v| 
      src, dst = v, v.gsub(%r/\-[\d\.]+\.rb$/, '.rb')
      lnk = nil
      begin
        if test ?l, dst
          lnk = "#{ dst }.lnk"
          puts "#{ dst } -> #{ lnk }"
          File::rename dst, lnk
        end
        unless test ?e, dst
          puts "#{ src } -> #{ dst }"
          File::copy src, dst 
          linked << dst
        end
      ensure
        if lnk
          at_exit do
            puts "#{ lnk } -> #{ dst }"
            File::rename lnk, dst
          end
        end
      end
    end
  end
  linked
#--}}}
end

#Lockfile(path, *a, &b) ⇒ Object



557
558
559
560
561
# File 'lib/crazy_ivan/vendor/lockfile-1.4.3/lib/lockfile.rb', line 557

def Lockfile path, *a, &b
#--{{{
  Lockfile.new(path, *a, &b)
#--}}}
end

#open4(*cmd, &b) ⇒ Object



401
# File 'lib/crazy_ivan/vendor/open4-1.0.1/lib/open4.rb', line 401

def open4(*cmd, &b) cmd.size == 0 ? Open4 : Open4::popen4(*cmd, &b) end

#shebangify(f) ⇒ Object

}}}



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/crazy_ivan/vendor/lockfile-1.4.3/install.rb', line 65

def shebangify f
#{{{
  open(f) do |fd|
    buf = fd.read 42 
    if buf =~ %r/^\s*#\s*!.*ruby/o
      ftmp = Tempfile::new("#{ $$ }_#{ File::basename(f) }")
      begin
        fd.rewind
        ftmp.puts "#!#{ $ruby  }"
        while((buf = fd.read(8192)))
          ftmp.write buf
        end
        ftmp.close
        yield ftmp.path
      ensure
        ftmp.close!
      end
    else
      yield f
    end
  end
#}}}
end

#show_failureObject



4
5
6
7
8
# File 'lib/crazy_ivan/vendor/open4-1.0.1/samples/timeout.rb', line 4

def show_failure
  fork{ yield }
  Process.wait
  puts
end

#timestamp(time = Time.now) ⇒ Object

do what we can to invalidate any nfs caching



17
18
19
20
21
22
23
# File 'lib/crazy_ivan/vendor/lockfile-1.4.3/samples/a.rb', line 17

def timestamp time = Time.now
#{{{
  usec = "#{ time.usec }"
  usec << ('0' * (6 - usec.size)) if usec.size < 6 
  time.strftime('%Y-%m-%d %H:%M:%S.') << usec
#}}}
end

#tmpnam(dir = Dir.tmpdir, seed = File.basename($0)) ⇒ Object

}}}



29
30
31
32
33
34
35
36
# File 'lib/crazy_ivan/vendor/lockfile-1.4.3/samples/a.rb', line 29

def tmpnam dir = Dir.tmpdir, seed = File.basename($0)
#{{{
  pid = Process.pid
  path = "%s_%s_%s_%s_%d" % 
    [hostname, seed, pid, timestamp.gsub(/\s+/o,'_'), rand(101010)]
  File.join(dir, path)
#}}}
end

#uncache(file) ⇒ Object

}}}



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/crazy_ivan/vendor/lockfile-1.4.3/samples/a.rb', line 37

def uncache file 
#{{{
  refresh = nil
  begin
    is_a_file = File === file
    path = (is_a_file ? file.path : file.to_s) 
    stat = (is_a_file ? file.stat : File.stat(file.to_s)) 
    refresh = tmpnam(File.dirname(path))
    File.link path, refresh rescue File.symlink path, refresh
    File.chmod stat.mode, path
    File.utime stat.atime, stat.mtime, path
  ensure 
    begin
      File.unlink refresh if refresh
    rescue Errno::ENOENT
    end
  end
#}}}
end