p4util 0.1.1 → 0.1.3
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 +4 -4
- data/README.md +2 -0
- data/Rakefile +4 -1
- data/lib/commands/init/changelist_model.rb +15 -4
- data/lib/commands/init/depot_model.rb +60 -0
- data/lib/commands/init/init_model.rb +3 -0
- data/lib/commands/init/p4_helpers.rb +5 -1
- data/lib/commands/init/user_model.rb +13 -3
- data/lib/commands/init.rb +38 -3
- data/lib/commands/kill.rb +7 -7
- data/lib/commands/util.rb +24 -2
- data/lib/p4util/version.rb +1 -1
- data/p4util.gemspec +1 -2
- metadata +6 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0edf6cc773707c1a4980752d791f5411f02d26d
|
4
|
+
data.tar.gz: 989fb3cc701d1211c69c7f3c64e28325f6381750
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b32a53524ad0e06c7f551ebeb7a8c77ec4da03bfad69880f53fb0e98635fa94642dda0a7a45c4a7582e38a831a0b29fc631f01e9f075fa1decdea31b5139f06b
|
7
|
+
data.tar.gz: fdad9a5c160ab074d20dda40c8fe9a3d9f7d441d795dbfdadff68c3a54fa8b5c5ac0010d9938101018dc947b1e350f47305e09d3962bc1f648f362dabebf48f7
|
data/README.md
CHANGED
@@ -35,6 +35,8 @@ Or install it yourself as:
|
|
35
35
|
|
36
36
|
## Changes
|
37
37
|
|
38
|
+
* 0.1.2: Added depot model and the ability to customize the view for changelists
|
39
|
+
|
38
40
|
* 0.1.1: Added documentation for Rake tasks and version string output
|
39
41
|
|
40
42
|
* 0.1.0: Added `p4util init` command that can do some common p4d configurations,
|
data/Rakefile
CHANGED
@@ -8,7 +8,7 @@ module Commands
|
|
8
8
|
class ChangelistModel < InitModel
|
9
9
|
include Commands::Init::P4Helpers
|
10
10
|
|
11
|
-
inheritable_attributes :description, :adds, :edits, :user
|
11
|
+
inheritable_attributes :description, :adds, :edits, :user, :view
|
12
12
|
|
13
13
|
# Please make this descriptive
|
14
14
|
@description = 'Init changelist'
|
@@ -23,6 +23,9 @@ module Commands
|
|
23
23
|
# user
|
24
24
|
@user = nil
|
25
25
|
|
26
|
+
# Don't use the default //depot/... mapping, use this instead
|
27
|
+
@view = nil
|
28
|
+
|
26
29
|
#========================================================================
|
27
30
|
# Internal implementation
|
28
31
|
#========================================================================
|
@@ -31,13 +34,14 @@ module Commands
|
|
31
34
|
true
|
32
35
|
end
|
33
36
|
|
34
|
-
attr_accessor :description, :adds, :edits, :user
|
37
|
+
attr_accessor :description, :adds, :edits, :user, :view
|
35
38
|
|
36
39
|
def initialize
|
37
40
|
@description = self.class.description
|
38
41
|
@adds = self.class.adds
|
39
42
|
@edits = self.class.edits
|
40
43
|
@user = self.class.user
|
44
|
+
@view = self.class.view
|
41
45
|
end
|
42
46
|
|
43
47
|
def execute(p4, models, super_user)
|
@@ -51,6 +55,9 @@ module Commands
|
|
51
55
|
options[:olduser] = super_user.login
|
52
56
|
options[:oldpass] = super_user.password
|
53
57
|
end
|
58
|
+
if view
|
59
|
+
options[:view] = view
|
60
|
+
end
|
54
61
|
|
55
62
|
# Define the logic of what the changelist model really does: make adds
|
56
63
|
# and edits for the most part
|
@@ -61,6 +68,8 @@ module Commands
|
|
61
68
|
results = p4.save_change(change_spec)
|
62
69
|
change_id = results[0].gsub(/^Change (\d+) created./, '\1')
|
63
70
|
|
71
|
+
puts "Preparing changelist #{change_id} with #{@adds.length} adds and #{@edits.length} edits"
|
72
|
+
|
64
73
|
@adds.each do |add|
|
65
74
|
add_path = File.join(client_path, add.path)
|
66
75
|
dir = File.dirname(add_path)
|
@@ -74,12 +83,14 @@ module Commands
|
|
74
83
|
elsif add.local_path
|
75
84
|
FileUtils.copy(add.local_path, add_path)
|
76
85
|
end
|
77
|
-
p4.run_add('-c', change_id, add_path)
|
86
|
+
results = p4.run_add('-c', change_id, add_path)
|
87
|
+
puts "Added file #{add_path} to #{change_id}: #{results}"
|
78
88
|
end
|
79
89
|
|
80
90
|
@edits.each do |edit|
|
81
91
|
edit_path = File.join(client_path, edit.path)
|
82
|
-
p4.run_edit('-c', change_id, edit_path)
|
92
|
+
results = p4.run_edit('-c', change_id, edit_path)
|
93
|
+
puts "Editing file #{edit_path} on #{change_id}: #{results}"
|
83
94
|
|
84
95
|
if edit.content
|
85
96
|
IO.write(edit_path, edit.content)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'commands/init/init_model'
|
2
|
+
require 'commands/init/p4_helpers'
|
3
|
+
|
4
|
+
module Commands
|
5
|
+
module Init
|
6
|
+
|
7
|
+
class DepotModel < InitModel
|
8
|
+
include Commands::Init::P4Helpers
|
9
|
+
|
10
|
+
inheritable_attributes :depot, :description, :type, :address, :suffix, :map, :spec_map
|
11
|
+
|
12
|
+
# The depot name
|
13
|
+
@depot = nil
|
14
|
+
|
15
|
+
@description = 'Init depot'
|
16
|
+
|
17
|
+
@type = 'local'
|
18
|
+
|
19
|
+
@address = nil
|
20
|
+
|
21
|
+
@suffix = nil
|
22
|
+
|
23
|
+
@map = 'depot/...'
|
24
|
+
|
25
|
+
@spec_map = nil
|
26
|
+
|
27
|
+
#========================================================================
|
28
|
+
# Internal implementation
|
29
|
+
#========================================================================
|
30
|
+
|
31
|
+
def self.abstract
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
attr_accessor :depot, :description, :type, :address, :suffix, :map, :spec_map
|
36
|
+
|
37
|
+
def initialize
|
38
|
+
@depot = self.class.depot
|
39
|
+
@description = self.class.description
|
40
|
+
@type = self.class.type
|
41
|
+
@address = self.class.address
|
42
|
+
@suffix = self.class.suffix
|
43
|
+
@map = self.class.map
|
44
|
+
@spec_map = self.class.spec_map
|
45
|
+
end
|
46
|
+
|
47
|
+
def execute(p4, models=nil, super_user=nil)
|
48
|
+
d = p4.fetch_depot(depot)
|
49
|
+
d._depot = depot
|
50
|
+
d._description = description if description
|
51
|
+
d._type = type if type
|
52
|
+
d._address = address if address
|
53
|
+
d._suffix = suffix if suffix
|
54
|
+
d._map = map if map
|
55
|
+
d._spec_map = spec_map if spec_map
|
56
|
+
p4.save_depot(d)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -44,7 +44,11 @@ module Commands
|
|
44
44
|
spec._root = dir
|
45
45
|
spec._client = name
|
46
46
|
spec._description = 'p4util init temp client'
|
47
|
-
|
47
|
+
if options.key?(:view)
|
48
|
+
spec._view = options[:view].map { |x| x.gsub("${name}", name) }
|
49
|
+
else
|
50
|
+
spec._view = ["//depot/... //#{name}/depot/..."]
|
51
|
+
end
|
48
52
|
|
49
53
|
p4.save_client(spec)
|
50
54
|
|
@@ -4,7 +4,7 @@ module Commands
|
|
4
4
|
module Init
|
5
5
|
|
6
6
|
class UserModel < InitModel
|
7
|
-
inheritable_attributes :login, :full_name, :password, :email, :super
|
7
|
+
inheritable_attributes :login, :full_name, :password, :email, :super, :skip
|
8
8
|
|
9
9
|
@login = nil
|
10
10
|
@full_name = nil
|
@@ -15,6 +15,12 @@ module Commands
|
|
15
15
|
# protections entry for this user exists
|
16
16
|
@super = false
|
17
17
|
|
18
|
+
# Set this to true if you actually just want to use this username/password
|
19
|
+
# combination and expect that the user actually exists in the system
|
20
|
+
# already. This basically allows us to use the same definition for
|
21
|
+
# existing users in initialization scripts.
|
22
|
+
@skip = false
|
23
|
+
|
18
24
|
#========================================================================
|
19
25
|
# Internal implementation - don't mess with this
|
20
26
|
#========================================================================
|
@@ -59,16 +65,20 @@ module Commands
|
|
59
65
|
end
|
60
66
|
|
61
67
|
def execute(p4, models=nil, super_user=nil)
|
68
|
+
return if self.class.skip
|
69
|
+
|
70
|
+
puts "user: #{to_spec} as #{p4.user}"
|
71
|
+
|
62
72
|
p4.save_user(to_spec, '-f')
|
63
73
|
|
64
74
|
p4.user = login
|
65
|
-
p4.password = ''
|
75
|
+
p4.password = '' if password
|
66
76
|
|
67
77
|
p4.run_password('', password) if password
|
68
78
|
|
69
79
|
if super_user
|
70
80
|
p4.user = super_user.login
|
71
|
-
p4.password = super_user.password
|
81
|
+
p4.password = super_user.password if super_user.password
|
72
82
|
end
|
73
83
|
end
|
74
84
|
end
|
data/lib/commands/init.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
require 'commands/start'
|
3
3
|
require 'commands/init/init_model'
|
4
4
|
require 'commands/init/changelist_model'
|
5
|
+
require 'commands/init/depot_model'
|
5
6
|
require 'commands/init/file_definition'
|
6
7
|
require 'commands/init/system_settings_model'
|
7
8
|
require 'commands/init/user_model'
|
@@ -10,9 +11,25 @@ module Commands
|
|
10
11
|
|
11
12
|
def Commands.init(options=nil)
|
12
13
|
init_dir = 'p4init'
|
13
|
-
|
14
|
-
# spurious and dangerous use case
|
14
|
+
|
15
15
|
p4port = '127.0.0.1:1666'
|
16
|
+
version = nil
|
17
|
+
|
18
|
+
if options and !options.params.empty?
|
19
|
+
|
20
|
+
op = OptionParser.new do |op|
|
21
|
+
op.on('-p PORT', '--port PORT', 'P4PORT setting') { |x| p4port = x }
|
22
|
+
op.on('-v VERSION', '--version VERSION', 'ftp.perforce.com version') do |v|
|
23
|
+
version = v
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
op.parse!(options.params)
|
28
|
+
|
29
|
+
if !options.params.empty?
|
30
|
+
init_dir = options.params.first
|
31
|
+
end
|
32
|
+
end
|
16
33
|
|
17
34
|
if options and !options.params.empty?
|
18
35
|
init_dir = options.params.shift
|
@@ -21,6 +38,8 @@ module Commands
|
|
21
38
|
if !p4d_running?
|
22
39
|
# The way this works: if you specify any options, like what to download
|
23
40
|
# you must specify the initialization directory.
|
41
|
+
options = OpenStruct.new
|
42
|
+
options.params = ['--version', version] unless version.nil?
|
24
43
|
Commands.start(options)
|
25
44
|
end
|
26
45
|
|
@@ -29,7 +48,7 @@ module Commands
|
|
29
48
|
|
30
49
|
def Commands.print_init_help
|
31
50
|
puts <<-END.gsub(/^ {6}/, '')
|
32
|
-
p4util init [p4_init_dir]
|
51
|
+
p4util init [-p P4PORT] [p4_init_dir]
|
33
52
|
|
34
53
|
Reads definitions in the directory p4_init_dir - by default, just
|
35
54
|
'p4init' - and then calls methods on a p4d instance assumed to be running
|
@@ -134,6 +153,22 @@ module Commands
|
|
134
153
|
as your super user, so set this to a UserModel instance that should exist
|
135
154
|
at this point.
|
136
155
|
|
156
|
+
## DepotModel ##
|
157
|
+
|
158
|
+
Example creating a new standard depot:
|
159
|
+
|
160
|
+
class ProjectDepot < DepotModel
|
161
|
+
def rank
|
162
|
+
1001
|
163
|
+
end
|
164
|
+
@depot = 'my_project'
|
165
|
+
@description = 'The My Project depot'
|
166
|
+
end
|
167
|
+
|
168
|
+
Other attributes that can be set that update the depot spec being written:
|
169
|
+
|
170
|
+
:type, :address, :suffix, :map, :spec_map
|
171
|
+
|
137
172
|
END
|
138
173
|
end
|
139
174
|
|
data/lib/commands/kill.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'commands/util'
|
2
|
-
require 'sys/proctable'
|
3
|
-
|
4
|
-
include Sys
|
5
2
|
|
6
3
|
module Commands
|
7
4
|
|
8
5
|
def Commands.kill(options=nil)
|
9
|
-
|
6
|
+
list_process_names.select{|p| p =~ /p4d/}.each do |p|
|
7
|
+
pid = pid_for_process(p)
|
10
8
|
begin
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
puts "killing p4d #{p} at #{pid}"
|
10
|
+
Process.kill('TERM', pid)
|
11
|
+
rescue Exception => e
|
12
|
+
puts "Problem killing #{p}: #{e.message}"
|
13
|
+
puts e.backtrace.join('\n')
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
data/lib/commands/util.rb
CHANGED
@@ -1,9 +1,31 @@
|
|
1
|
-
require 'sys/proctable'
|
2
1
|
require 'P4'
|
2
|
+
require 'osutil'
|
3
3
|
|
4
4
|
module Commands
|
5
5
|
def Commands.p4d_running?
|
6
|
-
|
6
|
+
list_process_names.select { |p| p =~ /p4d/ }.empty? == false
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.list_process_names
|
10
|
+
if OsUtil.osx? or OsUtil.linux?
|
11
|
+
return `ps aux | awk '{print $11}'`.split(/\n/).drop(1)
|
12
|
+
else
|
13
|
+
# TODO investigate using tasklist just for this
|
14
|
+
raise 'No support for windows just yet'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.pid_for_process(process)
|
19
|
+
if OsUtil.osx? or OsUtil.linux?
|
20
|
+
line = `ps aux | awk '{print $2,$11}'`.split(/\n/).drop(1).find { |p| p =~ /#{process}/ }
|
21
|
+
unless line.nil?
|
22
|
+
return line.split('\n').first.to_i
|
23
|
+
else
|
24
|
+
return nil
|
25
|
+
end
|
26
|
+
else
|
27
|
+
raise 'NO support for windows yet'
|
28
|
+
end
|
7
29
|
end
|
8
30
|
|
9
31
|
def Commands.p4d_available?(port=':1666')
|
data/lib/p4util/version.rb
CHANGED
data/p4util.gemspec
CHANGED
@@ -20,7 +20,6 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
22
|
|
23
|
-
spec.add_runtime_dependency '
|
24
|
-
spec.add_runtime_dependency 'p4ruby', '2014.2.0.pre1'
|
23
|
+
spec.add_runtime_dependency 'p4ruby', '~> 2014.2.0.pre'
|
25
24
|
spec.add_runtime_dependency 'rake', '~> 10.3'
|
26
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: p4util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tristan Juricek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -25,33 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: p4ruby
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2014.2.0.pre
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: p4ruby
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 2014.2.0.pre1
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 2014.2.0.pre1
|
40
|
+
version: 2014.2.0.pre
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rake
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,6 +72,7 @@ files:
|
|
86
72
|
- "./lib/commands/help.rb"
|
87
73
|
- "./lib/commands/init.rb"
|
88
74
|
- "./lib/commands/init/changelist_model.rb"
|
75
|
+
- "./lib/commands/init/depot_model.rb"
|
89
76
|
- "./lib/commands/init/file_definition.rb"
|
90
77
|
- "./lib/commands/init/init_model.rb"
|
91
78
|
- "./lib/commands/init/p4_helpers.rb"
|