medusa 0.0.1.6 → 0.0.1.7

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.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/bin/medusa +186 -0
  3. metadata +4 -3
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ Hen.lay! {{
14
14
  :gem => {
15
15
  :version => Medusa::VERSION,
16
16
  :summary => 'The terminology management software for perseus-a.',
17
- :files => FileList['lib/**/*.rb'].to_a,
17
+ :files => FileList['lib/**/*.rb', 'bin/*'].to_a,
18
18
  :extra_files => FileList['[A-Z]*'].to_a,
19
19
  :dependencies => %w[highline athena]
20
20
  }
@@ -0,0 +1,186 @@
1
+ #! /usr/bin/ruby
2
+
3
+ #--
4
+ ###############################################################################
5
+ # #
6
+ # medusa -- The terminology manager for perseus-a #
7
+ # #
8
+ # Copyright (C) 2007 Cologne University of Applied Sciences, #
9
+ # Claudiusstr. 1, #
10
+ # 50678 Cologne, Germany #
11
+ # #
12
+ # Authors: #
13
+ # Jens Wille <jens.wille@uni-koeln.de> #
14
+ # #
15
+ # medusa is free software; you can redistribute it and/or modify it under the #
16
+ # terms of the GNU General Public License as published by the Free Software #
17
+ # Foundation; either version 3 of the License, or (at your option) any later #
18
+ # version. #
19
+ # #
20
+ # medusa is distributed in the hope that it will be useful, but WITHOUT ANY #
21
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
22
+ # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
23
+ # details. #
24
+ # #
25
+ # You should have received a copy of the GNU General Public License along #
26
+ # with medusa. If not, see <http://www.gnu.org/licenses/>. #
27
+ # #
28
+ ###############################################################################
29
+ #++
30
+
31
+ require 'optparse'
32
+
33
+ require 'rubygems'
34
+ require 'highline/import'
35
+
36
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
37
+
38
+ require 'medusa'
39
+
40
+ # overwrite to allow default value and fix regexp
41
+ def agree(yes_or_no_question, default = 'no')
42
+ ask("#{yes_or_no_question} (yes/no): ", lambda { |yn| yn =~ /\Ay/i }) { |q|
43
+ q.validate = /\A(?:y(?:es)?|no?)\Z/i
44
+ q.responses[:not_valid] = 'Please enter "yes" or "no".'
45
+ q.responses[:ask_on_error] = :question
46
+ q.default = default
47
+ }
48
+ end
49
+
50
+ def open_file_or_std(file, mode = 'r')
51
+ if file
52
+ File.open(file, mode)
53
+ else
54
+ case mode
55
+ when 'r': STDIN
56
+ when 'w': STDOUT
57
+ when 'a': STDERR
58
+ else raise ArgumentError, "don't know how to handle mode '#{mode}'"
59
+ end
60
+ end
61
+ end
62
+
63
+ PROGRAM_NAME = File.basename($0)
64
+
65
+ USAGE = "\
66
+ Usage: #{$0} <action> <terminology> [options...]
67
+ #{$0} {-h|--help}"
68
+
69
+ abort USAGE if ARGV.empty?
70
+
71
+ options = {}
72
+
73
+ OptionParser.new { |opts|
74
+ opts.banner = USAGE
75
+
76
+ opts.separator ''
77
+ opts.separator 'Required arguments:'
78
+
79
+ opts.separator ' action The action to perform'
80
+ opts.separator ' terminology The name of the terminology to operate on'
81
+
82
+ opts.separator ''
83
+ opts.separator 'Options:'
84
+
85
+ opts.on('-f', '--file FILE', 'Operates on FILE (instead of STDIN/STDOUT)') { |f|
86
+ options[:file] = f
87
+ }
88
+
89
+ opts.on('-t', '--type TYPE', 'Type of file (Import/Export format)') { |t|
90
+ options[:type] = t
91
+ }
92
+
93
+ opts.separator ''
94
+ opts.separator 'Generic options:'
95
+
96
+ opts.on('-h', '--help', 'Print this help message and exit') {
97
+ abort opts.to_s
98
+ }
99
+
100
+ opts.on('--help-actions', 'List available actions and exit') {
101
+ puts "Available actions for #{PROGRAM_NAME}:"
102
+
103
+ actions = Medusa.actions
104
+ max = actions.map { |a, _| a.length }.max
105
+ actions.each { |a, d|
106
+ puts " - %-#{max}s : %s" % [a, d]
107
+ }
108
+
109
+ abort
110
+ }
111
+
112
+ opts.on('--help-import', 'List available import formats (types) and exit') {
113
+ puts 'Available import formats (types):'
114
+
115
+ formats = Medusa.import_formats
116
+ max = formats.map { |a, _| a.length }.max
117
+ formats.each { |t, k|
118
+ puts " - %-#{max}s = %s" % [t, k]
119
+ }
120
+
121
+ abort
122
+ }
123
+
124
+ opts.on('--help-export', 'List available export formats (types) and exit') {
125
+ puts 'Available export formats (types):'
126
+
127
+ formats = Medusa.export_formats
128
+ max = formats.map { |a, _| a.length }.max
129
+ formats.each { |t, k|
130
+ puts " - %-#{max}s = %s" % [t, k]
131
+ }
132
+
133
+ abort
134
+ }
135
+
136
+ opts.on('--version', 'Print program version and exit') {
137
+ abort "#{PROGRAM_NAME} v#{Medusa::VERSION}"
138
+ }
139
+ }.parse!
140
+
141
+ unless ARGV.size == 2
142
+ abort "Both action and terminology must be given.\n\n#{USAGE}"
143
+ else
144
+ action, terminology = ARGV.slice!(0..1).map { |a| a.downcase }
145
+ end
146
+
147
+ unless Medusa.valid_action?(action)
148
+ abort "Invalid action: '#{action}'. " <<
149
+ "See '--help-actions' for a list of available actions."
150
+ end
151
+
152
+ unless %w[create import].include?(action) && Medusa.terminology_exists?(terminology)
153
+ msg = "No such terminology: '#{terminology}'."
154
+ msg << " Please create one first with 'create'." unless action == 'delete'
155
+
156
+ abort msg
157
+ end
158
+
159
+ args = [terminology]
160
+
161
+ case action
162
+ when 'create'
163
+ if Medusa.terminology_exists?(terminology)
164
+ abort "Terminology already exists: '#{terminology}'."
165
+ end
166
+ when 'delete'
167
+ unless agree("Really delete terminology '#{terminology}'?")
168
+ abort "Aborted! Won't delete terminology '#{terminology}'."
169
+ end
170
+ when 'import', 'export'
171
+ unless options[:type]
172
+ abort "No #{action} format specified. Use '--type' to do so."
173
+ end
174
+
175
+ unless Medusa.valid_format?(action, options[:type])
176
+ abort "Invalid #{action} format: '#{options[:type]}'. " <<
177
+ "See '--help-#{action}' for a list of available #{action} formats."
178
+ end
179
+
180
+ args << open_file_or_std(options[:file], action == 'export' ? 'w' : 'r')
181
+ args << options[:type]
182
+ when 'dump'
183
+ args << open_file_or_std(options[:file], 'w')
184
+ end
185
+
186
+ Medusa.run(action, *args)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: medusa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.6
4
+ version: 0.0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
@@ -32,8 +32,8 @@ dependencies:
32
32
  version:
33
33
  description: The terminology management software for perseus-a.
34
34
  email: jens.wille@uni-koeln.de
35
- executables: []
36
-
35
+ executables:
36
+ - medusa
37
37
  extensions: []
38
38
 
39
39
  extra_rdoc_files:
@@ -44,6 +44,7 @@ files:
44
44
  - lib/medusa/version.rb
45
45
  - lib/medusa/terminology.rb
46
46
  - lib/medusa.rb
47
+ - bin/medusa
47
48
  - COPYING
48
49
  - HEADER
49
50
  - README