projmgr 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/NEWS.md CHANGED
@@ -1,3 +1,16 @@
1
+ 0.0.3 (January 09, 2011)
2
+ ===
3
+ - Added rspec tests for the Scm class
4
+ - Remove unnessesary requires from the library and moved them to the binary
5
+ - Add support for checkout/clone for SVN and GIT
6
+ - Add checks to see if the paths exist for each call that uses @path
7
+ - Optimized most of the code
8
+
9
+ 0.0.2 (January 04, 2011)
10
+ ===
11
+ - Minor bug fixes/typos
12
+
1
13
  0.0.1 (December 27, 2010)
2
14
  ===
3
- - Initial development
15
+ - Initial development
16
+
data/README.md CHANGED
@@ -9,8 +9,6 @@ Requirements
9
9
  * ruby
10
10
  * rubygems
11
11
  * choice
12
- * yaml
13
-
14
12
 
15
13
  Installation
16
14
  ---
@@ -32,16 +30,19 @@ This will create a empty skeleton config file, ~/.projmgr, edit this file. The f
32
30
  name: ruby-virustotal
33
31
  path: ~/Projects/public/ruby-virustotal
34
32
  type: git
33
+ url: git@github.com:hammackj/ruby-virustotal.git
35
34
 
36
35
  nessusdb:
37
36
  name: nessusdb
38
37
  path: ~/Projects/public/nessusdb
39
38
  type: git
39
+ url: git@github.com:hammackj/nessusdb.git
40
40
 
41
41
  projectname:
42
42
  name:
43
43
  path:
44
44
  type:
45
+ url:
45
46
 
46
47
  To configure ProjMgr just change projectname/name/path/type to fit your projects.
47
48
 
@@ -49,6 +50,7 @@ To configure ProjMgr just change projectname/name/path/type to fit your projects
49
50
  name - any string displayed during update/checks
50
51
  path - the path to the repo to check/update
51
52
  type - type of the repo either 'svn' or 'git'
53
+ url - the original url of the repo
52
54
 
53
55
  Once the config file is edited everything is ready to go.
54
56
 
data/Rakefile CHANGED
@@ -1,4 +1,8 @@
1
1
  $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+
3
+ require 'rake'
4
+ require 'spec/rake/spectask'
5
+
2
6
  require "projmgr"
3
7
 
4
8
  task :build do
@@ -11,4 +15,12 @@ end
11
15
 
12
16
  task :clean do
13
17
  system "rm *.gem"
14
- end
18
+ system "rm -rf coverage"
19
+ end
20
+
21
+ desc "Run all examples with RCov"
22
+ Spec::Rake::SpecTask.new('examples_with_rcov') do |t|
23
+ t.spec_files = FileList['spec/**/*.rb']
24
+ t.rcov = true
25
+ t.rcov_opts = ['--exclude', 'spec,rcov']
26
+ end
data/TODO.md CHANGED
@@ -1,7 +1,15 @@
1
1
  TODO
2
2
  ===
3
3
 
4
- 0.0.2
4
+ 0.0.4
5
5
  ---
6
- - Add support for other SCM's besides git and svn
7
- - Create rSpec tests for everything
6
+ - Add a detect option, to find projects in a directory not managed
7
+ - Add support for other SCM's
8
+ - CVS
9
+ - Mercurial
10
+ - Add more rspec tests
11
+ - Git Class
12
+ - Svn Class
13
+ - Application class
14
+ - Cvs Class
15
+
data/bin/projmgr CHANGED
@@ -7,6 +7,7 @@
7
7
  #
8
8
  # hammackj - 12-27-2010 - Version 0.0.1
9
9
  # hammackj - 01-05-2011 - Version 0.0.2
10
+ # hammackj - 01-09-2011 - Version 0.0.3
10
11
  #
11
12
 
12
13
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '/../lib'))
@@ -15,6 +16,9 @@ $stdout.sync = true
15
16
  $stderr.sync = true
16
17
 
17
18
  require 'rubygems'
19
+ require 'choice'
20
+ require 'yaml'
21
+
18
22
  require 'projmgr'
19
23
 
20
24
  module ProjMgr
@@ -27,7 +31,7 @@ module ProjMgr
27
31
  # Creates a ProjMgr instance
28
32
  #
29
33
  def initialize
30
- @root = `pwd`
34
+ @root = `pwd`.chomp
31
35
  end
32
36
 
33
37
  # Main class for the ProjMgr command line tool
@@ -37,7 +41,7 @@ module ProjMgr
37
41
  banner "#{APP_NAME} - v#{VERSION}"
38
42
  header 'Jacob Hammack'
39
43
  header 'http://hammackj.com'
40
- header 'Usage: #{APP_NAME} [OPTIONS]'
44
+ header "Usage: #{APP_NAME} [OPTIONS]"
41
45
  header ''
42
46
 
43
47
  option :check_local_changes do
@@ -52,6 +56,11 @@ module ProjMgr
52
56
  desc 'Updates each configured scm repository'
53
57
  end
54
58
 
59
+ option :checkout do
60
+ long '--checkout-repos'
61
+ desc "Checks out each repo if nothing exists at the 'path' variable"
62
+ end
63
+
55
64
  option :create_config do
56
65
  long '--create-config'
57
66
  desc 'Creates a skeleton config file to use'
@@ -59,7 +68,7 @@ module ProjMgr
59
68
  if File.exists?(File.expand_path(CONFIG_FILE)) == false
60
69
  File.open(File.expand_path(CONFIG_FILE), 'w+') do |f|
61
70
  3.times do
62
- f.write("projectname: \n\tname: \n\tpath: \n\ttype: \n\n")
71
+ f.write("projectname: \n\tname: \n\tpath: \n\ttype: \n\turl: \n\n")
63
72
  end
64
73
  end
65
74
 
@@ -110,20 +119,30 @@ module ProjMgr
110
119
  @repos.each_key do |key|
111
120
  t = Thread.new do
112
121
  if @repos[key]['type'] == "svn"
113
- repo = Svn.new @repos[key]['name'], @repos[key]['path'], @repos[key]['root']
122
+ repo = Svn.new @repos[key]['name'], @repos[key]['path'], @root, @repos[key]['url']
114
123
  elsif @repos[key]['type'] == "git"
115
- repo = Git.new @repos[key]['name'], @repos[key]['path'], @repos[key]['root']
124
+ repo = Git.new @repos[key]['name'], @repos[key]['path'], @root, @repos[key]['url']
125
+ #elsif @repos[key]['type'] == "cvs"
126
+ # repo = Cvs.new @repos[key]['name'], @repos[key]['path'], @repos[key]['root'], @repos[key]['url']
116
127
  end
117
-
128
+
118
129
  if repo == nil
119
- puts "[!] #{key} is a malformed entry please correct it."
130
+ print "[!] #{key} is a malformed entry please correct it.\n"
120
131
  next
121
132
  end
122
133
 
123
134
  if Choice.choices[:check_local_changes] != nil
124
- puts "[!] #{@repos[key]['name']} has local changes" if repo.has_local_changes?
135
+ status = repo.has_local_changes?
136
+
137
+ if status[0] == true
138
+ print "[!] #{@repos[key]['name']} has local changes\n"
139
+ else
140
+ print "[!] #{@repos[key]['name']} #{status[1]}\n"
141
+ end
125
142
  elsif Choice.choices[:update] != nil
126
- puts "[*] Updating #{@repos[key]['name']}...\n #{repo.update}"
143
+ print "[*] Updating #{@repos[key]['name']}...\n #{repo.update}\n"
144
+ elsif Choice.choices[:checkout] != nil
145
+ print "[*] Checking out #{@repos[key]['name']}...#{repo.checkout}\n"
127
146
  end
128
147
  end
129
148
  @threads << t
@@ -133,7 +152,8 @@ module ProjMgr
133
152
  t.join
134
153
  end
135
154
  rescue Exception => e
136
- puts "[!] Caught Exception: #{e.inspect}"
155
+ puts "[!] Caught Exception, if you feel this is a error please report it at http://github.com/hammackj/projmgr/issues\n"
156
+ puts "#{e.inspect}\n #{e.backtrace}"
137
157
  end
138
158
  end
139
159
  end
data/lib/projmgr.rb CHANGED
@@ -1,13 +1,12 @@
1
+ # encoding: utf-8
1
2
 
2
3
  module ProjMgr
3
4
  APP_NAME = "projmgr"
4
- VERSION = "0.0.2"
5
+ VERSION = "0.0.3"
5
6
  CONFIG_FILE = "~/.projmgr"
6
7
  end
7
8
 
8
- require 'choice'
9
- require 'yaml'
10
-
9
+ require 'projmgr/scm'
11
10
  require 'projmgr/git'
12
11
  require 'projmgr/svn'
13
- require 'projmgr/scm'
12
+ require 'projmgr/cvs'
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'projmgr/scm'
4
+
5
+ module ProjMgr
6
+
7
+ # A wrapper class for interacting with a cvs repository
8
+ #
9
+ # @author Jacob Hammack <jacob.hammack@hammackj.com>
10
+ class Cvs < Scm
11
+
12
+ # Checks out a cvs repo and places it, in the path specified by the @path variable
13
+ #
14
+ # @return [String] The results from the 'cvs co' command
15
+ def checkout
16
+ results = `cd #{@path} && cd .. && cvs co #{@url} && cd #{@root}`
17
+
18
+ return results
19
+ end
20
+
21
+ # Checks for updates in the target repo
22
+ #
23
+ # @return [String] the results of 'git pull' on the target repository
24
+ def update
25
+ results = `cd #{@path} && cvs update -dPA && cd #{@root}`
26
+
27
+ if results =~ /Already up-to-date./
28
+ return "Already up-to-date!\n"
29
+ else
30
+ return results
31
+ end
32
+ end
33
+
34
+ # Checks for local changes in the target repository
35
+ #
36
+ # @return [Boolean] if there is local changes or not
37
+ def has_local_changes?
38
+ results = `cd #{@path} && cvs status && cd #{@root}`
39
+
40
+ #if results !~ /nothing to commit/
41
+ # return true
42
+ #elsif results =~ /Your branch is ahead of/
43
+ # return true
44
+ #elsif results =~ /Untracked files/
45
+ # return true
46
+ #else
47
+ return false
48
+ #end
49
+ end
50
+ end
51
+ end
data/lib/projmgr/git.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'projmgr/scm'
2
4
 
3
5
  module ProjMgr
@@ -6,34 +8,60 @@ module ProjMgr
6
8
  #
7
9
  # @author Jacob Hammack <jacob.hammack@hammackj.com>
8
10
  class Git < Scm
11
+ alias :checkout :clone
9
12
 
10
- # Checks for updates in the target repo
13
+ # Checks out a git repo and places it, in the path specified by the @path variable
14
+ #
15
+ # @return [String] The results from the 'git clone' command
16
+ def checkout
17
+ if path_exists? == true
18
+ return "path exists, cannot checkout onto an existing repo"
19
+ else
20
+ parent = project_parent_directory
21
+
22
+ cmd = IO.popen "cd #{parent} && git clone #{@url} &> /dev/null && cd #{@root}"
23
+ results = cmd.readlines
24
+ cmd.close
25
+
26
+ return "project checked out to #{parent}/#{@project}"
27
+ end
28
+ end
29
+
30
+ # Checks for updates in the target repository
11
31
  #
12
32
  # @return [String] the results of 'git pull' on the target repository
13
33
  def update
14
- results = `cd #{@path} && git pull && cd #{@root}`
15
-
16
- if results =~ /Already up-to-date./
17
- return "Already up-to-date!\n"
18
- else
19
- return results
20
- end
34
+ if path_exists? == false
35
+ return "path does not exists, cannot update repository"
36
+ else
37
+ results = `cd #{@path} && git pull && cd #{@root}`
38
+
39
+ if results =~ /Already up-to-date./
40
+ return "Already up-to-date!\n"
41
+ else
42
+ return results
43
+ end
44
+ end
21
45
  end
22
46
 
23
47
  # Checks for local changes in the target repository
24
48
  #
25
49
  # @return [Boolean] if there is local changes or not
26
50
  def has_local_changes?
27
- results = `cd #{@path} && git status && cd #{@root}`
51
+ if path_exists? == false
52
+ return false, "path does not exists, please check the path or check it out"
53
+ else
54
+ results = `cd #{@path} && git status && cd #{@root}`
28
55
 
29
- if results !~ /nothing to commit/
30
- return true
31
- elsif results =~ /Your branch is ahead of/
32
- return true
33
- elsif results =~ /Untracked files/
34
- return true
35
- else
36
- return false
56
+ if results !~ /nothing to commit/
57
+ return true, "has local changes"
58
+ elsif results =~ /Your branch is ahead of/
59
+ return true, "has local changes"
60
+ elsif results =~ /Untracked files/
61
+ return true, "has local changes"
62
+ else
63
+ return false, "has no local changes"
64
+ end
37
65
  end
38
66
  end
39
67
  end
data/lib/projmgr/scm.rb CHANGED
@@ -1,20 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'pathname'
4
+
1
5
  module ProjMgr
2
6
 
3
7
  # A parent class for interacting with a source code repository
4
8
  #
5
9
  # @author Jacob Hammack <jacob.hammack@hammackj.com>
6
10
  class Scm
11
+ attr_accessor :project, :path, :root, :url
7
12
 
8
13
  # Creates a instance of a SCM repository
9
14
  #
10
15
  # @param project name of the project
11
16
  # @param path path to the project
12
17
  # @param root path back to the root
18
+ # @param url url of the repo for checkout/etc
13
19
  #
14
- def initialize project, path, root
20
+ # @return [Scm] returns a new instance of the Scm class
21
+ def initialize project=nil, path=nil, root=nil, url=nil
15
22
  @project = project
16
23
  @path = path
17
24
  @root = root
18
- end
25
+ @url = url
26
+ end
27
+
28
+ # Checks to see if a path exists
29
+ #
30
+ # @return [Boolean] True or False based on if the @path exists
31
+ def path_exists?
32
+ return File.exists?(File.expand_path(@path))
33
+ end
34
+
35
+ # Retrieves the parent directory of a path
36
+ #
37
+ # @return [String] parent directory of the @path variable
38
+ def project_parent_directory
39
+ pn = Pathname.new @path
40
+ return pn.parent.to_s
41
+ end
42
+
43
+ # Overloaded inspect
44
+ #
45
+ # @return [String] A representation of the class as a string
46
+ def inspect
47
+ return "Project: #{@project}\n" + "Path: #{@path}\n" + "Root: #{@root}\n" + "Url: #{@url}\n"
48
+ end
19
49
  end
20
50
  end
data/lib/projmgr/svn.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'projmgr/scm'
2
4
 
3
5
  module ProjMgr
@@ -7,24 +9,52 @@ module ProjMgr
7
9
  # @author Jacob Hammack <jacob.hammack@hammackj.com>
8
10
  class Svn < Scm
9
11
 
12
+ # Checks out a svn repo and places it, in the path specified by the @path variable
13
+ #
14
+ # @return [String] The results from the 'svn checkout' command
15
+ def checkout
16
+ if path_exists? == true
17
+ return "path exists, cannot checkout onto an existing repo"
18
+ else
19
+ parent = project_parent_directory
20
+
21
+ results = `cd #{parent} && svn checkout #{@url} #{@project} && cd #{@root}`
22
+
23
+ if results =~ /Could not resolve hostname/
24
+ return "unable to resolve hostname"
25
+ else
26
+ return "project checked out to #{parent}/#{@project}"
27
+ end
28
+ end
29
+ end
30
+
10
31
  # Checks for updates in the target repo
11
32
  #
12
33
  # @return [String] the results of 'git pull' on the target repository
13
34
  def update
14
- results = `cd #{@path} && svn stat && svn update && cd #{@root}`
15
- return results
35
+ if path_exists? == true
36
+ results = `cd #{@path} && svn stat && svn update && cd #{@root}`
37
+ else
38
+ return "path does not exists, cannot update repository"
39
+ end
40
+
41
+ return results
16
42
  end
17
43
 
18
44
  # Checks for local changes in the target repository
19
45
  #
20
46
  # @return [Boolean] if there is local changes or not
21
47
  def has_local_changes?
22
- results = `cd #{@path} && svn stat && cd #{@root}`
23
-
24
- if results.length > 0
25
- return true
26
- else
27
- return false
48
+ if path_exists? == false
49
+ return false, "Path does not exists, please check the path or check it out"
50
+ else
51
+ results = `cd #{@path} && svn stat && cd #{@root}`
52
+
53
+ if results.length > 0
54
+ return true, "has local changes"
55
+ else
56
+ return false, "has no local changes"
57
+ end
28
58
  end
29
59
  end
30
60
  end
data/projmgr.gemspec CHANGED
@@ -6,25 +6,26 @@ $:.unshift(File.join(File.dirname(base), 'lib'))
6
6
  require 'projmgr'
7
7
 
8
8
  Gem::Specification.new do |s|
9
- s.name = 'projmgr'
9
+ s.name = ProjMgr::APP_NAME
10
10
  s.version = ProjMgr::VERSION
11
11
  s.homepage = "http://github.com/hammackj/projmgr/"
12
- s.summary = "ProjMgr"
13
- s.description = "ProjMgr is a source code managment tool for automating project managment"
12
+ s.summary = ProjMgr::APP_NAME
13
+ s.description = "#{ProjMgr::APP_NAME} is a source code managment tool for automating project managment"
14
14
  s.license = "BSD"
15
15
 
16
16
  s.author = "Jacob Hammack"
17
17
  s.email = "jacob.hammack@hammackj.com"
18
18
 
19
19
  s.files = Dir['[A-Z]*'] + Dir['lib/**/*'] + ['projmgr.gemspec']
20
- s.default_executable = 'projmgr'
21
- s.executables = ['projmgr']
20
+ s.default_executable = ProjMgr::APP_NAME
21
+ s.executables = [ProjMgr::APP_NAME]
22
22
  s.require_paths = ["lib"]
23
23
 
24
24
  s.required_rubygems_version = ">= 1.3.6"
25
- s.rubyforge_project = "projmgr"
25
+ s.rubyforge_project = ProjMgr::APP_NAME
26
26
 
27
27
  s.add_development_dependency "rspec"
28
+ s.add_development_dependency "rcov"
28
29
 
29
30
  s.has_rdoc = 'yard'
30
31
  s.extra_rdoc_files = ["README.md", "LICENSE", "NEWS.md", "TODO.md"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: projmgr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jacob Hammack
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-04 00:00:00 -06:00
18
+ date: 2011-01-09 00:00:00 -06:00
19
19
  default_executable: projmgr
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -33,9 +33,23 @@ dependencies:
33
33
  type: :development
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- name: choice
36
+ name: rcov
37
37
  prerelease: false
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: choice
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
39
53
  none: false
40
54
  requirements:
41
55
  - - ">="
@@ -47,8 +61,8 @@ dependencies:
47
61
  - 4
48
62
  version: 0.1.4
49
63
  type: :runtime
50
- version_requirements: *id002
51
- description: ProjMgr is a source code managment tool for automating project managment
64
+ version_requirements: *id003
65
+ description: projmgr is a source code managment tool for automating project managment
52
66
  email: jacob.hammack@hammackj.com
53
67
  executables:
54
68
  - projmgr
@@ -65,6 +79,7 @@ files:
65
79
  - Rakefile
66
80
  - README.md
67
81
  - TODO.md
82
+ - lib/projmgr/cvs.rb
68
83
  - lib/projmgr/git.rb
69
84
  - lib/projmgr/scm.rb
70
85
  - lib/projmgr/svn.rb
@@ -106,6 +121,6 @@ rubyforge_project: projmgr
106
121
  rubygems_version: 1.4.1
107
122
  signing_key:
108
123
  specification_version: 3
109
- summary: ProjMgr
124
+ summary: projmgr
110
125
  test_files: []
111
126