mundane 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/README +17 -17
- data/bin/mundane +33 -27
- data/lib/mundane.rb +30 -25
- data/lib/mundane/algos/files_to_zips.rb +37 -37
- data/lib/mundane/algos/truncate_file_names.rb +42 -0
- data/lib/mundane/algos/zips_to_files.rb +49 -49
- data/lib/mundane/file_worker.rb +21 -21
- data/lib/mundane/prompter.rb +21 -21
- data/lib/mundane/version.rb +3 -3
- data/spec/hack_working_directory.rb +12 -12
- data/spec/spec_helper.rb +47 -37
- data/spec/unit/mundane_spec.rb +110 -79
- metadata +27 -26
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZjE5MmViNjA5MmE0MDU4ZWZlOWE1OWJiZWZhZjQ1MmE1MDU3NWZmYg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OTg5NWMxOTI3YmQyZWEzYzJhODBmM2NjYTA2MDU4ZGU1NGViOWI1Yw==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YjM1YWI1YzdlOGZjNTE2YWE1MjgwZjM3ZjZmNTViMzU5M2Q4MjY2MzA4NmMz
|
10
|
+
ODI4OWI0ZDk0ZDgyNTFiYTdiNDBjMTZkYTk0OTJjZDA3NTVlNTgwMzFiMzE3
|
11
|
+
NzU3NjM1ZGRkYmU0Mjg1NjIxZDNjNmU1NDE5YWJkYjM2ZWE2NGU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OGRlYzAxMjhhNjA5MDRkODg5YjljZWEzNjJiYjZmYzZjNmQ1OWM0ODE1ODI3
|
14
|
+
OTcxYmY3NDA4M2MyYTdjZjhjZmRkNmY5YjQ0MjIxMTg1NGEzZDBiOWFhNDNl
|
15
|
+
M2JhMjJmZmEyY2E0ZDM5NzgzZDU5ZWMxZTljZDk5YzVkZTQ2MDU=
|
data/README
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
Oh, why, hello there. I'm Notary Sojac, and you are inspecting one of my scripts which was originally designed to take all the files in the current working folder, and put them into \out. The catch? Oh yes, the catch is that they will become .zip files meaning that you will need to decrypt them before reading/seeing/interacting with them. There are no free lunches. This algo is helpful for getting NES rom files into a proper format for consumption by NestopiaX on hacked XBOXes.
|
2
|
-
|
3
|
-
There will be more mundane algorithms added, such as right now I've just added an algo to unzip a bunch of zip files and dump their contents into out/ (so a mass unzipping algo).
|
4
|
-
|
5
|
-
To make it do:
|
6
|
-
|
7
|
-
1) Have ruby installed on your machine.
|
8
|
-
|
9
|
-
2) do `$ gem install mundane` to install the gem.
|
10
|
-
|
11
|
-
3) Change directory into the folder you'd like to conduct a mundane task in.
|
12
|
-
|
13
|
-
4) Run the gem, specifying which mundane task you'd like performed, eg `$ mundane files2zips`
|
14
|
-
|
15
|
-
5) Investigate the "out" directory which was created when you ran the command.
|
16
|
-
|
17
|
-
6) Profit.
|
1
|
+
Oh, why, hello there. I'm Notary Sojac, and you are inspecting one of my scripts which was originally designed to take all the files in the current working folder, and put them into \out. The catch? Oh yes, the catch is that they will become .zip files meaning that you will need to decrypt them before reading/seeing/interacting with them. There are no free lunches. This algo is helpful for getting NES rom files into a proper format for consumption by NestopiaX on hacked XBOXes.
|
2
|
+
|
3
|
+
There will be more mundane algorithms added, such as right now I've just added an algo to unzip a bunch of zip files and dump their contents into out/ (so a mass unzipping algo).
|
4
|
+
|
5
|
+
To make it do:
|
6
|
+
|
7
|
+
1) Have ruby installed on your machine.
|
8
|
+
|
9
|
+
2) do `$ gem install mundane` to install the gem.
|
10
|
+
|
11
|
+
3) Change directory into the folder you'd like to conduct a mundane task in.
|
12
|
+
|
13
|
+
4) Run the gem, specifying which mundane task you'd like performed, eg `$ mundane files2zips`
|
14
|
+
|
15
|
+
5) Investigate the "out" directory which was created when you ran the command.
|
16
|
+
|
17
|
+
6) Profit.
|
data/bin/mundane
CHANGED
@@ -1,27 +1,33 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'thor'
|
4
|
-
require 'mundane'
|
5
|
-
|
6
|
-
class MundaneRunner < Thor
|
7
|
-
|
8
|
-
desc "version", "Prints Mundane's version"
|
9
|
-
def version
|
10
|
-
puts Mundane.version
|
11
|
-
end
|
12
|
-
|
13
|
-
desc "files2zips", "reads each file in the directory and zips it, placing it in a new folder named 'out'.\n
|
14
|
-
This will not include directorys, it will only work on files."
|
15
|
-
def files2zips
|
16
|
-
Mundane.files_to_zips
|
17
|
-
end
|
18
|
-
|
19
|
-
desc "zips2files", "Reads each zip file in the current directory and extracts its contents to a folder named 'out'.\n
|
20
|
-
"
|
21
|
-
def zips2files
|
22
|
-
Mundane.zips_to_files
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'mundane'
|
5
|
+
|
6
|
+
class MundaneRunner < Thor
|
7
|
+
|
8
|
+
desc "version", "Prints Mundane's version"
|
9
|
+
def version
|
10
|
+
puts Mundane.version
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "files2zips", "reads each file in the directory and zips it, placing it in a new folder named 'out'.\n
|
14
|
+
This will not include directorys, it will only work on files."
|
15
|
+
def files2zips
|
16
|
+
Mundane.files_to_zips
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "zips2files", "Reads each zip file in the current directory and extracts its contents to a folder named 'out'.\n
|
20
|
+
"
|
21
|
+
def zips2files
|
22
|
+
Mundane.zips_to_files
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "truncate n", "truncates the file names to the specified length, attempting to preserve extension.\n
|
26
|
+
"
|
27
|
+
def truncate(desired_length)
|
28
|
+
Mundane.truncate_file_names(desired_length)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
MundaneRunner.start
|
data/lib/mundane.rb
CHANGED
@@ -1,25 +1,30 @@
|
|
1
|
-
require 'zip'
|
2
|
-
|
3
|
-
require 'mundane/version'
|
4
|
-
require 'mundane/file_worker'
|
5
|
-
require 'mundane/prompter'
|
6
|
-
require 'mundane/algos/files_to_zips'
|
7
|
-
require 'mundane/algos/zips_to_files'
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
1
|
+
require 'zip'
|
2
|
+
|
3
|
+
require 'mundane/version'
|
4
|
+
require 'mundane/file_worker'
|
5
|
+
require 'mundane/prompter'
|
6
|
+
require 'mundane/algos/files_to_zips'
|
7
|
+
require 'mundane/algos/zips_to_files'
|
8
|
+
require 'mundane/algos/truncate_file_names'
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
module Mundane
|
13
|
+
|
14
|
+
def self.files_to_zips
|
15
|
+
FilesToZips.execute
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.zips_to_files
|
19
|
+
ZipsToFiles.execute
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.truncate_file_names(desired_length)
|
23
|
+
TruncateFileNames.execute(desired_length.to_i)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.version
|
27
|
+
Mundane::VERSION
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -1,37 +1,37 @@
|
|
1
|
-
module Mundane
|
2
|
-
class FilesToZips
|
3
|
-
extend Mundane::FileWorker
|
4
|
-
extend Mundane::Prompter
|
5
|
-
|
6
|
-
def self.execute
|
7
|
-
user_wants_to_proceed = prompt_user("Are you sure you want to make %count_targeted_files% zipped files and put them into ./out/ ?\n[Y/n]")
|
8
|
-
|
9
|
-
if user_wants_to_proceed
|
10
|
-
make_output_directory
|
11
|
-
files = get_files_in_current_folder
|
12
|
-
compress_files_and_write_to_out_as_zips(files)
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
def self.compress_files_and_write_to_out_as_zips(files)
|
19
|
-
files.each do |f|
|
20
|
-
pretty_name = f.chomp(File.extname(f))
|
21
|
-
|
22
|
-
if File.exists?("out/#{pretty_name}.zip")
|
23
|
-
puts "out/#{pretty_name}.zip ALREADY EXISTED, SKIPPING FILE. DELETE MANUALLY IF NEEDED =/"
|
24
|
-
next
|
25
|
-
end
|
26
|
-
|
27
|
-
Zip::File.open("out/#{pretty_name}.zip", Zip::File::CREATE) do |zipfile|
|
28
|
-
zipfile.add(f, f)
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
|
1
|
+
module Mundane
|
2
|
+
class FilesToZips
|
3
|
+
extend Mundane::FileWorker
|
4
|
+
extend Mundane::Prompter
|
5
|
+
|
6
|
+
def self.execute
|
7
|
+
user_wants_to_proceed = prompt_user("Are you sure you want to make %count_targeted_files% zipped files and put them into ./out/ ?\n[Y/n]")
|
8
|
+
|
9
|
+
if user_wants_to_proceed
|
10
|
+
make_output_directory
|
11
|
+
files = get_files_in_current_folder
|
12
|
+
compress_files_and_write_to_out_as_zips(files)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def self.compress_files_and_write_to_out_as_zips(files)
|
19
|
+
files.each do |f|
|
20
|
+
pretty_name = f.chomp(File.extname(f))
|
21
|
+
|
22
|
+
if File.exists?("out/#{pretty_name}.zip")
|
23
|
+
puts "out/#{pretty_name}.zip ALREADY EXISTED, SKIPPING FILE. DELETE MANUALLY IF NEEDED =/"
|
24
|
+
next
|
25
|
+
end
|
26
|
+
|
27
|
+
Zip::File.open("out/#{pretty_name}.zip", Zip::File::CREATE) do |zipfile|
|
28
|
+
zipfile.add(f, f)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Mundane
|
2
|
+
class TruncateFileNames
|
3
|
+
extend Mundane::FileWorker
|
4
|
+
extend Mundane::Prompter
|
5
|
+
|
6
|
+
def self.execute(desired_length)
|
7
|
+
user_wants_to_proceed = prompt_user("Are you sure you want to make %count_targeted_files% have there file name shortened to #{desired_length}?\n[Y/n]")
|
8
|
+
|
9
|
+
if user_wants_to_proceed
|
10
|
+
files = get_files_in_current_folder
|
11
|
+
|
12
|
+
truncate_file_names(files, desired_length)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
# This algo actually truncates the name and then tacs on the extension at the end
|
19
|
+
def self.truncate_file_names(files, desired_length)
|
20
|
+
require 'fileutils'
|
21
|
+
|
22
|
+
files.each do |f|
|
23
|
+
ugly_extension = File.extname(f)
|
24
|
+
pretty_name = f.chomp(File.extname(f))
|
25
|
+
|
26
|
+
file_name = f
|
27
|
+
|
28
|
+
amount_to_shorten_pretty_name_by = f.length - desired_length
|
29
|
+
|
30
|
+
if amount_to_shorten_pretty_name_by > 0
|
31
|
+
resulting_file_name = pretty_name[0,pretty_name.length - amount_to_shorten_pretty_name_by ] + ugly_extension
|
32
|
+
|
33
|
+
FileUtils.mv file_name, resulting_file_name
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
@@ -1,50 +1,50 @@
|
|
1
|
-
module Mundane
|
2
|
-
class ZipsToFiles
|
3
|
-
extend Mundane::FileWorker
|
4
|
-
extend Mundane::Prompter
|
5
|
-
|
6
|
-
def self.execute
|
7
|
-
user_wants_to_proceed = prompt_user("Are you sure you want to unzip %count_targeted_files% zip files and dump their contents into ./out/ ?\n[Y/n]")
|
8
|
-
|
9
|
-
if user_wants_to_proceed
|
10
|
-
make_output_directory
|
11
|
-
files = get_files_in_current_folder
|
12
|
-
decompress_files_and_dump_them_to_out(files)
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.decompress_files_and_dump_them_to_out(files)
|
18
|
-
incomplete_extractions = 0
|
19
|
-
all_files_were_archives = true
|
20
|
-
|
21
|
-
# decompress each file in the list
|
22
|
-
files.each do |zip|
|
23
|
-
# TODO: next if zip.extension != 'zip'
|
24
|
-
begin
|
25
|
-
Zip::File.open(zip) do |archive|
|
26
|
-
archive.each do |f|
|
27
|
-
output_path = "out/#{f.name}"
|
28
|
-
if File.exists? output_path # don't auto-overwrite anything...
|
29
|
-
puts "#{output_path} ALREADY EXISTED, SKIPPING FILE."
|
30
|
-
incomplete_extractions += 1
|
31
|
-
next
|
32
|
-
end
|
33
|
-
|
34
|
-
FileUtils.mkdir_p File.dirname(output_path)
|
35
|
-
f.extract output_path
|
36
|
-
end
|
37
|
-
end
|
38
|
-
rescue
|
39
|
-
# skip the file if it can't be opened like a zip
|
40
|
-
all_files_were_archives = false
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
puts "\nOperation terminated, there were #{incomplete_extractions} incomplete extractions." if incomplete_extractions > 0
|
46
|
-
puts "Not all files were valid archives" unless all_files_were_archives
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
1
|
+
module Mundane
|
2
|
+
class ZipsToFiles
|
3
|
+
extend Mundane::FileWorker
|
4
|
+
extend Mundane::Prompter
|
5
|
+
|
6
|
+
def self.execute
|
7
|
+
user_wants_to_proceed = prompt_user("Are you sure you want to unzip %count_targeted_files% zip files and dump their contents into ./out/ ?\n[Y/n]")
|
8
|
+
|
9
|
+
if user_wants_to_proceed
|
10
|
+
make_output_directory
|
11
|
+
files = get_files_in_current_folder
|
12
|
+
decompress_files_and_dump_them_to_out(files)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.decompress_files_and_dump_them_to_out(files)
|
18
|
+
incomplete_extractions = 0
|
19
|
+
all_files_were_archives = true
|
20
|
+
|
21
|
+
# decompress each file in the list
|
22
|
+
files.each do |zip|
|
23
|
+
# TODO: next if zip.extension != 'zip'
|
24
|
+
begin
|
25
|
+
Zip::File.open(zip) do |archive|
|
26
|
+
archive.each do |f|
|
27
|
+
output_path = "out/#{f.name}"
|
28
|
+
if File.exists? output_path # don't auto-overwrite anything...
|
29
|
+
puts "#{output_path} ALREADY EXISTED, SKIPPING FILE."
|
30
|
+
incomplete_extractions += 1
|
31
|
+
next
|
32
|
+
end
|
33
|
+
|
34
|
+
FileUtils.mkdir_p File.dirname(output_path)
|
35
|
+
f.extract output_path
|
36
|
+
end
|
37
|
+
end
|
38
|
+
rescue
|
39
|
+
# skip the file if it can't be opened like a zip
|
40
|
+
all_files_were_archives = false
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
puts "\nOperation terminated, there were #{incomplete_extractions} incomplete extractions." if incomplete_extractions > 0
|
46
|
+
puts "Not all files were valid archives" unless all_files_were_archives
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
50
|
end
|
data/lib/mundane/file_worker.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
module Mundane
|
2
|
-
module FileWorker
|
3
|
-
|
4
|
-
def make_output_directory
|
5
|
-
Dir.mkdir("out") unless Dir.exists?("out")
|
6
|
-
end
|
7
|
-
|
8
|
-
def get_files_in_current_folder
|
9
|
-
files = []
|
10
|
-
Dir.foreach(".") do |f|
|
11
|
-
next if File.directory?(f) # or f == __FILE__ # skip directory names and the script we're running...
|
12
|
-
files << f
|
13
|
-
end
|
14
|
-
return files
|
15
|
-
end
|
16
|
-
|
17
|
-
def count_targeted_files
|
18
|
-
get_files_in_current_folder.count
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
1
|
+
module Mundane
|
2
|
+
module FileWorker
|
3
|
+
|
4
|
+
def make_output_directory
|
5
|
+
Dir.mkdir("out") unless Dir.exists?("out")
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_files_in_current_folder
|
9
|
+
files = []
|
10
|
+
Dir.foreach(".") do |f|
|
11
|
+
next if File.directory?(f) # or f == __FILE__ # skip directory names and the script we're running...
|
12
|
+
files << f
|
13
|
+
end
|
14
|
+
return files
|
15
|
+
end
|
16
|
+
|
17
|
+
def count_targeted_files
|
18
|
+
get_files_in_current_folder.count
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
22
|
end
|
data/lib/mundane/prompter.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
module Mundane
|
2
|
-
module Prompter
|
3
|
-
extend Mundane::FileWorker
|
4
|
-
|
5
|
-
def prompt_user(prompt)
|
6
|
-
puts construct_informative_message(prompt)
|
7
|
-
proceed = STDIN.gets.strip.downcase
|
8
|
-
|
9
|
-
if proceed == "y" or proceed == "yes" or proceed == ""
|
10
|
-
true
|
11
|
-
else
|
12
|
-
false
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def construct_informative_message(prompt)
|
17
|
-
prompt.sub("%count_targeted_files%", count_targeted_files.to_s)
|
18
|
-
end
|
19
|
-
|
20
|
-
extend self # allows for unit testing...
|
21
|
-
end
|
1
|
+
module Mundane
|
2
|
+
module Prompter
|
3
|
+
extend Mundane::FileWorker
|
4
|
+
|
5
|
+
def prompt_user(prompt)
|
6
|
+
puts construct_informative_message(prompt)
|
7
|
+
proceed = STDIN.gets.strip.downcase
|
8
|
+
|
9
|
+
if proceed == "y" or proceed == "yes" or proceed == ""
|
10
|
+
true
|
11
|
+
else
|
12
|
+
false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def construct_informative_message(prompt)
|
17
|
+
prompt.sub("%count_targeted_files%", count_targeted_files.to_s)
|
18
|
+
end
|
19
|
+
|
20
|
+
extend self # allows for unit testing...
|
21
|
+
end
|
22
22
|
end
|
data/lib/mundane/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Mundane
|
2
|
-
VERSION = '0.0.
|
3
|
-
end
|
1
|
+
module Mundane
|
2
|
+
VERSION = '0.0.4'
|
3
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
include FileUtils
|
3
|
-
|
4
|
-
# We need to change our working directory to a virtual directory so we don't risk
|
5
|
-
# making a ton of files in ./out that will annoy testers... but we need to trigger
|
6
|
-
# this faked working directory only AFTER all the other requires are made in testing files
|
7
|
-
rm_rf fake_working_directory if File.exists? fake_working_directory
|
8
|
-
mkdir_p fake_working_directory
|
9
|
-
cd fake_working_directory
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
# We need to change our working directory to a virtual directory so we don't risk
|
5
|
+
# making a ton of files in ./out that will annoy testers... but we need to trigger
|
6
|
+
# this faked working directory only AFTER all the other requires are made in testing files
|
7
|
+
rm_rf fake_working_directory if File.exists? fake_working_directory
|
8
|
+
mkdir_p fake_working_directory
|
9
|
+
cd fake_working_directory
|
10
|
+
|
11
|
+
|
12
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -1,37 +1,47 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
touch "/tmp/mundane-virtual-working-directory/
|
19
|
-
touch "/tmp/mundane-virtual-working-directory/
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
1
|
+
require 'pry'
|
2
|
+
require 'fileutils'
|
3
|
+
include FileUtils
|
4
|
+
|
5
|
+
def fake_working_directory
|
6
|
+
"/tmp/mundane-virtual-working-directory"
|
7
|
+
end
|
8
|
+
|
9
|
+
def fake_out_directory
|
10
|
+
fake_working_directory + "/out"
|
11
|
+
end
|
12
|
+
|
13
|
+
def clean_dummy_working_directory
|
14
|
+
rm_rf(Dir.glob("/tmp/mundane-virtual-working-directory/*"))
|
15
|
+
end
|
16
|
+
|
17
|
+
def drop_dummy_files_in_working_directory
|
18
|
+
touch "/tmp/mundane-virtual-working-directory/a"
|
19
|
+
touch "/tmp/mundane-virtual-working-directory/b"
|
20
|
+
touch "/tmp/mundane-virtual-working-directory/c"
|
21
|
+
end
|
22
|
+
|
23
|
+
def drop_dummy_files_in_working_directory_with_varying_names
|
24
|
+
touch "/tmp/mundane-virtual-working-directory/houstonfoobar.txt"
|
25
|
+
touch "/tmp/mundane-virtual-working-directory/a"
|
26
|
+
touch "/tmp/mundane-virtual-working-directory/b."
|
27
|
+
touch "/tmp/mundane-virtual-working-directory/c.txt"
|
28
|
+
# touch "/tmp/mundane-virtual-working-directory/c.txtfdsdf"
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def drop_dummy_zip_file
|
33
|
+
# This string was coppied from a hex editor (bless) on linux
|
34
|
+
byte_array_of_zip_file = "50 4B 03 04 0A 03 00 00 00 00 9A 85 4C 43 05 40 6D 5B 08 00 00 00 08 00 00 00 01 00 00 00 61 68 65 6C 6C 6F 20 61 0A 50 4B 03 04 0A 03 00 00 00 00 B8 85 4C 43 C6 13 40 70 08 00 00 00 08 00 00 00 01 00 00 00 62 68 65 6C 6C 6F 20 62 0A 50 4B 01 02 3F 03 0A 03 00 00 00 00 9A 85 4C 43 05 40 6D 5B 08 00 00 00 08 00 00 00 01 00 00 00 00 00 00 00 00 00 20 80 A4 81 00 00 00 00 61 50 4B 01 02 3F 03 0A 03 00 00 00 00 B8 85 4C 43 C6 13 40 70 08 00 00 00 08 00 00 00 01 00 00 00 00 00 00 00 00 00 20 80 A4 81 27 00 00 00 62 50 4B 05 06 00 00 00 00 02 00 02 00 5E 00 00 00 4E 00 00 00 00 00"
|
35
|
+
bin_format = byte_array_of_zip_file.split.map {|s| s.to_i(16).chr}
|
36
|
+
File.binwrite("embedded.zip", bin_format.join)
|
37
|
+
end
|
38
|
+
|
39
|
+
def drop_dummy_zip_file_with_folders
|
40
|
+
byte_array_of_zip_file = "50 4B 03 04 0A 03 00 00 00 00 EA 72 4D 43 C6 13 40 70 08 00 00 00 08 00 00 00 05 00 00 00 62 2E 74 78 74 68 65 6C 6C 6F 20 62 0A 50 4B 03 04 14 03 00 00 00 00 80 72 4D 43 00 00 00 00 00 00 00 00 00 00 00 00 09 00 00 00 66 6F 6C 64 65 72 5F 61 2F 50 4B 03 04 0A 03 00 00 00 00 80 72 4D 43 05 40 6D 5B 08 00 00 00 08 00 00 00 0E 00 00 00 66 6F 6C 64 65 72 5F 61 2F 61 2E 74 78 74 68 65 6C 6C 6F 20 61 0A 50 4B 01 02 3F 03 0A 03 00 00 00 00 EA 72 4D 43 C6 13 40 70 08 00 00 00 08 00 00 00 05 00 00 00 00 00 00 00 00 00 20 80 A4 81 00 00 00 00 62 2E 74 78 74 50 4B 01 02 3F 03 14 03 00 00 00 00 80 72 4D 43 00 00 00 00 00 00 00 00 00 00 00 00 09 00 00 00 00 00 00 00 00 00 10 80 ED 41 2B 00 00 00 66 6F 6C 64 65 72 5F 61 2F 50 4B 01 02 3F 03 0A 03 00 00 00 00 80 72 4D 43 05 40 6D 5B 08 00 00 00 08 00 00 00 0E 00 00 00 00 00 00 00 00 00 20 80 A4 81 52 00 00 00 66 6F 6C 64 65 72 5F 61 2F 61 2E 74 78 74 50 4B 05 06 00 00 00 00 03 00 03 00 A6 00 00 00 86 00 00 00 00 00"
|
41
|
+
bin_format = byte_array_of_zip_file.split.map {|s| s.to_i(16).chr}
|
42
|
+
File.binwrite("embedded_with_folders.zip", bin_format.join)
|
43
|
+
end
|
44
|
+
|
45
|
+
def count_of_files_in(directory_path)
|
46
|
+
Dir.glob(File.join(directory_path, '**', '*')).select { |file| File.file?(file) }.count
|
47
|
+
end
|
data/spec/unit/mundane_spec.rb
CHANGED
@@ -1,80 +1,111 @@
|
|
1
|
-
require './spec/spec_helper'
|
2
|
-
require './lib/mundane'
|
3
|
-
|
4
|
-
require './spec/hack_working_directory' # this require must come LAST or reletive requires will fail hard... oh wait... if there are more test files... everything foobars...
|
5
|
-
|
6
|
-
describe "test the algos" do
|
7
|
-
|
8
|
-
describe "test files_to_zips algo" do
|
9
|
-
|
10
|
-
before :each do
|
11
|
-
Mundane::FilesToZips.stub(:prompt_user).and_return(true)
|
12
|
-
|
13
|
-
clean_dummy_working_directory
|
14
|
-
end
|
15
|
-
|
16
|
-
after :each do
|
17
|
-
Mundane::FilesToZips.unstub(:prompt_user)
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should make 3 files in the out folder' do
|
21
|
-
drop_dummy_files_in_working_directory
|
22
|
-
|
23
|
-
Mundane.files_to_zips
|
24
|
-
count_of_files_in(fake_out_directory).should be 3
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "test zips_to_files algo" do
|
31
|
-
before :each do
|
32
|
-
Mundane::ZipsToFiles.stub(:prompt_user).and_return(true)
|
33
|
-
|
34
|
-
clean_dummy_working_directory
|
35
|
-
end
|
36
|
-
|
37
|
-
after :each do
|
38
|
-
Mundane::ZipsToFiles.unstub(:prompt_user)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should make 2 files in the out folder' do
|
42
|
-
drop_dummy_zip_file
|
43
|
-
|
44
|
-
Mundane.zips_to_files
|
45
|
-
count_of_files_in(fake_out_directory).should be 2
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should work on zip archives that have a folder in them" do
|
49
|
-
drop_dummy_zip_file_with_folders
|
50
|
-
|
51
|
-
Mundane.zips_to_files
|
52
|
-
count_of_files_in(fake_out_directory).should be 2
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should ignore files that aren't really archives" do
|
56
|
-
drop_dummy_zip_file
|
57
|
-
drop_dummy_files_in_working_directory
|
58
|
-
|
59
|
-
Mundane.zips_to_files
|
60
|
-
count_of_files_in(fake_out_directory).should be 2
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
1
|
+
require './spec/spec_helper'
|
2
|
+
require './lib/mundane'
|
3
|
+
|
4
|
+
require './spec/hack_working_directory' # this require must come LAST or reletive requires will fail hard... oh wait... if there are more test files... everything foobars...
|
5
|
+
|
6
|
+
describe "test the algos" do
|
7
|
+
|
8
|
+
describe "test files_to_zips algo" do
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
Mundane::FilesToZips.stub(:prompt_user).and_return(true)
|
12
|
+
|
13
|
+
clean_dummy_working_directory
|
14
|
+
end
|
15
|
+
|
16
|
+
after :each do
|
17
|
+
Mundane::FilesToZips.unstub(:prompt_user)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should make 3 files in the out folder' do
|
21
|
+
drop_dummy_files_in_working_directory
|
22
|
+
|
23
|
+
Mundane.files_to_zips
|
24
|
+
count_of_files_in(fake_out_directory).should be 3
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "test zips_to_files algo" do
|
31
|
+
before :each do
|
32
|
+
Mundane::ZipsToFiles.stub(:prompt_user).and_return(true)
|
33
|
+
|
34
|
+
clean_dummy_working_directory
|
35
|
+
end
|
36
|
+
|
37
|
+
after :each do
|
38
|
+
Mundane::ZipsToFiles.unstub(:prompt_user)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should make 2 files in the out folder' do
|
42
|
+
drop_dummy_zip_file
|
43
|
+
|
44
|
+
Mundane.zips_to_files
|
45
|
+
count_of_files_in(fake_out_directory).should be 2
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should work on zip archives that have a folder in them" do
|
49
|
+
drop_dummy_zip_file_with_folders
|
50
|
+
|
51
|
+
Mundane.zips_to_files
|
52
|
+
count_of_files_in(fake_out_directory).should be 2
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should ignore files that aren't really archives" do
|
56
|
+
drop_dummy_zip_file
|
57
|
+
drop_dummy_files_in_working_directory
|
58
|
+
|
59
|
+
Mundane.zips_to_files
|
60
|
+
count_of_files_in(fake_out_directory).should be 2
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "test file_name_shortener" do
|
66
|
+
before :each do
|
67
|
+
Mundane::TruncateFileNames.stub(:prompt_user).and_return(true)
|
68
|
+
|
69
|
+
clean_dummy_working_directory
|
70
|
+
end
|
71
|
+
|
72
|
+
after :each do
|
73
|
+
Mundane::TruncateFileNames.unstub(:prompt_user)
|
74
|
+
clean_dummy_working_directory
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should shorten all the filenames to the requested length" do
|
78
|
+
extend Mundane::FileWorker
|
79
|
+
|
80
|
+
drop_dummy_files_in_working_directory_with_varying_names
|
81
|
+
|
82
|
+
Mundane.truncate_file_names(8)
|
83
|
+
|
84
|
+
|
85
|
+
files = get_files_in_current_folder
|
86
|
+
|
87
|
+
files.each do |f|
|
88
|
+
(f.length <= 8).should be_true
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
describe "prompter unit test..." do
|
98
|
+
before :each do
|
99
|
+
clean_dummy_working_directory
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should have a pleasant prompt message' do
|
103
|
+
drop_dummy_files_in_working_directory
|
104
|
+
|
105
|
+
prompt = "hello %count_targeted_files% bye"
|
106
|
+
Mundane::Prompter.construct_informative_message(prompt).should eq "hello 3 bye"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
80
111
|
end
|
metadata
CHANGED
@@ -1,102 +1,102 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mundane
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- n-jax
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - '>='
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - '>='
|
24
|
+
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: thor
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - '>='
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - '>='
|
38
|
+
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - '>='
|
45
|
+
- - ! '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - '>='
|
52
|
+
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - '>='
|
59
|
+
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - '>='
|
66
|
+
- - ! '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - '>='
|
73
|
+
- - ! '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - '>='
|
80
|
+
- - ! '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: pry
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - '>='
|
87
|
+
- - ! '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - '>='
|
94
|
+
- - ! '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description:
|
98
|
-
|
99
|
-
|
97
|
+
description: ! "files2zips - converts a bunch of files into individual .zip files\n
|
98
|
+
\ zips2files - unpacks all the zip files in a directory spilling there contents
|
99
|
+
into /out"
|
100
100
|
email: ''
|
101
101
|
executables:
|
102
102
|
- mundane
|
@@ -104,17 +104,18 @@ extensions: []
|
|
104
104
|
extra_rdoc_files:
|
105
105
|
- README
|
106
106
|
files:
|
107
|
+
- README
|
107
108
|
- bin/mundane
|
108
109
|
- lib/mundane.rb
|
109
|
-
- lib/mundane/
|
110
|
+
- lib/mundane/algos/files_to_zips.rb
|
111
|
+
- lib/mundane/algos/truncate_file_names.rb
|
112
|
+
- lib/mundane/algos/zips_to_files.rb
|
110
113
|
- lib/mundane/file_worker.rb
|
111
114
|
- lib/mundane/prompter.rb
|
112
|
-
- lib/mundane/
|
113
|
-
- lib/mundane/algos/files_to_zips.rb
|
115
|
+
- lib/mundane/version.rb
|
114
116
|
- spec/hack_working_directory.rb
|
115
|
-
- spec/unit/mundane_spec.rb
|
116
117
|
- spec/spec_helper.rb
|
117
|
-
-
|
118
|
+
- spec/unit/mundane_spec.rb
|
118
119
|
homepage: https://github.com/TheNotary/files_to_zips
|
119
120
|
licenses: []
|
120
121
|
metadata: {}
|
@@ -122,20 +123,20 @@ post_install_message:
|
|
122
123
|
rdoc_options:
|
123
124
|
- --charset=UTF-8
|
124
125
|
require_paths:
|
125
|
-
-
|
126
|
+
- lib
|
126
127
|
required_ruby_version: !ruby/object:Gem::Requirement
|
127
128
|
requirements:
|
128
|
-
- - '>='
|
129
|
+
- - ! '>='
|
129
130
|
- !ruby/object:Gem::Version
|
130
131
|
version: '0'
|
131
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
133
|
requirements:
|
133
|
-
- - '>='
|
134
|
+
- - ! '>='
|
134
135
|
- !ruby/object:Gem::Version
|
135
136
|
version: '0'
|
136
137
|
requirements: []
|
137
138
|
rubyforge_project: mundane
|
138
|
-
rubygems_version: 2.
|
139
|
+
rubygems_version: 2.4.5
|
139
140
|
signing_key:
|
140
141
|
specification_version: 4
|
141
142
|
summary: Mundane automates the mundane file operations you sometimes wind up needing
|