ztrening 0.0.3 → 0.0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +5 -0
- data/bin/zt +36 -32
- data/lib/ztrening.rb +67 -11
- data/test/test_ztrening.rb +3 -0
- metadata +5 -4
data/History.txt
CHANGED
data/bin/zt
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
|
-
|
3
|
+
|
4
|
+
# TODO: prebaciti ovo lib, nova klasa - eval 'CLI.exec ARGV'
|
4
5
|
|
5
6
|
require 'rubygems'
|
6
7
|
require File.expand_path(File.dirname(__FILE__) + "/../lib/ztrening")
|
@@ -11,6 +12,7 @@ USAGE = <<EOS
|
|
11
12
|
usage: zt.rb [refresh, list, find, open]
|
12
13
|
find [string]
|
13
14
|
open [filename] => file mora imati '// zt [ime zadatka]' na 1. liniji
|
15
|
+
todo [add, del[ete]/rem[ove]]
|
14
16
|
-h, --help
|
15
17
|
EOS
|
16
18
|
|
@@ -23,11 +25,12 @@ if !ARGV[0] || ARGV[0]=='-h' || ARGV[0]=='--help'
|
|
23
25
|
end
|
24
26
|
|
25
27
|
|
26
|
-
if ARGV[0] == '
|
28
|
+
if ARGV[0] == '-v' || ARGV[0] == '--version'
|
29
|
+
puts "Version: #{ZtreningM::VERSION}"
|
30
|
+
elsif %w(refresh download).include? ARGV[0]
|
27
31
|
z = Ztrening.new :web
|
28
32
|
puts 'New list downloaded'
|
29
33
|
elsif ARGV[0] == 'open' && ARGV[1]
|
30
|
-
# TODO: maknuti gore const file regex
|
31
34
|
z = Ztrening.new
|
32
35
|
|
33
36
|
if File.exists? ARGV[1]
|
@@ -64,45 +67,22 @@ elsif ARGV[0] == 'open' && ARGV[1]
|
|
64
67
|
end
|
65
68
|
|
66
69
|
if z.lista.nil? or z.lista.empty?
|
67
|
-
hh =
|
68
|
-
puts "Nema zadataka s
|
70
|
+
hh = ime.nil? ? "ID-om" : "imenom"
|
71
|
+
puts "Nema zadataka s takvim #{hh}!"
|
69
72
|
end
|
70
73
|
|
71
|
-
hh =
|
74
|
+
hh = ime.nil? ? "ID" : "ime"
|
72
75
|
puts "Oznaka zadatka iz datoteke: #{str} (#{hh})"
|
73
76
|
|
74
77
|
puts "cnt: #{z.lista.count}"
|
75
|
-
|
76
|
-
# puts "Postoji vise zadataka koji sadrze '#{ime}';"
|
77
|
-
# puts "Odaberi jedan:"
|
78
|
-
# limit, ok = 10, 1
|
79
|
-
# if z.lista.count > limit
|
80
|
-
# puts "Broj nadjenih zadataka prelazi limit (#{limit}) !"
|
81
|
-
# exit
|
82
|
-
# end
|
83
|
-
# z.lista.each_with_index { |l,idx| printf "%4s: %s\n", idx+1, l[1] }
|
84
|
-
# while ok > 0
|
85
|
-
# print " > "; STDOUT.flush
|
86
|
-
# id = STDIN.gets.chomp.to_i
|
87
|
-
# if id.nil? or id == '' or !id.is_a?(Integer)
|
88
|
-
# puts " ?? err 1"
|
89
|
-
# end
|
90
|
-
# # id -= 1
|
91
|
-
# if !(1..(z.lista.count)).include?(id)
|
92
|
-
# puts "izvan rangea!"; ok=1
|
93
|
-
# else ok=0 end
|
94
|
-
# end
|
95
|
-
# puts "Otvaram zadatak: #{z.lista[id.to_i-1][1]}"
|
96
|
-
# z.open id-1
|
97
|
-
# else
|
98
|
-
# z.open :name => ime | :id => id
|
78
|
+
|
99
79
|
z.open id
|
100
80
|
end
|
101
81
|
elsif ARGV[0] == 'find'
|
102
|
-
if ARGV[1]
|
82
|
+
if ARGV[1..ARGC-1]
|
103
83
|
z = Ztrening.new
|
104
84
|
#z.find ARGV[1..32].join ' '
|
105
|
-
if ARGV[1]
|
85
|
+
if ARGV[1][/.+/]
|
106
86
|
z.find ARGV[1]
|
107
87
|
z.lista_txt
|
108
88
|
else
|
@@ -115,6 +95,30 @@ elsif ARGV[0] == 'find'
|
|
115
95
|
elsif ARGV[0] == 'list'
|
116
96
|
z = Ztrening.new
|
117
97
|
z.lista_txt
|
98
|
+
# elsif ARGV[0] == 'todo'
|
99
|
+
# if %w[show list ls].include? ARGV[1]
|
100
|
+
# elsif %w[add].include? ARGV[1]
|
101
|
+
# elsif %w[del rem delete remove].include? ARGV[1]
|
102
|
+
# end
|
103
|
+
# TODO: zt set ZADATAK STATUS
|
104
|
+
# elsif ARGV[0] == 'set'
|
105
|
+
# if ARGV[1]
|
106
|
+
# z = Ztrening.new
|
107
|
+
# # set ID/NAME STATUS
|
108
|
+
# z.set ARGV[1], ARGV[2]
|
109
|
+
# else
|
110
|
+
# puts USAGE
|
111
|
+
# exit
|
112
|
+
# end
|
113
|
+
elsif ARGV[0] == 'init'
|
114
|
+
(puts USAGE; exit) if !ARGV[1].nil? # TODO: manual dir as arg1
|
115
|
+
z = Ztrening.new
|
116
|
+
if !z.in_zaddir?
|
117
|
+
z.create_zaddir `pwd`.chop
|
118
|
+
else
|
119
|
+
puts "Vec postoji zaddir conf file u ovom dir-u"
|
120
|
+
exit
|
121
|
+
end
|
118
122
|
else
|
119
123
|
puts USAGE
|
120
124
|
exit
|
data/lib/ztrening.rb
CHANGED
@@ -1,18 +1,22 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
require 'net/http'
|
3
4
|
|
4
5
|
class Array
|
5
6
|
def moj_keys() Hash[*self.collect { |v| [v, true] }.flatten] end
|
6
7
|
end
|
7
8
|
|
8
9
|
module ZtreningM
|
9
|
-
VERSION = '0.0.
|
10
|
+
VERSION = '0.0.4.1'
|
10
11
|
|
11
12
|
class Ztrening
|
12
13
|
def initialize(*opts)
|
13
|
-
@list_fname
|
14
|
-
@cmd_dwl
|
15
|
-
@
|
14
|
+
@list_fname = 'ztlista.txt'
|
15
|
+
# @cmd_dwl = "wget -q http://z-trening.com/training.php\?all_tasks\=1 -O #{@list_fname}"
|
16
|
+
@dwl_link = "z-trening.com|/training.php\?all_tasks\=1"
|
17
|
+
@link_base = 'http://z-trening.com/tasks.php?show_task=_ID_'
|
18
|
+
@ztdir_fname = '.ztconf' # bolje ztdata; file sa conf vars
|
19
|
+
@todo_fname = '_PROJDIR_/todo.txt'
|
16
20
|
|
17
21
|
@lista ||= []
|
18
22
|
@opts = opts.moj_keys
|
@@ -22,7 +26,7 @@ module ZtreningM
|
|
22
26
|
if !@opts[:web].nil?
|
23
27
|
web
|
24
28
|
execout = exec
|
25
|
-
(puts execerrmsg; exit) if execout.nil? || execout.empty?
|
29
|
+
(puts execerrmsg; exit) if (execout.nil? || execout.empty?)
|
26
30
|
@lista = parse(execout)
|
27
31
|
else
|
28
32
|
if !File.exists? @list_fname
|
@@ -33,6 +37,7 @@ module ZtreningM
|
|
33
37
|
(puts execerrmsg; exit) if execout.nil? || execout.empty?
|
34
38
|
@lista = parse(execout)
|
35
39
|
end
|
40
|
+
@lista.sort!
|
36
41
|
end
|
37
42
|
|
38
43
|
def find(str)
|
@@ -49,7 +54,7 @@ module ZtreningM
|
|
49
54
|
ll=[]
|
50
55
|
@lista.each { |e| ll << e if e[1] == str }
|
51
56
|
@lista = ll
|
52
|
-
puts "find_by_name lista cnt: #{@lista.count}"
|
57
|
+
# puts "find_by_name lista cnt: #{@lista.count}"
|
53
58
|
end
|
54
59
|
|
55
60
|
def find_by_id(id)
|
@@ -77,10 +82,6 @@ module ZtreningM
|
|
77
82
|
@lista
|
78
83
|
end
|
79
84
|
|
80
|
-
# def lista=(l)
|
81
|
-
# @lista=l
|
82
|
-
# end
|
83
|
-
|
84
85
|
def lista_txt
|
85
86
|
puts 'Zadatci:'
|
86
87
|
@lista.each { |l| puts "Zadatak: #{l[1]}" }
|
@@ -99,6 +100,53 @@ module ZtreningM
|
|
99
100
|
puts '</ul>' if opts[:li]
|
100
101
|
end
|
101
102
|
|
103
|
+
|
104
|
+
# get_zaddir
|
105
|
+
def findzaddir
|
106
|
+
# nadji DirName s datotekom '.ztprojdir', prema gore
|
107
|
+
# false ako nema
|
108
|
+
|
109
|
+
for n in (0..32)
|
110
|
+
p = ('../'*n)
|
111
|
+
return File.expand_path(p) if File.file?("#{p}#{@ztdir_fname}")
|
112
|
+
return false if File.expand_path p == "/"
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
def create_zaddir(dir) #(args) - koristi hash i symbole
|
118
|
+
# TODO: args: string dirname='', bool templates, ...
|
119
|
+
if File.directory? dir
|
120
|
+
File.open("#{File.dirname dir}/@ztdir_fname", "w"){ |f|
|
121
|
+
f.write(<<EOS)
|
122
|
+
todo_file = todo.txt
|
123
|
+
status_file = status.txt
|
124
|
+
EOS
|
125
|
+
}
|
126
|
+
FileUtils.touch "#{File.dirname dir}/todo.txt"
|
127
|
+
FileUtils.touch "#{File.dirname dir}/status.txt"
|
128
|
+
puts "Napravljen ztdir u dir-u #{dir}"
|
129
|
+
else
|
130
|
+
puts "Dir #{dir} ne postoji, ne mogu napraviti zaddir!"
|
131
|
+
return false
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def in_zaddir?
|
136
|
+
(@ztdir_fname && File.exists?("./#{@ztdir_fname}")) || false
|
137
|
+
end
|
138
|
+
|
139
|
+
def set(arg)
|
140
|
+
if arg.start_with? '500000'
|
141
|
+
id = arg
|
142
|
+
else
|
143
|
+
find_by_name arg
|
144
|
+
id = @lista[0][0]
|
145
|
+
end
|
146
|
+
# TODO: set()
|
147
|
+
end
|
148
|
+
|
149
|
+
|
102
150
|
private
|
103
151
|
|
104
152
|
def link(id)
|
@@ -106,6 +154,7 @@ module ZtreningM
|
|
106
154
|
end
|
107
155
|
|
108
156
|
def exec
|
157
|
+
# FIXME: open(@list_fname).read > stdin od thread-a
|
109
158
|
t = Thread.new { `#{cmd}` }
|
110
159
|
return t.value.split "\r\n"
|
111
160
|
end
|
@@ -118,7 +167,14 @@ module ZtreningM
|
|
118
167
|
|
119
168
|
def web
|
120
169
|
puts 'Downloading list ...'
|
121
|
-
%x[#{@cmd_dwl}]
|
170
|
+
# %x[#{@cmd_dwl}]
|
171
|
+
link = @dwl_link.split '|'
|
172
|
+
Net::HTTP.start(link[0]) { |http|
|
173
|
+
resp = http.get(link[1])
|
174
|
+
File.open(@list_fname, "wb") { |file|
|
175
|
+
file.write(resp.body)
|
176
|
+
}
|
177
|
+
}
|
122
178
|
end
|
123
179
|
|
124
180
|
def cmd
|
data/test/test_ztrening.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ztrening
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 93
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
|
9
|
+
- 4
|
10
|
+
- 1
|
11
|
+
version: 0.0.4.1
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- BKrsta
|
@@ -15,7 +16,7 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2010-06
|
19
|
+
date: 2010-08-06 00:00:00 +02:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|