Class: Autoproj::CLI::Query
Instance Attribute Summary
Attributes inherited from Base
#ws
Instance Method Summary
collapse
-
#find_all_matches(query, packages) ⇒ Object
-
#format_osdep_package(format, priority, name, handler, real_package_name) ⇒ Object
-
#format_source_package(format, priority, package) ⇒ Object
-
#os_package_resolver ⇒ Object
-
#query_os_packages(query_string, selected_packages, format: "$NAME", search_all: false) ⇒ Object
-
#query_source_packages(query_string, selected_packages, format: "$NAME", search_all: false, only_present: false) ⇒ Object
-
#run(query_string, format: "$NAME", search_all: false, only_present: false, osdeps: false) ⇒ Object
#finalize_setup, #initialize_and_load
Methods inherited from Base
#export_env_sh, #initialize, #normalize_command_line_package_selection, #notify_env_sh_updated, #resolve_selection, #resolve_user_selection, validate_options, #validate_options, #validate_user_selection
Methods included from Ops::Tools
#common_options, #create_autobuild_package, #load_autoprojrc, #load_main_initrb
Instance Method Details
#find_all_matches(query, packages) ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'lib/autoproj/cli/query.rb', line 11
def find_all_matches(query, packages)
matches = packages.map do |pkg|
if (priority = query.match(pkg))
[priority, pkg]
end
end.compact
matches.sort_by { |priority, pkg| [priority, pkg.name] }
end
|
68
69
70
71
72
73
74
75
|
# File 'lib/autoproj/cli/query.rb', line 68
def format_osdep_package(format, priority, name, handler, real_package_name)
fields = Hash.new
fields["NAME"] = name
fields["PRIORITY"] = priority
fields["HANDLER"] = handler
fields["REAL_PACKAGE"] = real_package_name
Autoproj.expand(format, fields)
end
|
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/autoproj/cli/query.rb', line 105
def format_source_package(format, priority, package)
autobuild_package = package.autobuild
fields = Hash.new
fields["SRCDIR"] = autobuild_package.srcdir
fields["BUILDDIR"] = if autobuild_package.respond_to?(:builddir)
autobuild_package.builddir
end
fields["PREFIX"] = autobuild_package.prefix
fields["NAME"] = package.name
fields["PRIORITY"] = priority
fields["URL"] = (package.vcs.url unless package.vcs.none?)
fields["PRESENT"] = File.directory?(autobuild_package.srcdir)
Autoproj.expand(format, fields)
end
|
#os_package_resolver ⇒ Object
7
8
9
|
# File 'lib/autoproj/cli/query.rb', line 7
def os_package_resolver
ws.os_package_resolver
end
|
#query_os_packages(query_string, selected_packages, format: "$NAME", search_all: false) ⇒ Object
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
|
# File 'lib/autoproj/cli/query.rb', line 32
def query_os_packages(query_string, selected_packages, format: "$NAME", search_all: false)
if query_string.empty?
query = OSPackageQuery.all
else
query = OSPackageQuery.parse_query(query_string.first, os_package_resolver)
end
if search_all
packages = os_package_resolver.all_package_names
else
packages = selected_packages
end
matches = find_all_matches(query, packages.to_a)
needs_real_package = (/\$REAL_PACKAGE\b/ === format)
needs_handler = (/\$HANDLER\b/ === format)
matches.each do |priority, pkg_name|
if needs_real_package || needs_handler
resolved = os_package_resolver.resolve_os_packages([pkg_name])
resolved.each do |handler, real_packages|
if needs_real_package
real_packages.each do |real_package_name|
puts format_osdep_package(format, priority, pkg_name, handler, real_package_name)
end
else
puts format_osdep_package(format, priority, pkg_name, handler, nil)
end
end
else
puts format_osdep_package(format, priority, pkg_name, nil, nil)
end
end
end
|
#query_source_packages(query_string, selected_packages, format: "$NAME", search_all: false, only_present: false) ⇒ Object
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
|
# File 'lib/autoproj/cli/query.rb', line 77
def query_source_packages(query_string, selected_packages, format: "$NAME", search_all: false, only_present: false)
if query_string.empty?
query = SourcePackageQuery.all
else
query = SourcePackageQuery.parse_query(query_string.first)
end
if search_all
packages = ws.manifest.each_package_definition.to_a
else
packages = selected_packages.map do |pkg_name|
ws.manifest.find_package_definition(pkg_name)
end
end
if only_present
packages = packages.find_all do |pkg|
File.directory?(pkg.autobuild.srcdir)
end
end
matches = find_all_matches(query, packages)
matches.each do |priority, pkg_def|
puts format_source_package(format, priority, pkg_def)
end
end
|
#run(query_string, format: "$NAME", search_all: false, only_present: false, osdeps: false) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/autoproj/cli/query.rb', line 20
def run(query_string, format: "$NAME", search_all: false, only_present: false, osdeps: false)
initialize_and_load
all_selected_packages, all_selected_osdeps_packages, * =
finalize_setup([], non_imported_packages: :return)
if osdeps
query_os_packages(query_string, all_selected_osdeps_packages, format: format, search_all: search_all)
else
query_source_packages(query_string, all_selected_packages, format: format, search_all: search_all, only_present: only_present)
end
end
|