ezfile 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34603bc458640c0a6df633fd43693949765eb206947e8323f54cb2596b9092f3
4
- data.tar.gz: ed0aae45477fb2c47bdeca9051a1ecde6c61bb5018e945263a62f63ef4128b7a
3
+ metadata.gz: 06bea03ff8d5923b4594dc2df04b891eebcc6665e614fb4664b2994984edb876
4
+ data.tar.gz: 1d2e0c330259a3ff264b4b36b1cc50d12bbcef2f25cd98acfb2521ebbcfa691b
5
5
  SHA512:
6
- metadata.gz: 75c9e14148d413e830d096612bf0975b79ec0ec504833b20a036cc8632c0596c4b1b2360974f376b9962c85e2ce8122058e04e3ab7637f1e4e6d42b7804ea684
7
- data.tar.gz: fcdd6773c088afbb1d6f7c2a7eb4f67484fe6fcba6d9d2a9c63abffcff00ccbc67c6c39574cf54ff7b90f99db09cbd69020d5ce9fed79865de40da11a8fd3205
6
+ metadata.gz: dd9859c2fb4217ab2b7c635f15b17980556d529f6533769f96941049e3fb29936c64557d8c2a40c730bcf86f9e33a484b878d055f9478ba3293bd3e7b56520c2
7
+ data.tar.gz: b3e04b4877abfb3966248579cb887ee5a14862788f35c5c219fad3daf3c1038b43a13972a1f2ec736fe73554445f9413b5915174725558d76cd372c8a039a752
data/README.md CHANGED
@@ -6,10 +6,8 @@ Ezfile is a file util more safety than another gem `FileUtils`
6
6
 
7
7
  ## Installation
8
8
 
9
-
10
9
  gem install ezfile
11
10
 
12
-
13
11
  ## Usage
14
12
 
15
13
  ```ruby
@@ -17,17 +15,19 @@ require 'ezfile'
17
15
 
18
16
  pwd = Dir.pwd
19
17
 
20
- Ezfile.files("*")
21
- .group_by{|fname| Ezfile.mainname}
22
- .select{|mname, fs| fs.any{|f| Ezfile.extname(f) == ".ass"}}
23
- .each do |fname, fs|
24
- ass = File.combine(pwd, fname +".ass")
25
- mp4 = File.combine(pwd, fname +".mp4")
26
- outf = fname+".done.mp4"
27
- system %Q(ffmpeg -i #{mp4.inspect} -vf subtitles=#{ass.inspect} -c:v h264_nvenc "./out/#{outf}")
28
- end
18
+ Ezfile.files("*") # default is "*"
19
+ .group_by{|fname| Ezfile.mainname}
20
+ .select{|mname, fs| fs.any{|f| Ezfile.extname(f) == ".ass"}}
21
+ .each do |fname, fs|
22
+ ass = File.combine(pwd, fname +".ass")
23
+ mp4 = File.combine(pwd, fname +".mp4")
24
+ outf = fname+".done.mp4"
25
+ system %Q(ffmpeg -i #{mp4.inspect} -vf subtitles=#{ass.inspect} -c:v h264_nvenc "./out/#{outf}")
26
+ end
29
27
  ```
28
+
30
29
  Use `Ezfile.help` to get help.
30
+
31
31
  ```ruby
32
32
  Ezfile.help
33
33
 
@@ -59,19 +59,10 @@ Ezfile.help
59
59
  EOF
60
60
  ```
61
61
 
62
- ## Development
63
-
64
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
65
-
66
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
67
-
68
62
  ## Contributing
69
63
 
70
- Bug reports and pull requests are welcome on GitHub at https://github.com/saisui/ezfilerb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/saisui/ezfilerb/blob/master/CODE_OF_CONDUCT.md).
64
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/saisui/ezfilerb>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/saisui/ezfilerb/blob/master/CODE_OF_CONDUCT.md).
71
65
 
72
66
  ## License
73
67
 
74
68
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
75
-
76
- ## Code of Conduct
77
-
@@ -0,0 +1 @@
1
+ b0c15a12ad7bbc27f8d972aecb20aecc7d63235c7106f86b0cfd0a6e1e33519cb67930f7e81e54fccff75efdd99160557a97f4db67791f5e0c4e75cbd41d3dc0
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ezfile
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/ezfile.rb CHANGED
@@ -20,27 +20,27 @@ module Ezfile
20
20
  # nut_a.black.you.one
21
21
 
22
22
  def test_rebasename path, new_basename
23
- File.join(File.dirname(File.expand_path(path)), new_basename + File.extname(path))
23
+ File.join(File.dirname(File.expand_path(path)), new_basename + File.extname(path))
24
24
  end
25
25
 
26
26
  # -[x] cannot move file or change its parent node | 重命名不改变源文件父节点,不移动源文件。
27
27
  def rebasename_file nodepath, new_basename
28
28
 
29
- if new_basename.split(/[\/\\]/).size == 0
30
- return throw puts " wrong ".on_light_yellow + " That's no new basename"
31
- elsif new_basename.split(/[\/\\]/).size >= 2
32
- return throw puts " FORBIDDEN ".light_white.on_yellow + " do not move its parent node, don't input a path"
33
- end
29
+ if new_basename.split(/[\/\\]/).size == 0
30
+ return throw puts " wrong ".on_light_yellow + " That's no new basename"
31
+ elsif new_basename.split(/[\/\\]/).size >= 2
32
+ return throw puts " FORBIDDEN ".light_white.on_yellow + " do not move its parent node, don't input a path"
33
+ end
34
34
 
35
- src_dirpath = File.dirname File.expand_path(nodepath)
35
+ src_dirpath = File.dirname File.expand_path(nodepath)
36
36
 
37
- unless File.exist? nodepath
38
- return throw puts " ERROR ".light_white.on_red + " File " + "non-exist".red
39
- end
40
- new_name = new_basename + File.extname(nodepath)
41
- unless Dir.entries(File.dirname nodepath).include? new_name
42
- File.rename nodepath, File.join(src_dirpath, new_name)
43
- end
37
+ unless File.exist? nodepath
38
+ return throw puts " ERROR ".light_white.on_red + " File " + "non-exist".red
39
+ end
40
+ new_name = new_basename + File.extname(nodepath)
41
+ unless Dir.entries(File.dirname nodepath).include? new_name
42
+ File.rename nodepath, File.join(src_dirpath, new_name)
43
+ end
44
44
  end
45
45
 
46
46
  # < means headpoint of a basename, > means lastpoint of a basename. like ^ and $ in RegEx
@@ -50,92 +50,95 @@ module Ezfile
50
50
  # headname <name
51
51
 
52
52
  def tailname fname
53
- Ezfile.basename(fname).match(/((\.[0-9A-Za-z\-_]+)+$)/)[0]
53
+ Ezfile.basename(fname).match(/((\.[0-9A-Za-z\-_]+)+$)/)[0]
54
+ end
55
+ def tailnames fname
56
+ Ezfile.basename(fname).match(/((\.[0-9A-Za-z\-_]+)+$)/)[0].split(/(?=\.)/)
54
57
  end
55
58
 
56
59
  def headname fname
57
- File.basename(fname)[0...-tailname(fname).size]
60
+ File.basename(fname)[0...-tailname(fname).size]
58
61
  end
59
62
 
60
63
  def mainname file_name
61
- File.basename file_name, ".*"
64
+ File.basename file_name, ".*"
62
65
  end
63
66
 
64
67
 
65
68
  def its_dir_base_ext file_path
66
- [File.dirname(file_path), File.basename(file_path, ".*"), File.extname(file_path)]
69
+ [File.dirname(file_path), File.basename(file_path, ".*"), File.extname(file_path)]
67
70
  end
68
71
 
69
72
  def basename file_name, suffix = ""
70
- File.basename file_name, suffix
73
+ File.basename file_name, suffix
71
74
  end
72
75
 
73
76
  def move_file file_path, target_dir, mkdir: false, rename: false, rename_fmt: "__%C"
74
- unless File.exist? file_path
75
- return throw puts " ERROR ".light_white.on_red + " File " + "non-exist".red
76
- end
77
- file_name = File.basename file_path
78
-
79
- # src_exist = File.exist? file_path
80
- # src_is_file = File.file? file_path rescue false
81
- # dest_exist = Dir.exist? target_dir
82
- # dest_is_dir = File.directory? target_dir rescue false
83
- # not_same_name = target_dir_entries.include? file_name rescue false
84
-
85
- isit_should_move = false
86
-
87
- if Dir.exist? target_dir
88
- target_dir_entries = Dir.entries target_dir
89
- if target_dir_entries.include? file_name
90
- if rename == true
91
-
92
- rename_count = 0
93
- # nDigits = rename_fmt.count("#")
94
- begin
95
- rename_count += 1
96
- # rename_postfix = rename_fmt.gsub(/#*/, "%0#{nDigits}d" % rename_count)
97
- src_dirpath, file_basename, file_ext = its_dir_base_ext(file_path)
98
- new_basename = file_basename + "__mv_rename_#{rename_count}"
99
- new_name = new_basename + file_ext
100
-
101
- new_name_file_path = File.join(src_dirpath, new_name)
102
- end while target_dir_entries.include? new_name
103
-
104
- rebasename_file(file_path, new_basename)
105
- return move_file(new_name_file_path, target_dir)
106
- end
107
- return throw puts " ERROR ".light_white.on_red + %Q( === Destination already has a same name node! -- "#{file_name.red}" ===)
108
- end
109
- isit_should_move = true
110
- elsif mkdir == true
111
- Dir.mkdir target_dir
112
- isit_should_move = true
113
- else
114
- return throw puts " ERROR ".light_white.on_red + " Destination Directory doesn't exist!"
77
+ unless File.exist? file_path
78
+ return throw puts " ERROR ".light_white.on_red + " File " + "non-exist".red
79
+ end
80
+ file_name = File.basename file_path
81
+
82
+ # src_exist = File.exist? file_path
83
+ # src_is_file = File.file? file_path rescue false
84
+ # dest_exist = Dir.exist? target_dir
85
+ # dest_is_dir = File.directory? target_dir rescue false
86
+ # not_same_name = target_dir_entries.include? file_name rescue false
87
+
88
+ isit_should_move = false
89
+
90
+ if Dir.exist? target_dir
91
+ target_dir_entries = Dir.entries target_dir
92
+ if target_dir_entries.include? file_name
93
+ if rename == true
94
+
95
+ rename_count = 0
96
+ # nDigits = rename_fmt.count("#")
97
+ begin
98
+ rename_count += 1
99
+ # rename_postfix = rename_fmt.gsub(/#*/, "%0#{nDigits}d" % rename_count)
100
+ src_dirpath, file_basename, file_ext = its_dir_base_ext(file_path)
101
+ new_basename = file_basename + "__mv_rename_#{rename_count}"
102
+ new_name = new_basename + file_ext
103
+
104
+ new_name_file_path = File.join(src_dirpath, new_name)
105
+ end while target_dir_entries.include? new_name
106
+
107
+ rebasename_file(file_path, new_basename)
108
+ return move_file(new_name_file_path, target_dir)
109
+ end
110
+ return throw puts " ERROR ".light_white.on_red + %Q( === Destination already has a same name node! -- "#{file_name.red}" ===)
115
111
  end
112
+ isit_should_move = true
113
+ elsif mkdir == true
114
+ Dir.mkdir target_dir
115
+ isit_should_move = true
116
+ else
117
+ return throw puts " ERROR ".light_white.on_red + " Destination Directory doesn't exist!"
118
+ end
116
119
 
117
- if isit_should_move
118
- FileUtils.move file_path, target_dir
119
- end
120
+ if isit_should_move
121
+ FileUtils.move file_path, target_dir
122
+ end
120
123
  end
121
124
 
122
125
  def copy_file file_path, dest_file_path
123
- if File.exist? dest_file_path
124
- return throw puts " FORBIDDEN ".light_white.on_yellow + " There is a same name node, cannot " + " COVER ".light_white.on_red.bold + " another existen node, Because will " + " LOSE ".light_white.on_red + " the FILE."
125
- end
126
- FileUtils.copy_file file_path, dest_file_path
126
+ if File.exist? dest_file_path
127
+ return throw puts " FORBIDDEN ".light_white.on_yellow + " There is a same name node, cannot " + " COVER ".light_white.on_red.bold + " another existen node, Because will " + " LOSE ".light_white.on_red + " the FILE."
128
+ end
129
+ FileUtils.copy_file file_path, dest_file_path
127
130
  end
128
131
 
129
132
  def move_file_mkdir file_path, target_dir
130
- self.move_file file_name, target_dir, mkdir: true
133
+ self.move_file file_name, target_dir, mkdir: true
131
134
  end
132
135
 
133
136
  def file_list dir = "*"
134
- Dir.glob(dir).select{File.file? _1}
137
+ Dir.glob(dir).select{File.file? _1}
135
138
  end
136
139
 
137
140
  def dir_list dir = "*"
138
- Dir.glob(dir).select{File.directory? _1}
141
+ Dir.glob(dir).select{File.directory? _1}
139
142
  end
140
143
 
141
144
  alias files file_list
@@ -160,35 +163,49 @@ module Ezfile
160
163
  end
161
164
 
162
165
  def help
163
- puts <<-EOF
164
- require #{"FileUtils".red} and #{"Dir".red}, #{"File".red}.
165
- methods:
166
- #{" MOVE ".bold.underline.on_red}:
167
- #{"::move_file".cyan} file_path target_dir, mkdir: false
168
- move file to target directory
169
- ! if directory is non-exist,
170
- throw an error.
171
- #{"::move_file ".cyan} file_path, target_dir
172
- if non-exist, mkdir
173
- #{" QUERY ".bold.underline.on_green}: its syntax like #{"Explorer Search".underline}
174
- #{"::file_list ".cyan} target_dir = "*" alias #{"::files".cyan}
175
- #{"::dir_list ".cyan} target_dir = "*" alias #{"::dirs".cyan}
176
- show list of files/directories, of target_dir.
177
- ! using #{"Dir.glob(target_dir)".italic.underline.yellow}
178
- #{"::its_dir_base_ext ".cyan} file_path
179
- return an array of file's dirpath basename extname.
180
- #{"::glob".cyan} query
181
- the same as #{"Dir.glob(query)".italic.underline.yellow}
182
-
183
- #{" RENAME ".bold.underline.on_yellow}:
184
- #{"::rebasename_file".cyan} src_file_path, new_basename
185
- it change a file's basename, and ensure never move it or change its parent node.
186
-
187
- #{" DELETE ".bold.underline.on_red}:
188
- #{"::ensure_permanently_delete_file".cyan} target_file alias #{"::files".cyan}
189
- #{"::ensure_permanently_delete_directory_and_its_descendant".cyan} target_dir alias #{"::files".cyan}
190
- EOF
166
+ puts <<-EOF
167
+ require #{"FileUtils".red} and #{"Dir".red}, #{"File".red}.
168
+ methods:
169
+ #{" MOVE ".bold.underline.on_red}:
170
+ #{"::move_file".cyan} file_path target_dir, mkdir: false
171
+ move file to target directory
172
+ ! if directory is non-exist,
173
+ throw an error.
174
+ #{"::move_file ".cyan} file_path, target_dir
175
+ if non-exist, mkdir
176
+ #{" QUERY ".bold.underline.on_green}: its syntax like #{"Explorer Search".underline}
177
+ #{"::file_list ".cyan} target_dir = "*" alias #{"::files".cyan}
178
+ #{"::dir_list ".cyan} target_dir = "*" alias #{"::dirs".cyan}
179
+ show list of files/directories, of target_dir.
180
+ ! using #{"Dir.glob(target_dir)".italic.underline.yellow}
181
+ #{"::its_dir_base_ext ".cyan} file_path
182
+ return an array of file's dirpath basename extname.
183
+ #{"::glob".cyan} query
184
+ the same as #{"Dir.glob(query)".italic.underline.yellow}
185
+
186
+ #{" RENAME ".bold.underline.on_yellow}:
187
+ #{"::rebasename_file".cyan} src_file_path, new_basename
188
+ it change a file's basename, and ensure never move it or change its parent node.
189
+
190
+ #{" DELETE ".bold.underline.on_red}:
191
+ #{"::ensure_permanently_delete_file".cyan} target_file alias #{"::files".cyan}
192
+ #{"::ensure_permanently_delete_directory_and_its_descendant".cyan} target_dir alias #{"::files".cyan}
193
+ EOF
191
194
  end
192
195
 
193
196
  end
194
197
  end
198
+
199
+ class String
200
+
201
+ def to_file_ezfile fpath = "file_" + Time.now.strftime("%y%m%s_%H%M%S") + ".txt"
202
+ if File.exist?(fpath)
203
+ puts ""
204
+ return throw puts " ERROR ".light_white.on_red + " Destination Directory doesn't exist!"
205
+ else
206
+ f = File.new(fpath, "w")
207
+ f.puts self
208
+ f.close
209
+ end
210
+ end
211
+ end
data/sig/ezfile.rbs CHANGED
@@ -1,4 +1,5 @@
1
1
  module Ezfile
2
2
  VERSION: String
3
3
  # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ def self.test_rebasename: Array
4
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ezfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - saisui
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-10 00:00:00.000000000 Z
11
+ date: 2023-11-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'More Safety than FileUtils. Like #move_file, #copy_file, #rename_file.
14
14
  If that destination string including a space, it will be a correct node name. If
@@ -26,6 +26,7 @@ files:
26
26
  - LICENSE.txt
27
27
  - README.md
28
28
  - Rakefile
29
+ - checksums/ezfile-0.1.1.gem.sha512
29
30
  - lib/ezfile.rb
30
31
  - lib/ezfile/version.rb
31
32
  - sig/ezfile.rbs
@@ -52,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
53
  - !ruby/object:Gem::Version
53
54
  version: '0'
54
55
  requirements: []
55
- rubygems_version: 3.4.21
56
+ rubygems_version: 3.4.22
56
57
  signing_key:
57
58
  specification_version: 4
58
59
  summary: A filetool for windows, It's more safety