Module: Gtk2AppLib::System

Defined in:
lib/gtk2applib/system.rb

Overview

The System module is where the library sets configurable values. It is loaded before the application's configuration, which then has the opportunity to modify these values. Configurable values are set in Hash or Array constants scoped in Gtk2AppLib::System. Gtk2AppLib::System also contains true constants which values are determined at run time and depend on the application's enviroment. Class methods which interface with OS are also found in gtk2applib/configuration.rb, altough packaged out of Gtk2AppLib::System remaining in Gtk2AppLib. Here are some additional constants RDoc rudely ignores for being in a case statement:

X = (OSTYPE=~/Win/i)? false: true
TASK_LIST = (OSTYPE=~/Win/i)?
  'WMIC PROCESS get Caption,Commandline,Processid' :
  'ps -eo pid,user,vsz,stat,comm,args'

Class Method Summary (collapse)

Class Method Details

+ (Object) _processes(line, &block)



84
85
86
87
88
# File 'lib/gtk2applib/system.rb', line 84

def self._processes(line, &block)
  $stderr.puts line if $trace && $verbose
  pid, command = System._processes_x(line)
  block.call(pid, command, line) if pid =~ /^\d+$/
end

+ (String) _processes_x(line)

Parameters:

Returns:



76
77
78
79
80
81
82
# File 'lib/gtk2applib/system.rb', line 76

def self._processes_x(line)
  data = line.strip.split(/\s+/)
  # ps -eo pid,user,vsz,stat,comm,args
  # pid, user, vsz, stat, *comm_args = *data
  # command = comm_args.join(' ')
  return data[0], data[4..-1].join(' ')
end

+ (String) _run_x(args, command, nkey)

Assembles the system command to be run on X like systems.

Parameters:

  • args (Array of String)

    to be given to command

  • command (String)

    system executable

  • nkey (Symbol)

    system mode

Returns:



60
61
62
63
# File 'lib/gtk2applib/system.rb', line 60

def self._run_x(args, command, nkey)
  args = args.join("' '") if args.class == Array
  "#{command}'#{args}'#{SysConfig::NULL[nkey]}"
end

+ (Array) path

Return the path list

Returns:

  • (Array)

    path



23
24
25
# File 'lib/gtk2applib/system.rb', line 23

def self.path
  ENV['PATH'].split(/:/)
end

+ (Strng) path_to(command)

Returns the first path to command in path list. Works just like Linux's which

Parameters:

Returns:

  • (Strng)

    full_path to command



32
33
34
35
36
37
38
# File 'lib/gtk2applib/system.rb', line 32

def self.path_to(command)
  System.path.each do |path|
    full_path = File.join(path, command)
    return full_path if File.exist?(full_path)
  end
  nil
end

+ (Object) processes(&block)

Linux 4426 username 434556 Sl gtk2alertapp /usr/local/bin/ruby /usr/...



92
93
94
95
96
# File 'lib/gtk2applib/system.rb', line 92

def self.processes(&block)
  # Might as well format ps to match maemo's ps which ignores options.
  task_list = `ps -eo pid,user,vsz,stat,comm,args`.split(/^/)
  task_list.each { |line| System._processes(line, &block) }
end

+ (Object) run(args, app = :BROWSER, nkey = SysConfig::NULL_DEFAULT)



65
66
67
68
69
70
71
# File 'lib/gtk2applib/system.rb', line 65

def self.run(args, app=:BROWSER, nkey=SysConfig::NULL_DEFAULT)
  if command = SysConfig::APPLICATION[app] then
    string = System._run_x(args, command, nkey)
    $stderr.puts string if $trace
    system(string)
  end
end

+ (String) which(commands)

Given a list of commands and their respective options, returns the first command (with options) it finds in path.

Parameters:

  • commands (Array of Array( (command, options) String pairs))

Returns:

  • (String)

    command + options



45
46
47
48
49
50
51
52
# File 'lib/gtk2applib/system.rb', line 45

def self.which(commands)
  which = nil
  commands.each do |command, options|
    which = System.path_to(command)
    return "#{which}#{options}" if which
  end
  return nil
end