rb_bins 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/TODO.md +8 -0
- data/exe/rb_clean +18 -11
- data/exe/rb_rename +77 -0
- data/lib/rb_bins/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 849cae97896a50adaacaa99109f826bb1f515b14
|
4
|
+
data.tar.gz: 0a5fb1c9327bd7b87961724889021f6e18315638
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c82b6ce713cc91c1957fc702d4525d670cdbcd525f0eb5660191c40910b972ed134275c740a508fd738f120c1c09ee4189a0221ccb0317f4746e66a6b01620c1
|
7
|
+
data.tar.gz: e8fc8827e605441ceee315c411b6d63b276e9178b002ec699bdceac1ebc4938de6e0294880ed1447866a697c3e6c25260107bd2300f1aff3d7d939d17aa8b461
|
data/TODO.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
- rb_clean: preserve folder modification time if changed. flattened files as well
|
2
|
+
- ??? - dash button executables
|
3
|
+
- monitor directory and copy files for acd_cli
|
4
|
+
- only one instance should be running
|
5
|
+
- how to detect stalled uploads
|
6
|
+
- aws iam temporary creds
|
7
|
+
|
8
|
+
|
data/exe/rb_clean
CHANGED
@@ -20,7 +20,7 @@ module RbBins
|
|
20
20
|
class_option "no-filename-patterns", type: :boolean, default: false
|
21
21
|
|
22
22
|
class_option "unwanted_exts", type: :array, default: %w(url htm mht)
|
23
|
-
class_option "video_file_exts", type: :array, default: %w(mkv flv mp4 rm avi m4v)
|
23
|
+
class_option "video_file_exts", type: :array, default: %w(mkv flv mp4 rm avi m4v wmv)
|
24
24
|
class_option "min_size", type: :string, default: "100 MB"
|
25
25
|
class_option "filename_patterns_file", type: :string, default: "~/.rb_clean_fn_patterns"
|
26
26
|
|
@@ -30,9 +30,10 @@ module RbBins
|
|
30
30
|
|
31
31
|
def folder_grep
|
32
32
|
@full_path = File.expand_path(folder_grep_arg)
|
33
|
-
@full_path = File.join(
|
34
|
-
@path_dir, @path_base = Pathname.new(
|
35
|
-
|
33
|
+
@full_path = File.join(full_path, '*') if File.directory?(full_path)
|
34
|
+
@path_dir, @path_base = Pathname.new(full_path).split
|
35
|
+
@path_timestamp = File.stat(path_dir.to_s).mtime
|
36
|
+
raise Thor::Error, "Path must exist" unless @path_dir.exist?
|
36
37
|
end
|
37
38
|
|
38
39
|
def del_unwanted_ext_in_dir
|
@@ -68,8 +69,10 @@ module RbBins
|
|
68
69
|
files = Dir.glob(File.join(Regexp.quote(path_dir.to_s), "**/*.{#{options[:video_file_exts].join(",")}}"), File::FNM_CASEFOLD)
|
69
70
|
files.each do |file|
|
70
71
|
if File.new(file).size <= min_filesize_in_bytes
|
71
|
-
|
72
|
-
|
72
|
+
if (file =~ /sample/i).nil?
|
73
|
+
print "+".colorize(:light_blue)
|
74
|
+
$stdout.flush
|
75
|
+
end
|
73
76
|
|
74
77
|
FileUtils.rm(file, {
|
75
78
|
verbose: options["verbose"],
|
@@ -83,22 +86,26 @@ module RbBins
|
|
83
86
|
if options["flatten"]
|
84
87
|
files = Dir.glob(File.join(Regexp.quote(path_dir.to_s), "**/*")).sort_by {|x| -x.count('/') }
|
85
88
|
files.each do |file|
|
86
|
-
FileUtils.mv(file, path_dir, {
|
89
|
+
FileUtils.mv(file, path_dir.to_s, {
|
87
90
|
verbose: options["verbose"],
|
88
91
|
noop: options["dry-run"],
|
89
92
|
force: true
|
90
93
|
}) unless File.dirname(file).to_s == path_dir.to_s
|
91
94
|
end
|
92
95
|
if !options["dry-run"]
|
93
|
-
|
94
|
-
`find "#{path_dir}" -type d -empty -exec rmdir "{}" \\\;` ##recursively delete all empty folders in path_dir
|
95
|
-
end
|
96
|
+
`find "#{path_dir.to_s}" -type d -empty -prune -exec rmdir "{}" \\\;` ##recursively delete all empty folders in path_dir
|
96
97
|
end
|
97
98
|
end
|
98
99
|
end
|
99
100
|
|
101
|
+
def reset_folder_timestamp
|
102
|
+
if (File.stat(path_dir.to_s).mtime != path_timestamp)
|
103
|
+
File.utime(path_timestamp, path_timestamp, path_dir)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
100
107
|
private
|
101
|
-
attr_reader :full_path, :path_dir, :path_base
|
108
|
+
attr_reader :full_path, :path_dir, :path_base, :path_timestamp
|
102
109
|
end
|
103
110
|
end
|
104
111
|
end
|
data/exe/rb_rename
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rb_bins'
|
4
|
+
require 'dotenv'
|
5
|
+
require 'thor'
|
6
|
+
require 'pathname'
|
7
|
+
require 'filesize'
|
8
|
+
|
9
|
+
module RbBins
|
10
|
+
module Cli
|
11
|
+
class RbRename < Thor::Group
|
12
|
+
argument :folder_arg, type: :string, desc: "Folder to target", default: Dir.pwd
|
13
|
+
|
14
|
+
class_option "source", type: :string, default: ''
|
15
|
+
class_option "dry-run", type: :boolean, default: false
|
16
|
+
class_option "verbose", type: :boolean, default: false
|
17
|
+
|
18
|
+
class_option "video_file_exts", type: :array, default: %w(mkv flv mp4 rm avi m4v wmv)
|
19
|
+
|
20
|
+
def setup_env
|
21
|
+
Dotenv.load
|
22
|
+
end
|
23
|
+
|
24
|
+
def check_source
|
25
|
+
# file = use the name from the largest video file in directroy
|
26
|
+
# directory - use the name from the directory
|
27
|
+
raise Thor::Error, "Must have a valid source" unless %w(folder file dir directory).include?(options["source"].downcase)
|
28
|
+
end
|
29
|
+
|
30
|
+
def set_attribs
|
31
|
+
full_path = File.expand_path(folder_arg)
|
32
|
+
if File.directory?(full_path)
|
33
|
+
@path_dir = full_path
|
34
|
+
else
|
35
|
+
@path_dir = Pathname.new(full_path).dirname.to_s
|
36
|
+
end
|
37
|
+
@path_timestamp = File.stat(path_dir).mtime
|
38
|
+
@largest_file = find_largest_media_file_in_directory(path_dir)
|
39
|
+
puts largest_file
|
40
|
+
end
|
41
|
+
|
42
|
+
def rename_resource
|
43
|
+
if %w(folder dir directory).include?(options["source"].downcase)
|
44
|
+
FileUtils.cd(path_dir, verbose: options["verbose"]) do
|
45
|
+
search_pattern = Regexp.quote(File.basename(largest_file, ".*"))
|
46
|
+
puts search_pattern
|
47
|
+
|
48
|
+
`rename #{options["verbose"] ? '-v': ''} #{options["dry-run"] ? '-n': ''} 's/#{search_pattern}/#{File.basename(path_dir)}/' *`
|
49
|
+
end
|
50
|
+
elsif options["source"].downcase == "file"
|
51
|
+
new_path_dir = File.join(File.dirname(path_dir), File.basename(largest_file, '.*'))
|
52
|
+
FileUtils.mv(path_dir, new_path_dir, {
|
53
|
+
verbose: options["verbose"],
|
54
|
+
noop: options["dry-run"]
|
55
|
+
})
|
56
|
+
@path_dir = new_path_dir unless options["dry-run"]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def reset_folder_timestamp
|
61
|
+
if (File.stat(path_dir).mtime != path_timestamp)
|
62
|
+
File.utime(path_timestamp, path_timestamp, path_dir)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
attr_reader :path_dir, :largest_file, :path_timestamp
|
68
|
+
|
69
|
+
def find_largest_media_file_in_directory(directory)
|
70
|
+
files = Dir.glob(File.join(Regexp.quote(path_dir), "**/*.{#{options[:video_file_exts].join(",")}}"), File::FNM_CASEFOLD)
|
71
|
+
files.max_by { |file| File.size(file) }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
RbBins::Cli::RbRename.start(ARGV)
|
data/lib/rb_bins/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rb_bins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yu-Hung Lin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -141,6 +141,7 @@ email:
|
|
141
141
|
- yuhung@yuhunglin.com
|
142
142
|
executables:
|
143
143
|
- rb_clean
|
144
|
+
- rb_rename
|
144
145
|
extensions: []
|
145
146
|
extra_rdoc_files: []
|
146
147
|
files:
|
@@ -150,9 +151,11 @@ files:
|
|
150
151
|
- LICENSE.txt
|
151
152
|
- README.md
|
152
153
|
- Rakefile
|
154
|
+
- TODO.md
|
153
155
|
- bin/console
|
154
156
|
- bin/setup
|
155
157
|
- exe/rb_clean
|
158
|
+
- exe/rb_rename
|
156
159
|
- lib/rb_bins.rb
|
157
160
|
- lib/rb_bins/version.rb
|
158
161
|
- rb_bins.gemspec
|