wikian 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 274ce53f95d131fe76efaecadf8b9ca1636c67922da81b6eab395645efa83b3b
4
- data.tar.gz: 5fc02ffd5461eeb7fb28686fc3defaa2046db44dd0feb479969e1106fb906648
3
+ metadata.gz: 66726501f7fd096888803fc73c97612ef35b26e3246c54c4f9fbb7ea887c9d78
4
+ data.tar.gz: 9cda60a1184cb39a79cec8a93cb36fba2cde382bb7d1d69ca7d1beb79f36dc4e
5
5
  SHA512:
6
- metadata.gz: 18211cf13b7adb90cdc92356e77f5fc776c869affabace2255be366e54048f25be37e89240490f3687aa4dab53a64e14f554329eb65c4158aa0c2226542d6876
7
- data.tar.gz: abe6b447651e7c884c04f1c62f6ab481cdf06915dbea677259664658cf249fda086da23418a2b34906e4db15eb3078a86e24ca4459e4922960d742df9b96b50f
6
+ metadata.gz: 5370603bfe66ffe85be969cbb5eadcd4f96dedcc59c594effb81f76c1b7538ba9588f822e7ef50c52c04a46e54217e086d93cd64cda742607018d1e5c9d81dc9
7
+ data.tar.gz: b9039ccf6311700d85ce6b80f62a8a9238e08ba3727a684e82764ace39778975bff5f543932e91b84749f1e094e89cef68a671d24607026fab75300366d3a85c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wikian (0.2.1)
4
+ wikian (0.2.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -78,6 +78,7 @@ class Wikian
78
78
  -a, --append append the input file
79
79
  -c, --captcha ID:MESSAGE captcha info
80
80
  -d, --debug print debugging messages
81
+ -f, --force force post (this ignores edit conflicts)
81
82
  -h, --help print this help message
82
83
  -m, --message MESSAGE add a commit message (HIGHLY recommended)
83
84
  -p, --prepend prepend the input file
@@ -21,7 +21,7 @@ class Wikian
21
21
 
22
22
  @api_url = URI("https://#{config['meta']['site']}/w/api.php?#{query}")
23
23
  rescue => e
24
- puts "#{e.class} in #{__FILE__}. #{e.message}"
24
+ puts "#{e.class} in #{__FILE__}", e.message
25
25
  exit
26
26
  end
27
27
 
@@ -24,7 +24,7 @@ class Wikian
24
24
 
25
25
  @api_url = URI("https://#{url.host}/w/api.php?#{query}")
26
26
  rescue => e
27
- puts "#{e.class} in #{__FILE__}. #{e.message}"
27
+ puts "#{e.class} in #{__FILE__}", e.message
28
28
  exit
29
29
  end
30
30
 
@@ -28,7 +28,7 @@ class Wikian
28
28
 
29
29
  @debug = (args & %w(-d)).length > 0 ? true : false
30
30
  rescue => e
31
- puts "#{e.class} in #{__FILE__}. #{e.message}"
31
+ puts "#{e.class} in #{__FILE__}", e.message
32
32
  exit
33
33
  end
34
34
 
@@ -55,9 +55,9 @@ class Wikian
55
55
 
56
56
  get_latest_revision
57
57
 
58
- if @body_text && Time.parse(params['starttimestamp']) < Time.parse(params['basetimestamp'])
59
- puts "\e[31mEdit conflict detected, merging with latest version\e[m"
60
- merge_versions
58
+ if !args.include?('-f') && @body_text && Time.parse(params['starttimestamp']) < Time.parse(params['basetimestamp'])
59
+ puts "Edit conflict detected"
60
+ merge_versions(@body_text, latest_content)
61
61
  end
62
62
 
63
63
  get_csrf_token
@@ -131,7 +131,7 @@ class Wikian
131
131
  timestamp
132
132
  else
133
133
  FileUtils.mkdir_p(Wikian.meta_dir)
134
- metadata = {'meta' => {'title' => {'timestamp' => File.ctime(input_file).utc.iso8601}}}
134
+ metadata = {'meta' => {'title' => {'timestamp' => File.mtime(input_file).utc.iso8601}}}
135
135
  File.write(Wikian.meta_file, YAML.dump(metadata))
136
136
  end
137
137
  wikitext = File.read(input_file)
@@ -154,16 +154,30 @@ class Wikian
154
154
  end
155
155
  end
156
156
 
157
- def merge_versions
158
- tmp_local = Tempfile.open {|f| f.write @body_text; f}
159
- tmp_latest = Tempfile.open {|f| f.write latest_content; f}
160
- @body_text = %x(diff --line-format %L #{tmp_local.path} #{tmp_latest.path})
161
- metadata['meta'].merge!(params['title'] => {'timestamp' => Time.now.utc.iso8601})
157
+ # merge two version with diff.
158
+ # TODO the merge command is ADDING differences, but it should MERGE differences.
159
+ def merge_versions(content_one, content_two)
160
+ tmp_local = Tempfile.open {|f| f.write content_one; f}
161
+ tmp_latest = Tempfile.open {|f| f.write content_two; f}
162
+
163
+ diff_cmd = "diff #{tmp_local.path} #{tmp_latest.path}"
164
+ system("#{diff_cmd}")
165
+
166
+ # raise error until the above TODO is solved
167
+ raise WikiMergeError, "Please merge with latest version and try again"
168
+
169
+ merge_cmd = "diff --line-format %L #{tmp_local.path} #{tmp_latest.path}"
170
+ @body_text = %x(#{merge_cmd})
162
171
  rescue => e
163
- puts "WikiMergeError in #{__FILE__}"
172
+ puts "#{e.class} in #{__FILE__}", e.message
164
173
  exit
165
174
  end
166
175
 
176
+ def update_metadata
177
+ metadata['meta'].merge!(params['title'] => {'timestamp' => Time.now.utc.iso8601})
178
+ File.write(Wikian.meta_file, YAML.dump(metadata))
179
+ end
180
+
167
181
  def upload_article
168
182
  @query = URI.encode_www_form(params)
169
183
  puts("\nUploading the wiki article using csrf token #{csrf_token}") if debug
@@ -182,6 +196,7 @@ class Wikian
182
196
  "Try pasing the '-r' option to remove '#{csrf_cookie_file}'",
183
197
  "Or pass '-d' option for debugging"
184
198
  else
199
+ update_metadata
185
200
  puts "Article uploaded"
186
201
  end
187
202
  end
@@ -14,7 +14,7 @@ class Wikian
14
14
 
15
15
  @api_url = URI("https://#{config['meta']['site']}/w/api.php?#{query}")
16
16
  rescue => e
17
- puts "#{e.class} in #{__FILE__}. #{e.message}"
17
+ puts "#{e.class} in #{__FILE__}", e.message
18
18
  exit
19
19
  end
20
20
 
@@ -65,7 +65,7 @@ class Wikian
65
65
 
66
66
  write_response
67
67
  rescue => e
68
- puts "#{e.class} in #{__FILE__}. #{e.message}"
68
+ puts "#{e.class} in #{__FILE__}", e.message
69
69
  exit
70
70
  end
71
71
 
@@ -1,3 +1,3 @@
1
1
  class Wikian
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sergioro