easyoperate 0.1.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/History.txt +4 -0
- data/Manifest.txt +13 -0
- data/README.rdoc +39 -0
- data/Rakefile +25 -0
- data/bin/eo +10 -0
- data/example/eorc +10 -0
- data/lib/easyoperate.rb +5 -0
- data/lib/eo.rb +49 -0
- data/lib/eo/eo.rb +138 -0
- data/lib/eo/scm.rb +93 -0
- data/test/test_easyoperate.rb +11 -0
- data/test/test_eo_cli.rb +15 -0
- data/test/test_helper.rb +3 -0
- metadata +90 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
= EasyOperate < eo >
|
2
|
+
|
3
|
+
== INSTALL:
|
4
|
+
$ sudo gem install easyoperate
|
5
|
+
|
6
|
+
== Why && How To Use:
|
7
|
+
## ~/.eorc
|
8
|
+
vim-rails:
|
9
|
+
path: ~/vim/vim-rails/ # Local path
|
10
|
+
|
11
|
+
repo: git://github.com/tpope/vim-rails.git # Remote path
|
12
|
+
|
13
|
+
autorun: 'puts "Thanks to Tim Pope";cp_autoload;cp_plugin'
|
14
|
+
# Splited by ';' , when init or update,'autorun' will autorun
|
15
|
+
|
16
|
+
scm: # svn/git,default is git
|
17
|
+
|
18
|
+
cmd: # Where define your methods
|
19
|
+
cp_autoload: `cp autoload/rails.vim ~/.vim/autoload/`
|
20
|
+
cp_plugin: `cp plugin/rails.vim '~/.vim/plugin/`
|
21
|
+
example: 'puts "Hi,This is example method"'
|
22
|
+
##
|
23
|
+
$ eo -i vim-rails => Clone vim-rails from github to the path your specify
|
24
|
+
$ eo -c vim-rails => Select vim-rails to operate
|
25
|
+
$ eo -u vim-rails => Update vim-rails
|
26
|
+
$ eo -u hi => Update all repository match /hi/,nothing for all
|
27
|
+
|
28
|
+
== More Help:
|
29
|
+
|
30
|
+
<shell>
|
31
|
+
$ eo -h for help
|
32
|
+
<program>
|
33
|
+
$ h for help
|
34
|
+
|
35
|
+
|
36
|
+
Copyright (c) 2008 Jinzhu Zhang (GPL3)
|
37
|
+
|
38
|
+
Web : http://www.zhangjinzhu.com
|
39
|
+
Email: wosmvp (no-spam) gmail (no-spam) com
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
2
|
+
require File.dirname(__FILE__) + '/lib/easyoperate'
|
3
|
+
|
4
|
+
$hoe = Hoe.new('easyoperate', Easyoperate::VERSION) do |p|
|
5
|
+
p.developer('Jinzhu Zhang', 'wosmvp@gmail.com')
|
6
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
7
|
+
p.rubyforge_name = "easyoperate"
|
8
|
+
p.url = "http://www.zhangjinzhu.com"
|
9
|
+
p.description = "Eo_oE"
|
10
|
+
|
11
|
+
p.extra_dev_deps = [
|
12
|
+
['newgem', ">= #{::Newgem::VERSION}"]
|
13
|
+
]
|
14
|
+
|
15
|
+
p.clean_globs |= %w[tmp *.log]
|
16
|
+
path = "\#{p.rubyforge_name}/\#{p.name}"
|
17
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
18
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
22
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
23
|
+
|
24
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
25
|
+
# task :default => [:spec, :features]
|
data/bin/eo
ADDED
data/example/eorc
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# hack hack hack, rename to ~/.eorc
|
2
|
+
vim-rails:
|
3
|
+
path: ~/vim/vim-rails/ # Local path
|
4
|
+
repo: git://github.com/tpope/vim-rails.git # Remote path
|
5
|
+
autorun: 'puts "Thanks to Tim Pope";cp_autoload;cp_plugin' # Splited by ;
|
6
|
+
scm: # svn/git,default is git
|
7
|
+
cmd: # Where can define your methods
|
8
|
+
cp_autoload: `cp autoload/rails.vim ~/.vim/autoload/`
|
9
|
+
cp_plugin: `cp plugin/rails.vim '~/.vim/plugin/`
|
10
|
+
example: 'puts "Hi,This is example method"'
|
data/lib/easyoperate.rb
ADDED
data/lib/eo.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
%w(optparse yaml eo/eo).each {|f| require f}
|
2
|
+
|
3
|
+
class Eo
|
4
|
+
|
5
|
+
def self.execute(stdout, arguments=[])
|
6
|
+
|
7
|
+
parser = OptionParser.new do |opts|
|
8
|
+
opts.banner = <<-BANNER.gsub(/^ /,'')
|
9
|
+
Usage: #{File.basename($0)} [options]
|
10
|
+
|
11
|
+
Options are:
|
12
|
+
BANNER
|
13
|
+
|
14
|
+
opts.on_tail("-h", "--help","Show this help message.") do |args|
|
15
|
+
stdout.puts opts; exit
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on_tail("-v", "--version","Show version information.") do
|
19
|
+
puts Easyoperate::VERSION; exit
|
20
|
+
end
|
21
|
+
|
22
|
+
opts.on("-u [ARGS]", "--update","Update Repository. <Regexp>") do |args|
|
23
|
+
self.update(args)
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on("-s [ARGS]", "--show","Show All Repositories. <Regexp>") do |args|
|
27
|
+
self.show(args)
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on("-c [ARGS]", "--choose","Choose Some Repository.") do |args|
|
31
|
+
self.choose(args)
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on("-i [ARGS]", "--init","Initialize Repository. <Regexp>") do |args|
|
35
|
+
self.init(args)
|
36
|
+
end
|
37
|
+
|
38
|
+
if arguments.empty?
|
39
|
+
self.run
|
40
|
+
else
|
41
|
+
begin
|
42
|
+
opts.parse!(arguments)
|
43
|
+
rescue OptionParser::InvalidOption
|
44
|
+
puts "\e[31m;(\tError\e[0m \n\tHelp?\t\e[33m$ eo -h \e[31m;)\e[0m"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/eo/eo.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'eo/scm'
|
2
|
+
class Eo
|
3
|
+
Repo = Hash.new
|
4
|
+
|
5
|
+
Config_file = File.join("#{ENV['HOME']}",".eorc")
|
6
|
+
|
7
|
+
unless File.exist?(Config_file)
|
8
|
+
puts " \e[31m;( No config file\e[0m \n\nexample file:"
|
9
|
+
puts File.read(File.join(File.dirname(__FILE__),'../../example/eorc'))
|
10
|
+
exit
|
11
|
+
end
|
12
|
+
|
13
|
+
YAML.load_file(Config_file).each_pair do |keys,value|
|
14
|
+
Repo[keys] = Scm.new.merge(value)
|
15
|
+
end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def run
|
19
|
+
loop do
|
20
|
+
printf("\e[33mInput Commands (q to quit| h for help) : \e[0m")
|
21
|
+
input = STDIN.gets.split(' ',2)
|
22
|
+
input[1].strip!
|
23
|
+
case input[0].to_s
|
24
|
+
when /S/i then show(input[1])
|
25
|
+
when /C/i then choose(input[1])
|
26
|
+
when /U/i then update(input[1])
|
27
|
+
when /I/i then init(input[1])
|
28
|
+
when /Q/i then exit(0)
|
29
|
+
else help
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def help
|
35
|
+
puts "Usage:"
|
36
|
+
puts " S /args/ : Show matched repositories <Regexp>"
|
37
|
+
puts " C /args/ : Choose Some Repository <Regexp>"
|
38
|
+
puts " U /args/ : Update matched Repository <Regexp>"
|
39
|
+
puts " I /args/ : Initialize matched Repository <Regexp>"
|
40
|
+
puts " Q : Quit"
|
41
|
+
puts " H : Show this help message."
|
42
|
+
puts "e.g:\n \e[32m s v.*m\e[0m"
|
43
|
+
end
|
44
|
+
|
45
|
+
def show(*args)
|
46
|
+
repos = pick(args,false)
|
47
|
+
puts "\e[33mAll Repo match < #{args} > :\e[0m"
|
48
|
+
repos.each_index do |x|
|
49
|
+
printf "\e[32m %-15s\t\e[0m" % [repos[x].rstrip]
|
50
|
+
printf("\n") if (x+1)%4==0
|
51
|
+
end
|
52
|
+
puts "\n" if repos.size%4 != 0
|
53
|
+
end
|
54
|
+
|
55
|
+
def choose(*args)
|
56
|
+
repos = pick(args)
|
57
|
+
if repos && repos = repos.to_s
|
58
|
+
return false unless exist_path(repos)
|
59
|
+
loop do
|
60
|
+
printf("\e[01;34m#{repos.first} >> \e[0m")
|
61
|
+
input = STDIN.gets.strip
|
62
|
+
break if input =~ /\A\s*q\s*\Z/
|
63
|
+
exit if input =~ /\A\s*Q\s*\Z/
|
64
|
+
Repo[repos].send(input) unless input.empty?
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def init(*args)
|
70
|
+
repos = pick(args,false)
|
71
|
+
repos.each do |x|
|
72
|
+
if File.exist?(File.expand_path(Repo[x]['path']))
|
73
|
+
puts "\e[32m %-18s: already Initialized\e[0m" % [x]
|
74
|
+
next
|
75
|
+
end
|
76
|
+
puts "\e[32m %-18s: Initializing\e[0m" % [x]
|
77
|
+
Repo[x].init
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def update(*args)
|
82
|
+
repos = pick(args,false)
|
83
|
+
repos.each do |x|
|
84
|
+
puts "\e[32mUpdating #{Repo[x]['path']} :\e[0m"
|
85
|
+
next if !exist_path(x)
|
86
|
+
Repo[x].update
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
protected
|
91
|
+
def pick(args,only_one=true)
|
92
|
+
repos = Repo.keys.grep(/#{args}/)
|
93
|
+
if only_one
|
94
|
+
if repos.size == 1
|
95
|
+
return repos
|
96
|
+
elsif repos.empty?
|
97
|
+
printf("\e[31mSorry,But No Result.\n\e[0m")
|
98
|
+
return false
|
99
|
+
else
|
100
|
+
return choose_one(repos)
|
101
|
+
end
|
102
|
+
else
|
103
|
+
return repos
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def choose_one(args)
|
108
|
+
puts "\e[33mPlease Choose One of them : \e[0m"
|
109
|
+
|
110
|
+
args.each_index do |x|
|
111
|
+
printf "\e[32m%-2d\e[0m %-15s\t" % [x+1,args[x].rstrip]
|
112
|
+
printf "\n" if (x+1)%4 == 0
|
113
|
+
end
|
114
|
+
printf "\n" if args.size%4 != 0
|
115
|
+
|
116
|
+
num = choose_range(args.size)
|
117
|
+
return num ? [args[num-1]] : false
|
118
|
+
end
|
119
|
+
|
120
|
+
def choose_range(size)
|
121
|
+
printf "\e[33mPlease Input A Valid Number (1..#{size}) (q to quit): \e[0m"
|
122
|
+
num = STDIN.gets
|
123
|
+
return false if num =~ /q/i
|
124
|
+
choosed_num = num.strip.empty? ? 1 : num.to_i
|
125
|
+
(1..size).member?(choosed_num) ? (return choosed_num) : choose_range(size)
|
126
|
+
end
|
127
|
+
|
128
|
+
def exist_path(repos)
|
129
|
+
if File.exist?(File.expand_path(Repo[repos]['path']))
|
130
|
+
Dir.chdir(File.expand_path(Repo[repos]['path']))
|
131
|
+
else
|
132
|
+
puts "\n l.l,Have You init \e[33m#{repos}\e[0m Repository?\n\n"
|
133
|
+
return false
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
end
|
data/lib/eo/scm.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
class Scm < Hash
|
2
|
+
|
3
|
+
def help
|
4
|
+
if self['cmd'] && cmd = self['cmd'].keys
|
5
|
+
printf("Your Defined Methods :\n")
|
6
|
+
cmd.each_index do |x|
|
7
|
+
puts " %-18s: %s" % [cmd[x].rstrip,self['cmd'][cmd[x]]]
|
8
|
+
end
|
9
|
+
puts
|
10
|
+
end
|
11
|
+
|
12
|
+
puts "Usage: "
|
13
|
+
puts " %-18s: %s." % ["update","Update"]
|
14
|
+
puts " %-18s: %s." % ["shell/sh","Goto shell"]
|
15
|
+
puts " %-18s: %s." % ["help/h","Show this help message"]
|
16
|
+
puts " %-18s: %s." % ["q","Quit this shell"]
|
17
|
+
puts " %-18s: %s." % ["Q","Exit this program"]
|
18
|
+
puts " %-18s: %s." % ["<Hash Method>","Run"]
|
19
|
+
puts " %-18s: %s." % ["<Your Method>","Run.if undefined by above"]
|
20
|
+
puts " %-18s: %s." % ["<Shell Command>","Run.if undefined by above"]
|
21
|
+
puts "e.g:\n \e[32m pwd \e[0m => The repository's path"
|
22
|
+
|
23
|
+
end
|
24
|
+
alias h help
|
25
|
+
|
26
|
+
def update
|
27
|
+
old_commit = now_commit
|
28
|
+
scm_update
|
29
|
+
new_commit = now_commit
|
30
|
+
if new_commit == old_commit
|
31
|
+
puts "NO Update"
|
32
|
+
else
|
33
|
+
if self['autorun']
|
34
|
+
self['autorun'].split(';').each do |x|
|
35
|
+
eval x
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def shell
|
42
|
+
system("sh")
|
43
|
+
end
|
44
|
+
alias sh shell
|
45
|
+
|
46
|
+
def init
|
47
|
+
command = case self['scm']
|
48
|
+
when /svn/ then 'svn co'
|
49
|
+
when /git/ then 'git clone'
|
50
|
+
when nil then 'git clone'
|
51
|
+
end
|
52
|
+
if command
|
53
|
+
system("#{command} #{self['repo']} #{self['path']}")
|
54
|
+
else
|
55
|
+
puts "\e[31mSorry,Maybe doesn't support #{self['scm']} rightnow.\e[0m"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def method_missing(m,*args)
|
60
|
+
m = m.to_s
|
61
|
+
methods = self['cmd'] ? self['cmd'].keys.grep(m) : []
|
62
|
+
|
63
|
+
if methods.size == 1
|
64
|
+
eval self['cmd'][m]
|
65
|
+
else
|
66
|
+
result = system(m + " " + args.join(' '))
|
67
|
+
puts "\e[31mlol, Some Wrong?\e[0m" unless result
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
protected
|
72
|
+
def scm
|
73
|
+
return 'git' if !Dir.entries('.').grep(".git").empty?
|
74
|
+
return 'svn' if !Dir.entries('.').grep(".svn").empty?
|
75
|
+
end
|
76
|
+
|
77
|
+
def scm_update
|
78
|
+
case scm
|
79
|
+
when /git/ then system("git pull")
|
80
|
+
when /svn/ then system("svn update")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def now_commit
|
85
|
+
case scm
|
86
|
+
when /git/ then return `git log --pretty=format:%H -1`
|
87
|
+
when /svn/ then return `svn -l 1 log -q | grep "\w" | awk '{print $1}'`
|
88
|
+
else
|
89
|
+
puts "\e[31mSorry,RightNow Only Support SVN/GIT\e[0m"
|
90
|
+
exit
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/test/test_eo_cli.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper.rb")
|
2
|
+
require 'eo'
|
3
|
+
|
4
|
+
class TestEo < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@stdout_io = StringIO.new
|
7
|
+
Eo.execute(@stdout_io, [])
|
8
|
+
@stdout_io.rewind
|
9
|
+
@stdout = @stdout_io.read
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_not_print_default_output
|
13
|
+
assert_no_match(/To update this executable/, @stdout)
|
14
|
+
end
|
15
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: easyoperate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jinzhu Zhang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-12-13 00:00:00 +08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: newgem
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hoe
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.0
|
34
|
+
version:
|
35
|
+
description: Eo_oE
|
36
|
+
email:
|
37
|
+
- wosmvp@gmail.com
|
38
|
+
executables:
|
39
|
+
- eo
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- History.txt
|
44
|
+
- Manifest.txt
|
45
|
+
- README.rdoc
|
46
|
+
files:
|
47
|
+
- History.txt
|
48
|
+
- Manifest.txt
|
49
|
+
- README.rdoc
|
50
|
+
- Rakefile
|
51
|
+
- bin/eo
|
52
|
+
- example/eorc
|
53
|
+
- lib/easyoperate.rb
|
54
|
+
- lib/eo.rb
|
55
|
+
- lib/eo/eo.rb
|
56
|
+
- lib/eo/scm.rb
|
57
|
+
- test/test_easyoperate.rb
|
58
|
+
- test/test_eo_cli.rb
|
59
|
+
- test/test_helper.rb
|
60
|
+
has_rdoc: true
|
61
|
+
homepage: http://www.zhangjinzhu.com
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options:
|
64
|
+
- --main
|
65
|
+
- README.rdoc
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
version:
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project: easyoperate
|
83
|
+
rubygems_version: 1.3.1
|
84
|
+
signing_key:
|
85
|
+
specification_version: 2
|
86
|
+
summary: ""
|
87
|
+
test_files:
|
88
|
+
- test/test_helper.rb
|
89
|
+
- test/test_eo_cli.rb
|
90
|
+
- test/test_easyoperate.rb
|