lib/ass_launcher/support/shell.rb in ass_launcher-0.3.4 vs lib/ass_launcher/support/shell.rb in ass_launcher-0.4.0
- old
+ new
@@ -61,10 +61,11 @@
l = Logger.new($stderr)
l.level = DEFAULT_LEVEL
l
end
end
+
module Support
# Shell utils for run 1C:Enterprise binary
module Shell
# TODO: delete it see todo in platform #cygpath func
class RunError < StandardError; end
@@ -100,12 +101,12 @@
attr_reader :cmd, :args, :ass_out_file, :options
attr_accessor :process_holder
private :process_holder=
private :ass_out_file
DEFAULT_OPTIONS = { silent_mode: true,
- capture_assout: true
- }
+ capture_assout: true,
+ disable_auto_check_version: true}.freeze
# @param cmd [String] path to 1C binary
# @param args [Array] arguments for 1C binary
# @option options [String] :assout_encoding encoding for assoutput file.
# Default 'cp1251'
# @option options [Boolean] :capture_assout capture assoutput.
@@ -113,16 +114,17 @@
# @option options [Boolean]:silent_mode run 1C with
# /DisableStartupDialogs and /DisableStartupMessages parameters.
# Default true
# @raise [ArgumentError] when +capture_assout: true+ and +args+
# include +/OUT+ parameter
+ # @api private
def initialize(cmd, args = [], options = {})
@options = DEFAULT_OPTIONS.merge(options).freeze
@cmd = cmd
@args = args
validate_args
- @args += _silent_mode
+ @args += (_silent_mode + _disable_auto_check_version)
@ass_out_file = _ass_out_file
end
def validate_args
fail ArgumentError,
@@ -157,10 +159,19 @@
def run(options = {})
return process_holder if running?
ProcessHolder.run(self, options)
end
+ def _disable_auto_check_version
+ if options[:disable_auto_check_version]
+ ['/AppAutoCheckVersion-', '']
+ else
+ []
+ end
+ end
+ private :_disable_auto_check_version
+
def _silent_mode
if options[:silent_mode]
['/DisableStartupDialogs', '',
'/DisableStartupMessages', '']
else
@@ -192,10 +203,13 @@
def exit_handling(exitstatus, out, err)
RunAssResult.new(exitstatus, encode_out(out),
encode_out(err), ass_out_file.read)
end
+ # @todo It's stub returns +out+ directly
+ # but may be require encoding out
+ # encoding must executed in try block
def encode_out(out)
out
end
private :encode_out
end
@@ -375,13 +389,19 @@
attr_reader :file, :path, :encoding
def initialize(encoding = nil)
@file = Tempfile.new('ass_out')
@file.close
@path = platform.path(@file.path)
- @encoding = encoding || Encoding::CP1251
+ @encoding = encoding || detect_ass_encoding
end
+ # @todo It's stub returns the CP1251 encoding
+ # but requires to detect 1C out encoding automatically
+ def detect_ass_encoding
+ Encoding::CP1251
+ end
+
def to_s
@path.to_s
end
def read
@@ -389,12 +409,19 @@
@file.open
s = @file.read
s.encode! Encoding::UTF_8, encoding unless linux?
ensure
@file.close
- @file.unlink
+ try_unlink
end
s.to_s
+ end
+
+ # File can be busy
+ def try_unlink
+ @file.unlink if @file
+ rescue Errno::EBUSY
+ # NOP
end
end
end
end
end