ucool 1.0.0
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.
- data/bin/ucool +124 -0
- metadata +62 -0
data/bin/ucool
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
require 'rubygems'
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
host_os = RbConfig::CONFIG['host_os']
|
8
|
+
if host_os =~ /mswin|msys|mingw32/
|
9
|
+
require "iconv"
|
10
|
+
alias _puts puts
|
11
|
+
def puts string
|
12
|
+
_puts Iconv.iconv("GB2312","UTF-8", string)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def bind_ucool(argv)
|
17
|
+
if argv[0].to_s == "--help" or argv[0].to_s == "-h"
|
18
|
+
help =<<-EOF
|
19
|
+
ucool 查看ucool当前状态
|
20
|
+
ucool [user_root] [dir] 切换到user_root/u_dir
|
21
|
+
ucool [dir] 绑定到当前用户文件夹的指定目录,当前用户文件夹是指环境变量ucool_root设定的值
|
22
|
+
ucool none 切换到未绑定状态
|
23
|
+
ucool prepub toggle绑定到预发
|
24
|
+
ucool debug toggle源代码模式
|
25
|
+
ucool cache toggle缓冲assets
|
26
|
+
ucool mpa toggle映射本地
|
27
|
+
ucool combo toggle本地combo
|
28
|
+
|
29
|
+
!!! [dir]参数不需要u_前缀
|
30
|
+
|
31
|
+
使用示例:
|
32
|
+
$ ucool xingdou sold_list
|
33
|
+
绑定ucool到xingdou/u_sold_list目录
|
34
|
+
|
35
|
+
$ ucool_root=xingdou
|
36
|
+
设定环境变量ucool_root为xingdou
|
37
|
+
|
38
|
+
$ ucool sold_list
|
39
|
+
绑定ucool到xingdou/u_sold_list目录
|
40
|
+
EOF
|
41
|
+
puts help
|
42
|
+
return
|
43
|
+
end
|
44
|
+
|
45
|
+
if argv.length > 1
|
46
|
+
root = argv[0]
|
47
|
+
|
48
|
+
sub = argv[1]
|
49
|
+
elsif
|
50
|
+
sub = argv[0]
|
51
|
+
end
|
52
|
+
if sub.nil?
|
53
|
+
map = {
|
54
|
+
"assetsdebugswitch" => " DEBUG模式",
|
55
|
+
"bindPrepub" => " 绑定预发环境",
|
56
|
+
"enableLocalCombo" => " 手动combo",
|
57
|
+
"enableAssets" => "使用服务器Assets目录",
|
58
|
+
"enableLocalMapping"=> " 本地目录映射",
|
59
|
+
"open" => "开启",
|
60
|
+
"close" => "关闭"
|
61
|
+
}
|
62
|
+
api="http://u.taobao.net/pz"
|
63
|
+
begin
|
64
|
+
echo = Net::HTTP.get(URI.parse(api))
|
65
|
+
rescue Exception => e
|
66
|
+
puts "error:" + e
|
67
|
+
end
|
68
|
+
begin
|
69
|
+
root=echo.match(/root-bind[\s\S]*?<\/select>/).to_s.match(/selected.*?>/).to_s.match(/value=[" ]?(.*?)[" >]+/)[1]
|
70
|
+
sub=echo.match(/dir-bind[\s\S]*?<\/select>/).to_s.match(/selected.*?>/).to_s.match(/value=[" ]?(.*?)[" >]+/)[1]
|
71
|
+
puts "绑定目录: #{root}/#{sub}"
|
72
|
+
rescue
|
73
|
+
end
|
74
|
+
links = echo.scan /<a[^>]*>.*?<\/a>/
|
75
|
+
links.each do |a|
|
76
|
+
if a =~ /switch-/
|
77
|
+
id = a.match(/id="(.*)"/)[1]
|
78
|
+
status = a.match(/class="switch-(.*?)"/)[1]
|
79
|
+
puts "#{map[id]}: #{map[status]}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
return
|
83
|
+
end
|
84
|
+
|
85
|
+
if %q(prepub,map,combo,debug,cache).include? sub
|
86
|
+
cmd_map = {
|
87
|
+
"prepub" => "bindPrepub",
|
88
|
+
"mpa" => "enableLocalMapping",
|
89
|
+
"combo" => "enableLocalCombo",
|
90
|
+
"debug" => "assetsdebugswitch",
|
91
|
+
"cache" => "enableAssets"
|
92
|
+
}
|
93
|
+
api="http://u.taobao.net/ppzbg.jsp?pid=#{cmd_map[sub]}&callback=UCOOL.Pz.change&t=#{rand}"
|
94
|
+
echo = Net::HTTP.get(URI.parse(api + "&rootDir=#{root}&subDir=u_#{sub}&t=#{rand}"))
|
95
|
+
#out = " ucool with prepub"
|
96
|
+
#puts echo
|
97
|
+
else
|
98
|
+
root = root || ENV["ucool_root"] || "-1"
|
99
|
+
root = "-1" if root == "none"
|
100
|
+
sub = sub || "-1"
|
101
|
+
if sub == "none"
|
102
|
+
sub = "-1"
|
103
|
+
elsif not sub =~ /^u_/
|
104
|
+
sub = "u_" + sub
|
105
|
+
end
|
106
|
+
|
107
|
+
api="http://u.taobao.net/ppzbg.jsp?pid=bindDir&callback=UCOOL.Pz.bindDir"
|
108
|
+
echo = Net::HTTP.get(URI.parse(api + "&rootDir=#{root}&subDir=#{sub}&t=#{rand}"))
|
109
|
+
#out = " ucool with #{root}/u_#{sub}"
|
110
|
+
end
|
111
|
+
#puts echo
|
112
|
+
if echo and !echo.empty?
|
113
|
+
echos = echo.sub(/^.*?,/,'').delete("')").split(",")
|
114
|
+
status = echos[0].delete(' ')
|
115
|
+
msg = echos[1]
|
116
|
+
if status =~ /ok/
|
117
|
+
puts "ok"
|
118
|
+
else
|
119
|
+
#puts "failed to bind#{out}"
|
120
|
+
puts "error: #{msg}"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
bind_ucool(ARGV)
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ucool
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Zhong Xingdou
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-08-31 00:00:00 +08:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: " ucool command for taobao.com\n"
|
22
|
+
email: zhongxingdou@gmail.com
|
23
|
+
executables:
|
24
|
+
- ucool
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- bin/ucool
|
31
|
+
has_rdoc: true
|
32
|
+
homepage:
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.3.6
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: ucool command for taobao.com
|
61
|
+
test_files: []
|
62
|
+
|