Top Level Namespace

Includes:
RicColorsObsolete

Defined Under Namespace

Modules: Enumerable, RicColorsObsolete, RicDebug, RicHelpModule, Sakuric Classes: Array, ItunesPlayer_MacOSX, ItunesPlayer_Win, MpdPlayer, RhythmboxPlayer, RicConf, RicException, String

Constant Summary collapse

LOREM_IPSUM =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin at purus id ante pulvinar dapibus. Donec risus justo, gravida ac vulputate a, lacinia eget leo. Duis quam tellus, tempus at feugiat a, eleifend et velit. Donec et enim id libero malesuada luctus nec at nibh. Sed elit est, interdum sit amet sollicitudin ac, vulputate eget metus. In hac habitasse platea dictumst. Cras vitae justo at turpis elementum sollicitudin. Etiam quis quam placerat erat tincidunt fermentum. Ut vel mauris magna. Vestibulum luctus leo eget lectus gravida ac dignissim enim vestibulum. Integer facilisis mi sed justo aliquet a lacinia lacus scelerisque.

Aliquam sed purus vel felis euismod pharetra eu a ipsum. Suspendisse potenti. Mauris aliquet, lorem id mattis ornare, dolor mauris tincidunt tellus, ac feugiat urna sem eget diam. Nulla venenatis urna et elit lobortis eleifend. Ut feugiat adipiscing nisi vitae accumsan. Aliquam ullamcorper odio a nibh scelerisque non tincidunt urna ullamcorper. Sed vitae eleifend quam. Nunc vulputate vulputate viverra. Duis eu enim eros. Nunc lacinia nibh neque, sit amet varius arcu.

Maecenas facilisis porttitor vestibulum. Phasellus nisl elit, porttitor id pulvinar nec, malesuada quis lectus. Suspendisse lacinia odio vitae eros molestie suscipit. Vivamus eu nulla ac augue adipiscing luctus. Curabitur rhoncus placerat dui a consectetur. Integer suscipit felis vitae eros mattis cursus. Integer sollicitudin ante in risus feugiat tincidunt sed sit amet libero. Nunc molestie lorem ut nulla aliquam viverra. Etiam bibendum mollis mattis. Phasellus ipsum tortor, egestas consequat sollicitudin non, hendrerit eu tortor. Nam at magna ipsum, non convallis ligula. Etiam ac eros a nunc elementum bibendum vitae vitae lacus. Vivamus placerat quam sit amet urna mattis in luctus nulla venenatis. Praesent tempus egestas interdum. Nulla facilisi. Nulla id ligula et nunc egestas dictum sed sodales tellus. Integer vestibulum commodo mauris, blandit porta lectus tincidunt quis. Vestibulum varius est eu turpis ultrices pellentesque.

Donec aliquam elit quis augue tristique id lacinia augue laoreet. Duis placerat tellus eget urna vehicula volutpat. Vestibulum tortor dui, ultricies quis luctus sed, ultricies sit amet dui. Sed nec magna ac mauris imperdiet venenatis in id velit. Vestibulum non nibh nisi, eu elementum metus. Integer porttitor scelerisque pharetra. Maecenas eu tincidunt augue. Donec viverra diam lacinia ligula rhoncus viverra. Cras dictum rhoncus nisi sit amet malesuada. Quisque consectetur sollicitudin magna, nec faucibus nulla lacinia ac. Donec accumsan gravida odio, nec vehicula enim hendrerit sed. Etiam in mauris et mi sollicitudin congue non sit amet augue. Praesent nisi tortor, posuere vehicula rutrum interdum, tincidunt non tortor. Aliquam adipiscing mollis odio, eget accumsan lectus blandit sed. Sed tristique, ipsum eu laoreet dignissim, nunc nisi rhoncus tellus, sed molestie turpis ante vitae orci. Nullam tincidunt suscipit ligula sit amet sodales. Curabitur auctor tempus rutrum.

Donec non venenatis lectus. Ut imperdiet felis quis augue viverra pellentesque. Duis sodales, magna at tincidunt volutpat, turpis tellus auctor lacus, et mollis ante odio in tellus. Aliquam euismod tempor aliquam. Vivamus at eros eget felis consequat faucibus dignissim consequat diam. Cras et dolor sagittis mi pharetra tincidunt vitae a tortor. Vestibulum at dictum augue. Sed commodo magna quis lectus bibendum accumsan. Aliquam consectetur feugiat augue, eget suscipit mi mattis ac. Donec at tristique lorem. Nulla non nisl sed felis volutpat ullamcorper."

Instance Method Summary collapse

Methods included from RicColorsObsolete

#_flag_nations, #bash_color, #color_test, #colora, #colors_flag, #colors_off, #colors_on, #daltonic_terminal?, #flag, #flag2, #flag3, #flag_n, #okno, #pcolor, #rainbow, #scolora, #set_color, #terminal, #visible_color

Instance Method Details

#_init(explaination = 'no explaination given', initial_debug_state = false) ⇒ Object

Sto qui inizializza TUTTO cazzo, ho detto TUTTO, non voglio codice qui fuori!

# puo' esser chiamato piu' volte...

$RELOAD_DEBUG serve a debuggare il tutto.


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
# File 'lib/init.rb', line 71

def _init(explaination='no explaination given', initial_debug_state = false)
  $RELOAD_DEBUG = false # 
  deb "pre init '#{explaination}'" if $RELOAD_DEBUG
  #$USER          = 'riccardo'
  $INIT_DEBUG    = false   # dice se debuggare la mia intera infrastruttura o no...
  $RELOADED_ONCE = 0    # aiuta a capuire quante volte includo sta cazo di lib! Sempre 2!!!
  $RIC_LIB_MODULES = %w{ classes/debug_ric } # to be explicitly included in this order.
  $HOME  = File.expand_path('~')
  $DEBUG ||= initial_debug_state 
  $PROG  = File.basename($0)
  case $PROG
    when 'irb'
      print "[DEB] Welcome to Sakura within IRB! Happy playing. Try 'Sakuric.VERSION'"
    when 'ruby'
      print "[DEB] Welcome to Sakura within RUBY! Happy playing. Try 'Sakuric.VERSION'"
    default
      # do nothing
  end
    
  ################################################################################	
  # Path to riccardo's Library... Library stuff
  $LOAD_PATH << './lib' 
  $LOAD_PATH << "#{$SAKURADIR}/lib/"

  # BEWARE: ORDER *IS* RELEVANT!
  $RICLIB = Hash.new unless defined?($RICLIB)
  $RICLIB['VERSION'] = $RICLIB_VERSION
  $RICLIB['libs'] ||= []
  $RICLIB['nreloaded'] ||= 0
  $RICLIB['nreloaded'] += 1  
  $RICLIB['help'] =<<-BURIDONE
This library contains all my enciclopedic knowledge (that is, notionistic). :
Finally solved the bug of double inclusion (cribsio, files included this!)
BURIDONE
  reload_doesnt_work_properly!(true) 
  $CONF = RicConf.new
  pyellow( riclib_info ) if debug?  
  puts "post init delle #{Time.now}" if $RELOAD_DEBUG
end

#autoregex(anything) ⇒ Object

supports: strings, arrays and regexes :)



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/ric_strings.rb', line 265

def autoregex(anything)
  deb "Autoregex() supercool! With a #{blue anything.class}"
  case anything.class.to_s
    when 'String' 
      if anything.match(/^\/.*\/$/) # '/asd/' is probably an error! The regex builder trails with '/' automatically
        fatal 23,"Attention, the regex is a string with trailing '/', are you really SURE this is what you want?!?"
      end
      return  Regexp.new(anything)
    when 'Regexp'
      return anything # already ok
    when 'Array'
      return Regexp.new(anything.join('|'))
    else
      #msg = "#{__FILE__}.#{__LINE__}: autoregex() Exception: Unknown class for autoregexing: #{red anything.class}"
      msg = "Unknown class for autoregexing: #{red anything.class}"
      $stderr.puts( msg )
      raise( msg )
  end
  return nil
end

#clear_screenObject Also known as: clear

Miscellaneous string functions



238
239
240
# File 'lib/ric_strings.rb', line 238

def clear_screen
  print "\e[2J\e[f"
end

#deb2(str) ⇒ Object



94
95
96
# File 'lib/classes/debug_ric.rb', line 94

def deb2(str)
  debug "(ERR) #{str}", :out => $stderr, :tag => 'stderr' # , :really_write => true,:write_always => false,
end

#deb?Boolean Also known as: if_deb, if_deb?

if DEBUG is true, then execute the code

Returns:

  • (Boolean)


107
108
109
# File 'lib/classes/debug_ric.rb', line 107

def deb?() 
	yield if $DEBUG
end

#debo(obj) ⇒ Object



117
118
119
# File 'lib/classes/debug_ric.rb', line 117

def debo(obj)
  deb "debo: #{obj.ispeziona}"
end

#debug(s, opts = {}) ⇒ Object Also known as: deb

This is a denbug with steroids

Introduced tags: NORMAL deb() works.
If you launch debug_on('reason', :tags => [ :this, :foo, :bar])
from this moment on normal debug is prevented unless you debug using the explicit tags..

Il vecchio debug era:
debug (s, :really_write => true,:write_always => false )


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/classes/debug_ric.rb', line 43

def debug(s, opts = {} )
  out = opts.fetch(:out, $stdout)
  tag = opts.fetch(:tag, '_DFLT_')
  really_write = opts.fetch(:really_write, true) # you can prevent ANY debug setting this to false
  write_always = opts.fetch(:write_always, false)

  raise "ERROR: ':tags' must be an array in debug(), maybe you meant to use :tag?" if ( opts[:tags] && opts[:tags].class != Array )
  final_str = "#RDeb#{write_always ? '!' : ''}[#{opts[:tag] || '-'}] #{s}"
  final_str = "\033[1;30m" +final_str + "\033[0m" if opts.fetch(:coloured_debug, true) # color by gray by default
  if (debug_tags_enabled? ) # tags
    puts( final_str ) if debug_tag_include?( opts )
  else # normal behaviour: if NOT tag
    puts( final_str ) if ((really_write && $DEBUG) || write_always) && ! opts[:tag]
  end
end

#debug?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/classes/debug_ric.rb', line 113

def debug?()
  $DEBUG == true
end

#debug_off(comment = "Disabling DEBUG for once in a while :)", opts = {}) ⇒ Object



83
84
85
86
# File 'lib/classes/debug_ric.rb', line 83

def debug_off(comment="Disabling DEBUG for once in a while :)", opts={})
  deb "debug_off(): #{comment}" 
  $DEBUG = false 
end

#debug_on(comment = "enabling debug (SVNID=#{$SVN_ID rescue 'ERR'})", opts = {}) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/classes/debug_ric.rb', line 75

def debug_on(comment="enabling debug (SVNID=#{$SVN_ID rescue 'ERR'})", opts={} )
  $DEBUG = true
  deb "debug_on(): #{comment}"
  _manage_debug_tags(opts)
  if opts[:tags]
    deb "debug_on(): new tags enabled (#{opts[:tags]}). Now ONLY debug called explicitly with one of those tags will work! To go back to normal behaviour just run: 'debug_reset_tags()'"
  end
end

#debug_reset_tagsObject



91
92
93
# File 'lib/classes/debug_ric.rb', line 91

def debug_reset_tags
  $_debug_tags = []
end

#debug_tag_include?(opts) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
72
# File 'lib/classes/debug_ric.rb', line 64

def debug_tag_include?(opts)
  assert_array($_debug_tags, 'debug_tags')
  assert_class( opts[:tag], Symbol, "tag must be a symbol, ", :dontdie => true ) if opts[:tag]
  assert_array( opts[:tags] , 'opts[:tags]' ) if opts[:tags]
  return $_debug_tags.include?(opts[:tag].to_sym) if opts[:tag]
  return ($_debug_tags & opts[:tags]).size > 0    if opts[:tags]
  #return $_debug_tags.include?(tag_or_tags.to_sym) if (tag.class == String || tag.class == Symbol)
  return false
end

#debug_tagsObject



88
89
90
# File 'lib/classes/debug_ric.rb', line 88

def debug_tags
  $_debug_tags
end

#debug_tags_enabled?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/classes/debug_ric.rb', line 60

def debug_tags_enabled?
  $_debug_tags != []
end

#err(str) ⇒ Object



121
122
123
# File 'lib/classes/debug_ric.rb', line 121

def err(str)
	$stderr.puts "ERR[RicLib] #{$0}: '#{str}'"
end

#fatal(ret, str) ⇒ Object



125
126
127
128
# File 'lib/classes/debug_ric.rb', line 125

def fatal(ret,str)
	err "#{get_red 'RubyFatal'}(#{ret}) #{str}"
	exit ret
end

#get_tagsObject



97
98
99
# File 'lib/classes/ricconf.rb', line 97

def get_tags()
  RicConf.new.get_tags
end

#get_usernameObject Also known as: username

/RicConf



92
93
94
# File 'lib/classes/ricconf.rb', line 92

def get_username
  $USER ||= `whoami`.strip
end

#load_auto_conf_migrated_to_ric_gem(confname, opts = {}) ⇒ Object

This wants to be a magic configuration loader who looks for configuration automatically in many places, like:

- ./.CONFNAME.yml
- ~/.CONFNAME.yml
- .CONFNAME/conf.yml

Loads a YAML file looked upon in common places and returns a hash with appropriate values, or an exception 
and maybe a nice explaination..


121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/init.rb', line 121

def load_auto_conf_migrated_to_ric_gem(confname, opts={})
  dirs          = opts.fetch :dirs,          ['.', '~', '/etc/']
  file_patterns = opts.fetch :file_patterns, [".#{confname}.yml", "#{confname}/conf.yml"]
  sample_hash   = opts.fetch :sample_hash,   {
     'load_auto_conf' => "please add an :sample_hash to me" , 
     :anyway => "I'm in #{__FILE__}" 
  }
  verbose       = opts.fetch :verbose,       true
  puts "load_auto_conf('#{confname}') start.." if verbose
  dirs.each{|d|
    dir = File.expand_path(d)
    deb "DIR: #{dir}"
    file_patterns.each{|fp|
      # if YML exists return the load..
      file = "#{dir}/#{fp}"
      deb " - FILE: #{file}"
      if File.exists?(file)
        puts "Found! #{green file}"
        yaml =  YAML.load( File.read(file) )
        deb "load_auto_conf('#{confname}') found: #{green yaml}"  
        return yaml
      end
    }
  }
  puts "Conf not found. Try this:
---------------------------
$ cat > ~/#{file_patterns.first}\n#{yellow "#Creatd by ric.rb:load_auto_conf()" + sample_hash.to_yaml }
---------------------------
"
  raise "LoadAutoConf: configuration not found for '#{confname}'!"
  return sample_hash
end

#lorem_ipsum(len = 0) ⇒ Object Also known as: lorem



256
257
258
259
260
# File 'lib/ric_strings.rb', line 256

def lorem_ipsum(len=0)
  len == 0 ? 
    LOREM_IPSUM :
    LOREM_IPSUM[0..len]
end

#obsolete(msg) ⇒ Object



155
156
157
158
159
# File 'lib/classes/debug_ric.rb', line 155

def obsolete(msg)
  puts "#{pink '_OBSOLETE_'} (#{file_line}): #{red msg}"
  #deb "TBD dammi la traccia chiamante, cazzo! Local functions: #{eval( 'local_variables') }"
  pgray("Obsolescense:\n -- " + caller().join("\n -- "))
end

#reload_doesnt_work_properly!(first_time = false, enable_debug = false) ⇒ Object

Configuratione… see _init @tags: obsolete, ric, r, lib, gem, init, loader @description: try instead



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/init.rb', line 45

def reload_doesnt_work_properly!(first_time=false,enable_debug=false)
  puts "[#{$$}] reload_doesnt_work_properly!(#{$0},#{first_time},#{enable_debug},#{$RELOADED_ONCE}) being called" if $RELOAD_DEBUG
  $RELOADED_ONCE += 1
  npass = $RICLIB['nreloaded']
  if npass > 1
    $stderr.puts "[ERR] More than first pass (pass=#{npass}): Should be quitting checcacchio!"
    #return 
  end
  debug_on("reload_doesnt_work_properly called with debug enabled!") if enable_debug
  str = "Reloaded Riclibs v#{$RICLIB_VERSION} -- per la #{$RICLIB['nreloaded']} a volta"
  first_time = false if $RICLIB['nreloaded'] > 1 
  modules_to_be_included = $RIC_LIB_MODULES + Sakuric.get_auto_files("classes/") 
  modules_to_be_included.each{ |cls| 
    was_necessary = require "#{$SAKURADIR}/lib/#{cls}.rb"
    deb "Pass[#{npass}] Loading: #{cls} (necessary: #{was_necessary})" rescue puts("nil #{$!}")
  }
  npass += 1
end

#ric_servicesObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/classes/ricconf.rb', line 14

def ric_services
  sane_service_regex = /^[a-z_\.-]+$/
  arr_services = [
     hostconf('services') , # .split(',').trim_all,  # host_services = 
     networkconf('services'), # .split(',').trim_all ,
  ] rescue [ "Eccezione: #{$!}" ]
  deb arr_services
  return arr_services.compact.flatten.join(',').split(',').trim_all.select{|srv| 
		# TODO rimuovi le right vuote
		# next if srv == ''
    ok = srv.match(sane_service_regex) 
    deb("ricconf.rb:#{__LINE__} Beware, illegal service here: ''#{red srv}'' (services: #{gray arr_services.join(', ')})") unless ok
    ok
  }
end

#silently(&block) ⇒ Object



162
163
164
165
166
167
168
169
# File 'lib/classes/debug_ric.rb', line 162

def silently(&block)
  deb( "[DEBUG] Calling silently! warn_level is '#{$VERBOSE}'" )
  warn_level = $VERBOSE
  $VERBOSE = nil
  result = block.call
  $VERBOSE = warn_level
  result
end

#stradebug(str) ⇒ Object Also known as: stradeb



97
98
99
# File 'lib/classes/debug_ric.rb', line 97

def stradebug(str)
  deb str, :tags => %w(verbose stradebug vvv)
end

#supports_64k_colors?Boolean

Terminal stuff

Returns:

  • (Boolean)


102
103
104
105
106
107
108
109
110
# File 'lib/classes/ricconf.rb', line 102

def supports_64k_colors?
  good_terminals = %w{ iTerm.app } # these support 64k, i.e. orange
  bad_terminals = %w{ Apple_Terminal }  # these support only 16 colors, i.e. red
  my_terminal = ENV['TERM_PROGRAM'].to_s
  return true if good_terminals.include?(my_terminal)
  return false if bad_terminals.include?(my_terminal)
  raise "Unknown terminal #{red my_terminal.quote}, please define me in: #{yellow __FILE__}"
  return nil
end

#title(s) ⇒ Object



243
244
245
# File 'lib/ric_strings.rb', line 243

def title(s)
  title_n(s)
end

#title_n(s, n = 2) ⇒ Object



246
247
248
# File 'lib/ric_strings.rb', line 246

def title_n(s,n=2)
  "== #{s} =="
end

#warning(s) ⇒ Object



130
131
132
# File 'lib/classes/debug_ric.rb', line 130

def warning(s)
	err "#{yellow 'WARN'} #{s}"
end