commons_upload 1.0.1 → 1.1.0

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
- SHA1:
3
- metadata.gz: 2628e2d11f98afd0f6f852271c70822dd7e3a13b
4
- data.tar.gz: 7bdea102ebb5e865f1140a4a5e0e88be3998dbc5
2
+ SHA256:
3
+ metadata.gz: eebc8ad7139529eb45960653266cc6a0656db1ef7f7f1b119bfd283151a40b38
4
+ data.tar.gz: a1fb75e17150721c83168e3591c70cda453b8e5ff3b378ff73da3fbb6a009088
5
5
  SHA512:
6
- metadata.gz: b6d526cd37d69badca5accdf2f1a30bdfa1cd98ceead2930b62e55376dec97e48460c7521c53feb8fa44ce46ee621f2ae1392ed266f5e5c9a8b7e61ee5f6f586
7
- data.tar.gz: 0e8dbbe13699a592773619568209b1d635c2185b161602ce9d338180d2a40a0bdf138e8f9cc4bec710012f0cff7e831b81334b99394332e9023532c77f239d39
6
+ metadata.gz: 011aae0dcf05a234f4534ae5352d6fb153a3cdff04c0ab7734aad052a7cc8db15ac3e0899e01254603cf951b589764df8d0fabffb447da5b5570b9275c6f40b7
7
+ data.tar.gz: 5f9181a46864f1660a080212b97bbb4ca762b74217f7cfe05d703e1dd79d2cde6b0e8e5b09ad519e6c39a50c68a221d75569645ea08ac9c0ccd9b1bf25352890
@@ -1,8 +1,6 @@
1
- inherit_from: .rubocop_todo.yml
2
-
3
1
  # Needed for ignoring leading whitespace in heredoc
4
2
  AllCops:
5
- TargetRubyVersion: 2.1
3
+ TargetRubyVersion: 2.3
6
4
 
7
5
  # The default is 15, which is too tight
8
6
  Metrics/AbcSize:
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.5
3
+ - 2.3
4
4
  install: bundle install
5
5
  script:
6
6
  - bundle exec rubocop
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in commons_upload.gemspec
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2016 Vikas Yaligar, Željko Filipin and Amir E. Aharoni
1
+ Copyright (c) 2014-2018 Vikas Yaligar, Željko Filipin and Amir E. Aharoni
2
2
  under the terms of The MIT License (MIT), as follows:
3
3
 
4
4
  This software consists of voluntary contributions made by many
data/README.md CHANGED
@@ -25,6 +25,8 @@ Or install it yourself as:
25
25
  To run the upload, do
26
26
 
27
27
  # optional, the default is ./screenshots
28
+ # file names have to be in this format VisualEditor_category_item-en.png
29
+ # language code is `en`, between `-` and `.`
28
30
  export LANGUAGE_SCREENSHOT_PATH=./screenshots
29
31
 
30
32
  # testing: https://commons.wikimedia.beta.wmflabs.org/w/api.php
@@ -43,3 +45,5 @@ To run the upload, do
43
45
  3. Commit your changes (`git commit -am 'Add some feature'`)
44
46
  4. Push to the branch (`git push origin my-new-feature`)
45
47
  5. Create new Pull Request
48
+
49
+ [![Build Status](https://travis-ci.org/amire80/commons_upload.svg?branch=master)](https://travis-ci.org/amire80/commons_upload)
data/Rakefile CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
data/bin/upload CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'commons_upload'
3
5
 
4
6
  CommonsUpload.images
@@ -1,5 +1,6 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'commons_upload/version'
5
6
 
@@ -14,15 +15,15 @@ Gem::Specification.new do |spec|
14
15
  spec.homepage = 'https://github.com/amire80/commons_upload'
15
16
  spec.license = 'MIT'
16
17
 
17
- spec.files = `git ls-files`.split($/)
18
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
19
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
21
  spec.require_paths = ['lib']
21
- spec.required_ruby_version = '~> 2.0'
22
+ spec.required_ruby_version = '~> 2.3'
22
23
 
23
- spec.add_runtime_dependency 'mediawiki_api', '~> 0.7.0'
24
+ spec.add_runtime_dependency 'mediawiki_api', '~> 0.7.1'
24
25
 
25
- spec.add_development_dependency 'bundler', '~> 1.3'
26
- spec.add_development_dependency 'rake', '~> 10.1'
27
- spec.add_development_dependency 'rubocop', '~> 0.42.0'
26
+ spec.add_development_dependency 'bundler', '~> 1.16', '>= 1.16.1'
27
+ spec.add_development_dependency 'rake', '~> 12.3'
28
+ spec.add_development_dependency 'rubocop', '~> 0.53.0'
28
29
  end
@@ -1,4 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Iterate over all images, create license, upload image by image
1
4
  module CommonsUpload
5
+ def self.edit(file_name, client)
6
+ page = "File:#{file_name}"
7
+ client.edit(title: page, text: license(file_name), summary: 'Update page text')
8
+ end
9
+
2
10
  def self.license(file_name)
3
11
  require 'date'
4
12
  date = Date.today.to_s
@@ -8,31 +16,41 @@ module CommonsUpload
8
16
  # in this case it is: en
9
17
  language_code = file_name.split('-')[1].split('.')[0]
10
18
 
11
- <<EOS
12
- =={{int:filedesc}}==
13
- {{Information
14
- |description={{en|1=#{file_name}}}
15
- |date=#{date}
16
- |source=[[User:LanguageScreenshotBot|Automatically created by LanguageScreenshotBot]]
17
- |author=[[User:LanguageScreenshotBot|Automatically created by LanguageScreenshotBot]]
18
- |permission=
19
- |other_versions=
20
- |other_fields=
21
- }}
22
-
23
- =={{int:license-header}}==
24
- {{Wikipedia-screenshot}}
25
-
26
- [[Category:VisualEditor-#{language_code}]]
27
- EOS
19
+ <<~LICENSE
20
+ =={{int:filedesc}}==
21
+ {{Information
22
+ |description={{en|1=#{file_name}}}
23
+ |date=#{date}
24
+ |source=[[User:LanguageScreenshotBot|Automatically created by LanguageScreenshotBot]]
25
+ |author=[[User:LanguageScreenshotBot|Automatically created by LanguageScreenshotBot]]
26
+ |permission=
27
+ |other_versions=
28
+ |other_fields=
29
+ }}
30
+
31
+ =={{int:license-header}}==
32
+ {{Wikimedia-screenshot}}
33
+
34
+ [[Category:VisualEditor-#{language_code}]]
35
+ LICENSE
28
36
  end
29
37
 
30
38
  def self.image(file_path, client)
31
39
  file_name = File.basename(file_path, '')
32
40
  file_license = license(file_name)
33
41
 
34
- client.upload_image(file_name, file_path, file_license, true)
35
- sleep 5 # Restriction in bot speed: https://commons.wikimedia.org/wiki/Commons:Bots#Bot_speed
42
+ begin
43
+ client.upload_image(
44
+ file_name, file_path, 'Upload new version of the file', true, file_license
45
+ )
46
+ return 'OK'
47
+ rescue MediawikiApi::ApiError => mwerr
48
+ raise mwerr if mwerr.code != 'fileexists-no-change'
49
+ return 'OK (file already uploaded)'
50
+ ensure
51
+ edit(file_name, client) # update page content
52
+ sleep 5 # Restriction in bot speed: https://commons.wikimedia.org/wiki/Commons:Bots#Bot_speed
53
+ end
36
54
  end
37
55
 
38
56
  def self.images
@@ -41,8 +59,16 @@ EOS
41
59
  client = MediawikiApi::Client.new ENV['MEDIAWIKI_API_UPLOAD_URL']
42
60
  client.log_in ENV['MEDIAWIKI_USER'], ENV['MEDIAWIKI_PASSWORD']
43
61
  Dir["#{screenshot_directory}/*.png"].each do |file_path|
44
- puts "Uploading #{file_path}"
45
- image file_path, client
62
+ print "Uploading #{file_path} ... "
63
+ STDOUT.flush
64
+ begin
65
+ message = image file_path, client
66
+ puts message
67
+ rescue StandardError => e
68
+ puts 'FAILED'
69
+ raise e
70
+ end
71
+ STDOUT.flush
46
72
  end
47
73
  end
48
74
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CommonsUpload
2
- VERSION = '1.0.1'.freeze
4
+ VERSION = '1.1.0'
3
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commons_upload
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vikas Yaligar
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-08-24 00:00:00.000000000 Z
13
+ date: 2018-03-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: mediawiki_api
@@ -18,56 +18,62 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: 0.7.0
21
+ version: 0.7.1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: 0.7.0
28
+ version: 0.7.1
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: bundler
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: '1.3'
35
+ version: '1.16'
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: 1.16.1
36
39
  type: :development
37
40
  prerelease: false
38
41
  version_requirements: !ruby/object:Gem::Requirement
39
42
  requirements:
40
43
  - - "~>"
41
44
  - !ruby/object:Gem::Version
42
- version: '1.3'
45
+ version: '1.16'
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 1.16.1
43
49
  - !ruby/object:Gem::Dependency
44
50
  name: rake
45
51
  requirement: !ruby/object:Gem::Requirement
46
52
  requirements:
47
53
  - - "~>"
48
54
  - !ruby/object:Gem::Version
49
- version: '10.1'
55
+ version: '12.3'
50
56
  type: :development
51
57
  prerelease: false
52
58
  version_requirements: !ruby/object:Gem::Requirement
53
59
  requirements:
54
60
  - - "~>"
55
61
  - !ruby/object:Gem::Version
56
- version: '10.1'
62
+ version: '12.3'
57
63
  - !ruby/object:Gem::Dependency
58
64
  name: rubocop
59
65
  requirement: !ruby/object:Gem::Requirement
60
66
  requirements:
61
67
  - - "~>"
62
68
  - !ruby/object:Gem::Version
63
- version: 0.42.0
69
+ version: 0.53.0
64
70
  type: :development
65
71
  prerelease: false
66
72
  version_requirements: !ruby/object:Gem::Requirement
67
73
  requirements:
68
74
  - - "~>"
69
75
  - !ruby/object:Gem::Version
70
- version: 0.42.0
76
+ version: 0.53.0
71
77
  description: Upload images to Wikimedia Commons. This is intended for uploading auto-translated
72
78
  screenshots for MediaWiki documentation.
73
79
  email:
@@ -79,7 +85,6 @@ extra_rdoc_files: []
79
85
  files:
80
86
  - ".gitignore"
81
87
  - ".rubocop.yml"
82
- - ".rubocop_todo.yml"
83
88
  - ".travis.yml"
84
89
  - Gemfile
85
90
  - LICENSE.txt
@@ -101,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
106
  requirements:
102
107
  - - "~>"
103
108
  - !ruby/object:Gem::Version
104
- version: '2.0'
109
+ version: '2.3'
105
110
  required_rubygems_version: !ruby/object:Gem::Requirement
106
111
  requirements:
107
112
  - - ">="
@@ -109,9 +114,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
114
  version: '0'
110
115
  requirements: []
111
116
  rubyforge_project:
112
- rubygems_version: 2.5.1
117
+ rubygems_version: 2.7.6
113
118
  signing_key:
114
119
  specification_version: 4
115
120
  summary: Upload images to Wikimedia Commons.
116
121
  test_files: []
117
- has_rdoc:
@@ -1,35 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2016-08-22 17:24:35 +0200 using RuboCop version 0.42.0.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 1
10
- Style/Documentation:
11
- Exclude:
12
- - 'spec/**/*'
13
- - 'test/**/*'
14
- - 'lib/commons_upload.rb'
15
-
16
- # Offense count: 6
17
- # Cop supports --auto-correct.
18
- # Configuration parameters: EnforcedStyle, SupportedStyles.
19
- # SupportedStyles: when_needed, always
20
- Style/FrozenStringLiteralComment:
21
- Exclude:
22
- - 'Gemfile'
23
- - 'Rakefile'
24
- - 'bin/upload'
25
- - 'commons_upload.gemspec'
26
- - 'lib/commons_upload.rb'
27
- - 'lib/commons_upload/version.rb'
28
-
29
- # Offense count: 1
30
- # Cop supports --auto-correct.
31
- # Configuration parameters: EnforcedStyle, SupportedStyles.
32
- # SupportedStyles: use_perl_names, use_english_names
33
- Style/SpecialGlobalVars:
34
- Exclude:
35
- - 'commons_upload.gemspec'