housekeeper 0.1.0

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,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 432db038e64efa65603ad13669f791ac44824f075b1490e4713d62b54a5a2886
4
+ data.tar.gz: d498c3567d638471798b206a2aa5c1d26a94dda5fd88243e5a3527d0298e0bce
5
+ SHA512:
6
+ metadata.gz: 6f1832946aad08f6c63593715a040fb481818e3c9cd70617ae0ac9818c31aafee0e173669e9eacc383032c2f87bcf43d32899b7d4a25ad89c2fa7b20840f7bad
7
+ data.tar.gz: 0c9c584c89130b3e7a9cb224a7218c045ef916213db0659b8e7cdb2e7e2b983244c653d67ecae2174e5680a8dc932c1a9022ae841df1f6c7b72152a13fdfd26d
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .byebug_history
10
+ *.gem
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.0
7
+ before_install: gem install bundler -v 1.16.4
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in housekeeper.gemspec
8
+ gemspec
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ housekeeper (0.1.0)
5
+ commander (~> 4)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ byebug (10.0.2)
11
+ commander (4.4.7)
12
+ highline (~> 2.0.0)
13
+ diff-lcs (1.3)
14
+ highline (2.0.0)
15
+ rake (10.5.0)
16
+ rspec (3.8.0)
17
+ rspec-core (~> 3.8.0)
18
+ rspec-expectations (~> 3.8.0)
19
+ rspec-mocks (~> 3.8.0)
20
+ rspec-core (3.8.0)
21
+ rspec-support (~> 3.8.0)
22
+ rspec-expectations (3.8.2)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.8.0)
25
+ rspec-mocks (3.8.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.8.0)
28
+ rspec-support (3.8.0)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 1.16)
35
+ byebug (~> 10.0)
36
+ housekeeper!
37
+ rake (~> 10.0)
38
+ rspec (~> 3.0)
39
+
40
+ BUNDLED WITH
41
+ 1.16.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Roman Lehnert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,57 @@
1
+ # Housekeeper
2
+
3
+ Housekeeper helps with keeping directories clean. It takes content that is older than a specified age and either deletes or archives it.
4
+
5
+ ## Usage
6
+
7
+ ```shell
8
+ $ housekeeper -h
9
+
10
+ Usage: housekeeper [options]
11
+ -a, --action ACTION Action (can be archive or delete)
12
+ -d, --dir DIRNAME Directory to cleanup
13
+ -m, --age AGE The minimum mtime age in seconds of contents to be cleaned up
14
+ ```
15
+
16
+
17
+ In order to have only contents in your `~/Downloads` directory, which are newer than 1 day, setup the following cronjob:
18
+
19
+ ```
20
+ * * * * * housekeeper --dir $HOME/Downloads --age 86400 --action archive
21
+ ```
22
+
23
+ And to keep only files in your `~/Downloads/archive` directory, which are newer than 5 days, setup the following cronjob:
24
+
25
+ ```
26
+ * * * * * housekeeper --dir $HOME/Downloads/archive --age 432000 --action delete
27
+ ```
28
+
29
+
30
+ Contents can be ignored by putting a file called `.housekeeper_ignore` with an [fnmatch pattern](https://ruby-doc.org/core-2.2.0/File.html#method-c-fnmatch), for example
31
+ ```
32
+ myfile.*
33
+ **.rb
34
+ ```
35
+
36
+
37
+
38
+ ## Installation
39
+
40
+ Install it with bundler
41
+
42
+ $ gem install housekeeper
43
+
44
+
45
+ ## Development
46
+
47
+ 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.
48
+
49
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/romanlehnert/housekeeper.
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'housekeeper'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'housekeeper'
5
+ require 'optparse'
6
+
7
+ options = {}
8
+
9
+ MANDATORY_ARGUMENTS = %i[action dir age].freeze
10
+ VALID_ACTIONS = %w[archive delete].freeze
11
+
12
+ parser = OptionParser.new do |parser|
13
+ parser.on('-a', '--action ACTION', String, 'Action (can be archive or delete)') do |action|
14
+ options[:action] = action
15
+ end
16
+
17
+ parser.on('-d', '--dir DIRNAME', String, 'Directory to cleanup') do |d|
18
+ options[:dir] = d
19
+ end
20
+
21
+ parser.on('-m', '--age AGE', Integer, 'The minimum mtime age in seconds of contents to be cleaned up') do |m|
22
+ options[:age] = m
23
+ end
24
+ end
25
+
26
+ begin
27
+ parser.parse!
28
+
29
+ missing = MANDATORY_ARGUMENTS.select { |param| options[param].nil? }
30
+
31
+ raise OptionParser::MissingArgument, missing.join(', ') unless missing.empty?
32
+ raise OptionParser::InvalidArgument, "action must be one of #{VALID_ACTIONS.join(', ')}" unless VALID_ACTIONS.include?(options[:action])
33
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument, OptionParser::InvalidArgument
34
+ puts $ERROR_INFO.to_s
35
+ puts
36
+ puts parser
37
+ exit
38
+ end
39
+
40
+ Housekeeper::Cleaner.new(options[:dir], min_age_seconds: options[:age]).send(options[:action])
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'housekeeper/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'housekeeper'
9
+ spec.version = Housekeeper::VERSION
10
+ spec.authors = ['Roman Lehnert']
11
+ spec.email = ['roman.lehnert@gmail.com']
12
+
13
+ spec.summary = 'Housekeeping for directories'
14
+ spec.description = 'Lets you delete or archive files and dirs'
15
+ spec.homepage = 'https://github.com/romanlehnert/housekeeper'
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
22
+ else
23
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
24
+ 'public gem pushes.'
25
+ end
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ spec.bindir = 'exe'
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ['lib']
35
+
36
+ spec.add_dependency 'commander', '~> 4'
37
+
38
+ spec.add_development_dependency 'bundler', '~> 1.16'
39
+ spec.add_development_dependency 'byebug', '~> 10.0'
40
+ spec.add_development_dependency 'rake', '~> 10.0'
41
+ spec.add_development_dependency 'rspec', '~> 3.0'
42
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'housekeeper/version'
4
+ require_relative 'housekeeper/cleaner'
5
+
6
+ module Housekeeper
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Housekeeper
4
+ class Cleaner
5
+ attr_reader :archive_path
6
+ attr_reader :min_age_seconds
7
+ attr_reader :base_path
8
+
9
+ IGNORES_FILE_NAME = '.housekeeper_ignore'
10
+ DEFAULT_IGNORES = ['.', '..', 'archive'].freeze
11
+
12
+ def initialize(base_path, min_age_seconds: nil)
13
+ @base_path = base_path
14
+ @archive_path = File.join(base_path, 'archive/')
15
+ @min_age_seconds = min_age_seconds || 0
16
+ end
17
+
18
+ def archive
19
+ Dir.mkdir(archive_path) unless Dir.exist?(archive_path)
20
+
21
+ Dir.new(base_path).each do |entry|
22
+ next if skip_entry?(entry)
23
+
24
+ FileUtils.mv(entry_path(entry), archive_path)
25
+ end
26
+ end
27
+
28
+ def delete
29
+ Dir.new(base_path).each do |entry|
30
+ next if skip_entry?(entry)
31
+
32
+ FileUtils.remove_entry_secure(entry_path(entry))
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def entry_path(entry_name)
39
+ File.join(base_path, entry_name)
40
+ end
41
+
42
+ def skip_entry?(entry)
43
+ return true if DEFAULT_IGNORES.include?(entry)
44
+ return true if filed_ignores.any? { |pattern| File.fnmatch(pattern, entry) }
45
+ return true if File.mtime(entry_path(entry)) > Time.now - min_age_seconds
46
+ end
47
+
48
+ def filed_ignores
49
+ ignore_file_path = File.join(base_path, IGNORES_FILE_NAME)
50
+
51
+ return [] unless File.exist?(ignore_file_path)
52
+
53
+ File.new(ignore_file_path).readlines
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Housekeeper
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: housekeeper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Roman Lehnert
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: commander
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Lets you delete or archive files and dirs
84
+ email:
85
+ - roman.lehnert@gmail.com
86
+ executables:
87
+ - housekeeper
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - exe/housekeeper
102
+ - housekeeper.gemspec
103
+ - lib/housekeeper.rb
104
+ - lib/housekeeper/cleaner.rb
105
+ - lib/housekeeper/version.rb
106
+ homepage: https://github.com/romanlehnert/housekeeper
107
+ licenses:
108
+ - MIT
109
+ metadata:
110
+ allowed_push_host: https://rubygems.org
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.7.7
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Housekeeping for directories
131
+ test_files: []