onboard 0.1.2 → 0.2.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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGI5YjdkODkxYmYyMTFjY2Q3ZjM0YjJiODE0OTIyN2IwN2M2YzYyMQ==
4
+ ZDFmNjkwZDVlMGFmMmI1NjYzY2I5OGZmMTgwNzRiYjkwMjBlNGI3YQ==
5
5
  data.tar.gz: !binary |-
6
- YmU4MzRiNjQ5ZjlhYWM3Y2Y0MzM4NDBmMmE3NzcyMmE2MmJkMmE3OA==
6
+ NWMyMTdkYTYwNTdmOWM0NDkyZTc3ZGQyMTEwMjJiYzM3MTcyNDE2Ng==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTRjYjNhYTcwYWYxNDk3NTYwZjMxZjJjYTg0ZTZhNGQ5ZWEwNjUyNWRjNzU2
10
- NzgyNjlhMGExNmJlYWY0N2YxM2U5NmZjMjlmMjAzZjhhYzE3ODQ4NDU1MjI4
11
- YzczYTRiMmRhMDdiZjExM2ZmODIyMDIxYzQzMDRmNTc3MzNiM2Q=
9
+ NWRkOTUyMzMxOTJjMGY2MDJmZDQxZDEyMDkxYjJkM2RhNmE0N2ZmM2I3YjE4
10
+ YTBlMGM1ODg5ZGRlM2UxZThkODkxNWM0ZWI2MjAxZTUxNzY0MTRjYWJiMjFi
11
+ NjYyZmNhYmI4OTQ2NzM3MWRjNzA1NTg4YTFiYWI1MmRiNzhmNjQ=
12
12
  data.tar.gz: !binary |-
13
- N2Q5YjNhNjMxMTU2YzQzNWUyOWNjZWZmMzdhOTU1Y2ZkZjIwNDc2MDE2YzFi
14
- ZTY4Y2FmNjA2NzAwNGViYTQzNWU0ZDU4YWJmMjJkMWE1NzAxNTFkMGU0MWI3
15
- MDBhYjY4MDBmMTAxYzc4ZWNiNThkMzIyYjNjODEzMDBlYzNmOGY=
13
+ MzQ3NzYwOWNiODMxNzJhNWViZDljODcyOTQyNzk3NWIzOWIzYWIwMzc3ODYw
14
+ NjNhZTkxNmFkNTgxMTU3MjQ1OGU3YTcyYmIwNTg2OTc4YjBhYTA2NDg4YWQ2
15
+ ZGJhMjcxODhhM2QyY2MyZTc0YjdjMmE3YjExYTYyZTcwZGEzOGM=
data/README.md CHANGED
@@ -21,32 +21,35 @@ Or install it yourself as:
21
21
  __COMMANDS:__
22
22
  ```
23
23
  Commands:
24
- onboard help [COMMAND] # Describe available commands or one s...
25
- onboard modules DOCROOT -c, --core=N # add default modules to DOCROOT
24
+ onboard help [COMMAND] # Describe available commands or one specific command
25
+ onboard projects CODEBASE -c, --core=N -p, --path=PATH # add projects to CODEBASE
26
26
  ```
27
27
 
28
28
  __MODULES:__
29
29
  ```
30
30
  Usage:
31
- onboard modules DOCROOT -c, --core=N
31
+ onboard projects CODEBASE -c, --core=N -p, --path=PATH
32
32
 
33
33
  Options:
34
- -a, [--addendum=one two three] # Add projects to the default list
35
- -c, --core=N # Specify Drupal core version
36
- -d, [--destination=DESTINATION] # Specify contrib destination relative to docroot
37
- -f, [--force=FORCE] # Force add modules
38
- -n, [--no=NO] # Assume 'no' for all prompts
39
- -p, [--projects=one two three] # Pass a custom list of projects
40
- -s, [--subdir=SUBDIR] # Specify contrib subdir relative to 'modules'
41
- -y, [--yes=YES] # Assume 'yes' for all prompts
34
+ -b, [--branch=BRANCH] # Specify repository branch to update
35
+ -c, --core=N # Specify Drupal core version
36
+ -p, --path=PATH # Specify project path relative to CODEBASE
37
+ -f, [--force=FORCE] # Force add modules (even if already present)
38
+ -n, [--no=NO] # Assume 'no' for all prompts
39
+ -m, [--modules=one two three] # Pass a list of modules
40
+ -t, [--themes=one two three] # Pass a list of themes
41
+ [--vc], [--no-vc] # Enable/Disable version control handling
42
+ # Default: true
43
+ -y, [--yes=YES] # Assume 'yes' for all prompts
42
44
 
43
45
  Description:
44
- onboard modules performs multiple steps when installing default contrib
45
- modules (acquia_connector, fast_404, memcache):
46
+ `onboard projects` performs multiple tasks when installing contrib projects:
46
47
 
47
- 1. Checks for each module in the docroot
48
- 2. Downloads the latest version of each module
49
- 3. Adds and commits each module
48
+ * Checks for each project in the CODEBASE
49
+
50
+ * Downloads the latest version of each project
51
+
52
+ * Adds and commits each project
50
53
  ```
51
54
 
52
55
  ## Contributing
data/lib/onboard/cli.rb CHANGED
@@ -1,95 +1,82 @@
1
1
  # encoding: utf-8
2
- require 'thor'
2
+
3
3
  require 'open-uri/cached'
4
- require_relative 'codebase'
4
+ require 'thor'
5
+
6
+ require_relative 'confirm'
7
+ require_relative 'find'
8
+ require_relative 'project'
9
+ require_relative 'repo'
5
10
 
6
11
  module Onboard
7
12
  class CLI < Thor
8
13
  # TODO: switch from DOCROOT to CODEBASE to enable more comprehensive searching
9
- desc "modules DOCROOT", "add default modules to DOCROOT"
14
+ desc "projects CODEBASE", "add projects to CODEBASE"
10
15
  long_desc <<-LONGDESC
11
- `onboard modules` performs multiple tasks when installing contrib
12
- modules:
16
+ `onboard projects` performs multiple tasks when installing contrib
17
+ projects:
13
18
 
14
- * Checks for each module in the docroot
19
+ * Checks for each project in the CODEBASE
15
20
 
16
- * Downloads the latest version of each module
21
+ * Downloads the latest version of each project
17
22
 
18
- * Adds and commits each module
23
+ * Adds and commits each project
19
24
 
20
- Default contrib modules: acquia_connector, fast_404, memcache
21
25
  LONGDESC
22
- option :addendum, :aliases => "-a", :type => :array, :desc => "Add projects to the default list"
23
- # TODO: Analyze codebase for core version?
26
+ # TODO: Analyze codebase for project version
24
27
  # ala - find ./CODEBASE -type f -name '*.info' | xargs -I {} grep -rn '^version = \"' {}
28
+ option :branch, :aliases => "-b", :desc => "Specify repository branch to update"
25
29
  option :core, :required => true, :aliases => "-c", :type => :numeric, :desc => "Specify Drupal core version"
26
- option :destination, :aliases => "-d", :desc => "Specify contrib destination relative to docroot"
30
+ option :path, :required => true, :aliases => "-p", :desc => "Specify project path relative to CODEBASE"
27
31
  option :force, :aliases => "-f", :desc => "Force add modules (even if already present)"
28
32
  option :no, :aliases => "-n", :desc => "Assume 'no' for all prompts"
29
- option :projects, :aliases => "-p", :type => :array, :desc => "Pass a custom list of projects"
30
- # option :remove, :aliases => "-r", :desc => "Remove all copies of existing modules"
31
- option :subdir, :aliases => "-s", :desc => "Specify contrib subdir relative to 'modules'"
33
+ option :modules, :aliases => "-m", :type => :array, :desc => "Pass a list of modules"
34
+ # option :delete, :aliases => "-d", :desc => "Delete existing projects"
35
+ # option :source, :aliases => "-s", :desc => "Specify a project source other than drupal.org"
36
+ option :themes, :aliases => "-t", :type => :array, :desc => "Pass a list of themes"
32
37
  option :vc, :type => :boolean, :default => true, :desc => "Enable/Disable version control handling"
33
38
  option :yes, :aliases => "-y", :desc => "Assume 'yes' for all prompts"
34
- def modules(docroot)
39
+ def projects(codebase)
35
40
  core = "#{options[:core]}.x"
36
- modules = []
37
- if options[:projects].nil? == false
38
- options[:projects].each { |x| modules.push x }
39
- else
40
- modules = ["acquia_connector", "fast_404", "memcache"]
41
- end
42
- if options[:addendum].nil? == false
43
- options[:addendum].each { |x| modules.push x }
44
- end
45
- subdir = options[:subdir].nil? == true ? "" : "/#{options[:subdir]}"
46
- destination = options[:destination].nil? ? "sites/all/modules#{subdir}" : "#{options[:destination]}#{subdir}"
47
- require 'find'
48
- found = []
49
- Find.find(docroot) do |e|
50
- if File.directory?(e)
51
- if modules.include?(File.basename(e))
52
- found.push e
53
- end
54
- end
41
+ projects = []
42
+ if options[:modules].nil? == false
43
+ options[:modules].each { |x| projects.push x }
44
+ elsif options[:themes].nil? == false
45
+ options[:themes].each { |x| projects.push x }
55
46
  end
47
+ path = "#{options[:path]}"
48
+ found = Finder.new(projects, codebase).locate
56
49
  if found.any?
57
50
  say("Projects exist at the following locations:", :yellow)
58
- found.each do |project|
59
- puts " " + project
60
- end
51
+ found.each { |x| puts " " + x }
61
52
  puts ""
62
53
  end
63
54
  if options[:force] != 'force'
64
55
  found.each do |x|
65
- modules.delete(File.basename(x))
56
+ projects.delete(File.basename(x))
66
57
  end
67
58
  end
68
- if modules.empty? == false
59
+ if projects.empty? == false
69
60
  say("Ready to add the following projects:", :green)
70
- modules.each do |x|
71
- puts " " + "#{docroot}/#{destination}/#{x}"
61
+ projects.each do |x|
62
+ puts " " + "#{codebase}/#{path}/#{x}"
72
63
  end
73
64
  puts ""
74
65
  if options[:no].nil? && options[:yes].nil?
75
- answer = ""
76
- while answer !~ /^[Y|N]$/i do
77
- answer = ask("Proceed? [Y|N]: ")
78
- puts ""
79
- end
80
- if answer =~ /^[N]$/i
81
- say("Script was exited.")
82
- exit
83
- end
66
+ Confirm.new("Proceed?").yes?
84
67
  elsif options[:no] == 'no'
85
68
  say("Script was exited.")
86
69
  exit
87
70
  end
88
- modules.each do |x|
89
- Codebase.new("#{docroot}/#{destination}/#{x}").rm
71
+ projects.each do |x|
72
+ prm = {}
73
+ prm['path'] = "#{codebase}/#{path}/#{x}"
74
+ Project.new(prm).rm
90
75
  # TODO: replace 'open().read' with custom caching solution
91
- require_relative 'contrib'
92
- dl = Contrib.new(x, core).dl
76
+ pdl = {}
77
+ pdl['project'] = x
78
+ pdl['core'] = core
79
+ dl = Project.new(pdl).dl
93
80
  feed_md5, archive = dl
94
81
  # TODO: replace 'open().read' with custom caching solution
95
82
  open(archive).read
@@ -98,26 +85,36 @@ module Onboard
98
85
  md5 = Digest::MD5.file(targz).hexdigest
99
86
  # TODO: retry download after failed download verification
100
87
  if md5 == feed_md5
101
- Codebase.new(targz, "#{docroot}/#{destination}").extract
88
+ pex = {}
89
+ pex['dest'] = "#{codebase}/#{path}"
90
+ pex['path'] = targz
91
+ Project.new(pex).extract
102
92
  else
103
93
  say("Verification failed for #{x} archive!", :red)
104
94
  exit
105
95
  end
106
96
  end
107
97
  if options[:vc] == true
108
- require_relative 'repo'
109
- require_relative 'screen'
110
- modules.each do |x|
111
- width = Screen.new().width
112
- msg = "Pushing #{x} to the remote repo..."
113
- spaces = " " * (width - msg.length - 8)
114
- say(msg + spaces)
115
- Repo.new(docroot, "docroot/#{destination}/#{x}").update
116
- # TODO: error handling and conditional messaging for failures
98
+ require_relative 'msg'
99
+ branch = options[:branch].nil? ? '' : options[:branch]
100
+ repo = {}
101
+ repo['branch'] = branch
102
+ repo['codebase'] = codebase
103
+ repo_info = Repo.new(repo).info
104
+ projects.each do |x|
105
+ acmsg = "Committing #{x} on #{repo_info['current_branch']} branch..."
106
+ say(Msg.new(acmsg).format)
107
+ repo['path'] = "#{path}/#{x}"
108
+ Repo.new(repo).update
117
109
  say(" [done]", :green)
110
+ # TODO: error handling and conditional messaging for failures
118
111
  end
112
+ pmsg = "Pushing all changes to #{repo_info['remotes']}..."
113
+ say(Msg.new(pmsg).format)
114
+ Repo.new(repo).push
115
+ say(" [done]", :green)
119
116
  else
120
- modules.each do |x|
117
+ projects.each do |x|
121
118
  say("#{x} added to codebase but changes are not yet tracked in version control.", :yellow)
122
119
  end
123
120
  end
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'thor'
4
+
5
+ module Onboard
6
+ class Confirm < Thor
7
+ attr_reader :message
8
+
9
+ no_tasks do
10
+ def initialize(message)
11
+ @message = message
12
+ end
13
+
14
+ def yes?
15
+ answer = ""
16
+ while answer !~ /^[Y|N]$/i do
17
+ answer = ask(message + " [Y|N]: ")
18
+ puts ""
19
+ end
20
+ if answer =~ /^[N]$/i
21
+ say("Script was exited.")
22
+ exit
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'find'
4
+
5
+ module Onboard
6
+ class Finder
7
+ attr_reader :needle, :haystack
8
+
9
+ def initialize(needle, haystack)
10
+ @needle = needle
11
+ @haystack = haystack
12
+ end
13
+
14
+ def locate
15
+ found = []
16
+ Find.find(haystack) do |e|
17
+ if File.directory?(e)
18
+ if needle.include?(File.basename(e))
19
+ Find.find(e) do |f|
20
+ if File.extname(f) == '.info'
21
+ found.push e
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ return found.uniq
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'thor'
4
+
5
+ require_relative 'screen'
6
+
7
+ module Onboard
8
+ class Msg < Thor
9
+ attr_reader :msg
10
+
11
+ no_tasks do
12
+ def initialize(msg = '')
13
+ @msg = msg
14
+ end
15
+
16
+ def format
17
+ width = Screen.new().width
18
+ spaces = " " * (width - msg.length - 8)
19
+ return msg + spaces
20
+ end
21
+ end
22
+ end
23
+ end
24
+
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'fileutils'
3
3
  require 'find'
4
+ require 'nokogiri'
4
5
  require 'rubygems/package'
5
6
  require 'zlib'
6
7
 
@@ -8,12 +9,29 @@ module Onboard
8
9
 
9
10
  TAR_LONGLINK = '././@LongLink'
10
11
 
11
- class Codebase
12
- attr_reader :path, :dest
12
+ class Project
13
+ attr_reader :feed, :path, :dest
13
14
 
14
- def initialize(path, dest = nil)
15
- @path = path
16
- @dest = dest
15
+ def initialize(args = {})
16
+ @feed = "http://updates.drupal.org/release-history/#{args['project']}/#{args['core']}"
17
+ @path = args['path']
18
+ @dest = args['dest']
19
+ end
20
+
21
+ def dl
22
+ doc = Nokogiri::XML(open(@feed).read)
23
+ releases = {}
24
+ doc.xpath('//releases//release').each do |item|
25
+ if !item.at_xpath('version_extra')
26
+ releases[item.at_xpath('mdhash').content] = item.at_xpath('download_link').content
27
+ end
28
+ end
29
+ if releases.nil?
30
+ doc.xpath('//releases//release').each do |item|
31
+ releases[item.at_xpath('mdhash').content] = item.at_xpath('download_link').content
32
+ end
33
+ end
34
+ return releases.first
17
35
  end
18
36
 
19
37
  def rm
@@ -47,3 +65,4 @@ module Onboard
47
65
  end
48
66
  end
49
67
  end
68
+
data/lib/onboard/repo.rb CHANGED
@@ -6,21 +6,32 @@ require 'pathname'
6
6
 
7
7
  module Onboard
8
8
  class Repo
9
- attr_reader :docroot, :path
9
+ attr_reader :g, :path, :branch
10
10
 
11
- def initialize(docroot, path)
12
- @docroot = docroot
13
- @path = path
11
+ def initialize(repo)
12
+ @codebase = repo['codebase']
13
+ @g = self.prepare(repo)
14
+ @path = repo['path']
15
+ @branch = repo['branch']
16
+ end
17
+
18
+ def info
19
+ repo = {}
20
+ repo['current_branch'] = g.current_branch
21
+ repo['remotes'] = g.remotes
22
+ return repo
23
+ end
24
+
25
+ def prepare(args)
26
+ repo = Git.open((Pathname.new(args['codebase'])).to_s)
27
+ selection = args['branch'].empty? ? repo.current_branch : args['branch']
28
+ repo.branch(selection).checkout
29
+ return repo
14
30
  end
15
31
 
16
32
  def update
17
- prj_root = Pathname.new(docroot)
18
- workdir = prj_root.parent.to_s
19
33
  project = File.basename(path)
20
34
 
21
- g = Git.open(workdir)
22
- g.branch('master').checkout
23
-
24
35
  changes = []
25
36
  g.status.changed.keys.each { |x| changes.push x }
26
37
  g.status.deleted.keys.each { |x| changes.push x }
@@ -28,11 +39,14 @@ module Onboard
28
39
 
29
40
  if changes.nil? == false
30
41
  g.add(path, :all=>true)
31
- g.commit("Adds #{project}")
32
- g.push
42
+ g.commit("Add #{project}")
33
43
  else
34
44
  puts "No changes to commit for #{project}"
35
45
  end
36
46
  end
47
+
48
+ def push
49
+ g.push
50
+ end
37
51
  end
38
- end
52
+ end
@@ -1,3 +1,3 @@
1
1
  module Onboard
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathaniel Hoag
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-19 00:00:00.000000000 Z
11
+ date: 2014-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -122,8 +122,10 @@ files:
122
122
  - bin/onboard
123
123
  - lib/onboard.rb
124
124
  - lib/onboard/cli.rb
125
- - lib/onboard/codebase.rb
126
- - lib/onboard/contrib.rb
125
+ - lib/onboard/confirm.rb
126
+ - lib/onboard/find.rb
127
+ - lib/onboard/msg.rb
128
+ - lib/onboard/project.rb
127
129
  - lib/onboard/repo.rb
128
130
  - lib/onboard/screen.rb
129
131
  - lib/onboard/version.rb
@@ -1,28 +0,0 @@
1
- # encoding: utf-8
2
- require 'nokogiri'
3
-
4
- module Onboard
5
- class Contrib
6
- attr_reader :project, :core
7
-
8
- def initialize(project, core)
9
- @feed = "http://updates.drupal.org/release-history/#{project}/#{core}"
10
- end
11
-
12
- def dl
13
- doc = Nokogiri::XML(open(@feed).read)
14
- releases = {}
15
- doc.xpath('//releases//release').each do |item|
16
- if !item.at_xpath('version_extra')
17
- releases[item.at_xpath('mdhash').content] = item.at_xpath('download_link').content
18
- end
19
- end
20
- if releases.nil?
21
- doc.xpath('//releases//release').each do |item|
22
- releases[item.at_xpath('mdhash').content] = item.at_xpath('download_link').content
23
- end
24
- end
25
- return releases.first
26
- end
27
- end
28
- end