revolt 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -214,3 +214,33 @@ can be matched or error is produced.
214
214
  For more information and options:
215
215
 
216
216
  rv_rename_level.rb -h
217
+
218
+ === rv_add_favorite.rb
219
+ Adds levels as favorites that are given as command line parameters.
220
+ The favorite levels are stored in a regular ascii file
221
+ (default is rv_levels.fav). The favorites file is meant to
222
+ be used in conjuction with rv_remove_extra_levels.rb script,
223
+ so that Re-Volt's track number limit is not exceeded. When
224
+ using favorites file only tracks that are not favorites will
225
+ be given as candidates to remove.
226
+
227
+ Match options format is similar as rv_find_levels.rb
228
+
229
+ For more information and options:
230
+
231
+ rv_add_favorite.rb -h
232
+
233
+ === rv_remove_extra_levels.rb
234
+ Removes levels so that Re-Volt's limit for levels is not exceeded
235
+ (which would cause some of the installed levels to be unplayable).
236
+ The proposed levels for removal are given starting from the oldest
237
+ installed level. The time is taken from the level folders modification
238
+ time.
239
+
240
+ A favorites file can be used so that those levels specified in the
241
+ favorites file are not given as candidates to delete.
242
+
243
+ For more information and options:
244
+
245
+ rv_remove_extra_levels.rb -h
246
+
data/Rakefile CHANGED
@@ -145,6 +145,7 @@ task "rubyforge-login" => ["rubyforge-setup"] do
145
145
  sh "rubyforge login", :verbose => true
146
146
  end
147
147
 
148
+ desc "Uploads the built packages to RubyForge"
148
149
  task "publish-packages" => ["package", "rubyforge-login"] do
149
150
  # Upload packages under pkg/ to RubyForge
150
151
  # This task makes some assumptions:
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/ruby
2
+ require 'optparse'
3
+ require 'pp'
4
+ require 'revolt'
5
+ require 'set'
6
+
7
+ $FAVORITE_FILE = "rv_levels.fav"
8
+
9
+ def main
10
+ cmd = CmdArguments.new(ARGV)
11
+ ReVolt::Logger.enable if cmd[:debug]
12
+ levels = ReVolt::Levels.at(cmd[:base])
13
+ add_levs = []
14
+
15
+ levels.each_level do |level|
16
+ all_matches = {}
17
+ nmatches = ReVolt::Util::Matcher.multi(level, cmd[:match], all_matches)
18
+ if nmatches > 0
19
+ keyvaluestr = all_matches.map{|(k,v)|"#{k}=#{v}"}.join(', ')
20
+ add_levs << level
21
+ puts "%s [%s]" % [level.inspect, keyvaluestr]
22
+ end
23
+ end
24
+
25
+ if add_levs.size > 0
26
+ unless cmd[:force]
27
+ puts ""
28
+ print "Add these levels to favorites in file %s? (y/N) " % [cmd[:file]]
29
+ answer = STDIN.gets.chomp
30
+ if answer.downcase != 'y'
31
+ puts "Levels not added to favorites"
32
+ exit(0)
33
+ end
34
+ end
35
+
36
+ favorites = ReVolt::Util::Favorites.new(cmd[:file])
37
+
38
+ add_levs.each do |l, match|
39
+ level_id = l.id.to_s
40
+ if favorites.add?(l.id.to_s)
41
+ puts "Added to favorites %s (%s)" % [l.name, level_id]
42
+ else
43
+ puts "Already exists in favorites, skipping %s (%s)" % [l.name, level_id]
44
+ end
45
+ end
46
+
47
+ favorites.commit
48
+ else
49
+ puts "No matching levels"
50
+ end
51
+ end
52
+
53
+ class CmdArguments < Hash
54
+ include ReVolt::Util::CommonCmdArgs
55
+
56
+ def initialize(cmd)
57
+ super()
58
+
59
+ self[:all] = false
60
+ self[:default_match_with] = :name
61
+ self[:file] = $FAVORITE_FILE
62
+
63
+ matchstrs = []
64
+ opts = OptionParser.new do |opts|
65
+ opts.banner = "Usage: #$0 [options] [name_match ...]\n"
66
+ opts.separator ""
67
+ opts.separator "Adds levels as favorites. The favorites are stored in a file"
68
+ opts.separator "in current directory unless otherwise specified."
69
+ opts.separator ""
70
+ opts.separator "Examples:"
71
+ opts.separator " Adds levels to favorites whose name includes temple:"
72
+ opts.separator " #$0 temple"
73
+
74
+ opts.separator ""
75
+ match_help(opts)
76
+ opts.separator ""
77
+
78
+ opts.separator "Options:"
79
+
80
+ on_match(opts) do |value|
81
+ matchstrs << value
82
+ end
83
+ on_default_match_modifier(opts)
84
+
85
+ opts.on('-d', '--debug',
86
+ 'Outputs debug information') do
87
+ self[:debug] = true
88
+ end
89
+
90
+ opts.on('-f', '--file',
91
+ 'The path to the file containing the favorite levels') do |value|
92
+ self[:file] = value
93
+ end
94
+
95
+ on_base_path(opts) do |value|
96
+ self[:base] = value
97
+ end
98
+
99
+ opts.on_tail('-h', '--help',
100
+ 'Display full help and exit') do
101
+ puts opts
102
+
103
+ exit(0)
104
+ end
105
+ end
106
+
107
+ opts.parse!(cmd)
108
+
109
+ name_or_id_matches(cmd) do |m|
110
+ matchstrs << m
111
+ end
112
+
113
+ if matchstrs.size == 0
114
+ puts "Error: no matches specified\n"
115
+ STDERR.puts opts.banner
116
+ exit 1
117
+ end
118
+
119
+ begin
120
+ # Create the matcher objects
121
+ self[:match] = []
122
+ for m in matchstrs
123
+ self[:match] << ReVolt::Util::Matcher.parse(m)
124
+ end
125
+ rescue ReVolt::Util::Matcher::ParseError => e
126
+ STDERR.puts e.errstr
127
+ exit(1)
128
+ end
129
+
130
+ self[:base] = ReVolt::Info::path if !self[:base]
131
+ end
132
+ end
133
+
134
+
135
+ main
@@ -46,7 +46,6 @@ class CmdArguments < Hash
46
46
  def initialize(cmd)
47
47
  super()
48
48
 
49
- self[:base] = ReVolt::Info::path
50
49
  self[:force] = false
51
50
  self[:default_match_with] = :name
52
51
 
@@ -117,6 +116,8 @@ class CmdArguments < Hash
117
116
  STDERR.puts e.errstr
118
117
  exit(1)
119
118
  end
119
+
120
+ self[:base] = ReVolt::Info::path if !self[:base]
120
121
  end
121
122
  end
122
123
 
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/ruby
2
- #
3
2
  require 'optparse'
4
3
  require 'pp'
5
4
  require 'revolt'
@@ -26,7 +25,6 @@ class CmdArguments < Hash
26
25
  def initialize(cmd)
27
26
  super()
28
27
 
29
- self[:base] = ReVolt::Info::path
30
28
  self[:default_match_with] = :name
31
29
 
32
30
  matchstrs = []
@@ -105,6 +103,8 @@ class CmdArguments < Hash
105
103
  STDERR.puts e.errstr
106
104
  exit(1)
107
105
  end
106
+
107
+ self[:base] = ReVolt::Info::path if !self[:base]
108
108
  end
109
109
  end
110
110
 
@@ -45,7 +45,6 @@ class CmdArguments < Hash
45
45
  def initialize(cmd)
46
46
  super()
47
47
 
48
- self[:base] = ReVolt::Info::path
49
48
  self[:all] = false
50
49
  self[:default_match_with] = :name
51
50
 
@@ -114,6 +113,8 @@ class CmdArguments < Hash
114
113
  STDERR.puts e.errstr
115
114
  exit(1)
116
115
  end
116
+
117
+ self[:base] = ReVolt::Info::path if !self[:base]
117
118
  end
118
119
  end
119
120
 
@@ -158,7 +158,6 @@ class CmdArguments < Hash
158
158
  def initialize(cmd)
159
159
  super()
160
160
  inf_matches = []
161
- self[:base] = ReVolt::Info::path
162
161
 
163
162
  opts = OptionParser.new do |opts|
164
163
  opts.banner = "Usage: #$0 [options]\n"
@@ -193,6 +192,8 @@ class CmdArguments < Hash
193
192
  end
194
193
 
195
194
  opts.parse!(cmd)
195
+
196
+ self[:base] = ReVolt::Info::path if !self[:base]
196
197
  end
197
198
  end
198
199
 
@@ -38,7 +38,6 @@ class CmdArguments < Hash
38
38
  def initialize(cmd)
39
39
  super()
40
40
  inf_matches = []
41
- self[:base] = ReVolt::Info::path
42
41
 
43
42
  opts = OptionParser.new do |opts|
44
43
  opts.banner = "Usage: #$0 [options] package1 [package2 ...]\n"
@@ -68,6 +67,8 @@ class CmdArguments < Hash
68
67
  puts opts
69
68
  exit(1)
70
69
  end
70
+
71
+ self[:base] = ReVolt::Info::path if !self[:base]
71
72
  end
72
73
  end
73
74
 
@@ -49,7 +49,6 @@ class CmdArguments < Hash
49
49
  def initialize(cmd)
50
50
  super()
51
51
 
52
- self[:base] = ReVolt::Info::path
53
52
  self[:force] = false
54
53
  self[:default_match_with] = :name
55
54
 
@@ -123,6 +122,8 @@ class CmdArguments < Hash
123
122
  STDERR.puts e.errstr
124
123
  exit(1)
125
124
  end
125
+
126
+ self[:base] = ReVolt::Info::path if !self[:base]
126
127
  end
127
128
  end
128
129
 
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/ruby
2
+ require 'optparse'
3
+ require 'pp'
4
+ require 'revolt'
5
+ require 'set'
6
+
7
+ $FAVORITE_FILE = "rv_levels.fav"
8
+ $RV_LEVELS_LIMIT = 255
9
+
10
+ def main
11
+ cmd = CmdArguments.new(ARGV)
12
+ ReVolt::Logger.enable if cmd[:debug]
13
+ levels = ReVolt::Levels.at(cmd[:base])
14
+
15
+ filtered_levels = filter_levels_with_matcher(levels.to_a, cmd[:match])
16
+
17
+ levels_to_remove = levels.size - cmd[:limit]
18
+ if levels_to_remove <= 0
19
+ puts "Number of installed levels (%d) does not exceed Re-Volt's limit (%d)" % [levels.size, cmd[:limit]]
20
+ exit(0)
21
+ end
22
+
23
+ favorites = ReVolt::Util::Favorites.new(cmd[:file])
24
+ sorted_levels = sort_levels_by_date(filtered_levels)
25
+ remove_levs = []
26
+ sorted_levels.each do |level|
27
+ if level.custom? && !favorites.include?(level.id) && remove_levs.size < levels_to_remove
28
+ puts "%s (modified %s)" % [level.inspect, level.path.mtime.localtime.asctime ]
29
+ remove_levs << level
30
+ end
31
+ end
32
+
33
+ if remove_levs.size > 0
34
+ unless cmd[:force]
35
+ puts ""
36
+ print "Delete these levels? (y/N) "
37
+ answer = STDIN.gets.chomp
38
+ if answer.downcase != 'y'
39
+ puts "Deleting not done"
40
+ exit(0)
41
+ end
42
+ end
43
+ remove_levs.each do |l, match|
44
+ puts "Deleting %s (%s)" % [l.name, l.id.to_s]
45
+ l.delete
46
+ end
47
+ else
48
+ puts "No levels that could be removed"
49
+ end
50
+ end
51
+
52
+ def sort_levels_by_date(levels)
53
+ levels.sort do |a,b|
54
+ a.path.mtime <=> b.path.mtime
55
+ end
56
+ end
57
+
58
+ def filter_levels_with_matcher(levels, matchers)
59
+ return levels if matchers.empty?
60
+
61
+ filtered_levels = []
62
+ levels.each do |level|
63
+ all_matches = {}
64
+ nmatches = ReVolt::Util::Matcher.multi(level, matchers, all_matches)
65
+ if nmatches > 0
66
+ keyvaluestr = all_matches.map{|(k,v)|"#{k}=#{v}"}.join(', ')
67
+ filtered_levels << level
68
+ end
69
+ end
70
+ filtered_levels
71
+ end
72
+
73
+ def read_favorites(filepath)
74
+ file = Pathname.new(filepath)
75
+
76
+ end
77
+
78
+ class CmdArguments < Hash
79
+ include ReVolt::Util::CommonCmdArgs
80
+
81
+ def initialize(cmd)
82
+ super()
83
+
84
+ self[:all] = false
85
+ self[:default_match_with] = :name
86
+ self[:file] = $FAVORITE_FILE
87
+ self[:limit] = $RV_LEVELS_LIMIT
88
+
89
+ matchstrs = []
90
+ opts = OptionParser.new do |opts|
91
+ opts.banner = "Usage: #$0 [options] [name_match ...]\n"
92
+ opts.separator ""
93
+ opts.separator "Removes levels in somewhat smart way so that there's not too many"
94
+ opts.separator "levels for Re-Volt to handle. Re-Volt has a limit of 256 installed tracks."
95
+ opts.separator "By default tries to use a file with favorite list of levels that should never"
96
+ opts.separator "be removed. Stock tracks are never removed, only custom tracks."
97
+ opts.separator ""
98
+ opts.separator "Without arguments levels are removed so that the limit Re-Volt can handle"
99
+ opts.separator "is not exceeded. If favorites exist they are never removed, otherwise"
100
+ opts.separator "the oldest levels by their installation directory timestamp are removed"
101
+ opts.separator ""
102
+ opts.separator "Examples:"
103
+ opts.separator " Removes (non-favorite) levels so that max #{$RV_LEVELS_LIMIT} are installed:"
104
+ opts.separator " #$0"
105
+ opts.separator " Removes (non-favorite) levels whose name contains temple that exceed the limit"
106
+ opts.separator " #$0 temple"
107
+
108
+ opts.separator ""
109
+ match_help(opts)
110
+ opts.separator ""
111
+
112
+ opts.separator "Options:"
113
+
114
+ on_match(opts) do |value|
115
+ matchstrs << value
116
+ end
117
+ on_default_match_modifier(opts)
118
+
119
+ opts.on('-d', '--debug',
120
+ 'Outputs debug information') do
121
+ self[:debug] = true
122
+ end
123
+
124
+ opts.on('-f', '--file',
125
+ 'The path to the file containing the favorite levels') do |value|
126
+ self[:file] = value
127
+ end
128
+
129
+ opts.on('-l', '--limit LIMIT', Integer,
130
+ "Sets the limit of levels Re-Volt can handle (default is #{$RV_LEVELS_LIMIT})") do |value|
131
+ self[:limit] = value
132
+ end
133
+
134
+ on_base_path(opts) do |value|
135
+ self[:base] = value
136
+ end
137
+
138
+ opts.on_tail('-h', '--help',
139
+ 'Display full help and exit') do
140
+ puts opts
141
+
142
+ exit(0)
143
+ end
144
+ end
145
+
146
+ opts.parse!(cmd)
147
+
148
+ name_or_id_matches(cmd) do |m|
149
+ matchstrs << m
150
+ end
151
+
152
+ begin
153
+ # Create the matcher objects
154
+ self[:match] = []
155
+ for m in matchstrs
156
+ self[:match] << ReVolt::Util::Matcher.parse(m)
157
+ end
158
+ rescue ReVolt::Util::Matcher::ParseError => e
159
+ STDERR.puts e.errstr
160
+ exit(1)
161
+ end
162
+
163
+ self[:base] = ReVolt::Info::path if !self[:base]
164
+ end
165
+ end
166
+
167
+
168
+ main
@@ -55,7 +55,6 @@ class CmdArguments < Hash
55
55
  def initialize(cmd)
56
56
  super()
57
57
 
58
- self[:base] = ReVolt::Info::path
59
58
  self[:force] = false
60
59
 
61
60
  matchstrs = []
@@ -132,6 +131,8 @@ class CmdArguments < Hash
132
131
  STDERR.puts e.errstr
133
132
  exit(1)
134
133
  end
134
+
135
+ self[:base] = ReVolt::Info::path if !self[:base]
135
136
  end
136
137
  end
137
138
 
data/lib/revolt.rb CHANGED
@@ -7,8 +7,9 @@ require 'revolt/util'
7
7
  require 'revolt/util/fs_browser'
8
8
  require 'revolt/util/common_cmd_args'
9
9
  require 'revolt/util/matcher'
10
+ require 'revolt/util/favorites'
10
11
  require 'revolt/args'
11
12
 
12
13
  module ReVolt
13
- VERSION = '0.8.5'
14
+ VERSION = '0.8.6'
14
15
  end
@@ -0,0 +1,74 @@
1
+ require 'revolt/logger'
2
+
3
+ #module ReVolt; module Util; end; end
4
+
5
+ module ReVolt::Util
6
+ # Can be used to maintain favorites file list. Usually not used
7
+ # directly, but by the utility programs
8
+ class Favorites
9
+ attr :filepath
10
+
11
+ # Initializes the favorites from given file.
12
+ # If the file exists the contents are read.
13
+ def initialize(filepath)
14
+ @filepath = Pathname.new(filepath)
15
+ @level_ids = []
16
+ @level_ids_set = Set.new
17
+ @level_ids_new = []
18
+ read_favorites if @filepath.exist?
19
+ end
20
+
21
+ # Returns true if the given level is included
22
+ # in favorites. Also level id is allowed.
23
+ def include?(level_or_id)
24
+ level_id = ReVolt::Level.to_level_id(level_or_id)
25
+ return @level_ids_set.include?(level_id)
26
+ end
27
+
28
+ # Adds the given level (or level id) to favorites.
29
+ # If the level already was in favorites returns
30
+ # nil. Otherwise returns the level_id.
31
+ def add?(level_or_id)
32
+ level_id = ReVolt::Level.to_level_id(level_or_id)
33
+ if @level_ids_set.add?(level_id)
34
+ @level_ids << level_id
35
+ @level_ids_new << level_id
36
+ return level_id
37
+ end
38
+ nil
39
+ end
40
+
41
+ # Commits the changes done to the favorites file.
42
+ # If no changes have been done, does nothing. If
43
+ # new levels have been added, those are added to
44
+ # the favorites file.
45
+ def commit()
46
+ commits = 0
47
+
48
+ return 0 if @level_ids_new.size <= 0
49
+
50
+ open(@filepath, 'a') do |file|
51
+ @level_ids_new.each do |level_id|
52
+ file.puts
53
+ file.print(level_id)
54
+ commits += 1
55
+ end
56
+ end
57
+ commits
58
+ end
59
+
60
+ private
61
+ def read_favorites()
62
+ open(@filepath) do |file|
63
+ file.each do |line|
64
+ level_id = line.chomp
65
+ if (!level_id.empty?)
66
+ level_id = ReVolt::Level.to_level_id(level_id)
67
+ @level_ids << level_id
68
+ @level_ids_set.add(level_id)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end # class Favorites
74
+ end # module
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: revolt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arto Jalkanen
@@ -9,14 +9,16 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-30 00:00:00 +03:00
12
+ date: 2008-11-21 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
16
  description:
17
17
  email: ajalkane@gmail.com
18
18
  executables:
19
+ - rv_remove_extra_levels.rb
19
20
  - rv_install_levels.rb
21
+ - rv_add_favorite.rb
20
22
  - rv_info_levels.rb
21
23
  - rv_package_levels.rb
22
24
  - rv_install_level_urls.rb
@@ -28,7 +30,9 @@ extensions: []
28
30
  extra_rdoc_files:
29
31
  - README
30
32
  files:
33
+ - bin/rv_remove_extra_levels.rb
31
34
  - bin/rv_install_levels.rb
35
+ - bin/rv_add_favorite.rb
32
36
  - bin/rv_info_levels.rb
33
37
  - bin/rv_package_levels.rb
34
38
  - bin/rv_install_level_urls.rb
@@ -50,6 +54,7 @@ files:
50
54
  - test/tc_level_package.rb
51
55
  - test/tc_level_installer.rb
52
56
  - lib/revolt.rb
57
+ - lib/revolt/util/favorites.rb
53
58
  - lib/revolt/util/fs_browser.rb
54
59
  - lib/revolt/util/common_cmd_args.rb
55
60
  - lib/revolt/util/matcher.rb
@@ -165,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
170
  requirements: []
166
171
 
167
172
  rubyforge_project: revolt
168
- rubygems_version: 1.1.1
173
+ rubygems_version: 1.2.0
169
174
  signing_key:
170
175
  specification_version: 2
171
176
  summary: Library for managing Re-Volt game, and some Commandline tools