beta_tools 0.0.4 → 0.0.5

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/gi ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Run this command in a newly created folder that you want to setup as a git repo
4
+ # It will:
5
+ #
6
+ # initialize a git repo in the newly created folder
7
+ # it will add the folder to the spicevan gitosis
8
+ # it will push the new gitosis to spicevan
9
+ # it will commit this new folder and push it to spicevan too
10
+
11
+ require 'it_tools/git'
12
+
13
+ git = Git::Helper.new
14
+ git.setup_new_project
@@ -1,3 +1,3 @@
1
1
  module BetaTools
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/it_tools/git.rb CHANGED
@@ -1,3 +1,173 @@
1
- class Git
1
+ require 'logger'
2
+ require 'fileutils'
3
+ require 'git'
2
4
 
5
+
6
+ # This module should provide helper functions to make working with GIT
7
+ # easier.
8
+
9
+ module Git
10
+ class Helper
11
+ attr_accessor :ops, :log
12
+ def initialize
13
+ @ops = {}
14
+ @log = Logger.new 'log.txt'
15
+ if level = @ops[:debug_level]
16
+ @log.level = level
17
+ else
18
+ @log.level = Logger::DEBUG
19
+ end
20
+ end
21
+
22
+ # When executed in a new folder it will
23
+ # * initialize a git repository there.
24
+ # * It will add two remote repositories, an internal and an external repo.
25
+ # * It will add the project into gitosis (int/ext)
26
+ # * and it will do an initial commit, into either the internal or exteral repository, depending if you are on the VPN or not.
27
+ def setup_new_project project_dir = '.', int_gitosis_dir = '../gitosis-admin', ext_gitosis_dir = '../spicevan/gitosis-admin', int_repo = 'git@linux1.hk.oracle.com', ext_repo = 'ft_git3@spicevan.com', gitosis_group = 'beta_projects'
28
+ dirname = get_dirname project_dir
29
+
30
+ @log.info "Project dir: " + dirname
31
+ g = Git.init project_dir
32
+ repo_tail = ":" + dirname + ".git"
33
+ g.add_remote 'origin', int_repo + repo_tail
34
+ g.add_remote 'spicevan', ext_repo + repo_tail
35
+ g.add '.'
36
+ g.commit 'initial commit'
37
+
38
+ gitosis = Git::Gitosis.new
39
+ gitosis_conf = 'gitosis.conf'
40
+ remote_name = 'spicevan'
41
+ gitosis_file = File.join ext_gitosis_dir, gitosis_conf
42
+ gitosis.add_project_to_gitosis dirname, gitosis_group, gitosis_file, gitosis_file
43
+
44
+ gtss = Git.open ext_gitosis_dir
45
+ gtss.add 'gitosis.conf'
46
+ gtss.commit '.'
47
+ gtss.push(gtss.remote( 'origin' ))
48
+
49
+ g.push(g.remote( remote_name ))
50
+ end
51
+
52
+ def get_dirname dir
53
+ file = File.new dir
54
+ path = File.absolute_path file
55
+ path_array = path.split '/'
56
+ dirname = path_array.last
57
+ return dirname
58
+ end
59
+ # - ++ ->
60
+ # * *Returns* :
61
+ # -
62
+ def remove_git_repo dir = '.'
63
+ FileUtils.rm_rf (File.join(dir,'.git'))
64
+ end
65
+ end
66
+
67
+ class Gitosis
68
+ attr_accessor :ops, :log
69
+ def initialize
70
+ @ops = {}
71
+ @log = Logger.new 'log.txt'
72
+ if level = @ops[:debug_level]
73
+ @log.level = level
74
+ else
75
+ @log.level = Logger::INFO
76
+ end
77
+ end
78
+
79
+ # Add a project to the gitosis security conf file
80
+ # * *Args* :
81
+ # - +project_folder+ -> This is the folder where the new project that you want to add to gitosis is located
82
+ # - +to_group+ -> This is the name of the group that you want to add this project to
83
+ # - +gitosis_read+ -> This is location of the gitosis file you are reading from
84
+ # - +gitosis_write+ -> This is location of the gitosis file you are writing to
85
+ # * *Returns* :
86
+ # -
87
+ def add_project_to_gitosis project_name, to_group, gitosis_read, gitosis_write
88
+ groups = consume_file gitosis_read
89
+ group = groups[to_group]
90
+ raise "Couldn't find group: #{to_group}, in file: #{gitosis_read}." if group.nil?
91
+ writable = group['writable'].strip
92
+ writable += " " + project_name + "\n"
93
+ group['writable'] = writable
94
+ groups[to_group] = group
95
+ write_gitosis_file gitosis_write, groups
96
+ end
97
+
98
+ # * *Args* :
99
+ # - ++ ->
100
+ # * *Returns* :
101
+ # -
102
+ def remove_project_from_gitosis project_name, from_group, gitosis_read, gitosis_write
103
+ groups = consume_file gitosis_read
104
+ group = groups[from_group]
105
+ raise "Couldn't find group: #{to_group}, in file: #{gitosis_read}." if group.nil?
106
+ writable = group['writable'].split " "
107
+ writable.delete_at(writable.index(project_name) || li.length)
108
+ group['writable'] = writable.join " "
109
+ group['writable'] += "\n"
110
+ groups[from_group] = group
111
+ write_gitosis_file gitosis_write, groups
112
+ end
113
+
114
+ # * *Args* :
115
+ # - ++ ->
116
+ # * *Returns* :
117
+ # -
118
+
119
+ def consume_file (gitosis_file = nil)
120
+ @log.debug "Will try to read file: " + File.absolute_path(gitosis_file)
121
+ groups = {}
122
+ File.open(gitosis_file, "r") do |infile|
123
+ while (line = infile.gets)
124
+ if /^\[group (.*)\]/ =~ line
125
+ group_name = $1
126
+ writable = infile.gets
127
+ members = infile.gets
128
+ group_data = { 'members' => members, 'writable' => writable }
129
+ groups[group_name] = group_data
130
+ end
131
+ end
132
+ end
133
+ return groups
134
+ end
135
+ # * *Args* :
136
+ # - +filename+ -> This will be the filename to write to, if it already exists it will be overwritten
137
+ # - +data+ -> The data to write into the +filename+. Should be of the form
138
+ # returned by the +consume_file+ command.
139
+ def write_gitosis_file filename, data
140
+ File.open(filename, 'w'){|f|
141
+ f.write "[gitosis]\n\n"
142
+ data.each_pair do |group,grp_data|
143
+ members = grp_data['members']
144
+ writable = grp_data['writable']
145
+ f.write "[group #{group}]\n"
146
+ f.write writable
147
+ f.write members + "\n"
148
+ end
149
+ }
150
+ end
151
+
152
+
153
+ # * *Args* :
154
+ # - +regex+ -> A regular expression. Should be surrounded by
155
+ # forward slashes '/', for example: /fe(..)on/
156
+ # - +candidate+ -> This is the string for which you want to test to
157
+ # see if the regular expression is in it. For example: fenton
158
+ # * *Returns* :
159
+ # - nil if the regex is not found in the candidate string, otherwise
160
+ # it returns the found regex, in the above example it would return
161
+ # the string nt
162
+
163
+ def match_line regex, candidate
164
+ if regex =~ candidate
165
+ return $1
166
+ end
167
+ return nil
168
+ end
169
+ end
3
170
  end
171
+
172
+
173
+
@@ -20,12 +20,8 @@ module NetworkTools
20
20
  return false
21
21
  end
22
22
 
23
- # * *Args* :
24
- # - ++ ->
25
23
  # * *Returns* :
26
24
  # - true if you are on the vpn or false if you are not on the vpn
27
- # * *Raises* :
28
- # - ++ ->
29
25
  def on_vpn
30
26
  if is_port_open?("spicevan.com", 22)
31
27
  return false
@@ -0,0 +1,123 @@
1
+ require "test/unit"
2
+ require_relative "../../lib/it_tools/git"
3
+
4
+ module TestGit
5
+ class TestHelper
6
+ def test_setup_new_project
7
+ git_helper = Git::Helper.new
8
+ test_data_folder = ''
9
+ git_helper.setup_new_project test_data_folder = ''
10
+ end
11
+ def add_new_project_to_gitosis proj_folder, proj_name, group, orig_gitosis, new_gitosis
12
+ gitosis = Git::Gitosis.new
13
+ gitosis.add_project_to_gitosis proj_folder, group, orig_gitosis, new_gitosis
14
+ orig_gitosis = 'testdata/gitosis.conf'
15
+ old_groups = gitosis.consume_file orig_gitosis
16
+ fenton_grp = old_groups['fenton']
17
+ projects = fenton_grp['writable']
18
+ if /project_dir/ =~ projects
19
+ assert false, "Found #{proj_name}, in writable projects for group #{group}, when it shouldn't be there."
20
+ end
21
+ new_groups = gitosis.consume_file new_gitosis
22
+ #p new_groups #########
23
+ fenton_grp = new_groups['fenton']
24
+ projects = fenton_grp['writable']
25
+ unless /project_dir/ =~ projects
26
+ assert false, "Couldn't find project: #{proj_name}, in writable projects for group: #{group}, in file: #{new_gitosis}."
27
+ end
28
+ end
29
+ end
30
+ class TestGitosis < Test::Unit::TestCase
31
+ def test_get_dirname
32
+ git_helper = Git::Helper.new
33
+ dirname = git_helper.get_dirname '.'
34
+ assert_equal 'beta_tools', dirname
35
+ end
36
+ def test_consume_file
37
+ gitosis = Git::Gitosis.new
38
+ groups = gitosis.consume_file 'testdata/gitosis.conf'
39
+ fenton_group = groups['fenton']
40
+ writable = fenton_group['writable']
41
+ members = fenton_group['members']
42
+ assert_equal writable, "writable = myConfig project2 project3\n"
43
+ assert_equal members, "members = fenton\n"
44
+ end
45
+ def test_write_file
46
+ gitosis = Git::Gitosis.new
47
+ orig_gitosis = 'testdata/gitosis.conf'
48
+ groups = gitosis.consume_file orig_gitosis
49
+ new_gitosis = 'testdata/gitosis2.conf'
50
+ gitosis.write_gitosis_file new_gitosis, groups
51
+ diff = `diff #{orig_gitosis} #{new_gitosis}`
52
+ p diff
53
+ end
54
+
55
+ def test_anptg
56
+ proj_name = 'project_dir'
57
+ proj_folder = 'testdata/project_dir'
58
+ group = 'fenton'
59
+ new_gitosis = 'testdata/gitosis3.conf'
60
+ orig_gitosis = 'testdata/gitosis.conf'
61
+ helper = TestGit::TestHelper.new "abc"
62
+ helper.add_new_project_to_gitosis proj_folder, proj_name, group, orig_gitosis, new_gitosis
63
+ gitosis = Git::Gitosis.new
64
+ groups = gitosis.consume_file 'testdata/gitosis3.conf'
65
+ fenton_group = groups['fenton']
66
+ writable = fenton_group['writable']
67
+ members = fenton_group['members']
68
+ if /project_dir/ =~ writable
69
+ has_project = true
70
+ else
71
+ has_project = false
72
+ end
73
+ assert has_project, "Couldn't find project: 'project_dir', in writable directive: #{writable}"
74
+ end
75
+ def test_remove_project_name_from_gitosis
76
+ proj_name = 'project2'
77
+ proj_folder = 'testdata/project_dir'
78
+ group = 'fenton'
79
+ new_gitosis = 'testdata/gitosis4.conf'
80
+ orig_gitosis = 'testdata/gitosis.conf'
81
+ gitosis = Git::Gitosis.new
82
+ gitosis.remove_project_from_gitosis proj_name, group, orig_gitosis, new_gitosis
83
+ groups = gitosis.consume_file 'testdata/gitosis4.conf'
84
+ fenton_group = groups['fenton']
85
+ writable = fenton_group['writable']
86
+ members = fenton_group['members']
87
+ if /project2/ =~ writable
88
+ have_project = true
89
+ else
90
+ have_project = false
91
+ end
92
+ assert ! have_project, "Found project: 'project2', in writable directive: #{writable}"
93
+ end
94
+ def test_match
95
+ regex = /^\[group (.*)\]/
96
+ no_match = "abc 123"
97
+ gitosis = Git::Gitosis.new
98
+ matched = gitosis.match_line regex, no_match
99
+ assert_nil matched
100
+ match = "[group fenton]"
101
+ matched = gitosis.match_line regex, match
102
+ assert_equal matched, 'fenton'
103
+ end
104
+ def test_regex
105
+ regex = /^\[group (.*)\]/
106
+ match = "[group fenton]"
107
+ regex =~ match
108
+ end
109
+ end
110
+ end
111
+ class Runner
112
+ def rdebug_anptg
113
+ proj_name = 'project_dir'
114
+ proj_folder = '../../testdata/project_dir'
115
+ group = 'fenton'
116
+ new_gitosis = '../../testdata/gitosis3.conf'
117
+ orig_gitosis = '../../testdata/gitosis.conf'
118
+ test = TestGit::TestGitosis.new 'abc'
119
+ test.add_new_project_to_gitosis proj_folder, proj_name, group, orig_gitosis, new_gitosis
120
+ end
121
+ end
122
+ #runner = Runner.new
123
+ #runner.rdebug_anptg
@@ -0,0 +1,26 @@
1
+ [gitosis]
2
+
3
+ [group gitosis-admin]
4
+ writable = gitosis-admin
5
+ members = alfred fenton ken masaki meenal derrick
6
+
7
+ [group docs]
8
+ writable = documentation work-doco
9
+ members = neeraja alfred amit clow derrick fenton jasmiao ken masaki meenal nitesh oracle@linux1 root@linux1 git@linux1 michelle susan
10
+
11
+ [group shared_dev]
12
+ writable = crmod-ws-wrapper credentials-jar myhelpCategories aps-crmod-intgrtn categorizationSpreadsheet myhelpCategories-EAR hibernateWrapper crmodTasItgrtn autoSR2 autoSR2-EAR massUpdate ngspParent hrmsToCrmodUserDataIntegration CRMOD_WS_Writer MyhelpCategorization crmodUserDataUpdation UpdateSRwithActivity
13
+ members = neeraja alfred amit clow derrick fenton jasmiao ken masaki meenal nitesh oracle@linux1 root@linux1 git@linux1 michelle susan
14
+
15
+ [group dormant_projects]
16
+ writable = jsonUtility credentials-EAR git-common currentWork commonProject indiaCrmodWrapper simpleSamples secondScala crmodRestServer crmodRestServer4 fenton MvnSesFe basic-archetype SES-CRMOD-EAR SesReader software sc ft.home.dir autoSR2-master tempHrmsDataPull AcceptanceTests credentials OssoWrapper it_library it_tools soap-helper environmentalInfo
17
+ members = alfred fenton meenal oracle@linux1 root@linux1 git@linux1
18
+
19
+ [group new]
20
+ writable = ruby_soap_cx wf_soap_ruby
21
+ members = alfred meenal fenton ken masaki
22
+
23
+ [group fenton]
24
+ writable = myConfig project2 project3
25
+ members = fenton
26
+
@@ -0,0 +1,26 @@
1
+ [gitosis]
2
+
3
+ [group gitosis-admin]
4
+ writable = gitosis-admin
5
+ members = alfred fenton ken masaki meenal derrick
6
+
7
+ [group docs]
8
+ writable = documentation work-doco
9
+ members = neeraja alfred amit clow derrick fenton jasmiao ken masaki meenal nitesh oracle@linux1 root@linux1 git@linux1 michelle susan
10
+
11
+ [group shared_dev]
12
+ writable = crmod-ws-wrapper credentials-jar myhelpCategories aps-crmod-intgrtn categorizationSpreadsheet myhelpCategories-EAR hibernateWrapper crmodTasItgrtn autoSR2 autoSR2-EAR massUpdate ngspParent hrmsToCrmodUserDataIntegration CRMOD_WS_Writer MyhelpCategorization crmodUserDataUpdation UpdateSRwithActivity
13
+ members = neeraja alfred amit clow derrick fenton jasmiao ken masaki meenal nitesh oracle@linux1 root@linux1 git@linux1 michelle susan
14
+
15
+ [group dormant_projects]
16
+ writable = jsonUtility credentials-EAR git-common currentWork commonProject indiaCrmodWrapper simpleSamples secondScala crmodRestServer crmodRestServer4 fenton MvnSesFe basic-archetype SES-CRMOD-EAR SesReader software sc ft.home.dir autoSR2-master tempHrmsDataPull AcceptanceTests credentials OssoWrapper it_library it_tools soap-helper environmentalInfo
17
+ members = alfred fenton meenal oracle@linux1 root@linux1 git@linux1
18
+
19
+ [group new]
20
+ writable = ruby_soap_cx wf_soap_ruby
21
+ members = alfred meenal fenton ken masaki
22
+
23
+ [group fenton]
24
+ writable = myConfig project2 project3
25
+ members = fenton
26
+
@@ -0,0 +1,26 @@
1
+ [gitosis]
2
+
3
+ [group gitosis-admin]
4
+ writable = gitosis-admin
5
+ members = alfred fenton ken masaki meenal derrick
6
+
7
+ [group docs]
8
+ writable = documentation work-doco
9
+ members = neeraja alfred amit clow derrick fenton jasmiao ken masaki meenal nitesh oracle@linux1 root@linux1 git@linux1 michelle susan
10
+
11
+ [group shared_dev]
12
+ writable = crmod-ws-wrapper credentials-jar myhelpCategories aps-crmod-intgrtn categorizationSpreadsheet myhelpCategories-EAR hibernateWrapper crmodTasItgrtn autoSR2 autoSR2-EAR massUpdate ngspParent hrmsToCrmodUserDataIntegration CRMOD_WS_Writer MyhelpCategorization crmodUserDataUpdation UpdateSRwithActivity
13
+ members = neeraja alfred amit clow derrick fenton jasmiao ken masaki meenal nitesh oracle@linux1 root@linux1 git@linux1 michelle susan
14
+
15
+ [group dormant_projects]
16
+ writable = jsonUtility credentials-EAR git-common currentWork commonProject indiaCrmodWrapper simpleSamples secondScala crmodRestServer crmodRestServer4 fenton MvnSesFe basic-archetype SES-CRMOD-EAR SesReader software sc ft.home.dir autoSR2-master tempHrmsDataPull AcceptanceTests credentials OssoWrapper it_library it_tools soap-helper environmentalInfo
17
+ members = alfred fenton meenal oracle@linux1 root@linux1 git@linux1
18
+
19
+ [group new]
20
+ writable = ruby_soap_cx wf_soap_ruby
21
+ members = alfred meenal fenton ken masaki
22
+
23
+ [group fenton]
24
+ writable = myConfig project2 project3 testdata/project_dir
25
+ members = fenton
26
+
@@ -0,0 +1 @@
1
+ abc123
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beta_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-01 00:00:00.000000000 Z
12
+ date: 2012-05-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pygments.rb
@@ -178,6 +178,7 @@ email:
178
178
  executables:
179
179
  - deploy
180
180
  - documentation_daemon
181
+ - gi
181
182
  - loginToUrl
182
183
  - onVpn
183
184
  - pub
@@ -194,6 +195,7 @@ files:
194
195
  - beta_tools.gemspec
195
196
  - bin/deploy
196
197
  - bin/documentation_daemon
198
+ - bin/gi
197
199
  - bin/loginToUrl
198
200
  - bin/onVpn
199
201
  - bin/pub
@@ -243,6 +245,7 @@ files:
243
245
  - test/it_tools/suite_it_tools.rb
244
246
  - test/it_tools/suite_it_tools.rb~
245
247
  - test/it_tools/test_deploy.rb
248
+ - test/it_tools/test_git.rb
246
249
  - test/it_tools/test_html_publish.rb
247
250
  - test/it_tools/test_maven.rb
248
251
  - test/it_tools/test_multipart.rb
@@ -256,8 +259,12 @@ files:
256
259
  - testdata/assembly_pom.xml
257
260
  - testdata/desir.txt
258
261
  - testdata/ear_pom.xml
262
+ - testdata/gitosis.conf
263
+ - testdata/gitosis2.conf
264
+ - testdata/gitosis3.conf
259
265
  - testdata/java.html
260
266
  - testdata/pom.xml
267
+ - testdata/project_dir/test_file.txt
261
268
  - testdata/publish/src_dir/#arch.mmd#
262
269
  - testdata/publish/src_dir/ajax-loader.gif
263
270
  - testdata/publish/src_dir/file1.mmd
@@ -326,6 +333,7 @@ test_files:
326
333
  - test/it_tools/suite_it_tools.rb
327
334
  - test/it_tools/suite_it_tools.rb~
328
335
  - test/it_tools/test_deploy.rb
336
+ - test/it_tools/test_git.rb
329
337
  - test/it_tools/test_html_publish.rb
330
338
  - test/it_tools/test_maven.rb
331
339
  - test/it_tools/test_multipart.rb