tools 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 111b792f5ad55d06285f46ee6341b8db57ed10f8a3f4e5656f580c7a22e4fa8c
4
- data.tar.gz: 4f3dc9bdd48a7ebef0f7b6a74341de51833e4e6d6fdb859bb38815ff58e02368
3
+ metadata.gz: 61950a249bdf881c27c25b12ad2fa00a1a367296a9d757e3e5d6a20c02bf215e
4
+ data.tar.gz: 7052e69306f06619d14742408f737ee4acb4c058962c1b840fff95160242c660
5
5
  SHA512:
6
- metadata.gz: f69dae9167d1b2df4ba9a2d5fd811d35717986a1fcb6da6dff142a29488421f0eaebf8f5134dfb5ea2eed232691edbdc4e520d5fd64c7a6cc5496e79b752d8dc
7
- data.tar.gz: a24148f3fed2b2ec77e5476000136108d107257bf3c25968e52a8b481cc8033a4a20a5c60336d61f0b194b8bba9e5d1df77b5bf7e6088dcf5d8c6e3159891eb3
6
+ metadata.gz: 81a58bbe0bd6e1233fa8f6e6929ea3fe594d28001fa580e8ca88583b4f554238ddfe6a0474f31be2f5d0a48e5a038fd0b6ceff364479ae0ba82a5ea46e36a3db
7
+ data.tar.gz: ab08b34343251ba9901376dfd60b0019ffc57fdc3369bda0286819c6a299f4b7bf52ed14c469fec75cd7536c8a0b33561a3fe73299c0d91e117e43f057cc3c5c
@@ -1 +1 @@
1
- tools
1
+ tools2.2.10
@@ -1 +1 @@
1
- ruby-2.2.9
1
+ ruby-2.2.10
data/aux2 CHANGED
@@ -3,13 +3,8 @@
3
3
  require 'rubygems'
4
4
  require 'tools'
5
5
 
6
- args = ["1","2","3"]
7
6
 
8
7
 
9
- ap args.extract_first.nil?
10
- ap args.extract_first
11
- ap args.extract_first
12
- ap args.extract_first
13
- ap args.extract_first.nil?
8
+ t = ToolsUtil.new
14
9
 
15
10
 
data/bin/tools CHANGED
@@ -40,6 +40,11 @@ class Tools_exec < Thor
40
40
  # ToolsConfig.config
41
41
  end
42
42
 
43
+ desc 'exec', ''
44
+ def exec(*args)
45
+ ToolsConsole.create_console
46
+ ToolsConsole.exec_console args
47
+ end
43
48
 
44
49
  desc 'console', ''
45
50
  def console
@@ -0,0 +1 @@
1
+ exit
@@ -0,0 +1,131 @@
1
+ class Array
2
+
3
+ # Self pop first element.
4
+ # @return first element
5
+ def extract_first
6
+ first = self[0]
7
+ self.delete_at(0)
8
+ return first
9
+ end
10
+
11
+ # Self extract symbol.
12
+ # @param symbol to retrive
13
+ # @return boolean
14
+ def extract_symbol symbol
15
+ status = false
16
+ if self.include? symbol
17
+ status = true
18
+ self.delete(symbol)
19
+ end
20
+ return status
21
+ end
22
+
23
+ # Self extract color.
24
+ # @return boolean
25
+ def extract_color
26
+ colors = String.colors
27
+ color = :default
28
+ self.each do |argument|
29
+ if argument.symbol?
30
+ if colors.include? argument
31
+ color = argument
32
+ self.delete(argument)
33
+ return color
34
+ end
35
+ else
36
+ if argument.string?
37
+ if argument.start_with? ':'
38
+ color_candidate = argument.gsub(':','').to_sym
39
+ color = color_candidate if colors.include? color_candidate
40
+ self.delete(argument)
41
+ return color
42
+ end
43
+ end
44
+ end
45
+ end
46
+ return color
47
+ end
48
+
49
+
50
+
51
+
52
+ # Self extract option.
53
+ # @param option to extract.
54
+ # @param single boolean to repeat
55
+ # @return variable boolean, arguments - extract_option
56
+ #
57
+ # Sample
58
+ # args = [xxx -x -vvv -c -vcv -v2 -vvvvv -s :json :yellow :red]
59
+ # args.extract_option '-x' => true
60
+ # args.extract_option '-f' => false
61
+ # args.extract_option '-v', false => 8
62
+ # args.extract_symbol :json => true
63
+ # args.extract_symbol :yaml => false
64
+ # args.extract_color => :yellow
65
+ # args.extract_color => red
66
+ # args => [-c -vcv -v2 -s ]
67
+ #
68
+ def extract_option option, single = true
69
+ if single
70
+ result = false
71
+ if self.include? option
72
+ index = self.index(option)
73
+ self.delete_at(index)
74
+ result = true
75
+ end
76
+ else
77
+ result = 0
78
+ self.each do |argument|
79
+ if argument.to_s.start_with? option
80
+ #puts "'#{option}' '#{argument}' #{argument.start_with? option} \n"
81
+ search_char = option.sub('-','')
82
+ aux_string = argument.to_s.sub('-','')
83
+ count = argument.to_s.count(search_char)
84
+ if (count == aux_string.size)
85
+ result = result + count
86
+ #self.delete(argument)
87
+ end
88
+ end
89
+
90
+ end
91
+ end
92
+ return result
93
+ end
94
+
95
+ def extract_option_value option, args={}
96
+
97
+ if args[:multiple].nil?
98
+ args[:multiple] = false
99
+ end
100
+
101
+ if args[:separator].nil?
102
+ args[:separator] = '='
103
+ end
104
+
105
+ result = false
106
+ if args[:multiple]
107
+ multiple_value = []
108
+ while self.include? option
109
+ index = self.index(option)
110
+ self.delete_at(index)
111
+ result = true
112
+ value = self.at(index)
113
+ multiple_value << self.at(index).split(args[:separator]).first
114
+ multiple_value << self.at(index).split(args[:separator]).last
115
+ self.delete_at(index)
116
+ end
117
+ return [result, multiple_value]
118
+ else
119
+ value = nil
120
+ while self.include? option
121
+ index = self.index(option)
122
+ self.delete_at(index)
123
+ result = true
124
+ value = self.at(index)
125
+ self.delete_at(index)
126
+ end
127
+ return [result, value]
128
+ end
129
+ end
130
+
131
+ end
@@ -62,7 +62,6 @@ class ToolsCache
62
62
  aux.merge! values
63
63
  cache[key] = aux
64
64
  rescue Exception => e
65
- log_file = ToolsUtil.get_variable "#{logger_name}_log_file"
66
65
  ToolsDisplay.show "\tError in ToolsCache: #{e.exception}", :light_yellow
67
66
  exit
68
67
  end
@@ -87,28 +86,28 @@ class ToolsCache
87
86
  # value = args.extract_first
88
87
  # cache.set(key, value, Time.now)
89
88
 
90
- when 'setext'
91
- key = args.extract_first
92
- values = args.extract_first
93
- unless cache.key?(key)
94
- ToolsCache.cmdapi_set key, values
95
- else
96
- aux = cache[key]
97
- values.keys.each do |value|
98
- aux[value] = values[value]
99
- end
100
- ToolsCache.cmdapi_set key, aux
101
- end
102
-
103
- when 'unsetext'
104
- key = args.extract_first
105
- key_internal = args.extract_first
106
- if cache.key?(key)
107
- aux = cache[key]
108
- if aux.key? key_internal
109
- aux
110
- end
111
- end
89
+ # when 'setext'
90
+ # key = args.extract_first
91
+ # values = args.extract_first
92
+ # unless cache.key?(key)
93
+ # ToolsCache.cmdapi_set key, values
94
+ # else
95
+ # aux = cache[key]
96
+ # values.keys.each do |value|
97
+ # aux[value] = values[value]
98
+ # end
99
+ # ToolsCache.cmdapi_set key, aux
100
+ # end
101
+
102
+ # when 'unsetext'
103
+ # key = args.extract_first
104
+ # key_internal = args.extract_first
105
+ # if cache.key?(key)
106
+ # aux = cache[key]
107
+ # if aux.key? key_internal
108
+ # aux
109
+ # end
110
+ # end
112
111
 
113
112
  when 'unset'
114
113
  key = args.extract_first
@@ -30,17 +30,18 @@ class ToolsConfig
30
30
  config = File.open(config_file, 'w')
31
31
  config.write JSON.pretty_generate(data)
32
32
  config.close
33
- ToolsLog.tools_info "Json config file '#{config_file}' was created!'"
34
- return true
33
+ #ToolsLog.tools_info "Json config file '#{config_file}' was created!'"
34
+ #return true
35
35
  when :yaml
36
36
  config = File.open(config_file, 'w')
37
37
  config.write data.to_yaml
38
38
  config.close
39
- ToolsLog.tools_info "Json config file '#{config_file}' was created!'"
40
- return true
39
+ #ToolsLog.tools_info "Json config file '#{config_file}' was created!'"
40
+ #return true
41
41
  end
42
42
  else
43
- ToolsLog.tools_warn "The file #{config_file} really exist. leaving operation...."
43
+ #ToolsLog.tools_warn "The file #{config_file} really exist. leaving operation...."
44
+ return false
44
45
  end
45
46
  ToolsUtil.set_variable "#{config_name}_config_file", config_file
46
47
  ToolsUtil.set_variable "#{config_name}_config_type", config_type
@@ -2,6 +2,20 @@ require 'singleton'
2
2
  class ToolsConsole
3
3
  include Singleton
4
4
 
5
+ def self.exec_console args
6
+ command_name = args.extract_first
7
+ cmd = Prompt.application.commands.select {|c| c.name.eql? command_name}.first
8
+ unless cmd.nil?
9
+ cmd.run cmd
10
+ return true
11
+ else
12
+ ToolsDisplay.show "Invalid command '#{command_name}'.! Aborting...", :light_yellow
13
+ return false
14
+ end
15
+ end
16
+
17
+ def initialize(options = {})
18
+ end
5
19
 
6
20
  def self.create_console
7
21
 
@@ -9,24 +23,6 @@ class ToolsConsole
9
23
 
10
24
  group "Console commands"
11
25
 
12
- desc "configure"
13
- param :config_type , "Config type search for roots locations...", %(location show)
14
- command "config :config_type" do |config_type|
15
-
16
- Prompt.application.prompt = "#{Tools.configuration.console_prompt} console > ".light_blue
17
- puts "Choise yuor config action .:".yellow
18
-
19
- end
20
-
21
- desc "history"
22
- command "history" do
23
- File.open(@history_file, 'r') do |f|
24
- while line = f.gets
25
- puts line
26
- end
27
- end
28
- end
29
-
30
26
  desc "test"
31
27
  command "test" do
32
28
  puts 'Im a test.!'.yellow
@@ -34,9 +30,6 @@ class ToolsConsole
34
30
 
35
31
  end
36
32
 
37
- def self.my_method_missing
38
- ap "my_method_missing"
39
- end
40
33
 
41
34
  def self.run_console
42
35
  Prompt.application.prompt = "#{Tools.configuration.console_prompt} console > ".light_green
@@ -61,7 +54,7 @@ end
61
54
 
62
55
  # def commands
63
56
 
64
- # extend Prompt::DSL
57
+ # extend Prompt::DSL
65
58
 
66
59
  # group "Commands"
67
60
 
@@ -84,7 +77,7 @@ end
84
77
  # ap k
85
78
  # ap v
86
79
  # end
87
- # else
80
+ # else
88
81
  # ap Tools.get_variable param
89
82
  # end
90
83
  # end
@@ -96,7 +89,7 @@ end
96
89
 
97
90
  # unless Tools.configuration.info[:directorys_to][from].nil?
98
91
  # from = Tools.configuration.info[:directorys_to][from]
99
- # from += ask("?? ")
92
+ # from += ask("?? ")
100
93
  # else
101
94
  # sourcefiles = File.join("**", from)
102
95
  # Dir.glob(sourcefiles).each do |source|
@@ -139,7 +132,7 @@ end
139
132
 
140
133
 
141
134
  # Prompt.application.prompt = " tools > ".light_red
142
- # history_file = ".tools-history"
135
+ # history_file = ".tools-history"
143
136
  # Prompt::Console.start history_file
144
137
 
145
138
  # end
@@ -2,6 +2,9 @@ require 'singleton'
2
2
  class ToolsDisplay
3
3
  include Singleton
4
4
 
5
+ def initialize(options = {})
6
+ end
7
+
5
8
  # Tools to awesome prints
6
9
  #
7
10
  # ToolsDisplay.show "teste"
@@ -19,21 +22,29 @@ class ToolsDisplay
19
22
 
20
23
  color = arguments.extract_color
21
24
  sameline = arguments.extract_symbol :sameline
22
- nocolor = arguments.extract_symbol :nocolor
25
+ #nocolor = arguments.extract_symbol :nocolor
23
26
  colorized = arguments.extract_symbol :colorized
24
27
 
25
28
  unless sameline
26
29
  post += "\n"
27
30
  end
28
- unless nocolor
29
- printf "#{post}".colorize(color)
31
+
32
+ if colorized
33
+ printf "#{post}"
30
34
  else
31
- if colorized
32
- ap post
33
- else
34
- printf "#{post}"
35
- end
35
+ printf "#{post}".colorize(color)
36
36
  end
37
+
38
+ # unless nocolor
39
+ # printf "#{post}".colorize(color)
40
+ # else
41
+ # if colorized
42
+ # ap post
43
+ # else
44
+ # printf "#{post}"
45
+ # end
46
+ # end
47
+
37
48
  end
38
49
 
39
50
  def self.show_colorize *arguments
@@ -6,6 +6,24 @@ class ToolsFiles
6
6
  end
7
7
 
8
8
 
9
+ # Purge files in directory
10
+ #
11
+ # Sample
12
+ # ToolsFiles. purge_files Cmdapi.configuration.home+'/.cmdapi/backup', '*', 14*24*60*60'
13
+ #
14
+ # @param path_to_clean
15
+ # @param select (sample: *.log)
16
+ # @param elipsed_time in seconds (sample: 2 weeks = 14*24*60*60)
17
+ # @return
18
+ def self.purge_files path, select, time #Cmdapi.configuration.home+'/.cmdapi/backup', '*', 14*24*60*60
19
+ to_clean = Dir.glob(File.join(path, select)).select { |a|
20
+ Time.now - File.ctime(a) > time }
21
+ to_clean.each do |file_to_delete|
22
+ File.delete(file_to_delete)
23
+ end
24
+ end
25
+
26
+
9
27
  # Create a directory in work area
10
28
  #
11
29
  # Sample
@@ -59,6 +77,21 @@ class ToolsFiles
59
77
  end
60
78
  end
61
79
 
80
+ # Delete a file in work area
81
+ #
82
+ # Sample
83
+ #
84
+ # ToolsFiles.delete_file file_to_delete
85
+ # @param file_to_delete Object
86
+ # @return
87
+ def self.remove_file file_to_removee
88
+ if File.exists? file_to_removee
89
+ file = FileUtils.remove_file( file_to_removee )
90
+ return file
91
+ end
92
+ end
93
+
94
+
62
95
  def self.open_file file, default_editor=nil
63
96
  begin
64
97
  if default_editor.nil?
@@ -71,4 +104,7 @@ class ToolsFiles
71
104
  end
72
105
  end
73
106
 
74
- end
107
+ end
108
+
109
+
110
+