ztil 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +4 -0
  4. data/Rakefile +0 -0
  5. data/bin/ztil +7 -0
  6. data/lib/ztil/command.rb +126 -0
  7. data/lib/ztil.rb +3 -0
  8. metadata +108 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a6839a88f4cf0db429b404edc3bb25acaa89858a
4
+ data.tar.gz: bd86cc3540ac94f42bc2d335859c4dd44ef78283
5
+ SHA512:
6
+ metadata.gz: 5911a3f795394899e5dbec597da51e59cf7102e61757d9e4961673f8a2e898d74daf6ead357b909d3024eaab3a792336578e6a3ee27b7fa0ef284b693f462537
7
+ data.tar.gz: 8e644cdeabfa1a94bda6c3959370b283fb3199f4bed72442ed1a8a2d9d36882d7dae43dac85c5a36801f02ab48886749035bb129a539906186aa7c725e4a298a
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Thierry Zires
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ ztil
2
+ ====
3
+
4
+ zires's utils
data/Rakefile ADDED
File without changes
data/bin/ztil ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+
5
+ require 'ztil/command'
6
+
7
+ Ztil::Command.start
@@ -0,0 +1,126 @@
1
+ # encoding: utf-8
2
+ require 'thor'
3
+ require 'rest-client'
4
+ require 'json'
5
+
6
+ module Ztil
7
+ class Command < Thor
8
+ include Thor::Actions
9
+
10
+ def self.source_root
11
+ File.expand_path File.join( File.dirname(__FILE__), '../../', 'Backup' )
12
+ end
13
+
14
+ BAIDU_AK = 'A0f00186ba072b824d88d6300c9f7f86'
15
+ BAIDU_URL = 'http://api.map.baidu.com'
16
+
17
+ # 百度的地理位置API | http://developer.baidu.com/map/index.php?title=webapi/guide/webservice-geocoding
18
+
19
+ desc 'geocoder ADDRESS', '根据百度API, 将地址转换成经纬度'
20
+ method_option :city, desc: '地址所在的城市', required: false
21
+ def geocoder(address)
22
+ r = JSON.parse RestClient.get("#{BAIDU_URL}/geocoder/v2/", { params: {address: address, output: :json, ak: BAIDU_AK, city: options[:city]} })
23
+ say JSON.pretty_generate(r)
24
+ end
25
+
26
+ desc 'coordcoder LOCATION', '根据百度API, 将经纬度转换成地址, 纬度(小)在前, 经度在后, 逗号分隔'
27
+ method_option :coordtype, desc: '坐标的类型', default: 'wgs84ll', required: false, aliases: 't',
28
+ desc: '目前支持的坐标类型包括:bd09ll(百度经纬度坐标)、gcj02ll(国测局经纬度坐标)、wgs84ll( GPS经纬度)'
29
+ def coordcoder(location)
30
+ r = JSON.parse RestClient.get("#{BAIDU_URL}/geocoder/v2/", { params: {location: location, output: :json, ak: BAIDU_AK, coordtype: options[:coordtype]} })
31
+ say JSON.pretty_generate(r)
32
+ end
33
+
34
+ # 备份数据库 | https://github.com/meskyanichi/backup
35
+
36
+ # 关心的是数据库,存储以及执行时间和邮件通知
37
+ #
38
+ # @example
39
+ # ztil backup --databases="mysql,mongodb" --storages="qi_niu" --email="xxx@xxx.com" --schedule="1.day&4:30 am"
40
+ desc 'backup DATABASE_NAME', '备份数据库, 传入all表示所有databases'
41
+ method_option :databases, desc: '需要备份的数据库类型, 支持mysql以及mongodb', required: true
42
+ method_option :storages, desc: '备份数据的存储方式, 支持存储到七牛'
43
+ method_option :email, desc: '备份成功后通知的邮箱'
44
+ method_option :schedule, desc: '按计划执行, 默认只执行一次'
45
+ def backup(name)
46
+ storages = options[:storages] || 'local'
47
+
48
+ run "backup_zh generate:model \
49
+ --trigger #{name} \
50
+ --databases=#{options[:databases]} \
51
+ --compressor=gzip \
52
+ --storages='#{storages}'"
53
+
54
+ file = File.join( File.expand_path('~/Backup'), 'models', "#{name}.rb" )
55
+
56
+ # 数据库名称
57
+ database_name = options[:name] || name
58
+ gsub_file file, /my_database_name/, database_name
59
+
60
+ # 注释掉一些没用的
61
+ options[:databases].split(',').map(&:strip).each do |database|
62
+ case database
63
+ when 'mysql'
64
+ comment_lines file, 'skip_tables'
65
+ comment_lines file, 'only_tables'
66
+ when 'mongodb'
67
+ comment_lines file, 'only_collections'
68
+ end
69
+ end
70
+
71
+ # 邮箱设置
72
+ if options[:email] && File.read(file) !~ /system@aukudu.com/
73
+ insert_into_file file, after: "compress_with Gzip\n" do
74
+ <<-MAIL
75
+ ##
76
+ # Mail [Notifier]
77
+ notify_by Mail do |mail|
78
+ mail.on_success = true
79
+ mail.on_warning = false
80
+ mail.on_failure = true
81
+ mail.from = 'system@aukudu.com'
82
+ mail.address = 'smtp.exmail.qq.com'
83
+ mail.port = 465
84
+ mail.domain = 'aukudu.com'
85
+ mail.user_name = 'system@aukudu.com'
86
+ mail.password = 'Zsb170523402'
87
+ mail.authentication = 'plain'
88
+ mail.encryption = :ssl
89
+ mail.to = '#{options[:email]}'
90
+ end
91
+ MAIL
92
+ end
93
+ end
94
+
95
+ run "vi #{file}"
96
+
97
+ # 周期执行
98
+ if options[:schedule]
99
+ schedule_path = File.join( File.expand_path('~/Backup'), 'schedule')
100
+ schedule_config_path = File.join(schedule_path, 'config')
101
+ FileUtils.mkdir_p(schedule_config_path) unless File.directory?(schedule_config_path)
102
+ run "wheneverize #{schedule_path}"
103
+ time, at = options[:schedule].split('&').map(&:strip)
104
+ append_to_file( File.join(schedule_config_path, 'schedule.rb') ) do
105
+ <<-SCH
106
+ every #{time}, :at => '#{at}' do
107
+ command "backup_zh perform -t #{name}"
108
+ end
109
+ SCH
110
+ end
111
+ run "whenever -f #{File.join(schedule_config_path, 'schedule.rb')}"
112
+ else
113
+ run "backup_zh perform -t #{name}"
114
+ end
115
+
116
+ end
117
+
118
+ # 静态文件服务
119
+ desc 'static_me', '在当前目录下开启静态文件服务, Ruby 1.9.2+'
120
+ method_option :port, desc: '端口', required: false, default: 8000, aliases: 'p'
121
+ def static_me
122
+ run "ruby -run -ehttpd . -p#{options[:port]}"
123
+ end
124
+
125
+ end
126
+ end
data/lib/ztil.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Ztil
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ztil
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - zires
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.7.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.7.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: backup_zh
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 4.0.3.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 4.0.3.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: whenever
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.2
69
+ description: The utils of zires...include Backup database to qi_niu
70
+ email:
71
+ - zshuaibin@gmail.com
72
+ executables:
73
+ - ztil
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - LICENSE
78
+ - README.md
79
+ - Rakefile
80
+ - bin/ztil
81
+ - lib/ztil.rb
82
+ - lib/ztil/command.rb
83
+ homepage: https://github.com/zires/ztil
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.2.2
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: The utils of zires
107
+ test_files: []
108
+ has_rdoc: