p4tools 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
1
+ require_relative 'validators/shelve_validator'
2
+
3
+ module P4Tools
4
+ module CommandUtils
5
+
6
+ # @param [Integer] changelist
7
+ # @param [Boolean] check_diff
8
+ # @return [Boolean]
9
+ def all_files_shelved?(changelist, check_diff=false)
10
+ validator = ShelveValidator.new(changelist, check_diff)
11
+ validator.valid?
12
+ end
13
+
14
+ # @param [Integer] changelist
15
+ # @return [Boolean]
16
+ def empty_changelist?(changelist)
17
+ p4 = P4Tools.connection
18
+ opened_files = p4.run(%W{ describe -s #{changelist} })[0]['depotFile']
19
+ opened_files.nil?
20
+ end
21
+
22
+ # @param [String] description
23
+ # @return [String]
24
+ # The number of the new changelist
25
+ def create_new_changelist(description='Created with P4Tools.')
26
+ p4 = P4Tools.connection
27
+
28
+ p4.input = {
29
+ 'Change' => 'new',
30
+ 'Description' => description,
31
+ }
32
+
33
+ confirmation = p4.run('change', '-i').first
34
+ confirmation.match(/\d+/)[0]
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,15 @@
1
+ module P4Tools
2
+ module Utils
3
+ # @param [String] string
4
+ # @return [String]
5
+ def self.classify(string)
6
+ string.gsub(/(^|_)(.)/) { $2.upcase }
7
+ end
8
+
9
+ # @param [String] string
10
+ def self.require_original(file)
11
+ require COMMANDS_ROOT + File::SEPARATOR + File.basename(file)
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,39 @@
1
+ module P4Tools
2
+ class ShelveValidator
3
+
4
+ def initialize(changelist, check_diff)
5
+ @changelist = changelist
6
+ @check_diff = check_diff
7
+ end
8
+
9
+ # @return [Boolean]
10
+ def valid?
11
+ @p4 = P4Tools.connection
12
+ @opened_files = @p4.run(%W{ describe -s #{@changelist} })[0]['depotFile']
13
+ @shelved_files = @p4.run(%W{ describe -s -S #{@changelist} })[0]['depotFile']
14
+
15
+ @opened_files.nil? || (!@shelved_files.nil? && all_opened_files_shelved? && files_are_identical?)
16
+ end
17
+
18
+ private
19
+
20
+ # @return [Boolean]
21
+ def all_opened_files_shelved?
22
+ (@opened_files - @shelved_files).empty?
23
+ end
24
+
25
+ # @return [Boolean]
26
+ def files_are_identical?
27
+ if @check_diff
28
+ intersection = @shelved_files & @opened_files
29
+
30
+ intersection.each do |file|
31
+ diff = @p4.run(%W{ diff -Od #{file}@=#{@changelist} })
32
+ return false unless diff.empty?
33
+ end
34
+ end
35
+
36
+ true
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,18 @@
1
+ module P4Tools
2
+ module WindowManager
3
+ def self.refresh
4
+ try_require
5
+
6
+ window = RAutomation::Window.new(:title => /Perforce P4V/i)
7
+ window.send_keys(:f5) if window.exist?
8
+ end
9
+
10
+ def self.try_require
11
+ begin
12
+ require 'rautomation'
13
+ rescue
14
+ raise(LoadError, "To use this module please install the 'rautomation' gem, version '0.14.1'. It might not work with other versions. Use command: 'gem install rautomation -v 0.14.1'")
15
+ end
16
+ end
17
+ end
18
+ end
data/p4tools.gemspec ADDED
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = 'p4tools'
3
+ gem.version = '0.1.1'
4
+
5
+ gem.author = ['Norbert Csibra']
6
+ gem.email = 'napispam@gmail.com'
7
+ gem.homepage = 'https://github.com/ncsibra/P4Tools'
8
+ gem.summary = 'Simple command line tool to run custom perforce commands.'
9
+ gem.description = %q{Simple command line tool to run custom perforce commands. }
10
+ gem.files = `git ls-files`.split($/).delete_if {|file| file =~ %r{^gem/|^lib/commands/custom/}}
11
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
12
+ gem.require_paths = ["lib"]
13
+
14
+ gem.add_runtime_dependency('P4Ruby-mingwx86', "~> 2014.1")
15
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: p4tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Norbert Csibra
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-04-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: P4Ruby-mingwx86
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2014.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2014.1'
30
+ description: ! 'Simple command line tool to run custom perforce commands. '
31
+ email: napispam@gmail.com
32
+ executables:
33
+ - p4tools
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - bin/p4tools
40
+ - lib/commands/move.rb
41
+ - lib/commands/revert.rb
42
+ - lib/commands/shelve.rb
43
+ - lib/config/README
44
+ - lib/p4_tools.rb
45
+ - lib/p4tools/environment.rb
46
+ - lib/p4tools/p4_delegate.rb
47
+ - lib/p4tools/parsers/command_entry.rb
48
+ - lib/p4tools/parsers/command_options.rb
49
+ - lib/p4tools/parsers/command_parser.rb
50
+ - lib/p4tools/parsers/trollop_custom.rb
51
+ - lib/p4tools/utils/command_utils.rb
52
+ - lib/p4tools/utils/utils.rb
53
+ - lib/p4tools/utils/validators/shelve_validator.rb
54
+ - lib/p4tools/utils/window_manager.rb
55
+ - p4tools.gemspec
56
+ homepage: https://github.com/ncsibra/P4Tools
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 1.8.28
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Simple command line tool to run custom perforce commands.
80
+ test_files: []