fvalve 0.0.1

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
+ SHA1:
3
+ metadata.gz: 30eedf099ebacdf8dbce9d1fb484c50315b46baf
4
+ data.tar.gz: 66251abfabef43b59d127237cf4fd2e0f1a4215f
5
+ SHA512:
6
+ metadata.gz: 94e58d5f48bec8c9a1f1a49ef3d97ee5bb74750c5cde06ccc21dbb063d0a12eb90320d5a219a3f8dd52c0755eb87295edb3975ed52b450ec9f91b1dbad33c071
7
+ data.tar.gz: 0930f84119b627af21fee61b8fd701032defc603aedfab9ab6730fad16bce5eaa9c54f7f509190bbb8e9e37cb0d86d136c0e39e1f66feed98e4f2069f8225044
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ /.vagrant/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fvalve.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 ksoichiro
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Fvalve
2
+
3
+ Simple file rotation script.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fvalve'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fvalve
18
+
19
+ ## Usage
20
+
21
+ Leaves 3 files with pattern `*.log` in `target` dir:
22
+
23
+ fvalve target "*.log" 3
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/fvalve/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ #require 'rake/testtask'
3
+ #
4
+ #desc 'Rotate files. example: rake "rotate[target, \'*.log\', 3]"'
5
+ #task :rotate, :target_dir, :pattern, :generations do |t, args|
6
+ # sh "ruby ./rotate.rb #{args.target_dir} #{args.pattern} #{args.generations}"
7
+ #end
8
+ #
9
+ #task :default => :test
10
+ #
11
+ #Rake::TestTask.new
@@ -0,0 +1,9 @@
1
+ # -*- mode: ruby -*- # vi: set ft=ruby :
2
+
3
+ VAGRANTFILE_API_VERSION = "2"
4
+
5
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
6
+ config.vm.box = "precise64"
7
+ config.vm.box_url = "http://files.vagrantup.com/precise64.box"
8
+ config.vm.provision :shell, :path => "provision.sh"
9
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fvalve'
4
+
5
+ if ARGV.length < 3 then
6
+ Fvalve::Fvalve.loge "Invalid params: example: fvalve target '*.log' 3"
7
+ exit 1
8
+ end
9
+
10
+ v = Fvalve::Fvalve.new
11
+ v.instance_variable_set(:@target_dir, ARGV[0])
12
+ v.instance_variable_set(:@pattern, ARGV[1])
13
+ v.instance_variable_set(:@generations, ARGV[2])
14
+ v.execute
15
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fvalve/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fvalve"
8
+ spec.version = Fvalve::VERSION
9
+ spec.authors = ["ksoichiro"]
10
+ spec.email = ["soichiro.kashima@gmail.com"]
11
+ spec.summary = %q{File generation keeper.}
12
+ spec.description = %q{fvalve keeps a certain number of files in a directory.}
13
+ spec.homepage = "https://github.com/ksoichiro/fvalve"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,61 @@
1
+ require "fvalve/version"
2
+
3
+ module Fvalve
4
+ class Fvalve
5
+ LOG_INFO = 'INFO'
6
+ LOG_WARN = 'WARN'
7
+ LOG_ERROR = 'ERROR'
8
+ def self.log(msg, level = LOG_INFO)
9
+ t = Time.now
10
+ puts "[#{t.strftime("%Y/%m/%d %H:%M:%S %Z")}] [#{level}] #{msg}"
11
+ end
12
+
13
+ def self.logi(msg)
14
+ self.log msg, LOG_INFO
15
+ end
16
+
17
+ def self.logw(msg)
18
+ self.log msg, LOG_WARN
19
+ end
20
+
21
+ def self.loge(msg)
22
+ self.log msg, LOG_ERROR
23
+ end
24
+
25
+ def initialize
26
+ @target_dir = nil
27
+ @pattern = "*.log"
28
+ @generations = -1
29
+ end
30
+
31
+ def execute
32
+ Fvalve.logi "Started."
33
+ Fvalve.logi "Parameters:"
34
+ Fvalve.logi " target_dir: #{@target_dir}"
35
+ Fvalve.logi " pattern: #{@pattern}"
36
+ Fvalve.logi " generations: #{@generations}"
37
+
38
+ if !Dir.exist?(@target_dir) then
39
+ Fvalve.loge "Target directory not found: #{@target_dir}"
40
+ exit 1
41
+ end
42
+
43
+ cwd = Dir.getwd
44
+ Dir.chdir(@target_dir)
45
+ gen = 0
46
+ deleted = 0
47
+ Dir.glob(@pattern).sort {|a, b| b <=> a}.each do |f|
48
+ gen = gen + 1
49
+ if @generations.to_i < gen then
50
+ Fvalve.logi "Remove file: #{f}"
51
+ File.delete f
52
+ deleted = deleted + 1
53
+ end
54
+ end
55
+ Dir.chdir(cwd)
56
+
57
+ Fvalve.logi "Deleted #{deleted} file(s)."
58
+ Fvalve.logi "Done."
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module Fvalve
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env bash
2
+
3
+ which vim > /dev/null 2>&1
4
+ if [ $? -ne 0 ]; then
5
+ apt-get update
6
+ apt-get install -y vim-gnome
7
+ apt-get install -y language-pack-ja
8
+ dpkg-reconfigure locales
9
+ echo "set encoding=utf-8" >> ~vagrant/.vimrc
10
+ echo "set fileencodings=utf-8" >> ~vagrant/.vimrc
11
+ echo "set number" >> ~vagrant/.vimrc
12
+ echo "set ts=4" >> ~vagrant/.vimrc
13
+ echo "set listchars=tab:^-,eol:$" >> ~vagrant/.vimrc
14
+ echo "set list" >> ~vagrant/.vimrc
15
+ chown vagrant:vagrant ~vagrant/.vimrc
16
+ fi
17
+
18
+ which git > /dev/null 2>&1
19
+ if [ $? -ne 0 ]; then
20
+ apt-get install -y git
21
+ fi
22
+
23
+ which bundle > /dev/null 2>&1
24
+ if [ $? -ne 0 ]; then
25
+ gem install bundler
26
+ fi
27
+
28
+ which curl > /dev/null 2>&1
29
+ if [ $? -ne 0 ]; then
30
+ apt-get install -y curl
31
+ fi
32
+
33
+ which rvm > /dev/null 2>&1
34
+ if [ $? -ne 0 ]; then
35
+ curl -sSL https://get.rvm.io | bash -s stable
36
+
37
+ source /usr/local/rvm/scripts/rvm
38
+
39
+ rvm requirements
40
+ rvm install 1.9.3
41
+ rvm use 1.9.3
42
+ fi
43
+
44
+ cd /vagrant
45
+ bundle install
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'fileutils'
3
+ require 'fvalve'
4
+
5
+ describe Fvalve::Fvalve, "when correctly initialized" do
6
+
7
+ before do
8
+ $stdout = File.new('/dev/null', 'w')
9
+
10
+ if Dir.exists?('tmp')
11
+ FileUtils.rm_rf('tmp')
12
+ end
13
+ Dir.mkdir('tmp')
14
+ 20.times do |i|
15
+ File.open("tmp/#{20140401 + i}.log", "w").close()
16
+ end
17
+ @valve = Fvalve::Fvalve.new
18
+ @valve.instance_variable_set(:@target_dir, 'tmp')
19
+ @valve.instance_variable_set(:@pattern, '*.log')
20
+ @valve.instance_variable_set(:@generations, '3')
21
+ end
22
+
23
+ it "should leave 3 files" do
24
+ @valve.execute
25
+ Dir.glob('tmp/*.log').length == 3
26
+ end
27
+
28
+ after do
29
+ FileUtils.rm_rf('tmp')
30
+ $stdout = STDOUT
31
+ end
32
+
33
+ end
@@ -0,0 +1 @@
1
+ puts 'Not yet implemented'
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fvalve
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ksoichiro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: fvalve keeps a certain number of files in a directory.
56
+ email:
57
+ - soichiro.kashima@gmail.com
58
+ executables:
59
+ - fvalve
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .rspec
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - Vagrantfile
70
+ - bin/fvalve
71
+ - fvalve.gemspec
72
+ - lib/fvalve.rb
73
+ - lib/fvalve/version.rb
74
+ - provision.sh
75
+ - spec/basic_spec.rb
76
+ - test/test_basic.rb
77
+ homepage: https://github.com/ksoichiro/fvalve
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.0.3
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: File generation keeper.
101
+ test_files:
102
+ - spec/basic_spec.rb
103
+ - test/test_basic.rb