td 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,79 @@
1
+ require 'td/error'
2
+
3
+ module TD
4
+
5
+
6
+ class Config
7
+ def initialize
8
+ @path = nil
9
+ @conf = {} # section.key = val
10
+ end
11
+
12
+ def self.read(path, create=false)
13
+ new.read(path)
14
+ end
15
+
16
+ def [](cate_key)
17
+ @conf[cate_key]
18
+ end
19
+
20
+ def []=(cate_key, val)
21
+ @conf[cate_key] = val
22
+ end
23
+
24
+ def save(path=@path)
25
+ @path = path
26
+ write
27
+ end
28
+
29
+ def read(path=@path)
30
+ @path = path
31
+ begin
32
+ data = File.read(@path)
33
+ rescue
34
+ e = ConfigNotFoundError.new($!.to_s)
35
+ e.set_backtrace($!.backtrace)
36
+ raise e
37
+ end
38
+
39
+ section = ""
40
+
41
+ data.each_line {|line|
42
+ line.strip!
43
+ case line
44
+ when /^#/
45
+ next
46
+ when /\[(.+)\]/
47
+ section = $~[1]
48
+ when /^(\w+)\s*=\s*(.+?)\s*$/
49
+ key = $~[1]
50
+ val = $~[2]
51
+ @conf["#{section}.#{key}"] = val
52
+ else
53
+ raise ConfigParseError, "invalid config line '#{line}' at #{@path}"
54
+ end
55
+ }
56
+
57
+ self
58
+ end
59
+
60
+ def write
61
+ require 'fileutils'
62
+ FileUtils.mkdir_p File.dirname(@path)
63
+ File.open(@path, "w") {|f|
64
+ @conf.keys.map {|cate_key|
65
+ cate_key.split('.',2)
66
+ }.zip(@conf.values).group_by {|(section,key),val|
67
+ section
68
+ }.each {|section,cate_key_vals|
69
+ f.puts "[#{section}]"
70
+ cate_key_vals.each {|(section,key),val|
71
+ f.puts " #{key} = #{val}"
72
+ }
73
+ }
74
+ }
75
+ end
76
+ end
77
+
78
+
79
+ end
@@ -0,0 +1,29 @@
1
+
2
+ module TD
3
+
4
+
5
+ class ConfigError < StandardError
6
+ end
7
+
8
+ class ConfigNotFoundError < ConfigError
9
+ end
10
+
11
+ class ConfigParseError < ConfigError
12
+ end
13
+
14
+
15
+ class APIError < StandardError
16
+ end
17
+
18
+ class AuthError < APIError
19
+ end
20
+
21
+ class AlreadyExistsError < APIError
22
+ end
23
+
24
+ class NotFoundError < APIError
25
+ end
26
+
27
+
28
+ end
29
+
@@ -0,0 +1,5 @@
1
+ module TD
2
+
3
+ VERSION = '0.7.0'
4
+
5
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: td
3
+ version: !ruby/object:Gem::Version
4
+ hash: 3
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 7
9
+ - 0
10
+ version: 0.7.0
11
+ platform: ruby
12
+ authors:
13
+ - Sadayuki Furuhashi
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-06 00:00:00 +09:00
19
+ default_executable: td
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: msgpack
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 0
32
+ - 4
33
+ - 4
34
+ version: 0.4.4
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: json
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 1
46
+ segments:
47
+ - 1
48
+ - 4
49
+ - 3
50
+ version: 1.4.3
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: hirb
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 5
62
+ segments:
63
+ - 0
64
+ - 4
65
+ - 5
66
+ version: 0.4.5
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ description:
70
+ email:
71
+ executables:
72
+ - td
73
+ extensions: []
74
+
75
+ extra_rdoc_files:
76
+ - ChangeLog
77
+ - README.rdoc
78
+ files:
79
+ - lib/td/api.rb
80
+ - lib/td/api_iface.rb
81
+ - lib/td/command/account.rb
82
+ - lib/td/command/common.rb
83
+ - lib/td/command/database.rb
84
+ - lib/td/command/import.rb
85
+ - lib/td/command/list.rb
86
+ - lib/td/command/query.rb
87
+ - lib/td/command/server.rb
88
+ - lib/td/command/table.rb
89
+ - lib/td/command/td.rb
90
+ - lib/td/config.rb
91
+ - lib/td/error.rb
92
+ - lib/td/version.rb
93
+ - ChangeLog
94
+ - README.rdoc
95
+ - bin/td
96
+ has_rdoc: true
97
+ homepage:
98
+ licenses: []
99
+
100
+ post_install_message:
101
+ rdoc_options:
102
+ - --charset=UTF-8
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ hash: 3
120
+ segments:
121
+ - 0
122
+ version: "0"
123
+ requirements: []
124
+
125
+ rubyforge_project:
126
+ rubygems_version: 1.3.7
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: Treasure Data command line tool
130
+ test_files: []
131
+