segua 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.yardopts +4 -0
- data/LICENSE.md +26 -0
- data/README.md +59 -0
- data/bin/segua +7 -0
- data/lib/segua/version.rb +4 -0
- data/lib/segua.rb +64 -0
- metadata +56 -0
data/.gitignore
ADDED
data/.yardopts
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2012 by the University of Arizona.
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are
|
6
|
+
met:
|
7
|
+
|
8
|
+
* Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
* Redistributions in binary form must reproduce the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer in
|
13
|
+
the documentation and/or other materials provided with the
|
14
|
+
distribution.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
20
|
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
23
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
Segua
|
2
|
+
=====
|
3
|
+
|
4
|
+
Introduction
|
5
|
+
------------
|
6
|
+
|
7
|
+
Segua is a tool that works similar to `tail -f`. The primary difference is that Segua uses a directory, not a file, as input. It then finds the file with the most recent modification time, and follows that file. After printing a line, Segua will review the directory entries to see if one has a newer modification time, and begin following that one.
|
8
|
+
|
9
|
+
Compatibility
|
10
|
+
-------------
|
11
|
+
|
12
|
+
Segua is tested on the following platforms:
|
13
|
+
|
14
|
+
* **ruby-1.9.3** on **Linux**
|
15
|
+
|
16
|
+
That is all.
|
17
|
+
|
18
|
+
Roadmap
|
19
|
+
-------
|
20
|
+
|
21
|
+
* Tests :P
|
22
|
+
* Do not print the whole file contents at the beginning. Act more like `tail -f`
|
23
|
+
* Make the `SEGUA` lines optional.
|
24
|
+
* Option for using creation time, instead of modification time
|
25
|
+
* Fix: `/home/sam/code/segua/lib/segua.rb:36:in `strip': invalid byte sequence in UTF-8 (ArgumentError)` when latest file is a Vim swap file.
|
26
|
+
|
27
|
+
Installation
|
28
|
+
------------
|
29
|
+
|
30
|
+
gem install segua
|
31
|
+
|
32
|
+
Contributing
|
33
|
+
------------
|
34
|
+
|
35
|
+
Please do! Contributing is easy. Please read the CONTRIBUTING.md document for more info. ... Whet exists.
|
36
|
+
|
37
|
+
Usage
|
38
|
+
-----
|
39
|
+
|
40
|
+
Segua is meant to be used primarily as the binary script that is provided, `segua`. You can also require the class itself, with
|
41
|
+
|
42
|
+
require 'segua'
|
43
|
+
segua = Segua.new("some/directory")
|
44
|
+
|
45
|
+
Versioning
|
46
|
+
----------
|
47
|
+
|
48
|
+
Segua follows [Semantic Versioning](http://semver.org/) (at least approximately) version 2.0.0-rc1.
|
49
|
+
|
50
|
+
Further Reading
|
51
|
+
---------------
|
52
|
+
|
53
|
+
* [tail man page](http://unixhelp.ed.ac.uk/CGI/man-cgi?tail)
|
54
|
+
|
55
|
+
License
|
56
|
+
-------
|
57
|
+
|
58
|
+
Please see [LICENSE.md|LICENSE.md].
|
59
|
+
|
data/bin/segua
ADDED
data/lib/segua.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), 'segua', 'version')
|
2
|
+
|
3
|
+
# Segua tracks changes in files in `@dir`, always following the most recently changed.
|
4
|
+
#
|
5
|
+
# It emulates `tail -f`. `tail's` argument, `-f`, stands for "follow." "Segua" is the imperative
|
6
|
+
# form of "to follow" in Italian.
|
7
|
+
class Segua
|
8
|
+
# Create a new Segua against `dir`.
|
9
|
+
def initialize(dir)
|
10
|
+
@dir = dir
|
11
|
+
end
|
12
|
+
|
13
|
+
# Print a few lines before switching to a new file, indicating the new file.
|
14
|
+
def print_file_update(file_name)
|
15
|
+
puts ""
|
16
|
+
puts "SEGUA: ==================" + ('='*file_name.length)
|
17
|
+
puts "SEGUA: most recent file: #{file_name}"
|
18
|
+
puts "SEGUA: ==================" + ('='*file_name.length)
|
19
|
+
puts ""
|
20
|
+
end
|
21
|
+
|
22
|
+
# Following the file with the most recent modification time, print each line of the file,
|
23
|
+
# indefinitely.
|
24
|
+
def follow
|
25
|
+
file_name = latest_file
|
26
|
+
while file_name.nil?
|
27
|
+
sleep 1
|
28
|
+
file_name = latest_file
|
29
|
+
end
|
30
|
+
|
31
|
+
print_file_update(file_name)
|
32
|
+
handle = File.open file_name
|
33
|
+
|
34
|
+
while true
|
35
|
+
line = handle.gets
|
36
|
+
if line.nil?
|
37
|
+
sleep 0.5
|
38
|
+
else
|
39
|
+
puts line.chomp.strip
|
40
|
+
end
|
41
|
+
new_file_name = latest_file
|
42
|
+
while new_file_name.nil?
|
43
|
+
sleep 1
|
44
|
+
new_file_name = latest_file
|
45
|
+
end
|
46
|
+
if new_file_name != file_name
|
47
|
+
print_file_update(new_file_name)
|
48
|
+
file_name = new_file_name
|
49
|
+
handle.close
|
50
|
+
handle = File.open file_name
|
51
|
+
next
|
52
|
+
end
|
53
|
+
end
|
54
|
+
handle.close
|
55
|
+
end
|
56
|
+
|
57
|
+
# Find, among all of the files located directly inside `dir`, the one with the most recent
|
58
|
+
# modification time. Returns the full file path as a String.
|
59
|
+
def latest_file
|
60
|
+
Dir.entries(@dir).map {|f| File.join(@dir, f) }.reject {|f| File.directory?(f) }.inject do |memo,file|
|
61
|
+
File.mtime(memo) > File.mtime(file) ? memo : file
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: segua
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sam Rawlins
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-09 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Segua acts like tail -f, except that it accepts a directory as input,
|
15
|
+
not a file. It then constantly evaluates which file is the most recently modified,
|
16
|
+
and follows that file.
|
17
|
+
email:
|
18
|
+
- katt-core@listserv.arizona.edu
|
19
|
+
executables:
|
20
|
+
- segua
|
21
|
+
extensions: []
|
22
|
+
extra_rdoc_files: []
|
23
|
+
files:
|
24
|
+
- .gitignore
|
25
|
+
- .yardopts
|
26
|
+
- LICENSE.md
|
27
|
+
- README.md
|
28
|
+
- bin/segua
|
29
|
+
- lib/segua.rb
|
30
|
+
- lib/segua/version.rb
|
31
|
+
homepage: http://uaz-kf-a09.mosaic.arizona.edu/
|
32
|
+
licenses: []
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.8.17
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: Follow the most recently modified files in a directory.
|
55
|
+
test_files: []
|
56
|
+
has_rdoc:
|