forked from rosindex/rosindex
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathrosindex_generator.rb
1817 lines (1559 loc) · 68.1 KB
/
rosindex_generator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# encoding: UTF-8
# NOTE: This whole file is one big hack. Don't judge.
require 'pp'
require 'awesome_print'
require 'colorator'
require 'fileutils'
require 'find'
require 'nokogiri'
require 'rexml/document'
require 'rexml/xpath'
require 'pathname'
require 'uri'
require 'set'
require 'yaml'
require "net/http"
require 'thread'
# local libs
require_relative '../_ruby_libs/common'
require_relative '../_ruby_libs/rosindex'
require_relative '../_ruby_libs/vcs'
require_relative '../_ruby_libs/conversions'
require_relative '../_ruby_libs/text_rendering'
require_relative '../_ruby_libs/pages'
require_relative '../_ruby_libs/asset_parsers'
require_relative '../_ruby_libs/roswiki'
require_relative '../_ruby_libs/lunr'
require_relative '../_ruby_libs/dependency_descriptions'
$fetched_uris = {}
$debug = false
$repo_scrape = {}
DEFAULT_LANGUAGE_PREFIX = 'en'
HEAVY_CHECKMARK = "\u2714"
HEAVY_MINUS = "\u2796"
def get_ros_api(elem)
return []
end
def get_readme(site, path, raw_uri, browse_uri)
return get_md_rst_txt(site, path, "README*", raw_uri, browse_uri)
end
def get_contributing(site, path, raw_uri, browse_uri)
return get_md_rst_txt(site, path, "CONTRIBUTING*", raw_uri, browse_uri)
end
def get_changelog(site, path, raw_uri, browse_uri)
return get_md_rst_txt(site, path, "CHANGELOG*", raw_uri, browse_uri)
end
# Get a raw URI from a repo uri
def get_raw_uri(uri_s, type, branch)
uri = URI(uri_s)
case uri.host
when 'github.com'
uri_split = File.split(uri.path)
path_split = uri_split[1].rpartition('.')
repo_name = if path_split[1] == '.' then path_split[0] else path_split[-1] end
return 'https://raw.githubusercontent.com/%s/%s/%s' % [uri_split[0].sub(/^\//, ''), repo_name, branch]
when 'gitlab.com'
uri_split = File.split(uri.path)
path_split = uri_split[1].rpartition('.')
repo_name = if path_split[1] == '.' then path_split[0] else path_split[-1] end
return 'https://gitlab.com/%s/%s/-/raw/%s' % [uri_split[0].sub(/^\//, ''), repo_name, branch]
when 'bitbucket.org'
uri_split = File.split(uri.path)
return 'https://bitbucket.org/%s/%s/raw/%s' % [uri_split[0], uri_split[1], branch]
when 'code.google.com'
uri_split = File.split(uri.path)
return "https://#{uri_split[1]}.googlecode.com/#{type}-history/#{branch}/"
end
return uri_s
end
# Get a browse URI from a repo uri
def get_browse_uri(uri_s, type, branch)
uri = URI(uri_s)
case uri.host
when 'github.com'
uri_split = File.split(uri.path)
path_split = uri_split[1].rpartition('.')
repo_name = if path_split[1] == '.' then path_split[0] else path_split[-1] end
return 'https://github.com/%s/%s/tree/%s' % [uri_split[0].sub(/^\//, ''), repo_name, branch]
when 'gitlab.com'
uri_split = File.split(uri.path)
path_split = uri_split[1].rpartition('.')
repo_name = if path_split[1] == '.' then path_split[0] else path_split[-1] end
return 'https://gitlab.com/%s/%s/-/tree/%s' % [uri_split[0].sub(/^\//, ''), repo_name, branch]
when 'bitbucket.org'
uri_split = File.split(uri.path)
return 'https://bitbucket.org/%s/%s/src/%s' % [uri_split[0], uri_split[1], branch]
when 'code.google.com'
uri_split = File.split(uri.path)
return "https://code.google.com/p/#{uri_split[1]}/source/browse/?name=#{branch}##{type}/"
end
return uri_s
end
def resolve_dep(ps, ms, os, ver, data)
# resolve rosdep
# ps: platforms
# ms: package managers
# os: desired os
# ver: desired os version
# data: yaml data
if data.is_a?(Array) then return data end
if data.is_a?(Hash)
if data.key?(os) then return resolve_dep(ps, ms, os, ver, data[os]) end
if data.key?(ver) then return resolve_dep(ps, ms, os, ver, data[ver]) end
if data.key?('source') and data['source'].key?('uri') then return data['source']['uri'] end
if data.key?('packages') then return data['packages'] end
ms.each do |manager_name, manager_oss|
if ((manager_oss.include?(os) or manager_oss.size == 0) and data.key?(manager_name)) then return resolve_dep(ps, ms, os, ver, data[manager_name]) end
end
end
return []
end
def expand_package_deps(package_name, package_names, deps, distro)
# Expand package dependencies at all levels for package_name.
if deps.include?(package_name)
return
end
deps.add(package_name)
if not package_names.key?(package_name)
return
end
if not package_names[package_name].snapshots.key?(distro)
return
end
package_snapshot = package_names[package_name].snapshots[distro]
if package_snapshot
package_snapshot.data['pkg_deps'].keys.each do |dep_name|
expand_package_deps(dep_name, package_names, deps, distro)
end
end
end
class Indexer < Jekyll::Generator
def initialize(config = {})
super(config)
# lunr search config
lunr_config = {
'excludes' => [],
'strip_index_html' => false,
'min_length' => 3,
'stopwords' => '_stopwords/stop-words-english1.txt'
}.merge!(config['lunr_search'] || {})
# lunr excluded files
@excludes = lunr_config['excludes']
# if web host supports index.html as default doc, then optionally exclude it from the url
@strip_index_html = lunr_config['strip_index_html']
# stop word exclusion configuration
@min_length = lunr_config['min_length']
@stopwords_file = lunr_config['stopwords']
if File.exists?(@stopwords_file)
@stopwords = IO.readlines(@stopwords_file, :encoding=>'UTF-8').map { |l| l.strip }
else
@stopwords = []
end
end
def update_local(site, repo_instances)
# add / fetch all the instances
repo_instances.instances.each do |id, repo|
begin
unless (site.config['repo_name_whitelist'].length == 0 or site.config['repo_name_whitelist'].include?(repo.name)) then next end
unless site.config['repo_id_whitelist'].size == 0 or site.config['repo_id_whitelist'].include?(repo.id)
next
end
# open or initialize this repo
local_path = File.join(@checkout_path, repo_instances.name, id)
puts "Updating repo / instance "+repo.name+" / "+repo.id+" from uri: "+repo.uri+" into path: "+local_path
# make sure there's an actual uri
unless repo.uri
raise IndexException.new("No URI for repo instance " + id, id)
end
if @domain_blacklist.include? URI(repo.uri).hostname
msg = "Repo instance " + id + " has a blacklisted hostname: " + repo.uri.to_s
puts ('WARNING:' + msg).yellow
repo.errors << msg
next
end
(1..3).each do |attempt|
begin
# open or create a repo
vcs = get_vcs(repo)
unless (not vcs.nil? and vcs.valid?) then next end
# fetch the repo
begin
vcs.fetch()
rescue VCSException => e
msg = "Could not update repo, using old version: "+e.msg
puts ("WARNING: "+msg).yellow
repo.errors << msg
vcs.close()
end
# too many open files if we don't do this
vcs.close()
break
rescue VCSException => e
puts ("Failed to communicate with source repo after #{attempt} attempt(s)").yellow
if attempt == 3
raise IndexException.new("Could not fetch source repo: "+e.msg, id)
end
end
end
rescue IndexException => e
@errors[repo_instances.name] << e
repo.accessible = false
repo.errors << e.msg
end
end
end
def map_build_result_to_icon(build_result)
if build_result == 'success'
return 'ok'
end
if build_result == 'unstable' || build_result == 'not_built'
return 'minus'
end
if build_result == 'failure' || build_result == 'aborted'
return 'remove'
end
# TODO: use better icon for unknown build statuses
return 'remove'
end
def get_ci_data(distro, package_name, repo_name)
ci_data = Hash.new
manifest_url = "/#{DEFAULT_LANGUAGE_PREFIX}/#{distro}/api/#{package_name}/manifest.yaml"
begin
manifest_response = Net::HTTP.get_response('docs.ros.org', manifest_url)
rescue StandardError => e
puts " Failed to fetch manifest from #{manifest_url} with error #{e.class}"
ci_data['tooltip'] = 'Error fetching CI information available for this package.'
ci_data['ci_available'] = false
return ci_data
rescue
puts " Failed to fetch manifest from #{manifest_url} with unknown error"
ci_data['tooltip'] = 'Error fetching CI information available for this package.'
ci_data['ci_available'] = false
return ci_data
end
if manifest_response.code != '200'
ci_data['tooltip'] = 'No CI information available for this package.'
ci_data['ci_available'] = false
return ci_data
end
manifest_yaml = YAML.load(manifest_response.body)
if !manifest_yaml.is_a?(Hash) || !manifest_yaml.key?('devel_jobs') || manifest_yaml['devel_jobs'].length == 0
ci_data['tooltip'] = 'No CI information available for this package.'
ci_data['ci_available'] = false
return ci_data
end
ci_data['ci_available'] = true
if manifest_response.header.key?('Last-Modified')
ci_data['timestamp'] = manifest_response.header['Last-Modified']
else
ci_data['timestamp'] = 'unknown'
end
ci_data['job_url'] = manifest_yaml['devel_jobs'][0]
# get additional test information if available
results_url = "/#{DEFAULT_LANGUAGE_PREFIX}/#{distro}/devel_jobs/#{repo_name}/results.yaml"
begin
results_response = Net::HTTP.get_response('docs.ros.org', results_url)
rescue
ci_data['tooltip'] = "Latest build information: " + ci_data['timestamp'] + "\n" \
'No test statistics available for this package.'
ci_data['result'] = 'success'
ci_data['stats_available'] = false
return ci_data
end
if results_response.code != '200'
ci_data['tooltip'] = "Latest build information: " + ci_data['timestamp'] + "\n" \
'No test statistics available for this package.'
ci_data['result'] = 'success'
ci_data['stats_available'] = false
return ci_data
end
results_yaml = YAML.load(results_response.body)
if !results_yaml.is_a?(Hash) || !results_yaml.key?('dev_job_data')
ci_data['tooltip'] = "Latest build information: " + ci_data['timestamp'] + "\n" \
'No test statistics available for this package.'
ci_data['result'] = 'success'
ci_data['stats_available'] = false
return ci_data
end
ci_data['stats_available'] = true
# if we're reporting results.yaml statistics, we should use that timestamp if available
if results_response.header.key?('Last-Modified')
ci_data['timestamp'] = results_response.header['Last-Modified']
end
dev_job_data = results_yaml['dev_job_data']
latest_build = dev_job_data['latest_build']
tests_skipped = latest_build ? latest_build['skipped'] : 0
tests_failed = latest_build ? latest_build['failed'] : 0
tests_total = latest_build ? latest_build['total'] : 0
# TODO: this essentially considers skipped tests as failures
tests_ok = tests_total - tests_failed - tests_skipped
ci_data['total_builds'] = dev_job_data.key?('total_builds') ? dev_job_data['total_builds'] : 0
ci_data['health'] = dev_job_data.key?('job_health') ? dev_job_data['job_health'] : 0
ci_data['tests_ok'] = tests_ok
ci_data['tests_total'] = tests_total
ci_data['tooltip'] = "Latest build information: " + ci_data['timestamp'] + "\n" \
" Total tests: #{ tests_total }\n" \
" Succeeded: #{ tests_ok }\n" \
" Skipped: #{ tests_skipped }\n" \
" Failed: #{ tests_failed }"
if tests_failed > 0
ci_data['result'] = 'failure'
elsif tests_skipped > 0
ci_data['result'] = 'unstable'
else
ci_data['result'] = 'success'
end
if !dev_job_data.key?('history') || dev_job_data['history'].length == 0
ci_data['tooltip'] << "\nNo build history available for this repository."
ci_data['history_available'] = false
return ci_data
end
ci_data['history_available'] = true
ci_data['tooltip'] << "\nClick to show more build history."
ci_data['history'] = Array.new
dev_job_data['history'].each do |build|
build_ = Hash.new
build_['id'] = build['build_id']
build_['uri'] = build['uri']
build_['result'] = build['result']
build_['icon'] = map_build_result_to_icon(build['result'])
build_['timestamp'] = Time.at(build['stamp'].to_f).strftime('%d-%b-%Y %H:%M')
# if there is test data available (not all jobs/builds have tests),
# add it to the ci data
if build.key?('tests')
build_test_data = build['tests']
tests_skipped = build_test_data['skipped'].to_i
tests_failed = build_test_data['failed'].to_i
tests_total = build_test_data['total'].to_i
# TODO: this essentially considers skipped tests as failures
tests_ok = tests_total - tests_failed - tests_skipped
tests_health = (100.0 * tests_ok / [tests_total, 1].max).round
build_['health'] = tests_health
build_['tests_ok'] = tests_ok
build_['tests_total'] = tests_total
else
build_['health'] = 'n/a'
build_['tests_ok'] = '?'
build_['tests_total'] = '?'
end
ci_data['history'] << build_
end
return ci_data
end
def extract_package(site, distro, repo, snapshot, checkout_path, path, pkg_type, manifest_xml)
data = snapshot.data
begin
# switch basic info based on build type
if pkg_type == 'catkin'
# read the package manifest
manifest_doc = REXML::Document.new(manifest_xml)
package_name = REXML::XPath.first(manifest_doc, "/package/name/text()").to_s.strip
version = REXML::XPath.first(manifest_doc, "/package/version/text()").to_s.strip
# if a build type (e.g. ament_python for ROS 2) has been declared explicitly, use that as the package type
build_type = REXML::XPath.first(manifest_doc, "/package/export/build_type/text()").to_s.strip
unless build_type.length == 0
pkg_type = build_type
end
# get dependencies
deps = REXML::XPath.each(
manifest_doc,
"/package/build_depend/text() | " +
"/package/build_export_depend/text() | " +
"/package/buildtool_depend/text() | " +
"/package/buildtool_export_depend/text() | " +
"/package/exec_depend/text() | " +
"/package/doc_depend/text() | " +
"/package/run_depend/text() | " +
"/package/test_depend/text() | " +
"package/depend/text()"
).map { |a| a.to_s.strip }.uniq
# determine which deps are packages or system deps
pkg_deps = {}
system_deps = {}
deps.each do |dep_name|
if @rosdeps.key?(dep_name)
system_deps[dep_name] = nil
else
pkg_deps[dep_name] = nil
end
end
elsif pkg_type == 'rosbuild'
# check for a stack.xml file
stack_xml_path = File.join(path,'stack.xml')
if File.exist?(stack_xml_path)
stack_xml = IO.read(stack_xml_path)
stack_doc = REXML::Document.new(stack_xml)
package_name = REXML::XPath.first(stack_doc, "/stack/name/text()").to_s.strip
if package_name.length == 0
package_name = File.basename(File.join(path)).strip
end
version = REXML::XPath.first(stack_doc, "/stack/version/text()").to_s.strip
else
package_name = File.basename(File.join(path)).strip
version = "UNKNOWN"
end
# read the package manifest
manifest_doc = REXML::Document.new(manifest_xml)
# get dependencies
pkg_deps = Hash[*REXML::XPath.each(manifest_doc, "/package/depend/@package").map { |a| a.to_s.strip }.uniq.collect {|d| [d, nil]}.flatten]
system_deps = Hash[*REXML::XPath.each(manifest_doc, "/package/rosdep/@name").map { |a| a.to_s.strip }.uniq.collect {|d| [d, nil]}.flatten]
else
return nil
end
dputs " ---- Found #{pkg_type} package \"#{package_name}\" in path #{path}"
# extract manifest metadata (same for manifest.xml and package.xml)
license = REXML::XPath.first(manifest_doc, "/package/license/text()").to_s
description = REXML::XPath.first(manifest_doc, "/package/description/text()").to_s
maintainers = REXML::XPath.each(manifest_doc, "/package/maintainer/text()").map { |m| m.to_s.sub('@', ' <AT> ') }
authors = REXML::XPath.each(manifest_doc, "/package/author/text()").map { |a| a.to_s.sub('@', ' <AT> ') }
urls = REXML::XPath.each(manifest_doc, "/package/url").map { |elem|
{
'uri' => elem.text.to_s,
'type' => (elem.attributes['type'] or 'Website').to_s,
}
}
# extract other standard exports
deprecated = REXML::XPath.first(manifest_doc, "/package/export/deprecated/text()").to_s
# extract rosindex exports
tags = REXML::XPath.each(manifest_doc, "/package/export/rosindex/tags/tag/text()").map { |t| t.to_s }
nodes = REXML::XPath.each(manifest_doc, "/package/export/rosindex/nodes").map { |nodes|
case nodes.attributes["format"]
when "hdf"
get_hdf(nodes.text)
else
REXML::XPath.each(manifest_doc, "/package/export/rosindex/nodes/node").map { |node|
{
'name' => REXML::XPath.first(node,'/name/text()').to_s,
'description' => REXML::XPath.first(node,'/description/text()').to_s,
'ros_api' => get_ros_api(REXML::XPath.first(node,'/description/api'))
}
}
end
}
# compute the relative path from the root of the repo to this directory
package_relpath = Pathname.new(File.join(*path)).relative_path_from(Pathname.new(checkout_path))
local_package_path = Pathname.new(path)
# extract package manifest info
raw_uri = File.join(data['raw_uri'], package_relpath)
browse_uri = File.join(data['browse_uri'], package_relpath)
# extract the paths to the readme files that were explicitly declared in the package
readmes_relpath = REXML::XPath.each(manifest_doc, "/package/export/rosindex/readme/text()").map(&:to_s)
# load the package's readme for this branch if it exists
readme_file = Dir.glob(File.join(path, "README*"), File::FNM_CASEFOLD)
unless readme_file.empty? then
readmes_relpath.push(File.basename(readme_file.first))
end
# Iterate over each of the readme file paths that were explicitly declared in package
readmes = Array.new
readmes_relpath.each do |readme_relpath|
tmp_readme_rendered, tmp_readme = get_md_rst_txt(site, path, readme_relpath, raw_uri, browse_uri)
readme = {
'browse_uri' => File.join(browse_uri, readme_relpath),
'readme' => tmp_readme,
'readme_rendered' => tmp_readme_rendered
}
if package_relpath.to_s. == "." then
readme['relpath'] = readme_relpath
else
readme['relpath'] = File.join(package_relpath, readme_relpath)
end
readmes.push(readme)
end
readmes.reject! do |x|
x['readme'].nil? || x['readme_rendered'].nil?
end
# check for changelog in same directory as package.xml
changelog_rendered, changelog = get_changelog(site, path, raw_uri, browse_uri)
# TODO: don't do this for cmake-based packages
# look for launchfiles in this package
launch_files = Dir[File.join(path,'**','*.launch')]
launch_files += Dir[File.join(path,'**','*.xml')].reject do |f|
begin
REXML::Document.new(IO.read(f)).root.name != 'launch'
rescue Exception => e
true
end
end
# look for message files in this package
msg_files = Dir[File.join(path,'**','*.msg')]
# look for service files in this package
srv_files = Dir[File.join(path,'**','*.srv')]
# look for plugin descriptions in this package
plugin_data = REXML::XPath.each(manifest_doc, '//export/*[@plugin]').map {|e| {'name'=>e.name, 'file'=>e.attributes['plugin'].sub('${prefix}','')}}
launch_data = []
launch_data = launch_files.map do |f|
relative_path = Pathname.new(f).relative_path_from(local_package_path).to_s
begin
parse_launch_file(f, relative_path)
rescue Exception => e
@errors[repo.name] << IndexException.new("Failed to parse launchfile #{relative_path}: " + e.to_s)
end
end
if $ros_distros.include? distro
# ROS 1
docs_uri = "http://docs.ros.org/#{DEFAULT_LANGUAGE_PREFIX}/#{distro}/api/#{package_name}/html/"
else
# ROS 2
docs_uri = "http://docs.ros.org/#{DEFAULT_LANGUAGE_PREFIX}/#{distro}/p/#{package_name}"
end
# try to acquire information on the CI status of the package
ci_data = get_ci_data(distro, package_name, repo.name)
package_info = {
'name' => package_name,
'pkg_type' => pkg_type,
'distro' => distro,
'raw_uri' => raw_uri,
'browse_uri' => browse_uri,
'docs_uri' => docs_uri,
# required package info
'version' => version,
'license' => license,
'description' => description,
'maintainers' => maintainers,
# optional package info
'authors' => authors,
'urls' => urls,
'ci_data' => ci_data,
# dependencies
'pkg_deps' => pkg_deps,
'system_deps' => system_deps,
'dependants' => {},
# exports
'deprecated' => deprecated,
# rosindex metadata
'tags' => tags,
'nodes' => nodes,
# readme
'readmes' => readmes,
# changelog
'changelog' => changelog,
'changelog_rendered' => changelog_rendered,
# assets
'launch_data' => launch_data,
'plugin_data' => plugin_data,
'msg_files' => msg_files.map {|f| Pathname.new(f).relative_path_from(local_package_path).to_s },
'srv_files' => srv_files.map {|f| Pathname.new(f).relative_path_from(local_package_path).to_s },
'wiki' => {'exists'=>false}
}
rescue REXML::ParseException => e
@errors[repo.name] << IndexException.new("Failed to parse package manifest: " + e.to_s)
return nil
end
return package_info
end
def find_packages(site, distro, repo, snapshot, local_path)
data = snapshot.data
packages = {}
# find packages in this branch
Find.find(local_path) do |path|
if FileTest.directory?(path)
# skip certain paths
if (File.basename(path)[0] == ?.) or File.exist?(File.join(path,'CATKIN_IGNORE')) or File.exist?(File.join(path,'AMENT_IGNORE')) or File.exist?(File.join(path,'.rosindex_ignore'))
Find.prune
end
# check for package.xml in this directory
package_xml_path = File.join(path,'package.xml')
manifest_xml_path = File.join(path,'manifest.xml')
stack_xml_path = File.join(path,'stack.xml')
if File.exist?(package_xml_path)
manifest_xml = IO.read(package_xml_path)
pkg_type = 'catkin'
elsif File.exist?(manifest_xml_path)
manifest_xml = IO.read(manifest_xml_path)
pkg_type = 'rosbuild'
else
next
end
# Try to extract a package from this path
package_info = extract_package(site, distro, repo, snapshot, local_path, path, pkg_type, manifest_xml)
unless package_info.nil?
packages[package_info['name']] = package_info
dputs " -- added package " << package_info['name']
# stop searching a directory after finding a package
Find.prune
end
end
end
return packages
end
def fetch(uri_str, limit = 10)
# get an http response, accounting for redirects.
if limit <= 0 then
raise StandardError.new "Redirect limit exceeded for #{uri_str}"
end
response = Net::HTTP.get_response(URI(uri_str))
case response
when Net::HTTPSuccess
response
when Net::HTTPRedirection
fetch(response['location'], limit - 1)
else
response.error!
end
end
def scrape_repo_page(uri_s)
# Scrapes a github repository home page to get various items
begin
# cache the results since this only depends on the repo uri
if $repo_scrape.key?(uri_s) then
return $repo_scrape[uri_s]
end
repo_uri = URI(uri_s)
if repo_uri.host == 'github.com' then
response = fetch(uri_s)
document = Nokogiri::HTML(response.body)
element = document.at(".Layout-sidebar .octicon-star + strong")
if element then
star_count_f = element.text.to_f
if element.text.include? 'k' then
star_count_f = 1000 * star_count_f
end
star_count = star_count_f.to_i
else
star_count = nil
end
element = document.at('.Layout-sidebar p')
description = if element then element.text.strip else '' end
tag_elements = document.css('h3:contains("Topics") + div a')
tags = []
tag_elements.each do |element|
tags.push(element.text.strip)
end
repo_parms = {
stars: star_count,
description: description,
tags: tags,
}
else
repo_parms = {}
end
rescue => e
puts "Error in scrape_repo_page: #{ e.message } for #{ uri_s }"
repo_parms = {}
end
$repo_scrape[uri_s] = repo_parms
return repo_parms
end
# scrape a version of a repository for packages and their contents
def scrape_version(site, repo, distro, snapshot, vcs)
unless repo.uri
puts ("WARNING: no URI for "+repo.name+" "+repo.id+" "+distro).yellow
return
end
# initialize this snapshot data
repo_page = scrape_repo_page(repo.uri)
data = snapshot.data = {
# get the uri for resolving raw links (for imgages, etc)
'raw_uri' => get_raw_uri(repo.uri, repo.type, snapshot.version),
'browse_uri' => get_browse_uri(repo.uri, repo.type, snapshot.version),
# get the date of the last modification
'last_commit_time' => vcs.get_last_commit_time(),
'readme' => nil,
'readme_rendered' => nil,
'contributing' => nil,
'contributing_rendered' => nil,
'stars' => repo_page.fetch(:stars, ''),
'description' => repo_page.fetch(:description, ''),
'tags' => repo_page.fetch(:tags, []),
}
# load the repo readme for this branch if it exists
data['readme_rendered'], data['readme'] = get_readme(
site, vcs.local_path, data['raw_uri'], data['browse_uri'])
# load the repo CONTRIBUTING.md for this branch if it exists
data['contributing_rendered'], data['contributing'] = get_contributing(
site, vcs.local_path, data['raw_uri'], data['browse_uri'])
unless repo.release_manifests[distro].nil?
package_info = extract_package(site, distro, repo, snapshot, vcs.local_path, vcs.local_path, 'catkin', repo.release_manifests[distro])
packages = {package_info['name'] => package_info}
else
packages = find_packages(site, distro, repo, snapshot, vcs.local_path)
end
# get all packages from the repo
# TODO: check if the repo has a release manifest for this distro, and in
# that case, use that file for package info
# TODO: split `find_packages` out into two functions:
# find_packages (get a list of all package paths in this repo)
# scrape_package (extract info from this package) (maybe just move this into the loop below)
# add the discovered packages to the index
packages.each do |package_name, package_data|
# create a new package snapshot
package = PackageSnapshot.new(package_name, repo, snapshot, package_data)
# store this package in the repo snapshot
snapshot.packages[package_name] = package
# collect tags from discovered packages
repo.tags = Set.new(repo.tags).merge(package_data['tags'])
# add any tags placed on a repo
repo.tags = repo.tags.merge(data['tags']).to_a
# collect wiki data
package.data['wiki'] = @wiki_data[package_name]
# add this package to the global package dict
@package_names[package_name].instances[repo.id] = repo
@package_names[package_name].tags = Set.new(@package_names[package_name].tags).merge(package_data['tags']).to_a
# add this package as the default for this distro
if @repo_names[repo.name].default
dputs " --- Setting repo instance " << repo.id << "as default for package " << package_name << " in distro " << distro
@package_names[package_name].repos[distro] = repo
@package_names[package_name].snapshots[distro] = package
end
end
end
def scrape_repo(site, repo)
if @domain_blacklist.include? URI(repo.uri).hostname
msg = "Repo instance " + repo.id + " has a blacklisted hostname: " + repo.uri.to_s
puts ('WARNING:' + msg).yellow
repo.errors << msg
return
end
# open or initialize this repo
begin
vcs = get_vcs(repo)
rescue VCSException => e
raise IndexException.new(e.msg, repo.id)
end
if (vcs.nil? or not vcs.valid?) then return end
some_version_found = false
# get versions suitable for checkout for each distro
repo.snapshots.each do |distro, snapshot|
# get explicit version (this is either set or nil)
explicit_version = snapshot.version
if explicit_version.nil?
dputs " -- no explicit version for distro " << distro << " looking for implicit version "
else
dputs " -- looking for version " << explicit_version.to_s << " for distro " << distro
end
begin
# get the version
unless explicit_version.nil?
dputs (" Looking for explicit version #{explicit_version}").green
end
version, snapshot.version = vcs.get_version(explicit_version)
# scrape the data (packages etc)
if version
puts (" --- scraping version for " << repo.name << " instance: " << repo.id << " distro: " << distro).blue
# check out this branch
vcs.checkout(version)
# check for ignore file
if File.exist?(File.join(vcs.local_path,'.rosindex_ignore'))
puts (" --- ignoring version for " << repo.name).yellow
snapshot.version = nil
else
some_version_found = true
scrape_version(site, repo, distro, snapshot, vcs)
end
else
dputs (" --- no version for " << repo.name << " instance: " << repo.id << " distro: " << distro).yellow
end
rescue VCSException => e
@errors[repo.name] << IndexException.new("Could not find version for distro #{distro}: "+e.msg, repo.id)
repo.errors << e.msg
end
end
if not some_version_found
msg = "Could not find any valid version."
@errors[repo.name] << IndexException.new(msg, repo.id)
repo.errors << (repo.id+': '+msg)
end
end
class SystemDep < Liquid::Drop
# This represents a system dependency ("rosdep")
attr_accessor :name, :repo, :snapshot, :version, :data
def initialize(name, repo, snapshot, data)
@name = name
# TODO: get rid of these back-pointers
@repo = repo
@snapshot = snapshot
@version = snapshot.version
# additionally-collected data
@data = data
end
end
def load_rosdeps(rosdistro_path, platforms, package_manager_names)
# this returns
# see here for parsing this thing: http://www.ros.org/reps/rep-0111.html
rosdep_data = Hash.new
manager_set = Set.new(package_manager_names)
Dir.glob(File.join(rosdistro_path,'rosdep','*.yaml')) do |rosdep_filename|
rosdep_yaml = YAML.load_file(rosdep_filename)
rosdep_data = rosdep_data.deep_merge(rosdep_yaml)
end
# update the platforms list
new_platforms = {}
# look for new platforms and versions
rosdep_data.each do |name, deps|
# iterate over platform names
deps.each do |platform_name, platform_deps|
if package_manager_names.include? platform_name then next end
unless new_platforms.key?(platform_name) then new_platforms[platform_name] = {'versions'=>[]} end
unless platform_deps.is_a?(Hash) then next end
if platform_deps.key?('packages') then next end
if platform_deps.key?('source') then next end
if manager_set.intersection(platform_deps.keys).length > 0 then next end
# iterate over version names
platform_deps.each do |version_or_manager_name, version_deps|
# add this version name
new_platforms[platform_name]['versions'] |= [version_or_manager_name]
end
end
end
dputs "New Platforms: "
dputs YAML.dump(new_platforms)
return rosdep_data
end
def generate_search_deps_list(site)
site.pages << SearchDepsListPage.new(site)
end
def generate_sorted_paginated_deps(site, elements_sorted, default_sort_key, n_elements, elements_per_page, page_class)
n_pages = (n_elements / elements_per_page).floor + 1
(1..n_pages).each do |page_index|
p_start = (page_index-1) * elements_per_page
elements_sliced = elements_sorted.slice(p_start, elements_per_page)
site.pages << page_class.new(site, default_sort_key, n_pages, page_index, elements_sliced)
# create page 1 without a page number or key in the url
if page_index == 1
site.pages << page_class.new(site, default_sort_key, n_pages, page_index, elements_sliced, true)
end
end
end
def generate_sorted_paginated(site, elements_sorted, default_sort_key, n_elements, elements_per_page, page_class)
n_pages = (n_elements / elements_per_page).floor + 1
(1..n_pages).each do |page_index|
p_start = (page_index-1) * elements_per_page
elements_sorted.each do |sort_key, elements|
# Get a subset of the elements
elements_sliced = Hash[
elements.collect do |distro, elements_in_distro|
[distro, elements_in_distro.slice(p_start, elements_per_page)]
end
]
site.pages << page_class.new(site, sort_key, n_pages, page_index, elements_sliced)
# create page 1 without a page number or key in the url
if sort_key == default_sort_key and page_index == 1
site.pages << page_class.new(site, sort_key, n_pages, page_index, elements_sliced, true)
end
end
end
end
def sort_repos(site)
repos_sorted = {'name' => {}, 'time' => {}, 'released' => {}}
repos_sorted_by_name = @repo_names.sort_by { |name, _| name }
$all_distros.collect do |distro|
repos_sorted['name'][distro] = repos_sorted_by_name
repos_sorted['time'][distro] = \
repos_sorted['name'][distro].sort_by do |_, instances|
instances.default.snapshots.select do |d, s|
distro == d and not s.nil?
end.map do |d,s|
s.data['last_commit_time'].to_s
end.max.to_s
end.reverse
repos_sorted['released'][distro] = \
repos_sorted['name'][distro].sort_by do |_, instances|
instances.default.snapshots.count do |d, s|
d == distro and not s.nil? and s.released
end
end.reverse
end
return repos_sorted
end
def sort_repos_filtered(site, filter)
repos_sorted = {'name' => {}, 'time' => {}, 'doc' => {}, 'released' => {}}
repos_filtered = @repo_names.select { |key,_| filter.include? key }
repos_sorted_by_name = repos_filtered.sort_by { |name, _| name }
$all_distros.collect do |distro|
repos_sorted['name'][distro] = repos_sorted_by_name
repos_sorted['time'][distro] = \
repos_sorted['name'][distro].sort_by do |_, instances|
instances.default.snapshots.select do |d, s|