modified version of jenkins debian glue (https://github.com/mika/jenkins-debian-glue) for devuan
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

97 lines
2.0 KiB

  1. #!/usr/bin/env ruby
  2. # encoding: utf-8
  3. # ruby1.8 doesn't provide Encoding, so make sure it's defined
  4. if defined? Encoding
  5. output_encoding = Encoding.default_external
  6. Encoding.default_external = 'BINARY'
  7. end
  8. require 'yaml'
  9. if ARGV[0].nil?
  10. $stderr.puts "Usage: #{File.basename $0} <file>"
  11. exit 1
  12. end
  13. if not system "which pep8 >/dev/null 2>&1"
  14. $stderr.puts "Error: program pep8 does not exist (install pep8 package)."
  15. exit 1
  16. end
  17. file = ARGV[0]
  18. if not File.exists? file
  19. $stderr.puts "Error: file #{file} could not be read."
  20. exit 1
  21. end
  22. # Make sure we're looking at Python code.
  23. mimetype = `file -b -i --keep-going #{file}`.gsub(/\n/,"")
  24. if not /.*x-python/i.match(mimetype)
  25. $stderr.puts "File #{file} doesn't look like Python [#{mimetype}]. Ignoring."
  26. exit 0
  27. end
  28. ISSUE_PREFIX = 'ISSUE:'
  29. output = %x{pep8 -r --show-source --format 'ISSUE:%(path)s:%(row)d:%(col)d: %(code)s %(text)s' #{file} 2>&1}
  30. def is_issue_line(l)
  31. l.start_with?(ISSUE_PREFIX)
  32. end
  33. class Issue
  34. def initialize(firstline, file)
  35. @firstline = firstline.sub(ISSUE_PREFIX, '')
  36. @file = file
  37. @source = []
  38. @code = @firstline.split(': ', 3)[1]
  39. @severity = case @code[0]
  40. when 'E'
  41. 'error'
  42. when 'W'
  43. 'warning'
  44. end
  45. end
  46. def add_source(line)
  47. @source << line
  48. end
  49. def format(counter)
  50. body = YAML.dump({
  51. 'message' => @firstline,
  52. 'severity' => @severity,
  53. 'code' => @code,
  54. 'source' => @source.join("\n"),
  55. 'file' => @file
  56. }) + '...' # end of yaml
  57. return ("not ok #{counter} #{@firstline}\n " + body.gsub("\n","\n "))
  58. end
  59. end
  60. issues = []
  61. output.each_line do |l|
  62. if defined? Encoding
  63. l = l.rstrip().encode(output_encoding, {:invalid => :replace, :undef => :replace})
  64. else
  65. l = l.rstrip()
  66. end
  67. if is_issue_line(l)
  68. issues << Issue.new(l, file)
  69. else
  70. issues.last.add_source(l) unless issues.last.nil?
  71. end
  72. end
  73. exit 0 if issues.length == 0
  74. # output result in TAP format
  75. puts "TAP version 13"
  76. puts "1..#{issues.length}"
  77. issues.each_index do |idx|
  78. puts issues[idx].format(idx+1)
  79. end