Skip to content

Commit

Permalink
Merge pull request #9270 from AriaXLi/PUP-11993/style_cops_R
Browse files Browse the repository at this point in the history
(PUP-11993) Style Cops - R
  • Loading branch information
joshcooper authored Mar 1, 2024
2 parents 95abb8a + be2c3e6 commit d068941
Show file tree
Hide file tree
Showing 174 changed files with 1,336 additions and 1,688 deletions.
46 changes: 0 additions & 46 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -646,52 +646,6 @@ Style/OptionalBooleanParameter:
Style/PreferredHashMethods:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, AllowedCompactTypes.
# SupportedStyles: compact, exploded
Style/RaiseArgs:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
Style/RedundantAssignment:
Exclude:
- 'lib/puppet/file_serving/mount/locales.rb'
- 'lib/puppet/file_serving/mount/pluginfacts.rb'
- 'lib/puppet/file_serving/mount/plugins.rb'
- 'lib/puppet/parameter.rb'
- 'lib/puppet/parser/ast/pops_bridge.rb'
- 'lib/puppet/pops/model/factory.rb'
- 'lib/puppet/pops/parser/parser_support.rb'
- 'lib/puppet/provider/nameservice/directoryservice.rb'
- 'lib/puppet/provider/nameservice/objectadd.rb'
- 'lib/puppet/provider/nameservice/pw.rb'
- 'lib/puppet/settings.rb'
- 'lib/puppet/type.rb'
- 'lib/puppet/type/file/ensure.rb'
- 'lib/puppet/util.rb'
- 'lib/puppet/util/execution.rb'

# This cop supports safe auto-correction (--auto-correct).
Style/RedundantBegin:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
Style/RedundantCondition:
Exclude:
- 'ext/windows/service/daemon.rb'
- 'lib/puppet/application/describe.rb'
- 'lib/puppet/environments.rb'
- 'lib/puppet/external/dot.rb'
- 'lib/puppet/graph/simple_graph.rb'
- 'lib/puppet/indirector/request.rb'
- 'lib/puppet/parser/templatewrapper.rb'
- 'lib/puppet/provider/package/blastwave.rb'
- 'lib/puppet/provider/package/pkgutil.rb'
- 'lib/puppet/provider/package/portage.rb'
- 'lib/puppet/type.rb'
- 'lib/puppet/util/command_line/trollop.rb'
- 'lib/puppet/util/inifile.rb'

# This cop supports safe auto-correction (--auto-correct).
Style/RedundantConditional:
Exclude:
Expand Down
94 changes: 44 additions & 50 deletions ext/windows/service/daemon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,23 @@ def service_main(*argsv)

service = self
@run_thread = Thread.new do
begin
while service.running? do
runinterval = service.parse_runinterval(ruby_puppet_cmd)

if service.state == RUNNING or service.state == IDLE
service.log_notice("Executing agent with arguments: #{args}")
pid = Process.create(:command_line => "#{ruby_puppet_cmd} agent --onetime #{args}", :creation_flags => CREATE_NEW_CONSOLE).process_id
service.log_debug("Process created: #{pid}")
else
service.log_debug("Service is paused. Not invoking Puppet agent")
end

service.log_debug("Service worker thread waiting for #{runinterval} seconds")
sleep(runinterval)
service.log_debug('Service worker thread woken up')
while service.running? do
runinterval = service.parse_runinterval(ruby_puppet_cmd)

if service.state == RUNNING or service.state == IDLE
service.log_notice("Executing agent with arguments: #{args}")
pid = Process.create(:command_line => "#{ruby_puppet_cmd} agent --onetime #{args}", :creation_flags => CREATE_NEW_CONSOLE).process_id
service.log_debug("Process created: #{pid}")
else
service.log_debug("Service is paused. Not invoking Puppet agent")
end
rescue Exception => e
service.log_exception(e)

service.log_debug("Service worker thread waiting for #{runinterval} seconds")
sleep(runinterval)
service.log_debug('Service worker thread woken up')
end
rescue Exception => e
service.log_exception(e)
end
@run_thread.join
rescue Exception => e
Expand Down Expand Up @@ -142,20 +140,18 @@ def log(msg, level)
end

def report_windows_event(type, id, message)
begin
eventlog = nil
eventlog = Puppet::Util::Windows::EventLog.open("Puppet")
eventlog.report_event(
:event_type => type, # EVENTLOG_ERROR_TYPE, etc
:event_id => id, # 0x01 or 0x02, 0x03 etc.
:data => message # "the message"
)
rescue Exception
# Ignore all errors
ensure
unless eventlog.nil?
eventlog.close
end
eventlog = nil
eventlog = Puppet::Util::Windows::EventLog.open("Puppet")
eventlog.report_event(
:event_type => type, # EVENTLOG_ERROR_TYPE, etc
:event_id => id, # 0x01 or 0x02, 0x03 etc.
:data => message # "the message"
)
rescue Exception
# Ignore all errors
ensure
unless eventlog.nil?
eventlog.close
end
end

Expand Down Expand Up @@ -186,30 +182,28 @@ def parse_log_level(puppet_path, cmdline_debug)
loglevel = :notice
end

LEVELS.index(cmdline_debug ? cmdline_debug : loglevel.to_sym)
LEVELS.index(cmdline_debug || loglevel.to_sym)
end

private

def load_env(base_dir)
begin
# ENV that uses backward slashes
ENV['FACTER_env_windows_installdir'] = base_dir.tr('/', '\\')
ENV['PL_BASEDIR'] = base_dir.tr('/', '\\')
ENV['PUPPET_DIR'] = File.join(base_dir, 'puppet').tr('/', '\\')
ENV['OPENSSL_CONF'] = File.join(base_dir, 'puppet', 'ssl', 'openssl.cnf').tr('/', '\\')
ENV['SSL_CERT_DIR'] = File.join(base_dir, 'puppet', 'ssl', 'certs').tr('/', '\\')
ENV['SSL_CERT_FILE'] = File.join(base_dir, 'puppet', 'ssl', 'cert.pem').tr('/', '\\')
ENV['Path'] = [
File.join(base_dir, 'puppet', 'bin'),
File.join(base_dir, 'bin'),
].join(';').tr('/', '\\') + ';' + ENV.fetch('Path', nil)

# ENV that uses forward slashes
ENV['RUBYLIB'] = "#{File.join(base_dir, 'puppet', 'lib')};#{ENV.fetch('RUBYLIB', nil)}"
rescue => e
log_exception(e)
end
# ENV that uses backward slashes
ENV['FACTER_env_windows_installdir'] = base_dir.tr('/', '\\')
ENV['PL_BASEDIR'] = base_dir.tr('/', '\\')
ENV['PUPPET_DIR'] = File.join(base_dir, 'puppet').tr('/', '\\')
ENV['OPENSSL_CONF'] = File.join(base_dir, 'puppet', 'ssl', 'openssl.cnf').tr('/', '\\')
ENV['SSL_CERT_DIR'] = File.join(base_dir, 'puppet', 'ssl', 'certs').tr('/', '\\')
ENV['SSL_CERT_FILE'] = File.join(base_dir, 'puppet', 'ssl', 'cert.pem').tr('/', '\\')
ENV['Path'] = [
File.join(base_dir, 'puppet', 'bin'),
File.join(base_dir, 'bin'),
].join(';').tr('/', '\\') + ';' + ENV.fetch('Path', nil)

# ENV that uses forward slashes
ENV['RUBYLIB'] = "#{File.join(base_dir, 'puppet', 'lib')};#{ENV.fetch('RUBYLIB', nil)}"
rescue => e
log_exception(e)
end
end

Expand Down
12 changes: 5 additions & 7 deletions lib/puppet/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def find(application_name)
################################################################

if clazz.nil?
raise Puppet::Error.new(_("Unable to load application class '%{class_name}' from file 'puppet/application/%{application_name}.rb'") % { class_name: class_name, application_name: application_name })
raise Puppet::Error, _("Unable to load application class '%{class_name}' from file 'puppet/application/%{application_name}.rb'") % { class_name: class_name, application_name: application_name }
end

return clazz
Expand Down Expand Up @@ -481,12 +481,10 @@ def handle_logdest_arg(arg)
Puppet[:logdest] = arg

logdest.each do |dest|
begin
Puppet::Util::Log.newdestination(dest)
options[:setdest] = true
rescue => detail
Puppet.log_and_raise(detail, _("Could not set logdest to %{dest}.") % { dest: arg })
end
Puppet::Util::Log.newdestination(dest)
options[:setdest] = true
rescue => detail
Puppet.log_and_raise(detail, _("Could not set logdest to %{dest}.") % { dest: arg })
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/application/describe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def wrap(txt, opts)
return "" unless txt && !txt.empty?

work = (opts[:scrub] ? scrub(txt) : txt)
indent = (opts[:indent] ? opts[:indent] : 0)
indent = (opts[:indent] || 0)
textLen = @width - indent
patt = Regexp.new("\\A(.{0,#{textLen}})[ \n]")
prefix = " " * indent
Expand Down
Loading

0 comments on commit d068941

Please sign in to comment.