attic-cleanup 0.0.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.
@@ -0,0 +1,99 @@
1
+ Attic-Cleanup
2
+ =============
3
+
4
+ About
5
+ =====
6
+ Attic-cleanup is a gem to manage files on your computer.
7
+
8
+ If you ever feel like you need to store your files you can throw them in your attic.
9
+
10
+ Let's say your attic is filled with files and folders and you just want to get them out of the way.
11
+
12
+ If you use the attic-cleanup gem all the files in the specified location will be moved into ~/MyAttic/Date-today.
13
+
14
+ An example of Date-today is ~/MyAttic/2011-11-23.
15
+
16
+ You can set specific location that you want to manage and create shortcuts for them.
17
+
18
+ A log will be kept of which files are moved to where, so if you ever forgot where you stored a specific file
19
+
20
+ you can find it in the log.txt file in the MyAttic folder.
21
+
22
+
23
+ Notes
24
+ =====
25
+ This gem has NOT been tested on Windows, and there's a big chance it won't work correctly.
26
+
27
+ This gem is still in beta, and moves, creates and deletes files / folders.
28
+
29
+ I use this gem every day and have never lost any folders or files.
30
+
31
+ However, if something does go wrong and you lose any files or folders I will not be held responsible.
32
+
33
+ Use at own risk
34
+
35
+ Installation
36
+ ============
37
+ gem install attic-cleanup
38
+
39
+
40
+ Usage
41
+ =====
42
+ Attic-cleanup is easy to use.
43
+ Here are a few examples to help you understand how to use it.
44
+
45
+ Example: We want to store all the files from our Desktop into MyAttic.
46
+ ======================================================================
47
+ attic-cleanup store -a -f
48
+
49
+ This line will store all the files from your Desktop to the MyAttic folder.
50
+
51
+ -a is an option to selected all the files.
52
+
53
+ -f is an option to force move everything, you wont have to type "y" to confirm.
54
+
55
+ You don't have to specify a path because Desktop is automatically the default location.
56
+
57
+ If you want to change your default location, you can simply do that in the default_path.txt file.
58
+
59
+
60
+ Another Example: I want to move certain items from my Projects folder, I made a shortcut called projects
61
+ ========================================================================================================
62
+ attic-cleanup store @projects
63
+
64
+
65
+ This line will take you to the projects folder, the @ sign stands for shortcut.
66
+
67
+ In the custom_paths.txt file you can set your own shortcuts. You can also create them with the 'new' command.
68
+
69
+ It's easy to do and there are already a few pre-generated shortcuts for you.
70
+
71
+ Since we didn't use the -a option, we can choose which files we want to store.
72
+
73
+ Now type 'ls' to view all the files and their IDs.
74
+
75
+ Then type the IDs of the files you wish to store. example: 1,3,6,12,25
76
+
77
+ Press enter, since we didn't use the -f option we will be asked if we want to move the files.
78
+
79
+ Type y to continue or type n to exit.
80
+
81
+ Once you press y all the file will be moved to the MyAttic folder and every file will be printed in the log.txt file.
82
+
83
+
84
+ Checking which shortcuts are available
85
+ ======================================
86
+ attic-cleanup shortcuts
87
+
88
+
89
+ This will display every shortcut in the custom_paths.txt file.
90
+
91
+
92
+ Creating a new shortcut with the 'new' command
93
+ ==============================================
94
+ attic-cleanup new --name projects --path ~/MyProjects/CurrentProject
95
+
96
+
97
+ This will generate a new shortcut. The shortcut name will be @projects and the path will be ~/MyProjects/CurrentProject
98
+
99
+ You can always adjust shortcuts and default location in MyAttic folder.
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path("../../lib/attic-cleanup", __FILE__)
3
+ require File.expand_path("../../lib/attic-cleanup/utility", __FILE__)
4
+ AtticCleanup::Utility.start
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ require "fileutils"
3
+ require "date"
4
+ require "time"
5
+
6
+ # Check for required gems
7
+ begin
8
+ require 'thor'
9
+ rescue LoadError
10
+ puts "Thor is not installed"
11
+ puts "Run 'gem install thor'"
12
+ exit 1
13
+ end
14
+
15
+ # require the classes
16
+ require File.expand_path("../../lib/attic-cleanup/storage/store_files", __FILE__)
17
+ require File.expand_path("../../lib/attic-cleanup/storage/folder_files", __FILE__)
18
+ require File.expand_path("../../lib/attic-cleanup/path/custom", __FILE__)
19
+ require File.expand_path("../../lib/attic-cleanup/log/log", __FILE__)
20
+ require File.expand_path("../../lib/attic-cleanup/initialize/init", __FILE__)
21
+
22
+ # All the constants and initializers
23
+ module MyAttic
24
+ ATTIC = File.join(ENV["HOME"], "MyAttic")
25
+ TODAY = File.join(ENV["HOME"], "MyAttic", Date.today.to_s)
26
+ CUSTOM = File.join(ENV["HOME"], "MyAttic/custom_paths.txt")
27
+ DEFAULT = File.join(ENV["HOME"], "MyAttic/default_path.txt")
28
+ LOG = File.join(ENV["HOME"], "MyAttic/log.txt")
29
+
30
+ # Checks if all the folders and files exist, also deletes any empty folders
31
+ AtticCleanup::Init.check_folder(MyAttic::ATTIC)
32
+ AtticCleanup::Init.check_folder(MyAttic::TODAY)
33
+ AtticCleanup::Init.check_file(MyAttic::DEFAULT)
34
+ AtticCleanup::Init.check_file(MyAttic::CUSTOM)
35
+ AtticCleanup::Init.clear
36
+
37
+ # This constant is set after the initializers because it reads
38
+ # the custom_paths.txt file. And it needs to be created first.
39
+ SHORTCUTS = AtticCleanup::Path::Custom.all(MyAttic::CUSTOM)
40
+ end
@@ -0,0 +1,51 @@
1
+ module AtticCleanup
2
+ module Init
3
+
4
+ # Default text for the custom_paths.txt file
5
+ CUSTOM_FILE = "#Write all your custom paths here.
6
+ #Or generate them with the 'attic-cleanup new' command
7
+ doc #{File.join(ENV['HOME'], 'Documents')}
8
+ pic #{File.join(ENV['HOME'], 'Pictures')}
9
+ mus #{File.join(ENV['HOME'], 'Music')}
10
+ mov #{File.join(ENV['HOME'], 'Movies')}
11
+ dow #{File.join(ENV['HOME'], 'Downloads')}"
12
+
13
+ # Default text for the default_path.txt file
14
+ DEFAULT_FILE = "#Write your default location here.
15
+ #{File.join(ENV['HOME'], 'Desktop')}"
16
+
17
+ # Checks if folder exists, if it doesn't it will be created
18
+ def self.check_folder(value)
19
+ if !File.directory? value
20
+ FileUtils.mkdir(value)
21
+ puts "#{value} doesn't exist yet.\nCreating #{value}.."
22
+ end
23
+ end
24
+
25
+ # Checks if file exists, if it doesn't it will be created
26
+ # and depending on which file, the default text will be set
27
+ def self.check_file(value)
28
+ if !File.exist?(value)
29
+ File.open(value, 'w') do |w|
30
+ if value == MyAttic::CUSTOM
31
+ text = CUSTOM_FILE
32
+ elsif value == MyAttic::DEFAULT
33
+ text = DEFAULT_FILE
34
+ end
35
+ w.write(text)
36
+ end
37
+ end
38
+ end
39
+
40
+ # Delete all folders in MyAttic that are empty
41
+ def self.clear
42
+ attic_folders = Dir.glob(File.join(MyAttic::ATTIC, "*"));
43
+ attic_folders.each do |f|
44
+ if f == MyAttic::CUSTOM || f == MyAttic::LOG || f == MyAttic::TODAY || f == MyAttic::DEFAULT
45
+ elsif Dir[File.join(f, "/*")].empty?
46
+ FileUtils.rm_rf(f)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,9 @@
1
+ module AtticCleanup
2
+ module Log
3
+ def self.save(file, destination)
4
+ File.open(MyAttic::LOG, "a") do |w|
5
+ w.write(file +" >> "+ destination + " || Date: " + Time.now.to_s + "\n")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,87 @@
1
+ module AtticCleanup
2
+ module Path
3
+ class Custom
4
+ attr_accessor :name, :path, :file, :line_nr
5
+
6
+ # Gets the last line in the default_path.txt file,
7
+ # which is the path to the default route
8
+ def self.default
9
+ File.open(MyAttic::DEFAULT, 'r') do |r|
10
+ line_array = []
11
+ while line = r.gets do
12
+ line_array << line
13
+ end
14
+ line_array.last
15
+ end
16
+ end
17
+
18
+ # Selects every line from the selected file
19
+ # but ignores lines where the first character is '#'
20
+ def self.all(file)
21
+ File.open(file, 'r') do |r|
22
+ line_array = []
23
+ while line = r.gets do
24
+ if line[0..0] == "#"
25
+ else
26
+ line_array << line
27
+ end
28
+ end
29
+ line_array
30
+ end
31
+ end
32
+
33
+ # Gets a specific line from a file
34
+ def find_line
35
+ File.open(@file, 'r') do |r|
36
+ k = []
37
+ k[0] = nil
38
+ while line = r.gets do
39
+ k << line
40
+ end
41
+ if k[@line_nr] == nil
42
+ "This line does not exist."
43
+ elsif k[@line_nr] == "\n"
44
+ "Empty"
45
+ else
46
+ k[@line_nr]
47
+ end
48
+ end
49
+ end
50
+
51
+ # Gets the custom shortcuts and looks in the custom_paths.txt file
52
+ # if there is a match. If there is it will select that line and
53
+ # extract the shortcut, so only the path remains
54
+ def find_custom
55
+ File.open(@file, 'r') do |r|
56
+ k = []
57
+ k[0] = nil
58
+ while line = r.gets do
59
+ name_count = @name.count("A-z, \s")
60
+ k << line[0..name_count]
61
+ this_name = k.last
62
+
63
+ if this_name == @name+" "
64
+ selected_line = line
65
+ the_name = this_name
66
+ end
67
+ end
68
+ if selected_line == nil
69
+ puts "Shortcut not found"
70
+ exit 1
71
+ else
72
+ the_name_count = the_name.count("A-z, \s")
73
+ line_count = selected_line.count("A-z, \s, '/'")
74
+ selected_line[the_name_count..line_count-1]
75
+ end
76
+ end
77
+ end
78
+
79
+ # Write to the custom_paths.txt file
80
+ def write
81
+ File.open(@file, 'a') do |w|
82
+ w.write("\n"+ @name + " " + @path)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,27 @@
1
+ module AtticCleanup
2
+ module Storage
3
+ class FolderFiles
4
+
5
+ def all_files
6
+ @all_files
7
+ end
8
+
9
+ # Select all files from the selected folder
10
+ def all_files= ( value )
11
+ Dir.chdir(value)
12
+ @all_files = Dir.glob("*");
13
+ end
14
+
15
+ # Find the file by it's ID
16
+ def self.find(files, number)
17
+ current_files = []
18
+ file_id = 0
19
+ files.each do |f|
20
+ current_files[file_id] = f
21
+ file_id += 1
22
+ end
23
+ current_files[number]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env ruby
2
+ module AtticCleanup
3
+ module Storage
4
+ class StoreFiles
5
+
6
+ # Easy method for input
7
+ def input
8
+ STDOUT.flush
9
+ @input = $stdin.gets.chomp
10
+ end
11
+
12
+ def location
13
+ @location
14
+ end
15
+
16
+ # Sets the location of the store method
17
+ # If the location wasn't set, the default
18
+ # location will be used from the default_path.txt file
19
+ def location= ( value )
20
+ if value == ""
21
+ value = AtticCleanup::Path::Custom.default
22
+ elsif value == "."
23
+ Dir.chdir(".")
24
+ value = Dir.getwd()
25
+ puts Dir.getwd()
26
+ end
27
+ @location = value
28
+ end
29
+
30
+ # Checks if the selected path exists
31
+ def check
32
+ if !File.directory? @location
33
+ puts "Invalid path " + @location
34
+ exit 1
35
+ end
36
+ end
37
+
38
+ # Puts the string of numbers in an array and removes the ','
39
+ def bundle(input)
40
+ bundle = input
41
+ bundle = bundle.scan( /\d+/ )
42
+ bundle.map!{ |bundle| bundle.to_i }
43
+ @bundle_items = bundle
44
+ @bundle_count = bundle.count
45
+
46
+ # If the user typed 'all' instead of numbers, every file will
47
+ # be set into the the array.
48
+ if @input == "all"
49
+ @bundle_items = []
50
+ p = 0
51
+ folder_files = AtticCleanup::Storage::FolderFiles.new
52
+ folder_files.all_files = location
53
+ folder_files.all_files.each do
54
+ @bundle_items[p] = p
55
+ p += 1
56
+ @bundle_count = "all"
57
+ end
58
+ end
59
+ end
60
+
61
+
62
+ def store(a, f)
63
+ folder_files = AtticCleanup::Storage::FolderFiles.new
64
+ # Selects all files from the current location
65
+ folder_files.all_files = location
66
+
67
+ # If option a is nil, the files will have to be selected manually
68
+ if a == nil
69
+ i = 1
70
+ while i == 1
71
+ # Message with the current location and simple instructions
72
+ puts "\n"+location
73
+ puts "Which files do you want to store in your attic?"
74
+ puts "Type ls for the list of items"
75
+ puts "Select the items by id. Example: 1,3,5"
76
+ input()
77
+
78
+ file_id = 0
79
+ # If input is "all" all the files and folders will be added to the array
80
+ if @input == "all"
81
+ @bundle_count = "all"
82
+ bundle("1")
83
+ i = 0
84
+ # If input is "ls" all the files and folder will be shown with their IDs
85
+ elsif @input == "ls"
86
+ folder_files.all_files.each do |k|
87
+ puts file_id.to_s + " - " + AtticCleanup::Storage::FolderFiles.find(folder_files.all_files, file_id)
88
+ file_id += 1
89
+ end
90
+ elsif @input == "exit"
91
+ exit 1
92
+ else
93
+ bundle(@input)
94
+ i = 0
95
+ end
96
+ end
97
+ else
98
+ # If option a was selected, all files will be added to the array
99
+ @bundle_count = "all"
100
+ @input = "all"
101
+ bundle(@input)
102
+ end
103
+
104
+ if f == nil
105
+ i = 1
106
+ # If no items were selected, go back to the input
107
+ if @bundle_count == 0
108
+ puts "\n\nNo file was selected."
109
+ store(nil, nil)
110
+ end
111
+ while i == 1
112
+ # If option f was not selected, you will get a warning before moving the files
113
+ puts "\nAre you sure you want to move #{@bundle_count} files/folders?\n [y/n]"
114
+ input()
115
+ if @input == "y"
116
+ i = 0
117
+ elsif @input == "n"
118
+ exit 1
119
+ else
120
+ puts "y or n?"
121
+ end
122
+ end
123
+ end
124
+
125
+ # Moves each file to the MyAttic folder
126
+ @bundle_items.each do |b|
127
+ # If the file wasn't found, print error
128
+ if AtticCleanup::Storage::FolderFiles.find(folder_files.all_files, b) == nil
129
+ puts "File ID " + b.to_s + " was not found"
130
+ else
131
+ # If file was found move it, print it and record it in the log
132
+ selected_file = File.join( location, AtticCleanup::Storage::FolderFiles.find(folder_files.all_files, b) )
133
+ puts "Moving " + selected_file + " to your attic.."
134
+ AtticCleanup::Log.save(selected_file, MyAttic::TODAY)
135
+ FileUtils.mv(selected_file, MyAttic::TODAY)
136
+ end
137
+ end
138
+ puts "The files have been moved to " + MyAttic::TODAY
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,65 @@
1
+ module AtticCleanup
2
+ class Utility < Thor
3
+ include Thor::Actions
4
+
5
+ desc "store",
6
+ "Choose a path or shortcut to store the contents of the given folder.
7
+ custom paths are called by placing an '@' sign in front of it.
8
+ example: @mypath
9
+
10
+ -a => 'all'
11
+ -f => 'force'\n\n"
12
+ method_options :a => :boolean, :f => :boolean
13
+ def store(input="")
14
+
15
+ # Checks if the options are set
16
+ if options[:a]
17
+ a = true
18
+ end
19
+ if options[:f]
20
+ f = true
21
+ end
22
+
23
+ # If the input for store has an "@" at the beginning
24
+ # it's a shortcut.
25
+ if input[0..0] == "@"
26
+ c = AtticCleanup::Path::Custom.new
27
+ # The input without the first character (the @ sign)
28
+ c.name = input[1..-1]
29
+ c.file = MyAttic::CUSTOM
30
+ input = c.find_custom
31
+ end
32
+ # The input is the location, if the input had an @ sign
33
+ # at the beginning, the custom path will be stored in input variable
34
+ s = AtticCleanup::Storage::StoreFiles.new
35
+ s.location = input
36
+ s.check
37
+ s.store(a, f)
38
+ end
39
+
40
+ desc "new", "Create a custom path.
41
+ --name => 'Name for your custom path'
42
+ --path => 'The path for your shortcut'\n\n"
43
+ method_options :name => :string, :path => :string
44
+ def new
45
+ if options[:path] != "path" && options[:path] && options[:name] != "name" && options[:name]
46
+ c = AtticCleanup::Path::Custom.new
47
+ # Sets name and path, adds it to the custom_paths.txt file
48
+ c.name = options[:name]
49
+ c.path = options[:path]
50
+ c.file = MyAttic::CUSTOM
51
+ c.write
52
+ else
53
+ puts "Please enter a path and name"
54
+ end
55
+ end
56
+
57
+ desc "shortcuts", "View all available shortcuts"
58
+ # Show all the availible shortcuts from the custom_paths.txt file
59
+ def shortcuts
60
+ MyAttic::SHORTCUTS.each do |s|
61
+ puts s
62
+ end
63
+ end
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: attic-cleanup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kevin van Rooijen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-04 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: &70360767219960 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70360767219960
25
+ description:
26
+ email: kevin.van.rooijen@gmail.com
27
+ executables:
28
+ - attic-cleanup
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - README.md
33
+ - bin/attic-cleanup
34
+ - lib/attic-cleanup.rb
35
+ - lib/attic-cleanup/utility.rb
36
+ - lib/attic-cleanup/initialize/init.rb
37
+ - lib/attic-cleanup/log/log.rb
38
+ - lib/attic-cleanup/path/custom.rb
39
+ - lib/attic-cleanup/storage/folder_files.rb
40
+ - lib/attic-cleanup/storage/store_files.rb
41
+ homepage: http://rubygems.org/gems/attic-cleanup
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ - bin
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.11
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: attic-cleanup is a gem to easily store your files when you need to get them
66
+ out of the way.
67
+ test_files: []