web_translate_it 1.8.3 → 1.8.4

Sign up to get free protection for your applications and to get access to all the features.
data/bin/wti CHANGED
@@ -61,11 +61,21 @@ EOS
61
61
  opt :low_priority, "WTI will process this file with a low priority"
62
62
  opt :config, "Path to a translation.yml file", :short => "-c", :default => ".wti"
63
63
  end
64
+ when "rm"
65
+ Trollop::options do
66
+ banner "Delete a master language file"
67
+ opt :config, "Path to a translation.yml file", :short => "-c", :default => ".wti"
68
+ end
64
69
  when "addlocale"
65
70
  Trollop::options do
66
71
  banner "Add a new locale to the project"
67
72
  opt :config, "Path to a translation.yml file", :short => "-c", :default => ".wti"
68
73
  end
74
+ when "rmlocale"
75
+ Trollop::options do
76
+ banner "Delete a locale from the project"
77
+ opt :config, "Path to a translation.yml file", :short => "-c", :default => ".wti"
78
+ end
69
79
  when "server"
70
80
  Trollop::options do
71
81
  banner <<-EOS
data/history.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## Version 1.8.4 / 2011-11-14
2
+
3
+ * Add new command `wti rmlocale locale_code_1 locale_code_2 ...` to delete a locale from a project.
4
+ * Add new command `wti rm path_to_file1 path_to_file2 ...` to delete a master file from a project.
5
+ * `wti` sends client name and version in custom headers. #73.
6
+
1
7
  ## Version 1.8.3 / 2011-11-14
2
8
 
3
9
  * Bring back `-c` option to specify a configuration file with a specific name. `wti pull -c config/translations.yml` for instance. See #67 and #71.
@@ -63,7 +63,7 @@ module WebTranslateIt
63
63
  STDOUT.sync = true
64
64
  if parameters == []
65
65
  puts StringUtil.failure("No master file given.")
66
- puts "Usage: wti add master_file1 master_file2 ..."
66
+ puts "Usage: wti add master_file_1 master_file_2 ..."
67
67
  exit
68
68
  end
69
69
  WebTranslateIt::Util.http_connection do |http|
@@ -74,12 +74,36 @@ module WebTranslateIt
74
74
  end
75
75
  puts StringUtil.success("Master file added.")
76
76
  end
77
+
78
+ def rm
79
+ STDOUT.sync = true
80
+ if parameters == []
81
+ puts StringUtil.failure("No master file given.")
82
+ puts "Usage: wti rm master_file_1 master_file_2 ..."
83
+ exit
84
+ end
85
+ WebTranslateIt::Util.http_connection do |http|
86
+ parameters.each do |param|
87
+ if Util.ask_yes_no("Are you certain you want to delete the master file #{param} and its attached target files and translations?", false)
88
+ configuration.files.find_all{ |file| file.file_path == param }.each do |master_file|
89
+ master_file.delete(http)
90
+ # delete files
91
+ File.delete(master_file.file_path) if File.exists?(master_file.file_path)
92
+ configuration.files.find_all{ |file| file.master_id == master_file.id }.each do |target_file|
93
+ File.delete(target_file.file_path) if File.exists?(target_file.file_path)
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+ puts StringUtil.success("Master file deleted.")
100
+ end
77
101
 
78
102
  def addlocale
79
103
  STDOUT.sync = true
80
104
  if parameters == []
81
105
  puts StringUtil.failure("No locale code given.")
82
- puts "Usage: wti addlocale locale1 locale2 ..."
106
+ puts "Usage: wti addlocale locale_code_1 locale_code_2 ..."
83
107
  exit
84
108
  end
85
109
  parameters.each do |param|
@@ -88,11 +112,26 @@ module WebTranslateIt
88
112
  end
89
113
  puts "Done!"
90
114
  end
115
+
116
+ def rmlocale
117
+ STDOUT.sync = true
118
+ if parameters == []
119
+ puts StringUtil.failure("No locale code given.")
120
+ puts "Usage: wti rmlocale locale_code_1 locale_code_2 ..."
121
+ exit
122
+ end
123
+ parameters.each do |param|
124
+ if Util.ask_yes_no("Are you certain you want to delete the locale #{param} and its attached target files and translations?", false)
125
+ print StringUtil.success("Deleting locale #{param}... ")
126
+ puts WebTranslateIt::Project.delete_locale(configuration.api_key, param)
127
+ end
128
+ end
129
+ puts "Done!"
130
+ end
91
131
 
92
132
  def init
93
133
  api_key = Util.ask("Project API Key:")
94
134
  path = Util.ask("Configuration file path:", '.wti')
95
- puts path.split('/')[0..path.split('/').size-2].join('/')
96
135
  FileUtils.mkpath(path.split('/')[0..path.split('/').size-2].join('/')) unless path.split('/').count == 1
97
136
  project = YAML.load WebTranslateIt::Project.fetch_info(api_key)
98
137
  project_info = project['project']
@@ -171,7 +210,6 @@ module WebTranslateIt
171
210
 
172
211
  def configuration_file_path
173
212
  if self.command_options.config
174
- puts self.command_options.config
175
213
  return self.command_options.config
176
214
  else
177
215
  if File.exists?('config/translation.yml')
@@ -6,6 +6,8 @@ module WebTranslateIt
6
6
  begin
7
7
  WebTranslateIt::Util.http_connection do |http|
8
8
  request = Net::HTTP::Get.new("/api/projects/#{api_key}.yaml")
9
+ request.add_field("X-Client-Name", "web_translate_it")
10
+ request.add_field("X-Client-Version", WebTranslateIt::Util.version)
9
11
  response = http.request(request)
10
12
  if response.is_a?(Net::HTTPSuccess)
11
13
  return response.body
@@ -26,6 +28,8 @@ module WebTranslateIt
26
28
  begin
27
29
  WebTranslateIt::Util.http_connection do |http|
28
30
  request = Net::HTTP::Get.new("/api/projects/#{api_key}/stats.yaml")
31
+ request.add_field("X-Client-Name", "web_translate_it")
32
+ request.add_field("X-Client-Version", WebTranslateIt::Util.version)
29
33
  Util.handle_response(http.request(request), true)
30
34
  end
31
35
  rescue Timeout::Error
@@ -39,6 +43,8 @@ module WebTranslateIt
39
43
  begin
40
44
  WebTranslateIt::Util.http_connection do |http|
41
45
  request = Net::HTTP::Post.new("/api/projects/#{api_key}/locales")
46
+ request.add_field("X-Client-Name", "web_translate_it")
47
+ request.add_field("X-Client-Version", WebTranslateIt::Util.version)
42
48
  request.set_form_data({ 'id' => locale_code }, ';')
43
49
  Util.handle_response(http.request(request), true)
44
50
  end
@@ -48,5 +54,20 @@ module WebTranslateIt
48
54
  self.create_locale(api_key, locale_code)
49
55
  end
50
56
  end
57
+
58
+ def self.delete_locale(api_key, locale_code)
59
+ begin
60
+ WebTranslateIt::Util.http_connection do |http|
61
+ request = Net::HTTP::Delete.new("/api/projects/#{api_key}/locales/#{locale_code}")
62
+ request.add_field("X-Client-Name", "web_translate_it")
63
+ request.add_field("X-Client-Version", WebTranslateIt::Util.version)
64
+ Util.handle_response(http.request(request), true)
65
+ end
66
+ rescue Timeout::Error
67
+ puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
68
+ sleep(5)
69
+ self.delete_locale(api_key, locale_code)
70
+ end
71
+ end
51
72
  end
52
73
  end
@@ -42,9 +42,12 @@ module WebTranslateIt
42
42
  display.push "#{StringUtil.checksumify(self.local_checksum.to_s)}..#{StringUtil.checksumify(self.remote_checksum.to_s)}"
43
43
  if !File.exist?(self.file_path) or force or self.remote_checksum != self.local_checksum
44
44
  begin
45
- response = http_connection.get(api_url)
45
+ request = Net::HTTP::Get.new(api_url)
46
+ request.add_field("X-Client-Name", "web_translate_it")
47
+ request.add_field("X-Client-Version", WebTranslateIt::Util.version)
46
48
  FileUtils.mkpath(self.file_path.split('/')[0..-2].join('/')) unless File.exist?(self.file_path) or self.file_path.split('/')[0..-2].join('/') == ""
47
49
  begin
50
+ response = http_connection.request(request)
48
51
  File.open(self.file_path, 'wb'){ |file| file << response.body } if response.code.to_i == 200 and response.body != ''
49
52
  display.push Util.handle_response(response)
50
53
  rescue
@@ -80,6 +83,8 @@ module WebTranslateIt
80
83
  File.open(self.file_path) do |file|
81
84
  begin
82
85
  request = Net::HTTP::Put::Multipart.new(api_url, {"file" => UploadIO.new(file, "text/plain", file.path), "merge" => merge, "ignore_missing" => ignore_missing, "label" => label, "low_priority" => low_priority })
86
+ request.add_field("X-Client-Name", "web_translate_it")
87
+ request.add_field("X-Client-Version", WebTranslateIt::Util.version)
83
88
  display.push Util.handle_response(http_connection.request(request))
84
89
  puts ArrayUtil.to_columns(display)
85
90
  rescue Timeout::Error
@@ -93,7 +98,7 @@ module WebTranslateIt
93
98
  end
94
99
  end
95
100
 
96
- # Create a language file to Web Translate It by performing a POST Request.
101
+ # Create a master language file to Web Translate It by performing a POST Request.
97
102
  #
98
103
  # Example of implementation:
99
104
  #
@@ -105,14 +110,15 @@ module WebTranslateIt
105
110
  # actually takes place. This is due to the fact that language file imports are handled by background processing.
106
111
  #
107
112
  def create(http_connection, low_priority=false)
108
- puts low_priority
109
113
  display = []
110
114
  display.push file_path
111
115
  display.push "#{StringUtil.checksumify(self.local_checksum.to_s)}..[ ]"
112
116
  if File.exists?(self.file_path)
113
117
  File.open(self.file_path) do |file|
114
118
  begin
115
- request = Net::HTTP::Post::Multipart.new(api_url_for_create, { "name" => self.file_path, "file" => UploadIO.new(file, "text/plain", file.path), "low_priority" => low_priority })
119
+ request = Net::HTTP::Post::Multipart.new(api_url_for_create, { "name" => self.file_path, "file" => UploadIO.new(file, "text/plain", file.path), "low_priority" => low_priority })
120
+ request.add_field("X-Client-Name", "web_translate_it")
121
+ request.add_field("X-Client-Version", WebTranslateIt::Util.version)
116
122
  display.push Util.handle_response(http_connection.request(request))
117
123
  puts ArrayUtil.to_columns(display)
118
124
  rescue Timeout::Error
@@ -125,7 +131,32 @@ module WebTranslateIt
125
131
  puts StringUtil.failure("\nFile #{self.file_path} doesn't exist!")
126
132
  end
127
133
  end
128
-
134
+
135
+ # Delete a master language file from Web Translate It by performing a DELETE Request.
136
+ #
137
+ def delete(http_connection)
138
+ display = []
139
+ display.push file_path
140
+ # display.push "#{StringUtil.checksumify(self.local_checksum.to_s)}..[ ]"
141
+ if File.exists?(self.file_path)
142
+ File.open(self.file_path) do |file|
143
+ begin
144
+ request = Net::HTTP::Delete.new(api_url_for_delete)
145
+ request.add_field("X-Client-Name", "web_translate_it")
146
+ request.add_field("X-Client-Version", WebTranslateIt::Util.version)
147
+ display.push Util.handle_response(http_connection.request(request))
148
+ puts ArrayUtil.to_columns(display)
149
+ rescue Timeout::Error
150
+ puts StringUtil.failure("Request timeout. Will retry in 5 seconds.")
151
+ sleep(5)
152
+ delete
153
+ end
154
+ end
155
+ else
156
+ puts StringUtil.failure("\nFile #{self.file_path} doesn't exist!")
157
+ end
158
+ end
159
+
129
160
  def exists?
130
161
  File.exists?(file_path)
131
162
  end
@@ -150,6 +181,10 @@ module WebTranslateIt
150
181
  "/api/projects/#{self.api_key}/files"
151
182
  end
152
183
 
184
+ def api_url_for_delete
185
+ "/api/projects/#{self.api_key}/files/#{self.id}"
186
+ end
187
+
153
188
  def local_checksum
154
189
  require 'digest/sha1'
155
190
  begin
data/version.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 8
4
- :patch: 3
4
+ :patch: 4
5
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_translate_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.3
4
+ version: 1.8.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-14 00:00:00.000000000 Z
12
+ date: 2011-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multipart-post
16
- requirement: &70137380190740 !ruby/object:Gem::Requirement
16
+ requirement: &70301606155960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.1.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70137380190740
24
+ version_requirements: *70301606155960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: trollop
27
- requirement: &70137380190240 !ruby/object:Gem::Requirement
27
+ requirement: &70301606155360 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.16.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70137380190240
35
+ version_requirements: *70301606155360
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sinatra
38
- requirement: &70137380189780 !ruby/object:Gem::Requirement
38
+ requirement: &70301606154700 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.2.6
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70137380189780
46
+ version_requirements: *70301606154700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70137380189320 !ruby/object:Gem::Requirement
49
+ requirement: &70301606153740 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 2.6.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70137380189320
57
+ version_requirements: *70301606153740
58
58
  description:
59
59
  email: edouard@atelierconvivialite.com
60
60
  executables:
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  requirements: []
119
119
  rubyforge_project:
120
- rubygems_version: 1.8.11
120
+ rubygems_version: 1.8.10
121
121
  signing_key:
122
122
  specification_version: 3
123
123
  summary: A CLI to sync locale files with webtranslateit.com.