tmxsuite 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,6 @@
1
+ = tmxsuite
2
+
3
+ Describe your project here
4
+
5
+ :include:tmxsuite.rdoc
6
+
data/bin/tmxsuite ADDED
@@ -0,0 +1,234 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ require 'yaml'
4
+ require_relative 'parser'
5
+
6
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + '/../lib')
7
+
8
+ begin # XXX: Remove this begin/rescue before distributing your app
9
+ require 'tmxsuite'
10
+ rescue LoadError
11
+ STDERR.puts "In development, you need to use `bundle exec bin/tmxsuite` to run your app"
12
+ STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path"
13
+ STDERR.puts "Feel free to remove this message from bin/tmxsuite now"
14
+ exit 64
15
+ end
16
+
17
+ include GLI::App
18
+ include Parser
19
+
20
+
21
+ program_desc 'A simple program for importing TMX files into database friendly formats and exporting segments again'
22
+ version Tmxsuite::VERSION
23
+
24
+
25
+ # accept(Dokument::TMX) do |string|
26
+ # Dokument::TMX.new(string)
27
+ # end
28
+
29
+
30
+ ##DEFAULTS & OPTIONS
31
+ # config_file File.join(ENV['PWD'],'/lib/.todo.rc.yaml')
32
+
33
+
34
+
35
+
36
+ ##GLOBAL OPTIONS - also external configuration file
37
+ #automatically created with initconfig
38
+ config_file File.join(File.expand_path(File.dirname(__FILE__)),'.tmxsuite.rc.yaml')
39
+ mem_file = File.join(File.expand_path(File.dirname(__FILE__)),'.memories.yaml')
40
+
41
+ desc 'Specify the directory where the tmxtemplates live'
42
+ arg_name 'tmxtemplates'
43
+ default_value File.join(File.expand_path File.dirname(__FILE__),'/TEMPLATES')
44
+ flag [:tmxtemplates]
45
+
46
+ desc 'Specify the file where the memorylist lives'
47
+ arg_name 'memlist'
48
+ default_value mem_file
49
+ flag [:memorylist]
50
+
51
+ desc 'Specify the directory where the exported memories live'
52
+ arg_name 'exportpath'
53
+ default_value File.join(File.expand_path File.dirname(__FILE__),'/EXPORT')
54
+ flag [:exportpath]
55
+
56
+ desc 'Enter a default user name'
57
+ arg_name 'user'
58
+ default_value ENV['USER']
59
+ flag [:username]
60
+
61
+
62
+ ##END
63
+
64
+ desc 'Imports a new memory or directory of memories'
65
+ long_desc """
66
+ A memory must be TMX compliant.
67
+ The memory or memories are parsed and the segments are turned into the specified format
68
+ Subdirectories will be ignored
69
+ E.g. Creates a JSON file memoryname.json.
70
+ It makes sense to arrange memories by tags since tags can only be added per import
71
+
72
+ """
73
+ arg_name 'memories'
74
+ command :import do |c|
75
+
76
+ desc 'Choose x for xpath, otherwise going to use SAX'
77
+ c.switch [:X,:xpath]
78
+
79
+ # c.desc 'The directory of memory to import'
80
+ # c.flag [:d, :directory]
81
+
82
+
83
+
84
+ c.flag [:t,:tags], :arg_name => 'tags',
85
+ :type => Array,
86
+ :desc => 'The domain-style tags for these memories'
87
+
88
+ c.desc 'The format to turn the TMX into'
89
+ c.arg_name 'json|csv|pretty|yaml|db'
90
+ # c.default_value defaults[:format]
91
+ c.flag :format
92
+
93
+ c.action do |global_options,options,memory_paths|
94
+
95
+ ## memory_paths are the args to ARGV an array
96
+
97
+ # allow for memories to be added from standard input stream
98
+
99
+ if memory_paths.empty?
100
+ puts "Reading new memories from stdin...."
101
+ memory_paths = STDIN.readlines.map { |a| a.chomp }
102
+ end
103
+
104
+ # puts "START"
105
+ # puts memory_paths
106
+ # puts "END"
107
+
108
+ # TMX Sanity check
109
+ memory_paths.each do |m|
110
+ memory_paths.delete(m) if File.extname(m) != ".tmx"
111
+ end
112
+
113
+ # puts "START2"
114
+ # puts memory_paths
115
+ # puts "END2"
116
+
117
+
118
+ # memory_paths.delete_if {|x| File.extname(x) == ".tmx" }
119
+
120
+ File.open(global_options[:memorylist], 'a+') do |memorylist|
121
+
122
+ memories = 0
123
+ memory_paths.each do |mem|
124
+
125
+
126
+ ##CHECK AGAIN FOR VALIDITY AFTER IMPORT
127
+ #if these are real memories, add to list - bring in Document module
128
+
129
+ #memname, mempath, createdon, createdby
130
+ meminfo = {
131
+ :memoryname => File.basename(mem),
132
+ :size => '%.2f' % ((File.size(mem).to_f)/1024000) + " MB",
133
+ :imported => Time.now.strftime("%F at %T"),
134
+ :previouswrite => File.mtime(mem).strftime("%F at %T"),
135
+ :previousread => File.atime(mem).strftime("%F at %T"),
136
+ :owner => global_options[:username],
137
+ :tags => options[:tags]
138
+ }
139
+
140
+ YAML::dump(meminfo, memorylist)
141
+ warn "added memories to memory list #{global_options[:memorylist]}"
142
+ memories +=1
143
+ end
144
+
145
+ if memories ==0
146
+ raise "Invalid memories on the command line or via standard input"
147
+ end
148
+ options[:memorycount] = memories
149
+ options[:files] = memory_paths
150
+ end
151
+
152
+
153
+ puts options.inspect
154
+ puts "Running import command...."
155
+ puts "Running Parser...."
156
+ Parser::TMXMultiParser.new(options)
157
+ end
158
+
159
+
160
+
161
+
162
+ # # Your command logic here
163
+
164
+ # # If you have any errors, just raise them
165
+ # # raise "that command made no sense"
166
+ # puts options.inspect
167
+ # puts "import command ran"
168
+ # end
169
+ end
170
+
171
+ desc 'Exports a JSON style segment block to a new TMX, adds to memory list'
172
+ arg_name 'Describe arguments to export here'
173
+ command :export do |c|
174
+
175
+ c.desc 'The format of the input file'
176
+ c.flag :f
177
+
178
+ c.action do |global_options,options,args|
179
+
180
+ puts options.inspect
181
+ puts "export command ran"
182
+ end
183
+ end
184
+
185
+ desc 'Lists the memories you have imported previously'
186
+ arg_name 'Describe arguments to list here'
187
+ command :list do |c|
188
+
189
+ c.flag :s
190
+
191
+ c.action do |global_options,options,args|
192
+ puts global_options.inspect
193
+
194
+ puts "list command ran"
195
+
196
+ #sorting
197
+ if options[:s] == 'date'
198
+ #sort list by date
199
+ end
200
+
201
+ end
202
+ end
203
+
204
+
205
+ ### DO THE DIRECTORY TMX CHECK HERE
206
+
207
+ pre do |global_options,command,options,args|
208
+ # Pre logic here
209
+ # Return true to proceed; false to abort and not call the
210
+ # chosen command
211
+ # Use skips_pre before a command to skip this block
212
+ # on that command only
213
+
214
+ #does file exist? if not create it
215
+ unless File.exists? global_options[:memorylist]
216
+ global_options[:memorylist] = File.open(mem_file, 'w')
217
+ warn "Created new memories file #{mem_file}"
218
+ end
219
+ true
220
+ end
221
+
222
+ post do |global,command,options,args|
223
+ # Post logic here
224
+ # Use skips_post before a command to skip this
225
+ # block on that command only
226
+ end
227
+
228
+ on_error do |exception|
229
+ # Error logic here
230
+ # return false to skip default error handling
231
+ true
232
+ end
233
+
234
+ exit run(ARGV)
data/lib/tmxsuite.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'tmxsuite/version.rb'
2
+
3
+ # Add requires for other files you add to your project here, so
4
+ # you just need to require this one file in your bin file
@@ -0,0 +1,3 @@
1
+ module Tmxsuite
2
+ VERSION = '0.0.1'
3
+ end
data/tmxsuite.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = tmxsuite
2
+
3
+ Generate this with
4
+ tmxsuite rdoc
5
+ After you have described your command line interface
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tmxsuite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Coder Vince
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: aruba
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: gli
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 2.5.4
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 2.5.4
78
+ description:
79
+ email: publicvince102@gmail.com
80
+ executables:
81
+ - tmxsuite
82
+ extensions: []
83
+ extra_rdoc_files:
84
+ - README.rdoc
85
+ - tmxsuite.rdoc
86
+ files:
87
+ - bin/tmxsuite
88
+ - lib/tmxsuite/version.rb
89
+ - lib/tmxsuite.rb
90
+ - README.rdoc
91
+ - tmxsuite.rdoc
92
+ homepage: http://www.termz.net
93
+ licenses: []
94
+ post_install_message:
95
+ rdoc_options:
96
+ - --title
97
+ - tmxsuite
98
+ - --main
99
+ - README.rdoc
100
+ - -ri
101
+ require_paths:
102
+ - lib
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ segments:
111
+ - 0
112
+ hash: 2020861769513580170
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ segments:
120
+ - 0
121
+ hash: 2020861769513580170
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 1.8.25
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: A gem for processing Localization/Translation .TMX files into frontend and
128
+ backend friendly formats
129
+ test_files: []