undrive_google 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +7 -1
- data/README.md +37 -1
- data/exe/undrive_google +0 -4
- data/lib/undrive_google/actions/liberate.rb +2 -2
- data/lib/undrive_google/actions/sweep.rb +23 -0
- data/lib/undrive_google/captive_file.rb +7 -1
- data/lib/undrive_google/config_file.rb +4 -1
- data/lib/undrive_google/helpers/parse.rb +3 -3
- data/lib/undrive_google/options.rb +16 -6
- data/lib/undrive_google/transformation.rb +6 -6
- data/lib/undrive_google/transformations/fix_html.rb +14 -4
- data/lib/undrive_google/transformations/rename_html.rb +1 -0
- data/lib/undrive_google/version.rb +1 -1
- data/lib/undrive_google.rb +18 -4
- data.tar.gz.sig +0 -0
- metadata +4 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0081f9e7ae701e26550ffe3e37cf522a2b10d5a907abb62445e386e0940c1a25'
|
4
|
+
data.tar.gz: c7d6711773d08db4e5069662f232b05fdeb7e49c0a885bd98723067ff8541101
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 530ded67ba7e198d26904929375a07f1bb09b66442abbccc287187f14f68a7b098ed6da4f4388c1b2b1114fd8768dd14fb7b1a1dbc19962d6176190b982ec3c1
|
7
|
+
data.tar.gz: 8cf1db466b609713de60873ff2622b3c1f647e8a9f1c8fdb4d5bdc207b59e890ab55f77ec0fe1c594f3eaac7d71df796aa92c5b4ed4fd1382c9354f919eb735e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -10,8 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
10
10
|
### Fixed
|
11
11
|
### Removed
|
12
12
|
|
13
|
+
## 1.0.3 - 2022-11-01
|
14
|
+
### Added
|
15
|
+
- Support for sweep option
|
16
|
+
### Fixed
|
17
|
+
- Documentation for how to use CLI (with config file, Gemfile, etc. See README)
|
18
|
+
|
13
19
|
## 1.0.2 - 2022-10-27
|
14
|
-
###
|
20
|
+
### Fixed
|
15
21
|
- Fixed typo in warning when wrong version of google_drive is loaded
|
16
22
|
|
17
23
|
## 1.0.1 - 2022-10-27
|
data/README.md
CHANGED
@@ -33,12 +33,48 @@ Therefore, if you need to unzip to HTML add another line to the `Gemfile` from a
|
|
33
33
|
gem "rubyzip", github: "rubyzip/rubyzip", branch: "master"
|
34
34
|
```
|
35
35
|
|
36
|
-
When liberating your files, ensure the script will use the Gemfile:
|
36
|
+
When liberating your files, ensure the script will use the Gemfile if it isn't in the same directory where you are running the `undrive_google` command:
|
37
37
|
```shell
|
38
38
|
BUNDLE_GEMFILE=path/to/Gemfile bundle update
|
39
39
|
BUNDLE_GEMFILE=path/to/Gemfile undrive_google -c path/to/config
|
40
40
|
```
|
41
41
|
|
42
|
+
My complete `Gemfile` looks like this:
|
43
|
+
```ruby
|
44
|
+
# frozen_string_literal: true
|
45
|
+
|
46
|
+
source "https://rubygems.org"
|
47
|
+
|
48
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
49
|
+
git_source(:gitlab) { |repo_name| "https://gitlab.com/#{repo_name}" }
|
50
|
+
|
51
|
+
gem "undrive_google", "~> 1.0.3"
|
52
|
+
|
53
|
+
# See: https://github.com/gimite/google-drive-ruby/pull/427
|
54
|
+
gem "google_drive", github: "pboling/google-drive-ruby", branch: "pboling-epub-mimetype"
|
55
|
+
|
56
|
+
# See: https://github.com/rubyzip/rubyzip#updating-to-version-30
|
57
|
+
gem "rubyzip", github: "rubyzip/rubyzip", branch: "master"
|
58
|
+
```
|
59
|
+
|
60
|
+
My config file looks like this (sanitized a bit):
|
61
|
+
```yaml
|
62
|
+
file_id: "the-key-to-my-google-drive-file(find-in-the-url)"
|
63
|
+
key_file: serviceid-1234567890.json
|
64
|
+
dir: /my/path/to/my/cv
|
65
|
+
rename_html: resume.html
|
66
|
+
rename_pattern:
|
67
|
+
- " "
|
68
|
+
- "_"
|
69
|
+
extensions: zip
|
70
|
+
keep_zip: true
|
71
|
+
unzip: true
|
72
|
+
verbose: true
|
73
|
+
sweep: true
|
74
|
+
```
|
75
|
+
|
76
|
+
The liberated files get published at [https://railsbling.com/cv](https://railsbling.com/cv).
|
77
|
+
|
42
78
|
## Story Time
|
43
79
|
|
44
80
|
Imagine Google Drive is a 🐭
|
data/exe/undrive_google
CHANGED
@@ -25,7 +25,7 @@ module UndriveGoogle
|
|
25
25
|
|
26
26
|
if Options.instance.unzip
|
27
27
|
@tr.unzip = Transformations::Unzip.new(@file_path)
|
28
|
-
@tr.fix_html = Transformations::FixHtml.new(@tr.unzip)
|
28
|
+
@tr.fix_html = Transformations::FixHtml.new(@tr.unzip) if Options.instance.lang || Options.instance.title
|
29
29
|
@tr.rename_html = Transformations::RenameHtml.new(@tr.unzip) if Options.instance.rename[:html]
|
30
30
|
end
|
31
31
|
|
@@ -42,7 +42,7 @@ module UndriveGoogle
|
|
42
42
|
exact_name = Options.instance.rename[extension]
|
43
43
|
return exact_name if exact_name
|
44
44
|
|
45
|
-
Options.instance.rename_proc.call(file.title)
|
45
|
+
Options.instance.rename[extension] = Options.instance.rename_proc.call(file.title)
|
46
46
|
end
|
47
47
|
|
48
48
|
# The zip is an HTML file packaged in a .zip archive
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UndriveGoogle
|
4
|
+
module Actions
|
5
|
+
# Empty the directory before putting liberated files into it?
|
6
|
+
class Sweep
|
7
|
+
attr_accessor :dir
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@dir = Options.instance.dir
|
11
|
+
end
|
12
|
+
|
13
|
+
def sweep!
|
14
|
+
return if !dir || dir.length.zero? || dir == "/"
|
15
|
+
return unless Dir.exist?(dir)
|
16
|
+
return if Dir.empty?(dir)
|
17
|
+
|
18
|
+
puts "Sweeping directory clean #{dir}" if Options.instance.verbose
|
19
|
+
FileUtils.rm_rf Dir.glob("#{dir}/*")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -8,10 +8,11 @@ module UndriveGoogle
|
|
8
8
|
|
9
9
|
# @return nil
|
10
10
|
def liberate!
|
11
|
+
sweep! if Options.instance.sweep
|
11
12
|
@exports = []
|
12
13
|
extensions.each do |format|
|
13
14
|
liberate = Actions::Liberate.new(format)
|
14
|
-
exports << liberate.file_path
|
15
|
+
@exports << liberate.file_path
|
15
16
|
liberate.liberate!
|
16
17
|
end
|
17
18
|
|
@@ -20,6 +21,11 @@ module UndriveGoogle
|
|
20
21
|
|
21
22
|
private
|
22
23
|
|
24
|
+
def sweep!
|
25
|
+
sweep = Actions::Sweep.new
|
26
|
+
sweep.sweep!
|
27
|
+
end
|
28
|
+
|
23
29
|
def extensions
|
24
30
|
Options.instance.extensions
|
25
31
|
end
|
@@ -21,6 +21,9 @@ module UndriveGoogle
|
|
21
21
|
rename[key.to_sym] = @args.delete(k.to_sym)
|
22
22
|
end
|
23
23
|
end
|
24
|
+
@args[:dir] = @args[:dir].strip if key?(:dir)
|
25
|
+
@args[:lang] = @args[:lang].strip if key?(:lang)
|
26
|
+
@args[:title] = @args[:title].strip if key?(:title)
|
24
27
|
@args[:extensions] = Helpers::Parse.extensions(@args[:extensions]) if key?(:extensions)
|
25
28
|
rename_pattern = @args.delete(:rename_pattern)
|
26
29
|
@args[:rename_proc] = Helpers::Parse.rename_proc(rename_pattern) if rename_pattern
|
@@ -48,7 +51,7 @@ module UndriveGoogle
|
|
48
51
|
|
49
52
|
def validate(config)
|
50
53
|
unknown = config.keys - YAML_KEYS
|
51
|
-
unknown.
|
54
|
+
unknown -= ALL_FILE_TYPES.map { |f| "rename_#{f}".to_sym }
|
52
55
|
return if unknown.empty?
|
53
56
|
|
54
57
|
raise UndriveGoogle::Error, "Unhandled config keys #{unknown.inspect}"
|
@@ -8,13 +8,13 @@ module UndriveGoogle
|
|
8
8
|
|
9
9
|
def extensions(val)
|
10
10
|
if val.is_a?(Array)
|
11
|
-
unknown = val.map(&:to_sym) -
|
11
|
+
unknown = val.map(&:to_sym) - DL_FILE_TYPES
|
12
12
|
raise UndriveGoogle::Error, "Unknown extensions: #{unknown}" if unknown.any?
|
13
13
|
|
14
14
|
val
|
15
15
|
elsif val == "all"
|
16
|
-
|
17
|
-
elsif
|
16
|
+
DL_FILE_TYPES
|
17
|
+
elsif DL_FILE_TYPES.include?(val.to_sym)
|
18
18
|
[val]
|
19
19
|
else
|
20
20
|
raise UndriveGoogle::Error, "Unknown extensions: #{val}"
|
@@ -7,7 +7,7 @@ module UndriveGoogle
|
|
7
7
|
|
8
8
|
attr_accessor :config_yaml, :key_file, :file_id, :file_by, :extensions, :unzip,
|
9
9
|
:keep_zip, :rename, :rename_proc, :lang, :title,
|
10
|
-
:dir, :verbose
|
10
|
+
:dir, :sweep, :verbose
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
load_yaml(true)
|
@@ -31,6 +31,7 @@ module UndriveGoogle
|
|
31
31
|
dir_option(parser)
|
32
32
|
lang_option(parser)
|
33
33
|
title_option(parser)
|
34
|
+
sweep_option(parser)
|
34
35
|
verbose_option(parser)
|
35
36
|
|
36
37
|
parser.separator ""
|
@@ -96,7 +97,7 @@ module UndriveGoogle
|
|
96
97
|
end
|
97
98
|
|
98
99
|
def rename_options(parser)
|
99
|
-
|
100
|
+
ALL_FILE_TYPES.each do |ft|
|
100
101
|
parser.on("--rename-#{ft} [FILENAME]", "Rename #{ft} to FILENAME") do |rename|
|
101
102
|
self.rename[ft] = rename
|
102
103
|
end
|
@@ -109,19 +110,27 @@ module UndriveGoogle
|
|
109
110
|
def dir_option(parser)
|
110
111
|
parser.on("-d", "--dir PATH", String,
|
111
112
|
"Path to directory where liberated files will go") do |dir|
|
112
|
-
self.dir = dir
|
113
|
+
self.dir = dir.strip
|
113
114
|
end
|
114
115
|
end
|
115
116
|
|
116
117
|
def lang_option(parser)
|
117
118
|
parser.on("-l", "--lang LANG", String, 'Add lang="LANG" attribute to <html> tag of unzipped HTML') do |lang|
|
118
|
-
self.lang = lang
|
119
|
+
self.lang = lang.strip
|
119
120
|
end
|
120
121
|
end
|
121
122
|
|
122
123
|
def title_option(parser)
|
123
124
|
parser.on("-t", "--title TITLE", String, "Add <title>TITLE</title> element to unzipped HTML") do |title|
|
124
|
-
self.title = title
|
125
|
+
self.title = title.strip
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def sweep_option(parser)
|
130
|
+
# Boolean switch.
|
131
|
+
parser.on("-s", "--[no-]sweep",
|
132
|
+
"Delete all files from directory specified by -d or --dir prior to liberation") do |sweep|
|
133
|
+
self.sweep = sweep
|
125
134
|
end
|
126
135
|
end
|
127
136
|
|
@@ -138,7 +147,7 @@ module UndriveGoogle
|
|
138
147
|
self.key_file = KEY_FILE_PATH
|
139
148
|
self.file_id = nil
|
140
149
|
self.file_by = :key
|
141
|
-
self.extensions =
|
150
|
+
self.extensions = DL_FILE_TYPES # "all" expands to FILE_TYPES
|
142
151
|
self.unzip = true
|
143
152
|
self.keep_zip = true
|
144
153
|
self.rename = {}
|
@@ -146,6 +155,7 @@ module UndriveGoogle
|
|
146
155
|
self.title = nil
|
147
156
|
self.dir = nil
|
148
157
|
self.lang = "en"
|
158
|
+
self.sweep = false
|
149
159
|
self.verbose = false
|
150
160
|
end
|
151
161
|
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module UndriveGoogle
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
Transformation = Struct.new(:download,
|
5
|
+
:unzip,
|
6
|
+
:fix_html,
|
7
|
+
:rename_html,
|
8
|
+
:delete_zip,
|
9
|
+
keyword_init: true) do
|
10
10
|
def liberate!
|
11
11
|
each(&:process)
|
12
12
|
end
|
@@ -17,6 +17,7 @@ module UndriveGoogle
|
|
17
17
|
|
18
18
|
def_delegator :@unzip, :html_path
|
19
19
|
|
20
|
+
# @param unzip [UndriveGoogle::Transformations::Unzip]
|
20
21
|
def initialize(unzip)
|
21
22
|
@unzip = unzip
|
22
23
|
@lang = Options.instance.lang
|
@@ -25,20 +26,29 @@ module UndriveGoogle
|
|
25
26
|
|
26
27
|
# @return nil
|
27
28
|
def process
|
28
|
-
return unless
|
29
|
+
return unless lang_valid? || title_valid?
|
30
|
+
raise UndriveGoogle::Error, "No file at #{html_path}" unless File.exist?(html_path)
|
29
31
|
|
30
32
|
puts "Checking html in #{html_path}" if Options.instance.verbose
|
31
33
|
file = File.open(html_path)
|
32
34
|
html = file.read
|
33
|
-
return unless html
|
35
|
+
return unless html.length >= 12 # open & close <html> or <head> is at least 12 chars
|
34
36
|
|
35
37
|
puts "Fixing html in #{html_path}" if Options.instance.verbose
|
36
|
-
html.sub!("<html>", "<html lang=\"#{lang}\">") if
|
37
|
-
html.sub!("<head>", "<head><title>#{title}</title>") if
|
38
|
+
html.sub!("<html>", "<html lang=\"#{lang}\">") if lang_valid?
|
39
|
+
html.sub!("<head>", "<head><title>#{title}</title>") if title_valid?
|
38
40
|
File.write(html_path, html)
|
39
41
|
|
40
42
|
nil
|
41
43
|
end
|
44
|
+
|
45
|
+
def lang_valid?
|
46
|
+
lang && lang.length >= 2
|
47
|
+
end
|
48
|
+
|
49
|
+
def title_valid?
|
50
|
+
title && title.length >= 1
|
51
|
+
end
|
42
52
|
end
|
43
53
|
end
|
44
54
|
end
|
data/lib/undrive_google.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Std-lib
|
4
|
-
require "
|
4
|
+
require "fileutils" # The Ruy File Utilities Library
|
5
5
|
require "forwardable" # The Ruby Delegation library
|
6
|
+
require "optparse" # The Ruby CLI Options Parsing library
|
7
|
+
require "psych" # The Ruby YAML library
|
6
8
|
require "singleton" # The Ruby Singleton library
|
7
9
|
|
8
10
|
# third party gems
|
@@ -13,13 +15,16 @@ rescue LoadError
|
|
13
15
|
end
|
14
16
|
require "version_gem"
|
15
17
|
require "google_drive"
|
16
|
-
|
17
|
-
|
18
|
+
HAS_EPUB = GoogleDrive::Util::EXT_TO_CONTENT_TYPE.key?(".epub")
|
19
|
+
unless HAS_EPUB
|
20
|
+
warn "[WARN] Your version of google_drive does not support .epub. If you need .epub support see: https://sr.ht/~galtzo/undrive_google/#note-export-epub-amp-unzip-html"
|
21
|
+
end
|
18
22
|
|
19
23
|
require_relative "undrive_google/version"
|
20
24
|
|
21
25
|
require_relative "undrive_google/helpers/parse"
|
22
26
|
require_relative "undrive_google/actions/liberate"
|
27
|
+
require_relative "undrive_google/actions/sweep"
|
23
28
|
require_relative "undrive_google/transformations/delete_zip"
|
24
29
|
require_relative "undrive_google/transformations/download"
|
25
30
|
require_relative "undrive_google/transformations/fix_html"
|
@@ -39,7 +44,15 @@ module UndriveGoogle
|
|
39
44
|
title: :title,
|
40
45
|
key: :key
|
41
46
|
}.freeze
|
42
|
-
|
47
|
+
# epub is conditionally in DL_FILE_TYPES depending on the google_drive gem used.
|
48
|
+
DL_FILE_TYPES = if HAS_EPUB
|
49
|
+
%i[docx odt rtf pdf txt zip epub].freeze
|
50
|
+
else
|
51
|
+
%i[docx odt rtf pdf txt zip].freeze
|
52
|
+
end
|
53
|
+
# html is not in DL_FILE_TYPES because you can't download it directly.
|
54
|
+
# html is downloaded as zip, and must then be unzipped.
|
55
|
+
ALL_FILE_TYPES = DL_FILE_TYPES + %i[html].freeze
|
43
56
|
RENAME_PROC = ->(orig) { orig.tr(" ", "_") }
|
44
57
|
YAML_KEYS = %i[
|
45
58
|
key_file
|
@@ -52,6 +65,7 @@ module UndriveGoogle
|
|
52
65
|
title
|
53
66
|
dir
|
54
67
|
lang
|
68
|
+
sweep
|
55
69
|
verbose
|
56
70
|
].freeze
|
57
71
|
CONFIG_YAML_PATH = "undrive_google.yaml"
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: undrive_google
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Boling
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
gwGrEXGQGDZ0NIgBcmvMOqlXjkGQwQvugKycJ024z89+fz2332vdZIKTrSxJrXGk
|
37
37
|
4/bR9A==
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date: 2022-
|
39
|
+
date: 2022-11-01 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: google_drive
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- exe/undrive_google
|
118
118
|
- lib/undrive_google.rb
|
119
119
|
- lib/undrive_google/actions/liberate.rb
|
120
|
+
- lib/undrive_google/actions/sweep.rb
|
120
121
|
- lib/undrive_google/captive_file.rb
|
121
122
|
- lib/undrive_google/cli.rb
|
122
123
|
- lib/undrive_google/config_file.rb
|
@@ -138,7 +139,7 @@ metadata:
|
|
138
139
|
source_code_uri: https://git.sr.ht/~galtzo/undrive_google
|
139
140
|
changelog_uri: https://git.sr.ht/~galtzo/undrive_google
|
140
141
|
bug_tracker_uri: https://todo.sr.ht/~galtzo/undrive_google
|
141
|
-
documentation_uri: https://www.rubydoc.info/gems/undrive_google/1.0.
|
142
|
+
documentation_uri: https://www.rubydoc.info/gems/undrive_google/1.0.3
|
142
143
|
wiki_uri: https://man.sr.ht/~galtzo/undrive_google/
|
143
144
|
funding_uri: https://liberapay.com/pboling
|
144
145
|
mailing_list_uri: https://lists.sr.ht/~galtzo/undrive_google-devel
|
metadata.gz.sig
CHANGED
Binary file
|