ric 0.11.4 → 0.11.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,9 @@
1
1
  # would like to have this in YML format :)
2
- 2011-01-24 v0.11.4:
2
+ 2011-02-06 v0.11.6:
3
+ - Added xconf
4
+ 2011-02-06 v0.11.5:
5
+ - Added septober binary
6
+ 2011-02-06 v0.11.4:
3
7
  - Added some tests but they dont work :P
4
8
  2011-01-24 v0.11.3:
5
9
  - Added debug() alias
data/Manifest CHANGED
@@ -8,17 +8,21 @@ VERSION
8
8
  bin/itunes
9
9
  bin/ric
10
10
  bin/riclib-test
11
+ bin/septober
11
12
  init.rb
12
13
  lib/rails/acts_as_carlesso.rb
13
14
  lib/rails/helpers/rails_helper.rb
14
15
  lib/ric.rb
15
16
  lib/ric/colors.rb
17
+ lib/ric/conf.rb
16
18
  lib/ric/debug.rb
19
+ lib/ric/files.rb
17
20
  lib/ric/html.rb
18
21
  lib/ric/zibaldone.rb
19
22
  lib/ruby_classes/strings.rb
20
23
  lib/tmp/uniquify.rb
21
24
  rails/init.rb
25
+ ric.gemspec
22
26
  sbin/reboot.rb
23
27
  sbin/ric_reboot.rb
24
28
  test/strings_helper.rb
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.11.4
1
+ 0.11.6
@@ -0,0 +1,246 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ =begin
4
+ ############################################################
5
+ # $Id: script.rb 5582 2011-01-18 15:18:36Z rcarlesso $
6
+ ##########################################################
7
+ @author: Riccardo Carlesso
8
+ @email: riccardo.carlesso@heanet.ie
9
+ @maturity: development
10
+ @language: Ruby
11
+ @synopsis: Brief Description here
12
+ @tags: development, rcarlesso
13
+ @description:
14
+ septober.heroku.com client to add and list todos!
15
+
16
+ @history:
17
+ 0.9.4 2011-02-04 added 'done' action (and 'delete' ?)
18
+ 0.9.3 2011-02-04 better 'list'
19
+ 0.9.2 2011-02-04 'add' operation succefully added!
20
+ 0.9.1 2011-01-18 First version
21
+ ############################################################
22
+ =end
23
+ $PROG_VER = '0.9.4'
24
+
25
+ require 'optparse'
26
+ require 'rubygems'
27
+ require 'ric'
28
+ require 'active_resource'
29
+ require 'socket'
30
+
31
+ $DEBUG = false
32
+
33
+ $opts = {
34
+ :app_name => 'septober client',
35
+ :hello => 'Welcome to this terrific application',
36
+ :septober_url => 'http://septober.heroku.com/' ,
37
+ :dflt_config => '~/.septober.yml' ,
38
+ :local => false ,
39
+ }
40
+
41
+ class RemoteTodo < ActiveResource::Base
42
+ self.site = "http://septober.example.com/" # uninitialized
43
+ self.element_name = 'todo'
44
+ self.timeout = 5
45
+ #self.proxy = nil
46
+ @@sample_yml_config = 'septober:
47
+ # YAML file with septober configuration. For more info: http://septober.heroku.com/
48
+ site: "http://localhost:3000/api/" # or http://septober.heroku.com/api/
49
+ user: guest
50
+ password: guest'
51
+
52
+ # self.ssl_options = {:cert => OpenSSL::X509::Certificate.new(File.open(pem_file))
53
+ # :key => OpenSSL::PKey::RSA.new(File.open(pem_file)),
54
+ # :ca_path => "/path/to/OpenSSL/formatted/CA_Certs",
55
+ # :verify_mode => OpenSSL::SSL::VERIFY_PEER}
56
+
57
+ def self.import_config(file=nil)
58
+ file ||= $opts[:dflt_config]
59
+ real_file = File.expand_path file
60
+ deb "Importing config from #{file}.."
61
+ if File.exists?(real_file)
62
+ #puts "TODO import from #{file} (local=#{$opts[:local]})"
63
+ sub_conf = $opts[:local] ? 'septober_local' : 'septober'
64
+ conf_hash = YAML.load_file(real_file)[sub_conf] rescue nil
65
+ self.site = conf_hash['site']
66
+ self.user = conf_hash['user']
67
+ self.password = conf_hash['password']
68
+ deb "Conf imported successuflly: #{blue self.user}@#{self.site}"
69
+ else
70
+ pred "Missing file: #{file} !!! Try to do the following:"
71
+ puts "cat > #{file}\n#{@@sample_yml_config rescue "Err#{$!}" }"
72
+ exit 79
73
+ end
74
+ end
75
+
76
+ def to_s
77
+ self.name
78
+ end
79
+
80
+ def colored_project_name()
81
+ colora(project.color || :grey ,project.name)
82
+ end
83
+
84
+ # TODO put this into todo.rb model and add it to the controller like "cli_colored_string" and "cli_neutral_string"
85
+ def colored_due_explaination(override_explaination=nil)
86
+ mycolor = case due_explaination
87
+ when 'overdue' ; :red
88
+ when 'close' ; :yellow
89
+ when 'far' ; :green
90
+ else ; :gray
91
+ #default ; :gray
92
+ end
93
+ return colora(mycolor, override_explaination || due_explaination)
94
+ end
95
+
96
+ def priority_str(priority)
97
+ case priority.to_s
98
+ when '1' ; return '--'
99
+ when '2' ; return '-'
100
+ when '3' ; return ' '
101
+ when '4' ; return '!'
102
+ when '5' ; return '!!'
103
+ end
104
+ return "'?' #{priority}"
105
+ end
106
+
107
+ def show_entry(opts={})
108
+ mywhere = where ? azure( " @#{where}") : ''
109
+ return sprintf "%-3d %-30s %2s %s %s%s",
110
+ id, colored_project_name , priority_str(priority), colored_due_explaination(due), name, mywhere
111
+ end
112
+
113
+ def show_full_entry(opts={})
114
+ attributes = %w{name id due where url progress_status active description }
115
+ key_vals = attributes.map{|attr| [attr,send(attr)] } # array of [key, val]
116
+ key_vals << ['ProjectName', project.name ]
117
+ key_vals.map{ |k,v| "#{k}: #{v}" }.join("\n")
118
+ end
119
+ end # /RemoteTodo
120
+
121
+
122
+ #############################
123
+ # Program start..
124
+
125
+ def usage(comment=nil)
126
+ puts "#{$0} v.#{$PROG_VER}"
127
+ puts "Usage: #{File.basename $0} [-dhjv] [--local] [--no-colors] OPTIONS"
128
+ puts " add <FREE TEXT> # V adds new task in free text with some magic.."
129
+ puts " delete <ID> # T delete ticket.ID (DONT USE IF U CAN!)"
130
+ puts " list # V shows a list of your todos yet to complete"
131
+ puts " show <ID> # V shows details about todo with id=ID"
132
+ puts " done <ID> # T posts ticket.ID :done (resolved)"
133
+ puts " mail <ID> # T mail to yourself ticket.ID !!!"
134
+ #puts " search <QUERY> # look for TODOs relating to 'QUERY' string"
135
+ pred comment if comment
136
+ exit 78
137
+ end
138
+
139
+ def bannerino(desc)
140
+ "#Todo #{white desc.to_s} (user: #{blue RemoteTodo.user}@#{cyan RemoteTodo.site.to_s.split('/')[2] })"
141
+ end
142
+
143
+ def todo_list(opts={})
144
+ show_only_active = opts.fetch :only_active, true
145
+ puts bannerino( "Index" )
146
+ all = RemoteTodo.find(:all)
147
+ all.each{|todo|
148
+ puts( todo.show_entry ) unless( show_only_active && ! todo.active )
149
+ } if all
150
+ end
151
+
152
+ def todo_add(words_from_argv)
153
+ puts bannerino( "Add(#{words_from_argv})" )
154
+ t = RemoteTodo.create(
155
+ :name => words_from_argv,
156
+ :description => "sent by CLI #{$0} v.#{$PROG_VER}, due tomorrow by test",
157
+ #:due => Date.tomorrow,
158
+ :where => Socket.gethostname,
159
+ :source => "CLI v.#{$PROG_VER}"
160
+ #:project_id => 5,
161
+ #:priority => 4
162
+ )
163
+ deb "DEB todo: #{t}"
164
+ ret = t.save
165
+ if t.errors
166
+ pred "Some errors: '#{t.errors.full_messages}'"
167
+ end
168
+ #puts "save returned: #{ret}"
169
+ if ret
170
+ pgreen "Todo created successfully:\n #{t.inspect}"
171
+ else
172
+ pred "Some error saving todo: #{t.inspect}"
173
+ end
174
+ pgray "TODO get meaningful explaination from api/todos_controller!"
175
+ #puts "errors: #{ret.errors}"
176
+ end
177
+
178
+ def todo_show(id)
179
+ todo = RemoteTodo.find(id)
180
+ puts bannerino("Show(#{id})")
181
+ puts( todo.show_full_entry )
182
+ end
183
+
184
+ def todo_done(id,done_or_undone=true)
185
+ todo_generic_put(id,:done)
186
+ end
187
+ def todo_toggle(id,done_or_undone=true)
188
+ todo_generic_put(id,:done)
189
+ end
190
+
191
+ def todo_generic_put(id,action,opts={})
192
+ puts bannerino("GenericAction(#{action},#{id})")
193
+ begin
194
+ todo = RemoteTodo.find(id)
195
+ puts "Todo.#{id} ok #{green action}: #{yellow( todo.to_s )}"
196
+ todo.put(action, :my_action => action, :from_cli_in_test_ric => Socket.gethostname ) # test stuff
197
+ rescue ActiveResource::ResourceNotFound
198
+ puts "Sorry ResourceNotFound: #{red $!}"
199
+ exit 11
200
+ rescue ActiveResource::ServerError
201
+ puts "Sorry ServerError: #{red $!}"
202
+ exit 12
203
+ end
204
+ # todo is good
205
+ #todo.put(:generic_action, :my_action => action)
206
+ end
207
+
208
+ def todo_search(q)
209
+ puts "# Todo.Search('#{q}') (user: #{blue RemoteTodo.user})"
210
+ pred "To Be implemented Yet"
211
+ end
212
+
213
+ def init
214
+ #$opts = {}
215
+ optparse = OptionParser.new do |opts|
216
+ opts.banner = "#{$0} v.#{$PROG_VER}\n Usage: #{File.basename $0} [add|list|done|del] [args]"
217
+ opts.on( '-c', '--config', 'uses a different configfile from: '+$opts[:dflt_config] ) { $opts[:jabba] = true }
218
+ opts.on( '-d', '--debug', 'enables debug (DFLT=false)' ) { $opts[:debug] = true }
219
+ opts.on( '-h', '--help', 'Display this screen' ) { puts(opts); exit 1 }
220
+ opts.on( '-j', '--jabba', 'Activates my Jabber powerful CLI' ) { $opts[:jabba] = true }
221
+ opts.on( '-l', '--local', 'uses local instead' ) { $opts[:local] = true }
222
+ opts.on( '-v', '--verbose', 'Output more information' ) { $opts[:verbose] = true}
223
+ end
224
+ optparse.parse!
225
+ RemoteTodo.import_config()
226
+ end
227
+
228
+ def main()
229
+ init()
230
+ # Maybe you may want to check on ARGV
231
+ unless ARGV.size > 0
232
+ usage "Give me at least 1 argument" # Maybe default to list?!?
233
+ end
234
+ # i dont need it for help :)
235
+ case ARGV[0]
236
+ when 'list' ; todo_list()
237
+ when 'show' ; todo_show(ARGV[1])
238
+ when 'done' ; todo_done(ARGV[1],true)
239
+ when 'add' ; todo_add(ARGV[1..-1].join(' ')) # all except last one
240
+ else ; usage "Unrecognized command: #{ARGV[0]}"
241
+ end
242
+ end
243
+
244
+ #########################################################
245
+ # real program...
246
+ main()
data/lib/ric.rb CHANGED
@@ -1,6 +1,8 @@
1
1
 
2
- # Riccardo New Stuff
3
2
  require 'ric/colors'
3
+ require 'ric/conf'
4
+ require 'ric/debug'
5
+ require 'ric/files'
4
6
  require 'ric/debug'
5
7
  require 'ric/html'
6
8
  require 'ric/zibaldone'
@@ -0,0 +1,47 @@
1
+ module Ric
2
+ module Conf
3
+
4
+
5
+ =begin
6
+ This wants to be a magic configuration loader who looks for configuration automatically in many places, like:
7
+
8
+ - ./.CONFNAME.yml
9
+ - ~/.CONFNAME.yml
10
+ - .CONFNAME/conf.yml
11
+
12
+ Loads a YAML file looked upon in common places and returns a hash with appropriate values, or an exception
13
+ and maybe a nice explaination..
14
+
15
+ so you can call load_auto_conf('foo') and it will look throughout any ./.foo.yml, ~/.foo.yml or even /etc/foo.yml !
16
+
17
+ =end
18
+
19
+ def load_auto_conf(confname, opts={})
20
+ dirs = opts.fetch :dirs, ['.', '~', '/etc/', '/etc/ric/auto_conf/']
21
+ file_patterns = opts.fetch :file_patterns, [".#{confname}.yml", "#{confname}/conf.yml"]
22
+ sample_hash = opts.fetch :sample_hash, { 'load_auto_conf' => "please add an :sample_hash to me" , :anyway => "I'm in #{__FILE__}"}
23
+ verbose = opts.fetch :verbose, true
24
+ puts "load_auto_conf('#{confname}') start.." if verbose
25
+ dirs.each{|d|
26
+ dir = File.expand_path(d)
27
+ deb "DIR: #{dir}"
28
+ file_patterns.each{|fp|
29
+ # if YML exists return the load..
30
+ file = "#{dir}/#{fp}"
31
+ deb " - FILE: #{file}"
32
+ if File.exists?(file)
33
+ puts "Found! #{green file}"
34
+ yaml = YAML.load( File.read(file) )
35
+ deb "load_auto_conf('#{confname}') found: #{green yaml}"
36
+ return yaml
37
+ end
38
+ }
39
+ }
40
+ puts "Conf not found. Try this:\n---------------------------\n$ cat > ~/#{file_patterns.first}\n#{yellow "#Creatd by ric.rb:load_auto_conf()\n" +sample_hash.to_yaml}\n---------------------------\n"
41
+ raise "LoadAutoConf: configuration not found for '#{confname}'!"
42
+ return sample_hash
43
+ end
44
+
45
+
46
+ end
47
+ end
@@ -0,0 +1,59 @@
1
+ module Ric
2
+ module Files
3
+
4
+ =begin
5
+ # This tries to implement the xcopy for my git programs
6
+ # similar to xcopy
7
+
8
+ Originally called 'tra va sa'
9
+ =end
10
+ def xcopy(from,to,glob_files, opts={})
11
+ n_actions = 0
12
+ puts "+ Travasing: #{yellow from} ==> #{green to}"
13
+ verbose = opts.fetch :verbose, true
14
+
15
+ unless File.exists?("#{to}/.git")
16
+ fatal "Sorry cant travase data to an unversioned dir, u'know the casin?!?"
17
+ exit 1
18
+ end
19
+ unless File.exists?("#{to}/.safe_xcopy")
20
+ fatal 12, "Sorry cant travase data unless you ask me to. You have to do this before:\n #{yellow "touch #{to}/.safe_xcopy"} . Thanks"
21
+ end
22
+
23
+ # With this i can understand what has been deleted, with lots of magic from git on both ends.. :)
24
+ deb "+ First the differences:"
25
+ deb `diff -qr #{from} #{to} |egrep -v '\\.git' `
26
+
27
+ puts "+ Files: #{cyan glob_files}"
28
+ Dir.chdir(from)
29
+ Dir.glob(glob_files).each{ |file|
30
+ from_file = "#{from}/#{file}"
31
+ to_file = "#{to}/#{file}"
32
+ destdir = File.dirname(to_file)
33
+ deb "Copying: #{yellow from_file}.."
34
+ # could need creating the dir..
35
+ if File.exists?(destdir)
36
+ # just copy the file
37
+ command = "cp \"#{from_file}\" \"#{to_file}\""
38
+ else
39
+ # mkdir dest AND copy file
40
+ pred "Hey, Dir '#{destdir}' doesnt exist! Creating it.."
41
+ command = "mkdir -p \"#{destdir}\" && cp \"#{from_file}\" \"#{to_file}\""
42
+ end
43
+
44
+ if opts.fetch(:dryrun, false)
45
+ puts "[DRYRUN] Skipping #{gray command}"
46
+ else
47
+ ret = `#{command} 2>&1`
48
+ puts "EXE: #{gray command}" if verbose
49
+ n_actions += 1
50
+ print( "[ret=$?]", ret, "\n") if (ret.length > 1 || $? != 0) # if output or not zero
51
+ end
52
+ }
53
+ puts "#{n_actions} commands executed."
54
+ end
55
+
56
+
57
+ end
58
+ end
59
+
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ric}
5
- s.version = "0.11.4"
5
+ s.version = "0.11.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Riccardo Carlesso"]
@@ -11,9 +11,9 @@ Gem::Specification.new do |s|
11
11
  My name is Riccardo, hence 'ric' (ok I admit it, this was just ot prove Im able to build a sentence
12
12
  with hence!)}
13
13
  s.email = %q{['p','ll','diusbonton].join('a') @ gmail.com}
14
- s.executables = ["itunes", "ric", "riclib-test"]
15
- s.extra_rdoc_files = ["LICENSE", "README.md", "TODO", "bin/itunes", "bin/ric", "bin/riclib-test", "lib/rails/acts_as_carlesso.rb", "lib/rails/helpers/rails_helper.rb", "lib/ric.rb", "lib/ric/colors.rb", "lib/ric/debug.rb", "lib/ric/html.rb", "lib/ric/zibaldone.rb", "lib/ruby_classes/strings.rb", "lib/tmp/uniquify.rb"]
16
- s.files = ["HISTORY.yml", "LICENSE", "Manifest", "README.md", "Rakefile", "TODO", "VERSION", "bin/itunes", "bin/ric", "bin/riclib-test", "init.rb", "lib/rails/acts_as_carlesso.rb", "lib/rails/helpers/rails_helper.rb", "lib/ric.rb", "lib/ric/colors.rb", "lib/ric/debug.rb", "lib/ric/html.rb", "lib/ric/zibaldone.rb", "lib/ruby_classes/strings.rb", "lib/tmp/uniquify.rb", "rails/init.rb", "sbin/reboot.rb", "sbin/ric_reboot.rb", "test/strings_helper.rb", "test/test_helper.rb", "var/www/index.html", "ric.gemspec"]
14
+ s.executables = ["itunes", "ric", "riclib-test", "septober"]
15
+ s.extra_rdoc_files = ["LICENSE", "README.md", "TODO", "bin/itunes", "bin/ric", "bin/riclib-test", "bin/septober", "lib/rails/acts_as_carlesso.rb", "lib/rails/helpers/rails_helper.rb", "lib/ric.rb", "lib/ric/colors.rb", "lib/ric/conf.rb", "lib/ric/debug.rb", "lib/ric/files.rb", "lib/ric/html.rb", "lib/ric/zibaldone.rb", "lib/ruby_classes/strings.rb", "lib/tmp/uniquify.rb"]
16
+ s.files = ["HISTORY.yml", "LICENSE", "Manifest", "README.md", "Rakefile", "TODO", "VERSION", "bin/itunes", "bin/ric", "bin/riclib-test", "bin/septober", "init.rb", "lib/rails/acts_as_carlesso.rb", "lib/rails/helpers/rails_helper.rb", "lib/ric.rb", "lib/ric/colors.rb", "lib/ric/conf.rb", "lib/ric/debug.rb", "lib/ric/files.rb", "lib/ric/html.rb", "lib/ric/zibaldone.rb", "lib/ruby_classes/strings.rb", "lib/tmp/uniquify.rb", "rails/init.rb", "ric.gemspec", "sbin/reboot.rb", "sbin/ric_reboot.rb", "test/strings_helper.rb", "test/test_helper.rb", "var/www/index.html"]
17
17
  s.homepage = %q{http://github.com/palladius/riclib}
18
18
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ric", "--main", "README.md"]
19
19
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ric
3
3
  version: !ruby/object:Gem::Version
4
- hash: 59
4
+ hash: 63
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 11
9
- - 4
10
- version: 0.11.4
9
+ - 6
10
+ version: 0.11.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Riccardo Carlesso
@@ -28,6 +28,7 @@ executables:
28
28
  - itunes
29
29
  - ric
30
30
  - riclib-test
31
+ - septober
31
32
  extensions: []
32
33
 
33
34
  extra_rdoc_files:
@@ -37,11 +38,14 @@ extra_rdoc_files:
37
38
  - bin/itunes
38
39
  - bin/ric
39
40
  - bin/riclib-test
41
+ - bin/septober
40
42
  - lib/rails/acts_as_carlesso.rb
41
43
  - lib/rails/helpers/rails_helper.rb
42
44
  - lib/ric.rb
43
45
  - lib/ric/colors.rb
46
+ - lib/ric/conf.rb
44
47
  - lib/ric/debug.rb
48
+ - lib/ric/files.rb
45
49
  - lib/ric/html.rb
46
50
  - lib/ric/zibaldone.rb
47
51
  - lib/ruby_classes/strings.rb
@@ -57,23 +61,26 @@ files:
57
61
  - bin/itunes
58
62
  - bin/ric
59
63
  - bin/riclib-test
64
+ - bin/septober
60
65
  - init.rb
61
66
  - lib/rails/acts_as_carlesso.rb
62
67
  - lib/rails/helpers/rails_helper.rb
63
68
  - lib/ric.rb
64
69
  - lib/ric/colors.rb
70
+ - lib/ric/conf.rb
65
71
  - lib/ric/debug.rb
72
+ - lib/ric/files.rb
66
73
  - lib/ric/html.rb
67
74
  - lib/ric/zibaldone.rb
68
75
  - lib/ruby_classes/strings.rb
69
76
  - lib/tmp/uniquify.rb
70
77
  - rails/init.rb
78
+ - ric.gemspec
71
79
  - sbin/reboot.rb
72
80
  - sbin/ric_reboot.rb
73
81
  - test/strings_helper.rb
74
82
  - test/test_helper.rb
75
83
  - var/www/index.html
76
- - ric.gemspec
77
84
  has_rdoc: true
78
85
  homepage: http://github.com/palladius/riclib
79
86
  licenses: []