Class: RSCM::Accurev::Command
- Inherits:
-
Object
- Object
- RSCM::Accurev::Command
- Defined in:
- lib/rscm/scm/accurev/command.rb
Overview
Executes accurev commands and deals with the output. This class is a thread local singleton: each thread calling Command.instance
gets a different instance.
Instance Attribute Summary collapse
-
#accurev_bin ⇒ Object
Returns the value of attribute accurev_bin.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#debug_to ⇒ Object
Returns the value of attribute debug_to.
-
#xmlmapper ⇒ Object
If you need to swap out the mapper class.
Class Method Summary collapse
-
.discard ⇒ Object
Discard the current thread’s Command object.
-
.instance {|| ... } ⇒ Object
Retrieve this thread’s
Command
instance.
Instance Method Summary collapse
-
#accurev(cmd, *opts) ⇒ Object
Execute the given accurev subcommand using
accurev_xml
, and return an object tree mirroring the structure of the XML output. -
#accurev_cmdline(cmd, *opts) ⇒ Object
Returns a command line string for executing the given accurev subcomment
cmd
with argumentsopts
. -
#accurev_nofx(cmd, *opts) ⇒ Object
Executes the given accurev subcommand
cmd
with the given argumentsopts
. -
#accurev_xml(cmd, *opts) ⇒ Object
Executes the given accurev subcommand
cmd
with the given argumentsopts
in XML mode. -
#initialize ⇒ Command
constructor
A new instance of Command.
Constructor Details
Instance Attribute Details
#accurev_bin ⇒ Object
Returns the value of attribute accurev_bin.
13 14 15 |
# File 'lib/rscm/scm/accurev/command.rb', line 13 def accurev_bin @accurev_bin end |
#debug ⇒ Object
Returns the value of attribute debug.
13 14 15 |
# File 'lib/rscm/scm/accurev/command.rb', line 13 def debug @debug end |
#debug_to ⇒ Object
Returns the value of attribute debug_to.
13 14 15 |
# File 'lib/rscm/scm/accurev/command.rb', line 13 def debug_to @debug_to end |
#xmlmapper ⇒ Object
If you need to swap out the mapper class
16 17 18 |
# File 'lib/rscm/scm/accurev/command.rb', line 16 def xmlmapper @xmlmapper end |
Class Method Details
.discard ⇒ Object
Discard the current thread’s Command object. The next call to Command.instance
in this thread will return a new instance configured with the defaults.
135 136 137 |
# File 'lib/rscm/scm/accurev/command.rb', line 135 def Command.discard() Thread.current[ :RSCM_ACCUREV_COMMAND ] = nil end |
.instance {|| ... } ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/rscm/scm/accurev/command.rb', line 124 def Command.instance() if Thread.current[ :RSCM_ACCUREV_COMMAND ].nil? Thread.current[ :RSCM_ACCUREV_COMMAND ] = Command.new end yield Thread.current[ :RSCM_ACCUREV_COMMAND ] if block_given? return Thread.current[ :RSCM_ACCUREV_COMMAND ] end |
Instance Method Details
#accurev(cmd, *opts) ⇒ Object
Execute the given accurev subcommand using accurev_xml
, and return an object tree mirroring the structure of the XML output.
This uses XMLMapper
to build the object tree.
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rscm/scm/accurev/command.rb', line 100 def accurev( cmd, *opts ) doc = self.accurev_xml( cmd, opts ) if @debug @debug_to.puts( "doc>" ) @debug_to.puts( doc ) end if doc.elements.size==0 raise "Unexpected output from #{cmd}: #{doc}" end mapper = @xmlmapper.new() return mapper.map( doc.root ) end |
#accurev_cmdline(cmd, *opts) ⇒ Object
Returns a command line string for executing the given accurev subcomment cmd
with arguments opts
.
29 30 31 |
# File 'lib/rscm/scm/accurev/command.rb', line 29 def accurev_cmdline( cmd, *opts ) return "#{@accurev_bin} #{cmd} #{opts.join(' ')}"; end |
#accurev_nofx(cmd, *opts) ⇒ Object
Executes the given accurev subcommand cmd
with the given arguments opts
. The command will be executed with standard (non-xml) output format. This method returns the stdout from the command execution.
(Not all accurev subcommands (eg, ‘accurev info`) support `-fx` for xml output.)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rscm/scm/accurev/command.rb', line 42 def accurev_nofx( cmd, *opts ) ## # nativepath_to_filepath is actually generic to native ## dir = PathConverter.nativepath_to_filepath( @working_dir ) ## dir = File.expand_path( dir ) ## with_working_dir( dir ) do cmdline = self.accurev_cmdline( cmd, opts ) if @debug @debug_to.puts("ac> #{cmdline}") end Better.popen( cmdline ) do |stdout| return stdout.read() end ## end end |
#accurev_xml(cmd, *opts) ⇒ Object
Executes the given accurev subcommand cmd
with the given arguments opts
in XML mode. The output of the command will be converted to an REXML document and returned. The command’s options list will have ‘-fx` appended, to specify xml output format.
Certain quirks in <AcResponse>-type documents will be corrected (see Accurev::AcXMLScrubIO). Note that not all accurev subcommands support the “-fx” option.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rscm/scm/accurev/command.rb', line 68 def accurev_xml( cmd, *opts ) opts << "-fx" ## # nativepath_to_filepath is actually generic to native ## dir = PathConverter.nativepath_to_filepath( @working_dir ) ## dir = File.expand_path( dir ) ## with_working_dir( dir ) do cmdline = self.accurev_cmdline( cmd, opts ) if @debug @debug_to.puts("ac> #{cmdline}") end Better.popen( cmdline ) do |stdout| output = stdout.read() if @debug @debug_to.puts( "raw>" ) @debug_to.puts( output ) end begin return REXML::Document.new( AcXMLScrubIO.new( output ) ) rescue Exception => e raise "Unexpected output from #{cmdline}: #{e}" end end ## end end |