mundane 0.0.0 → 0.0.1

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
2
  SHA1:
3
- metadata.gz: 20449c7c8e3ff9ad2aeec4956726476ba8b07b06
4
- data.tar.gz: 501721ae5254cb5f8a9e76245aa64c222b7c5b87
3
+ metadata.gz: 14540f02f5fe1ea047a6a7e68af94bcfa44b50b1
4
+ data.tar.gz: c975d603d3883f09b65940d4be8b6708be0d3792
5
5
  SHA512:
6
- metadata.gz: 58e185cd77bb6b55ece2ad35f0e865a11b02fc3c6c00f2299f72c452d133ee1c5b0644d2d80edc136cf0b3eb64ad4d36412bf750150a3846cca98c262535b70d
7
- data.tar.gz: a44b72ae6c9ff63edb8155f7916e0bd193596a4319bb9d06f59b401a3fd91b4fda38579b1d6dfdef2f52fe8669d291391293bdb1e1f760c29a25e5cb5aa9625d
6
+ metadata.gz: 3aa7a0b89dcfcee21523679d04d423a3fb3614e96d0408bc1875f8e8f904c58d349d787a123ba4314c5c3dc92e0a54585e8a3b1bc5248b144ce10a4ba4f3b120
7
+ data.tar.gz: 51f314566f12ba45d249769d81e9c2f2ce91ddedd59400d062aaae6dc9aae40a7dbf69ef5f220c92c136b335e2a77f29957ee85cd499b251638f0fb5b23ee3ed
data/README CHANGED
@@ -1,15 +1,17 @@
1
- Oh, why, hello there. I'm Notary Sojac, and you are inspecting one of my scripts which was 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.
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. But this algo is helpful for getting NES rom files into a proper format for consumption by NestopiaX.
2
+
3
+ There will be more mundane algorithms added, such as right now, an algo to unzip a bunch of zip files and dump their contents into out/ (so a mass unzipping algo).
2
4
 
3
5
  To make it do:
4
6
 
5
- 1) Have ruby installed on your machine
7
+ 1) Have ruby installed on your machine.
6
8
 
7
- 2) do $ gem install rubyzip to install the dependancy
9
+ 2) do `$ gem install mundane` to install the gem.
8
10
 
9
- 3) Copy my snazzy script files_to_zips.rb into the folder you have laying around which contains the files you would like individually zipped.
11
+ 3) Change directory into the folder you'd like to conduct a mundane task in.
10
12
 
11
- 4) Run my script in that directory ($ ruby files_to_zips.rb)
13
+ 4) Run the gem, specifying which mundane task you'd like performed, eg `$ mundane files2zips`
12
14
 
13
- 5) Investigate the "out" directory which was created throughout this process.
15
+ 5) Investigate the "out" directory which was created when you ran the command.
14
16
 
15
- 6) Profit
17
+ 6) Profit.
@@ -4,19 +4,24 @@ require 'thor'
4
4
  require 'mundane'
5
5
 
6
6
  class MundaneRunner < Thor
7
-
8
- #default_task :help
9
-
10
- desc "files2zips", "reads each file in the directory and zips it, placing it in a new folder named 'out'."
11
- def files2zips
12
- Mundane.files_to_zips
13
- end
14
7
 
15
8
  desc "version", "Prints Mundane's version"
16
9
  def version
17
10
  puts Mundane.version
18
11
  end
19
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
+
20
25
  end
21
26
 
22
27
  MundaneRunner.start
@@ -2,18 +2,25 @@ require 'pry'
2
2
  require 'zip'
3
3
 
4
4
  require 'mundane/version'
5
- require 'mundane/files_to_zips'
5
+ require 'mundane/file_worker'
6
+ require 'mundane/prompter'
7
+ require 'mundane/algos/files_to_zips'
8
+ require 'mundane/algos/zips_to_files'
9
+
6
10
 
7
11
 
8
12
  module Mundane
9
13
 
10
14
  def self.files_to_zips
11
15
  FilesToZips.execute
12
- #puts "this here is a stub"
16
+ end
17
+
18
+ def self.zips_to_files
19
+ ZipsToFiles.execute
13
20
  end
14
21
 
15
22
  def self.version
16
- puts Mundane::VERSION
23
+ Mundane::VERSION
17
24
  end
18
25
 
19
26
  end
@@ -0,0 +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
+
@@ -0,0 +1,41 @@
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
+
20
+ # decompress each file in the list
21
+ files.each do |zip|
22
+ # TODO: next if zip.extension != 'zip'
23
+ Zip::File.open(zip) do |archive|
24
+ archive.each do |f|
25
+ output_path = "out/#{f.name}"
26
+ if File.exists? output_path # don't auto-overwrite anything...
27
+ puts "#{output_path} ALREADY EXISTED, SKIPPING FILE. DELETE MANUALLY IF NEEDED =/"
28
+ incomplete_extractions += 1
29
+ next
30
+ end
31
+ f.extract output_path
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ puts "\nOperation terminated, there were #{incomplete_extractions} incomplete extractions." if incomplete_extractions > 0
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +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
22
+ end
@@ -0,0 +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
22
+ end
@@ -1,3 +1,3 @@
1
1
  module Mundane
2
- VERSION = '0.0.0'
2
+ VERSION = '0.0.1'
3
3
  end
@@ -0,0 +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
+
@@ -0,0 +1,31 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ def fake_working_directory
5
+ "/tmp/mundane-virtual-working-directory"
6
+ end
7
+
8
+ def fake_out_directory
9
+ fake_working_directory + "/out"
10
+ end
11
+
12
+ def clean_dummy_working_directory
13
+ rm_rf(Dir.glob("/tmp/mundane-virtual-working-directory/*"))
14
+ end
15
+
16
+ def drop_dummy_files_in_working_directory
17
+ touch "/tmp/mundane-virtual-working-directory/a"
18
+ touch "/tmp/mundane-virtual-working-directory/b"
19
+ touch "/tmp/mundane-virtual-working-directory/c"
20
+ end
21
+
22
+ def drop_dummy_zip_file
23
+ # This string was coppied from a hex editor (bless) on linux
24
+ 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"
25
+ bin_format = byte_array_of_zip_file.split.map {|s| s.to_i(16).chr}
26
+ File.binwrite("mine_embedded.zip", bin_format.join)
27
+ end
28
+
29
+ def count_of_files_in(directory_path)
30
+ Dir.glob(File.join(directory_path, '**', '*')).select { |file| File.file?(file) }.count
31
+ end
@@ -1,11 +1,65 @@
1
1
  require './spec/spec_helper'
2
-
3
2
  require './lib/mundane'
4
3
 
5
- describe "get testing" do
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...
6
5
 
7
- it 'should test' do
8
- Mundane.files_to_zips
9
- end
6
+ describe "test the algos" do
10
7
 
11
- end
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
+ end
49
+
50
+
51
+ describe "prompter unit test..." do
52
+ before :each do
53
+ clean_dummy_working_directory
54
+ end
55
+
56
+ it 'should have a pleasant prompt message' do
57
+ drop_dummy_files_in_working_directory
58
+
59
+ prompt = "hello %count_targeted_files% bye"
60
+ Mundane::Prompter.construct_informative_message(prompt).should eq "hello 3 bye"
61
+ end
62
+ end
63
+
64
+
65
+ end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mundane
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
- - ''
7
+ - n-jax
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
@@ -107,7 +107,11 @@ files:
107
107
  - bin/mundane
108
108
  - lib/mundane.rb
109
109
  - lib/mundane/version.rb
110
- - lib/mundane/files_to_zips.rb
110
+ - lib/mundane/file_worker.rb
111
+ - lib/mundane/prompter.rb
112
+ - lib/mundane/algos/zips_to_files.rb
113
+ - lib/mundane/algos/files_to_zips.rb
114
+ - spec/hack_working_directory.rb
111
115
  - spec/unit/mundane_spec.rb
112
116
  - spec/spec_helper.rb
113
117
  - README
@@ -1,65 +0,0 @@
1
- module Mundane
2
- class FilesToZips
3
-
4
- def self.execute
5
- binding.pry
6
- user_wants_to_proceed = ask_user_if_theyd_like_to_make_zips
7
-
8
- if user_wants_to_proceed
9
- make_output_directory
10
-
11
- files = get_files_in_current_folder
12
-
13
- compress_files_and_write_to_out_as_zips(files)
14
- end
15
-
16
- end
17
-
18
- def self.compress_files_and_write_to_out_as_zips(files)
19
- files.each do
20
- |f|
21
- pretty_name = f.chomp(File.extname(f))
22
- if File.exists?("out/#{pretty_name}.zip")
23
- puts "out/#{pretty_name}.zip ALREADY EXISTED, SKIPPING FILE. DELETE MANUALLY IF PREFERED =/"
24
- next
25
- end
26
- Zip::File.open("out/#{pretty_name}.zip", Zip::File::CREATE) {
27
- |zipfile|
28
- zipfile.add(f, f)
29
- }
30
- end
31
- end
32
-
33
- def self.get_files_in_current_folder
34
- files = []
35
- Dir.foreach(".") do
36
- |f|
37
- next if File.directory?(f) or f == __FILE__ # skip directory names and the script we're running...
38
- files << f
39
- end
40
- return files
41
- end
42
-
43
- def self.make_output_directory
44
- Dir.mkdir("out") unless Dir.exists?("out")
45
- end
46
-
47
- def self.ask_user_if_theyd_like_to_make_zips
48
- puts "Are you sure you want to make X zip files and put them into ./out/ ?"
49
- puts "[Y/n]"
50
- proceed = STDIN.gets.strip.downcase
51
-
52
- if proceed == "y" or proceed == "yes" or proceed == ""
53
- proceed = true
54
- else
55
- proceed = false
56
- end
57
- return proceed
58
- end
59
-
60
-
61
-
62
- end
63
- end
64
-
65
-