sysadmin 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/doc/ChangeLog +20 -0
- data/doc/README +60 -0
- data/doc/README.ja +13 -0
- data/lib/sysadmin.rb +3 -3
- data/lib/sysadmin/file_handler.rb +29 -0
- data/lib/sysadmin/file_string.rb +1 -1
- data/sysadmin.gemspec +5 -2
- data/test/lib/file_handler_test.rb +40 -0
- data/test/sysadmin_test.rb +1 -1
- metadata +5 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/doc/ChangeLog
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
=== 0.0.5 / 2012-06-06
|
2
|
+
|
3
|
+
* Add Class
|
4
|
+
|
5
|
+
* Sysadmin::FileHandler
|
6
|
+
|
7
|
+
* Add Methods
|
8
|
+
|
9
|
+
* File.zread
|
10
|
+
|
11
|
+
* Add English doc
|
12
|
+
|
13
|
+
|
14
|
+
=== 0.0.4 / 2012-06-04
|
15
|
+
|
16
|
+
* Bug fix
|
17
|
+
|
18
|
+
* Tempfile handling improvement for ruby 1.8.x
|
19
|
+
|
20
|
+
|
1
21
|
=== 0.0.3 / 2012-05-28
|
2
22
|
|
3
23
|
* Add docs
|
data/doc/README
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
sysadmin
|
2
|
+
|
3
|
+
Name
|
4
|
+
sysadmin - general-purpose library for system management
|
5
|
+
|
6
|
+
Syntax
|
7
|
+
require 'sysadmin'
|
8
|
+
|
9
|
+
Description
|
10
|
+
This is a collection of general-purpose processing library
|
11
|
+
frequently used in scripts for system administration.
|
12
|
+
|
13
|
+
|
14
|
+
============
|
15
|
+
Installation
|
16
|
+
============
|
17
|
+
|
18
|
+
$ gem install sysadmin
|
19
|
+
|
20
|
+
|
21
|
+
======
|
22
|
+
Module
|
23
|
+
======
|
24
|
+
|
25
|
+
- Sysadmin::FileString
|
26
|
+
|
27
|
+
String manipulation in the file.
|
28
|
+
|
29
|
+
- Sysadmin::FileHandler
|
30
|
+
|
31
|
+
Extend the File class.
|
32
|
+
|
33
|
+
|
34
|
+
======
|
35
|
+
Method
|
36
|
+
======
|
37
|
+
|
38
|
+
* Sysadmin::FileString.append(file, str)
|
39
|
+
|
40
|
+
Append a string to a file.
|
41
|
+
|
42
|
+
* Sysadmin::FileString.newfile(file, str)
|
43
|
+
|
44
|
+
Create a new file.
|
45
|
+
|
46
|
+
* Sysadmin::FileString.replace(file, src, out)
|
47
|
+
|
48
|
+
Replace the string in the file.
|
49
|
+
|
50
|
+
* Sysadmin :: FileString.delete(file, str)
|
51
|
+
|
52
|
+
Remove the rows that match the string from the file.
|
53
|
+
|
54
|
+
|
55
|
+
* File.zread (file)
|
56
|
+
|
57
|
+
Referred by Sysadmin::FileHandler.
|
58
|
+
Read the file regardless of the uncompressed / compressed gz.
|
59
|
+
|
60
|
+
|
data/doc/README.ja
CHANGED
@@ -24,6 +24,12 @@ $ gem install sysadmin
|
|
24
24
|
|
25
25
|
- Sysadmin::FileString
|
26
26
|
|
27
|
+
ファイル内の文字列操作をおこなう
|
28
|
+
|
29
|
+
- Sysadmin::FileHandler
|
30
|
+
|
31
|
+
File クラスを拡張する
|
32
|
+
|
27
33
|
|
28
34
|
========
|
29
35
|
メソッド
|
@@ -45,3 +51,10 @@ $ gem install sysadmin
|
|
45
51
|
|
46
52
|
ファイルから文字列にマッチする行を取り除く
|
47
53
|
|
54
|
+
|
55
|
+
* File.zread(file)
|
56
|
+
|
57
|
+
Sysadmin::FileHandler を呼ぶと追加される
|
58
|
+
gz 圧縮 / 非圧縮に関わらずファイルを読み込む
|
59
|
+
|
60
|
+
|
data/lib/sysadmin.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# Name:: Sysadmin::Ruby
|
3
3
|
# Author:: 774 <http://id774.net>
|
4
|
-
# Version:: 0.0.3
|
5
4
|
# Created:: Mar 23, 2012
|
6
|
-
# Updated:: Jun
|
5
|
+
# Updated:: Jun 06, 2012
|
7
6
|
# Copyright:: 774 Copyright (c) 2012
|
8
7
|
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
9
8
|
|
10
9
|
module Sysadmin
|
11
|
-
VERSION = "0.0.
|
10
|
+
VERSION = "0.0.5"
|
12
11
|
USER_DIR = "/."
|
13
12
|
ROOT_DIR = File.expand_path("..", File.dirname(__FILE__))
|
14
13
|
$:.unshift ROOT_DIR
|
@@ -16,4 +15,5 @@ module Sysadmin
|
|
16
15
|
$:.unshift ROOT_DIR + '/lib/sysadmin'
|
17
16
|
|
18
17
|
require 'file_string'
|
18
|
+
require 'file_handler'
|
19
19
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Name:: Sysadmin::FileString
|
2
|
+
# Author:: 774 <http://id774.net>
|
3
|
+
# Created:: Jun 06, 2012
|
4
|
+
# Updated:: Jun 06, 2012
|
5
|
+
# Copyright:: 774 Copyright (c) 2012
|
6
|
+
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
7
|
+
|
8
|
+
|
9
|
+
module Sysadmin
|
10
|
+
module FileHandler
|
11
|
+
require 'zlib'
|
12
|
+
Zlib::GZIP_MAGIC = "\x1F\x8B"
|
13
|
+
Zlib::GZIP_MAGIC.force_encoding("ASCII-8BIT") if RUBY_VERSION >= "1.9"
|
14
|
+
|
15
|
+
def File.zread(file)
|
16
|
+
Object.module_eval do
|
17
|
+
open(file) {|f|
|
18
|
+
magic = f.read(2)
|
19
|
+
f.rewind
|
20
|
+
if magic == Zlib::GZIP_MAGIC
|
21
|
+
Zlib::GzipReader.wrap(f) {|gz|gz.read}
|
22
|
+
else
|
23
|
+
f.read
|
24
|
+
end
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/sysadmin/file_string.rb
CHANGED
data/sysadmin.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "sysadmin"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["id774"]
|
12
|
-
s.date = "2012-06-
|
12
|
+
s.date = "2012-06-06"
|
13
13
|
s.description = "System Administration General Library"
|
14
14
|
s.email = "idnanashi@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -25,12 +25,15 @@ Gem::Specification.new do |s|
|
|
25
25
|
"doc/COPYING.LESSER",
|
26
26
|
"doc/ChangeLog",
|
27
27
|
"doc/LICENSE",
|
28
|
+
"doc/README",
|
28
29
|
"doc/README.ja",
|
29
30
|
"lib/sysadmin.rb",
|
31
|
+
"lib/sysadmin/file_handler.rb",
|
30
32
|
"lib/sysadmin/file_string.rb",
|
31
33
|
"script/.gitkeep",
|
32
34
|
"script/build",
|
33
35
|
"sysadmin.gemspec",
|
36
|
+
"test/lib/file_handler_test.rb",
|
34
37
|
"test/lib/file_string_1_test.rb",
|
35
38
|
"test/lib/file_string_2_test.rb",
|
36
39
|
"test/sysadmin_test.rb",
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'test/unit'
|
6
|
+
require 'tempfile'
|
7
|
+
require 'zlib'
|
8
|
+
require 'sysadmin'
|
9
|
+
|
10
|
+
class Test_FileHandler < Test::Unit::TestCase
|
11
|
+
def test_zread_uncompressed
|
12
|
+
@uncompressed = Tempfile::new("test.txt")
|
13
|
+
try = "uncompressed"
|
14
|
+
expect = "uncompressed\n"
|
15
|
+
|
16
|
+
Sysadmin::FileString.append(@uncompressed.path, try)
|
17
|
+
|
18
|
+
text = File.zread(@uncompressed.path)
|
19
|
+
assert_not_nil(text)
|
20
|
+
assert_equal(expect, text)
|
21
|
+
|
22
|
+
@uncompressed.close
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_zread_compressed
|
26
|
+
try = "compressed"
|
27
|
+
expect = "compressed\n"
|
28
|
+
|
29
|
+
@compressed = Tempfile::new("test2.txt")
|
30
|
+
Zlib::GzipWriter.open(@compressed.path) do |gz|
|
31
|
+
gz.puts try
|
32
|
+
end
|
33
|
+
|
34
|
+
text = File.zread(@compressed.path)
|
35
|
+
assert_not_nil(text)
|
36
|
+
assert_equal(expect, text)
|
37
|
+
|
38
|
+
@compressed.close
|
39
|
+
end
|
40
|
+
end
|
data/test/sysadmin_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sysadmin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cucumber
|
@@ -75,12 +75,15 @@ files:
|
|
75
75
|
- doc/COPYING.LESSER
|
76
76
|
- doc/ChangeLog
|
77
77
|
- doc/LICENSE
|
78
|
+
- doc/README
|
78
79
|
- doc/README.ja
|
79
80
|
- lib/sysadmin.rb
|
81
|
+
- lib/sysadmin/file_handler.rb
|
80
82
|
- lib/sysadmin/file_string.rb
|
81
83
|
- script/.gitkeep
|
82
84
|
- script/build
|
83
85
|
- sysadmin.gemspec
|
86
|
+
- test/lib/file_handler_test.rb
|
84
87
|
- test/lib/file_string_1_test.rb
|
85
88
|
- test/lib/file_string_2_test.rb
|
86
89
|
- test/sysadmin_test.rb
|