p4util 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/bin/p4util +9 -0
- data/lib/commands/download.rb +89 -0
- data/lib/commands/help.rb +30 -0
- data/lib/commands/kill.rb +24 -0
- data/lib/commands/start.rb +31 -0
- data/lib/commands.rb +4 -0
- data/lib/conventions.rb +29 -0
- data/lib/osutil.rb +52 -0
- data/lib/p4_util/version.rb +3 -0
- data/lib/p4_util.rb +29 -0
- data/p4util.gemspec +25 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b7427b07b614b4b912c90eacd5d9d304c773b239
|
4
|
+
data.tar.gz: 29a165e47defc8e7c1bdc71d248f95c8532caeb8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b1b00491f1b0dd76e43fda03fefed8aff019c0227a30e7caf5a7428529e116123da920a0b9e1eae244b713b1e95529b1b4a0dda124712a4f364b2dcb073b3d65
|
7
|
+
data.tar.gz: 0d5458e1b84fe0b6bec09381287d55333dfd7b439188ec0efb62430b1be4405d7f49ad183be4f691d597fb703016dc90c5687f7e4c517ae9954ebdaeae9bc090
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Perforce Software, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# P4util
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'p4util'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install p4util
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/p4util/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/p4util
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'conventions'
|
2
|
+
require 'optparse'
|
3
|
+
require 'osutil'
|
4
|
+
require 'net/ftp'
|
5
|
+
|
6
|
+
module Commands
|
7
|
+
|
8
|
+
def Commands.download(options=nil)
|
9
|
+
version = 'r14.2'
|
10
|
+
binary = 'p4d'
|
11
|
+
|
12
|
+
if options and !options.params.empty?
|
13
|
+
|
14
|
+
op = OptionParser.new do |op|
|
15
|
+
op.on('-v VERSION', '--version VERSION', 'ftp.perforce.com version') do |v|
|
16
|
+
version = v
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
op.parse!(options.params)
|
21
|
+
|
22
|
+
if !options.params.empty?
|
23
|
+
binary = options.params.first
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
case binary
|
28
|
+
when 'p4d'
|
29
|
+
download_p4d_via_ftp(version)
|
30
|
+
when 'p4api'
|
31
|
+
download_p4api_via_ftp(version)
|
32
|
+
else
|
33
|
+
raise "Don't know how to download #{binary}, check 'p4util help download'"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def Commands.print_download_help
|
38
|
+
puts <<-END.gsub(/^ {6}/, '')
|
39
|
+
p4util download [p4d|p4api]
|
40
|
+
|
41
|
+
Downloads one of the following utilities (in lieu of an installer) into
|
42
|
+
a local work/ directory.
|
43
|
+
|
44
|
+
* p4d
|
45
|
+
* p4api
|
46
|
+
|
47
|
+
Will default to the latest release unless you don't know what that is.
|
48
|
+
|
49
|
+
Options:
|
50
|
+
|
51
|
+
--version X where X looks like the version in the ftp.perforce.com site,
|
52
|
+
e.g., 'r14.2' instead of '2014.2'
|
53
|
+
END
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def Commands.download_p4d_via_ftp(version)
|
59
|
+
download_via_ftp(version, OsUtil.p4d_executable, OsUtil.p4d_path)
|
60
|
+
|
61
|
+
if !File.executable?(OsUtil.p4d_path)
|
62
|
+
File.chmod(0755, OsUtil.p4d_path)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def Commands.download_p4api_via_ftp(version)
|
67
|
+
download_via_ftp(version, OsUtil.p4api_file, OsUtil.p4api_path)
|
68
|
+
|
69
|
+
# um, probably should expand this guy out
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def Commands.download_via_ftp(version, filename, output_path)
|
75
|
+
ftp = Net::FTP.new('ftp.perforce.com')
|
76
|
+
ftp.login
|
77
|
+
|
78
|
+
dir = OsUtil.ftp_download_dir(version)
|
79
|
+
ftp.chdir(dir)
|
80
|
+
|
81
|
+
ftp.passive=true
|
82
|
+
|
83
|
+
Conventions.init_working_dir
|
84
|
+
|
85
|
+
ftp.getbinaryfile(filename, output_path)
|
86
|
+
ensure
|
87
|
+
ftp.close if ftp and !ftp.closed?
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
module Commands
|
3
|
+
|
4
|
+
def Commands.help(options)
|
5
|
+
if !options.params.empty? && Commands.respond_to?(options.params.first.to_sym)
|
6
|
+
method_name = "print_#{options.params.first}_help".to_sym
|
7
|
+
Commands.method(method_name).call()
|
8
|
+
else
|
9
|
+
print_general_help
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def Commands.print_general_help
|
16
|
+
puts <<-END.gsub(/^ {6}/, '')
|
17
|
+
p4util [command] [params]
|
18
|
+
|
19
|
+
Executes various commands useful when writing Perforce applications.
|
20
|
+
|
21
|
+
Use `p4util help [command]` for more information on each command.
|
22
|
+
|
23
|
+
List of available commands:
|
24
|
+
download - Download Perforce binaries for your platform
|
25
|
+
init - Seed the local p4d instance using local configuration files
|
26
|
+
kill - Shutdown p4d processes using SIGTERM
|
27
|
+
start - Spawn the p4d process in your working directory
|
28
|
+
END
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'sys/proctable'
|
2
|
+
|
3
|
+
include Sys
|
4
|
+
|
5
|
+
module Commands
|
6
|
+
|
7
|
+
def Commands.kill(options=nil)
|
8
|
+
ProcTable.ps().find_all{|p| p.comm =~ /p4d/}
|
9
|
+
.each{|p| Process.kill('TERM', p.pid)}
|
10
|
+
end
|
11
|
+
|
12
|
+
def Commands.print_kill_help
|
13
|
+
puts <<-END.gsub(/^ {6}/,'')
|
14
|
+
p4util kill
|
15
|
+
|
16
|
+
Finds local p4d processes and kills them.
|
17
|
+
|
18
|
+
There should be a timeout that will force kill anything that appears stuck.
|
19
|
+
|
20
|
+
On unix machines, will probably use `ps -x` and 'p4d', then will send
|
21
|
+
SIGTERM signals to each process.
|
22
|
+
END
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
module Commands
|
3
|
+
|
4
|
+
def Commands.start(options)
|
5
|
+
if !File.exists?(OsUtil.p4d_path)
|
6
|
+
Commands.download
|
7
|
+
end
|
8
|
+
Conventions.init_p4droot_dir
|
9
|
+
spawn_p4d
|
10
|
+
end
|
11
|
+
|
12
|
+
def Commands.spawn_p4d
|
13
|
+
pid = Process.spawn("#{OsUtil.p4d_path} -r #{Conventions.p4droot_dir} "+
|
14
|
+
"-v server=1 -L #{Conventions.p4d_log_path}")
|
15
|
+
Process.detach(pid)
|
16
|
+
end
|
17
|
+
|
18
|
+
def Commands.print_start_help
|
19
|
+
puts <<-END.gsub(/^ {6}/,'')
|
20
|
+
p4util start
|
21
|
+
|
22
|
+
Spawns a Perforce process in your local work/p4droot directory.
|
23
|
+
|
24
|
+
If the Perforce executable does not exist, will download the binary first.
|
25
|
+
|
26
|
+
Will try to set up a server log at work/server.log. It'll be fairly
|
27
|
+
verbose by default; this is *not* intended for any kind of performance
|
28
|
+
testing.
|
29
|
+
END
|
30
|
+
end
|
31
|
+
end
|
data/lib/commands.rb
ADDED
data/lib/conventions.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Conventions
|
5
|
+
|
6
|
+
def Conventions.working_dir
|
7
|
+
File.expand_path('work')
|
8
|
+
end
|
9
|
+
|
10
|
+
def Conventions.init_working_dir
|
11
|
+
if !File.directory?(working_dir)
|
12
|
+
FileUtils::makedirs(working_dir)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def Conventions.p4droot_dir
|
17
|
+
File.expand_path(File.join(working_dir,'p4droot'))
|
18
|
+
end
|
19
|
+
|
20
|
+
def Conventions.init_p4droot_dir
|
21
|
+
if !File.directory?(p4droot_dir)
|
22
|
+
FileUtils::makedirs(p4droot_dir)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def Conventions.p4d_log_path
|
27
|
+
File.expand_path(File.join(working_dir, 'server.log'))
|
28
|
+
end
|
29
|
+
end
|
data/lib/osutil.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
require 'rbconfig'
|
3
|
+
|
4
|
+
module OsUtil
|
5
|
+
|
6
|
+
def OsUtil.p4d_executable
|
7
|
+
if windows?
|
8
|
+
'p4d.exe'
|
9
|
+
else
|
10
|
+
'p4d'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def OsUtil.p4d_path
|
15
|
+
File.expand_path(File.join(Conventions.working_dir, OsUtil.p4d_executable))
|
16
|
+
end
|
17
|
+
|
18
|
+
def OsUtil.osx?
|
19
|
+
RbConfig::CONFIG['host_os'] =~ /darwin/
|
20
|
+
end
|
21
|
+
|
22
|
+
def OsUtil.windows?
|
23
|
+
RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
|
24
|
+
end
|
25
|
+
|
26
|
+
def OsUtil.platform_dir_prefix
|
27
|
+
if osx?
|
28
|
+
'darwin90'
|
29
|
+
elsif windows?
|
30
|
+
'nt'
|
31
|
+
else
|
32
|
+
raise "OsUtil doesn't know platform: #{RbConfig::CONFIG['host_os']}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def OsUtil.ftp_download_dir(version)
|
37
|
+
"perforce/#{version}/bin.#{platform_dir_prefix}#{RbConfig::CONFIG['build_cpu']}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def OsUtil.p4api_file
|
41
|
+
if windows?
|
42
|
+
raise 'hey you need a visual studio version defined somehow'
|
43
|
+
'p4api.zip'
|
44
|
+
else
|
45
|
+
'p4api.tgz'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def OsUtil.p4api_path
|
50
|
+
File.expand_path(File.join(Conventions.working_dir, OsUtil.p4api_file))
|
51
|
+
end
|
52
|
+
end
|
data/lib/p4_util.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'p4_util/version'
|
2
|
+
require 'commands'
|
3
|
+
require 'optparse'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
module P4Util
|
7
|
+
|
8
|
+
def P4Util.run(args)
|
9
|
+
options = parse_options(args)
|
10
|
+
Commands.method(options.command).call(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Returns the options as an OpenStruct object
|
14
|
+
def P4Util.parse_options(args)
|
15
|
+
options = OpenStruct.new
|
16
|
+
|
17
|
+
options.command = :help
|
18
|
+
options.params = []
|
19
|
+
|
20
|
+
if args && !args.empty?
|
21
|
+
options.command = args.first.to_sym
|
22
|
+
if args.length > 1
|
23
|
+
options.params.concat(args.drop(1))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
options
|
28
|
+
end
|
29
|
+
end
|
data/p4util.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'p4_util/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'p4util'
|
8
|
+
spec.version = P4Util::VERSION
|
9
|
+
spec.authors = ['Tristan Juricek']
|
10
|
+
spec.email = ['tjuricek@perforce.com']
|
11
|
+
spec.summary = %q{The p4util command line app eases setup of Perforce instances, mostly for testing.}
|
12
|
+
spec.description = %q{The p4util command itself provides other commands, see 'p4util help' after install. This allows you to things like download a p4d, start it, kill it, etc mostly for quick setup of testing systems.}
|
13
|
+
spec.homepage = 'http://perforce.com'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `find . -type f -not -path '*/\.*' -not -name '*.lock'`.split
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
|
24
|
+
spec.add_runtime_dependency 'sys-proctable', '~> 0.9'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: p4util
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tristan Juricek
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sys-proctable
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
55
|
+
description: The p4util command itself provides other commands, see 'p4util help'
|
56
|
+
after install. This allows you to things like download a p4d, start it, kill it,
|
57
|
+
etc mostly for quick setup of testing systems.
|
58
|
+
email:
|
59
|
+
- tjuricek@perforce.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- "./Gemfile"
|
65
|
+
- "./LICENSE.txt"
|
66
|
+
- "./README.md"
|
67
|
+
- "./Rakefile"
|
68
|
+
- "./bin/p4util"
|
69
|
+
- "./lib/commands.rb"
|
70
|
+
- "./lib/commands/download.rb"
|
71
|
+
- "./lib/commands/help.rb"
|
72
|
+
- "./lib/commands/kill.rb"
|
73
|
+
- "./lib/commands/start.rb"
|
74
|
+
- "./lib/conventions.rb"
|
75
|
+
- "./lib/osutil.rb"
|
76
|
+
- "./lib/p4_util.rb"
|
77
|
+
- "./lib/p4_util/version.rb"
|
78
|
+
- "./p4util.gemspec"
|
79
|
+
homepage: http://perforce.com
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.2.2
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: The p4util command line app eases setup of Perforce instances, mostly for
|
103
|
+
testing.
|
104
|
+
test_files: []
|