popo 0.1.4 → 0.1.6

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/envy CHANGED
@@ -1,16 +1,69 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'optparse'
2
3
  require 'yaml'
3
4
 
4
- ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..'))
5
- BASH_PATH = `which bash`.strip
6
- ENV_PATH = `which env`.strip
7
- POPO_PATH = ENV['popo_path'] if ENV.include?('popo_path')
8
- POPO_TARGET = ENV['popo_target'] if ENV.include?('popo_target')
9
- POPO_WORK_PATH = '.manifest'
10
- ENVYRC = File.expand_path(File.join(File.dirname(__FILE__), '../script/envyrc'))
5
+ module Popo
6
+ class Envy
7
+ POPO_CONFIG_FILE = 'popo.yml'
8
+ ENVYRC_FILE = 'envyrc'
9
+ BASH_PATH = `which bash`.strip
10
+ ENVY_CMD = `which env`.strip
11
+ ENVYRC = File.expand_path("../../script/#{ENVYRC_FILE}", __FILE__)
11
12
 
12
- cmd = ARGV.join(' ')
13
+ def self.boot(args)
14
+ options = {}
13
15
 
14
- finale = "#{ENV_PATH} popo_path=#{POPO_PATH} popo_target=#{POPO_TARGET} #{BASH_PATH} -c 'source #{ENVYRC}; cd #{POPO_PATH}; #{cmd}'"
15
- system(finale)
16
+ optparse = OptionParser.new do |opts|
17
+ opts.on('-C', '--chdir DIRECTORY', 'Changed to a given directory') do |d|
18
+ options[:directory] = d
19
+ end
20
+ end
16
21
 
22
+ optparse.parse!
23
+
24
+ self.new(args, options)
25
+ end
26
+
27
+ def initialize(args, options)
28
+ @root_path = args.shift
29
+ @options = options
30
+ @commands = []
31
+
32
+ # set commands
33
+ args.each do |a|
34
+ @commands << a
35
+ end
36
+
37
+ config_file = File.join(@root_path, POPO_CONFIG_FILE)
38
+
39
+ if File.exists?(config_file)
40
+ cfg = YAML.load_file(config_file)
41
+ @popo_path = cfg['path']
42
+ @popo_target = cfg['target']
43
+ else
44
+ raise "#{config_file} doesn't exist!"
45
+ end
46
+
47
+ if !@options[:directory].nil?
48
+ @directory = File.join(@popo_path, @options[:directory])
49
+ else
50
+ @directory = ''
51
+ end
52
+ end
53
+
54
+ def run!
55
+ cmd = "#{ENVY_CMD} popo_path=#{@popo_path} \
56
+ popo_target=#{@popo_target} #{BASH_PATH} \
57
+ -c 'source #{ENVYRC}; #{@commands.join(' ')}'"
58
+
59
+ if @directory.empty?
60
+ `#{cmd}`
61
+ else
62
+ Dir.chdir(@directory) { `#{cmd}` }
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ Popo::Envy.boot(ARGV).run!
69
+ exit $?.exitstatus
@@ -5,5 +5,6 @@ module Popo
5
5
  POPO_WORK_PATH = ".manifest"
6
6
  POPO_YML_FILE = "popo.yml"
7
7
  POPO_CONFIG = {}
8
+ POPO_DIRECTORY_KEY = "sync.directories"
8
9
  end
9
10
  end
@@ -54,6 +54,32 @@ module Popo
54
54
  end
55
55
  end
56
56
  end
57
+
58
+ def self.branch_diff(cwd, branches = ['master', 'development'])
59
+ if is_git?(cwd)
60
+ diff_msg = `#{GIT_CMD} log --abbrev-commit --format=short \
61
+ origin/#{branches[0]}..origin/#{branches[1]}`
62
+
63
+ parsed = diff_msg.scan(/(commit [0-9a-f]+)\n+(.*?)\n+(.*?)(?:\n|$)/)
64
+
65
+ puts "Commits in #{branches[0]} not found in #{branches[1]}"
66
+
67
+ parsed.each do |p|
68
+ commit_id = p[0].gsub(/commit/,'').strip
69
+ author = p[1].scan(/Author: (.*) <.*>/)
70
+ commit_msg = p[2].strip
71
+
72
+ Utils.say "#{commit_id} \<#{author}\> #{commit_msg}"
73
+ end
74
+ else
75
+ raise "#{cwd} is not a git repo!"
76
+ end
77
+
78
+ end
79
+
80
+ def self.is_git?(cwd)
81
+ File.exists?(File.join(cwd, '.git'))
82
+ end
57
83
  end
58
84
  end
59
85
 
data/lib/popo/runner.rb CHANGED
@@ -3,9 +3,10 @@ module Popo
3
3
  include Constants
4
4
 
5
5
  def self.boot(args)
6
- Popo::Constants.const_set("BASH_CMD", `which bash`.strip)
7
- Popo::Constants.const_set("ENV_CMD", `which env`.strip)
8
- Popo::Constants.const_set("GIT_CMD", `which git`.strip)
6
+ Popo::Constants.const_set("BASH_CMD", `which bash 2>/dev/null`.strip)
7
+ Popo::Constants.const_set("ZSH_CMD", `which zsh 2>/dev/null`.strip)
8
+ Popo::Constants.const_set("ENV_CMD", `which env 2>/dev/null`.strip)
9
+ Popo::Constants.const_set("GIT_CMD", `which git 2>/dev/null`.strip)
9
10
 
10
11
  self.new(args)
11
12
  end
@@ -129,6 +130,10 @@ module Popo
129
130
  puts "Pushing!"
130
131
  when 'bash'
131
132
  bash!
133
+ when 'zsh'
134
+ zsh!
135
+ when 'diff'
136
+ GitUtils.branch_diff(Dir.pwd)
132
137
  else
133
138
  puts "I don't know what to do."
134
139
  end
@@ -152,6 +157,25 @@ module Popo
152
157
  end
153
158
  end
154
159
 
160
+ def zsh!
161
+ if Utils.has_popo_config?(Dir.pwd)
162
+
163
+ zdotdir = File.join(Dir.pwd, POPO_WORK_PATH, 'script')
164
+ target = POPO_CONFIG['target']
165
+ path = POPO_CONFIG['path']
166
+ location = POPO_CONFIG['location']
167
+
168
+ zshcmd = "%s popo_target=%s popo_path=%s \
169
+ popo_location=%s ZDOTDIR=%s\
170
+ %s" \
171
+ % [ENV_CMD, target, path, location, zdotdir, ZSH_CMD]
172
+
173
+ exec(zshcmd)
174
+ else
175
+ raise "#{POPO_YML_FILE} not found or it may be wrong!"
176
+ end
177
+ end
178
+
155
179
  def get_config!
156
180
  if File.exist?(File.join(ENV['HOME'], ".#{DEFAULT_CONFIG_FILE}"))
157
181
  config_file_path = File.join(ENV['HOME'], ".#{DEFAULT_CONFIG_FILE}")
data/lib/popo/sync.rb CHANGED
@@ -12,24 +12,26 @@ module Popo
12
12
  end
13
13
 
14
14
  def gather
15
- @repos.each do |repo|
16
- if repo =~ /\//
17
- r = repo.split('/')
18
- @info[:parent], @info[:name] = r
19
- @info[:key] = [@info[:parent], @info[:name]].join('.')
20
- @info[:path] = File.join(@app_root, @info[:parent], @info[:name])
15
+ trap("INT") { exit -1 }
21
16
 
22
- get_repo_values(@info[:key])
17
+ if !@repos.empty?
18
+ @repos.each do |repo|
19
+ if repo =~ /\//
20
+ r = repo.split('/')
21
+ @info[:parent], @info[:name] = r
22
+ @info[:key] = [@info[:parent], @info[:name]].join('.')
23
+ @info[:path] = File.join(@app_root, @info[:parent], @info[:name])
23
24
 
24
- clone_or_update
25
- else
26
- gather_many(repo)
27
- end
28
- end
25
+ get_repo_values(@info[:key])
29
26
 
30
- if @repos.empty?
31
- if @cwd.eql? @app_root
32
- popo_folders = @db.get("sync.directories").split(',')
27
+ clone_or_update
28
+ else
29
+ gather_many(repo)
30
+ end
31
+ end
32
+ else
33
+ if @cwd == @app_root
34
+ popo_folders = @db.get(POPO_DIRECTORY_KEY).split(',')
33
35
  popo_folders.each { |p| gather_many(p) }
34
36
  else
35
37
  repo = File.basename(@cwd)
@@ -41,7 +43,9 @@ module Popo
41
43
  def gather_many(repo)
42
44
  children = @db.get_children(repo)
43
45
 
44
- raise "No values for parent key \'#{repo}\'." if children.empty?
46
+ if children.empty?
47
+ raise "No values for parent key \'#{repo}\'."
48
+ end
45
49
 
46
50
  children.each do |c|
47
51
  @info[:key] = [repo, c].join('.')
data/lib/popo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Popo
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.6"
3
3
  end
data/script/envyrc CHANGED
@@ -13,4 +13,4 @@ unset PALMADE_GEMS_DIR
13
13
  export PATH="$popo_path/rvm/bin:$popo_path/tools:$PATH"
14
14
  export CABLING_PATH=$popo_path/.popo/cabling.yml
15
15
  export CABLING_TARGET=$popo_target
16
-
16
+ export DBGET_PATH=$popo_path/.manifest
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: popo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-10 00:00:00.000000000Z
12
+ date: 2012-02-07 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel
16
- requirement: &22157620 !ruby/object:Gem::Requirement
16
+ requirement: &6695400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *22157620
24
+ version_requirements: *6695400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &22157000 !ruby/object:Gem::Requirement
27
+ requirement: &6694780 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *22157000
35
+ version_requirements: *6694780
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: cableguy
38
- requirement: &22156360 !ruby/object:Gem::Requirement
38
+ requirement: &6692780 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *22156360
46
+ version_requirements: *6692780
47
47
  description: Ruby and rails repo tool
48
48
  email:
49
49
  - poymode@gmail.com
@@ -75,7 +75,6 @@ files:
75
75
  - lib/templates/envy.yml
76
76
  - popo.gemspec
77
77
  - script/Rakefile
78
- - script/envy
79
78
  - script/envyrc
80
79
  - script/poporc
81
80
  - targets/beta.rb
data/script/envy DELETED
@@ -1,24 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'yaml'
3
-
4
- ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..'))
5
- BASH_PATH = `which bash`.strip
6
- ENV_PATH = `which env`.strip
7
-
8
- env_config_file = File.join(ROOT_PATH, 'config/envy.yml')
9
-
10
- if File.exists? env_config_file
11
- env_conf = YAML.load_file(env_config_file)
12
- popo_path = env_conf['popo_path']
13
- popo_target = env_conf['popo_target']
14
- envyrc = "#{ROOT_PATH}/#{env_conf['envyrc_path']}"
15
- else
16
- puts "envyrc file not found. Byebye!"
17
- exit
18
- end
19
-
20
- cmd = ARGV.join(' ')
21
-
22
- finale = "#{ENV_PATH} popo_path=#{popo_path} popo_target=#{popo_target} #{BASH_PATH} -c 'source #{envyrc}; cd #{popo_path}; #{cmd}'"
23
- system(finale)
24
- exit $?.exitstatus