yank 1.0.1
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.
- checksums.yaml +7 -0
- data/bin/yank +53 -0
- data/lib/logging.rb +25 -0
- data/lib/vcs/git.rb +36 -0
- data/lib/yank.kwalify +40 -0
- data/lib/yank.rb +77 -0
- data/lib/yank_exception.rb +12 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4707b4b285e8f4572037682fcb3229695b8e18b3
|
4
|
+
data.tar.gz: 6caf86b471ae378c6d5afe1d325a892f2f4f404c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 26bd47ec04a27dd5a6c8e68dc2fa1849365000108bcb8fa1385c7d7c54b916dadfd263e5db02724238b4446413e0e2bd155ce80fc9a809e92d10b77b007efbd2
|
7
|
+
data.tar.gz: 89126f9d8d831e76bbeac0512da259f27f0e59ca122b7141cbf30f7d0d066df0743d1d33caf348b0130acb526d7f99d85c6ac95afd5ab3d2a180015b636164d3
|
data/bin/yank
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
require 'optparse'
|
5
|
+
require 'fileutils'
|
6
|
+
require_relative '../lib/yank'
|
7
|
+
require_relative '../lib/logging'
|
8
|
+
|
9
|
+
include Yank::Logging
|
10
|
+
|
11
|
+
yank_file = '.yank'
|
12
|
+
yank_target = './target'
|
13
|
+
$yank_debug = nil
|
14
|
+
|
15
|
+
OptionParser.new do |opts|
|
16
|
+
opts.banner = "Usage: #{__FILE__} [options]\n\nOptions:\n"
|
17
|
+
|
18
|
+
opts.on('-h', '--help', 'Prints usage.'){
|
19
|
+
puts opts
|
20
|
+
exit 0
|
21
|
+
}
|
22
|
+
|
23
|
+
opts.on('-f', '--file FILE', "Yank file to use, defaults to '.yank'"){|v| yank_file = v}
|
24
|
+
opts.on('-t', '--target TARGET', 'Directory to install yanks to'){|v| yank_target = v}
|
25
|
+
opts.on('-d', '--debug', 'Turn on debug logging'){|v| $yank_debug = Logger::DEBUG}
|
26
|
+
end.parse!
|
27
|
+
|
28
|
+
begin
|
29
|
+
# Load the yank file
|
30
|
+
unless File.exists?(yank_file)
|
31
|
+
raise Yank::YankException.new("missing '#{yank_file}' file.")
|
32
|
+
end
|
33
|
+
|
34
|
+
files_to_remove = Dir[File.join(yank_target, '*')]
|
35
|
+
logger.debug("removing previous yanks: #{files_to_remove}")
|
36
|
+
FileUtils.rm_rf(files_to_remove)
|
37
|
+
|
38
|
+
# For now just default to using the .yank file for parameters
|
39
|
+
yanks = Yank.parse_yanks(yank_file)
|
40
|
+
|
41
|
+
# Check the yank target directory exists
|
42
|
+
unless File.exists?(yank_target)
|
43
|
+
raise Yank::YankException.new("target directory is missing #{yank_target}.")
|
44
|
+
end
|
45
|
+
|
46
|
+
Yank::Yank.new.install(yanks, yank_target)
|
47
|
+
rescue Yank::YankException => e
|
48
|
+
puts "ERROR: #{e.message}"
|
49
|
+
exit e.exit_code
|
50
|
+
end
|
51
|
+
|
52
|
+
puts "Yank successful."
|
53
|
+
exit 0
|
data/lib/logging.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Yank
|
4
|
+
module Logging
|
5
|
+
def logger
|
6
|
+
@logger ||= Logging.logger_for(self.class.name)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Use a hash class-ivar to cache a unique Logger per class:
|
10
|
+
@loggers = {}
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def logger_for(classname)
|
14
|
+
@loggers[classname] ||= configure_logger_for(classname)
|
15
|
+
end
|
16
|
+
|
17
|
+
def configure_logger_for(classname)
|
18
|
+
logger = Logger.new(STDOUT)
|
19
|
+
logger.progname = classname
|
20
|
+
logger.level = $yank_debug || Logger::INFO
|
21
|
+
logger
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/vcs/git.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require_relative '../logging'
|
3
|
+
|
4
|
+
module Yank
|
5
|
+
class Git
|
6
|
+
attr_reader :repo_name
|
7
|
+
|
8
|
+
include ::Yank::Logging
|
9
|
+
|
10
|
+
def initialize(repo_name, repo, version)
|
11
|
+
git = `which git`
|
12
|
+
if git.nil? or git.empty?
|
13
|
+
raise ::Yank::YankException.new("git must be installed and on the PATH.")
|
14
|
+
end
|
15
|
+
|
16
|
+
@repo = repo
|
17
|
+
@repo_name = repo_name || @repo.split(".git")[0].split("/").last
|
18
|
+
@version = version
|
19
|
+
|
20
|
+
logger.debug("git repo: #{@repo}")
|
21
|
+
logger.debug("git repo name: #{@repo_name}")
|
22
|
+
logger.debug("git repo version: #{@version}")
|
23
|
+
end
|
24
|
+
|
25
|
+
def install(dir)
|
26
|
+
logger.debug("Cloning into #{@repo}...")
|
27
|
+
logger.debug(Open3.capture3("git clone --recursive #{@repo} #{dir}/#{@repo_name}"))
|
28
|
+
|
29
|
+
case @version["type"]
|
30
|
+
when "branch", "tag", "commit"
|
31
|
+
logger.debug("Checking out #{@version["value"]}...")
|
32
|
+
logger.debug(Open3.capture3("cd #{dir}/#{@repo_name} && git checkout #{@version["value"]}"))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/yank.kwalify
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
type: map
|
2
|
+
mapping:
|
3
|
+
"path":
|
4
|
+
type: str
|
5
|
+
required: false
|
6
|
+
"yanks":
|
7
|
+
required: true
|
8
|
+
type: seq
|
9
|
+
sequence:
|
10
|
+
- type: map
|
11
|
+
mapping:
|
12
|
+
"recurse":
|
13
|
+
type: bool
|
14
|
+
required: false
|
15
|
+
default: true
|
16
|
+
"alias":
|
17
|
+
type: str
|
18
|
+
required: false
|
19
|
+
"vcs":
|
20
|
+
type: str
|
21
|
+
enum:
|
22
|
+
- git
|
23
|
+
required: true
|
24
|
+
"repo":
|
25
|
+
type: str
|
26
|
+
required: true
|
27
|
+
"version":
|
28
|
+
required: true
|
29
|
+
type: map
|
30
|
+
mapping:
|
31
|
+
"type":
|
32
|
+
required: true
|
33
|
+
type: str
|
34
|
+
enum:
|
35
|
+
- tag
|
36
|
+
- branch
|
37
|
+
- commit
|
38
|
+
"value":
|
39
|
+
type: str
|
40
|
+
required: true
|
data/lib/yank.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'kwalify'
|
2
|
+
require_relative 'vcs/git'
|
3
|
+
require_relative 'yank_exception'
|
4
|
+
require_relative 'logging'
|
5
|
+
|
6
|
+
module Yank
|
7
|
+
class Yank
|
8
|
+
include ::Yank::Logging
|
9
|
+
|
10
|
+
def install(options, target)
|
11
|
+
for yank in options["yanks"]
|
12
|
+
logger.debug("verifying yank: #{yank}")
|
13
|
+
vcs = get_vcs(yank)
|
14
|
+
|
15
|
+
if ::Yank.yank_exists?(yank["alias"].nil?? vcs.repo_name: yank["alias"], target)
|
16
|
+
logger.debug("yank already installed, skipping")
|
17
|
+
next
|
18
|
+
end
|
19
|
+
|
20
|
+
logger.debug("installing yank with vcs: #{vcs}")
|
21
|
+
vcs.install(target)
|
22
|
+
|
23
|
+
if yank["recurse"]
|
24
|
+
yank_file = ::Yank.get_yanks_file(target, yank["alias"].nil?? vcs.repo_name: yank["alias"])
|
25
|
+
|
26
|
+
return if yank_file.nil?
|
27
|
+
|
28
|
+
logger.debug("recursing into #{yank_file}")
|
29
|
+
return install(::Yank::parse_yanks(yank_file), target)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def get_vcs(yank)
|
36
|
+
vcs = nil
|
37
|
+
|
38
|
+
case yank["vcs"]
|
39
|
+
when 'git'
|
40
|
+
vcs = ::Yank::Git.new(yank["alias"], yank["repo"], yank["version"])
|
41
|
+
end
|
42
|
+
|
43
|
+
if vcs.nil?
|
44
|
+
raise ::Yank::YankException.new("illegal vcs.")
|
45
|
+
end
|
46
|
+
|
47
|
+
return vcs
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.yank_exists?(name, target)
|
52
|
+
return File.exists?(File.join(target, name))
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.get_yanks_file(target, name)
|
56
|
+
yanks_file = File.join(target, name, ".yanks")
|
57
|
+
|
58
|
+
if yanks_file.nil? || !File.exists?(yanks_file)
|
59
|
+
return nil
|
60
|
+
else
|
61
|
+
return yanks_file
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.parse_yanks(yank_file)
|
66
|
+
schema = Kwalify::Yaml.load_file("#{File.join(File.dirname(__FILE__), 'yank.kwalify')}")
|
67
|
+
validator = Kwalify::Validator.new(schema)
|
68
|
+
document = Kwalify::Yaml.load_file(yank_file)
|
69
|
+
errors = validator.validate(document)
|
70
|
+
|
71
|
+
if !errors.nil? && !errors.empty?
|
72
|
+
raise ::Yank::YankException.new("unable to validate '#{yank_file}' file: #{errors.join('\n')}.")
|
73
|
+
end
|
74
|
+
|
75
|
+
return document
|
76
|
+
end
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yank
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Lathrop
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: kwalify
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.7.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.7.2
|
27
|
+
description: Dependency manager
|
28
|
+
email: jelathrop@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- bin/yank
|
34
|
+
- lib/logging.rb
|
35
|
+
- lib/vcs/git.rb
|
36
|
+
- lib/yank.kwalify
|
37
|
+
- lib/yank.rb
|
38
|
+
- lib/yank_exception.rb
|
39
|
+
homepage: https://github.com/jelathro/yank
|
40
|
+
licenses: []
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.0.14.1
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: Generic dependency management for popular version control systems
|
62
|
+
test_files: []
|