Skip to content
Snippets Groups Projects
Unverified Commit dc92286e authored by Paul Wise's avatar Paul Wise
Browse files

Add option to disable updating the cache when it is populated

This makes running how-can-i-help multiple times in a loop faster.

This is most useful for running how-can-i-help on the data from
multiple different hosts; first run for the local system,
updating the cache then run once for each set of packages
without hitting the network to update the cache each time.
parent 8d553de2
No related branches found
Tags 0.109
No related merge requests found
......@@ -44,6 +44,7 @@ $old = false
$kas = false
$apt = false
$show = []
$download = true
$proxy_url = ENV['HTTP_PROXY'] || ENV['http_proxy']
optparse = OptionParser.new do |opts|
......@@ -88,6 +89,10 @@ optparse = OptionParser.new do |opts|
$show = show
end
opts.on("--[no-]download", "Enable/disable cache update when cache is populated") do |download|
$download = download
end
end
optparse.parse!
......@@ -145,15 +150,17 @@ http_object = Net::HTTP.new(uri.host, uri.port, proxy_uri.host, proxy_uri.port,
http_object.use_ssl = uri.scheme == 'https'
# proceeding get_response
begin
response = http_object.request(request)
rescue
puts "how-can-i-help: Error downloading data file: #{$!}"
exit(1)
unless $download == false && File::exists?(CACHE)
begin
response = http_object.request(request)
rescue
puts "how-can-i-help: Error downloading data file: #{$!}"
exit(1)
end
open CACHE, 'w' do |cc|
cc.write response.body.to_s
end if response.is_a?(Net::HTTPSuccess)
end
open CACHE, 'w' do |cc|
cc.write response.body.to_s
end if response.is_a?(Net::HTTPSuccess)
gz = Zlib::GzipReader.open(CACHE)
helpitems = JSON::parse(gz.read)
......
......@@ -2,6 +2,7 @@ how-can-i-help (17) UNRELEASED; urgency=medium
[ Paul Wise ]
* Switch from `dpkg -l` to dpkg-query
* Add an option to disable updating the cache when it is populated
-- Paul Wise <pabs@debian.org> Sat, 29 Jun 2019 10:39:53 +0800
......
......@@ -42,6 +42,10 @@ Options must come before the other command line arguments.
*-s <type>...*, *--show <type>...*::
Show only specific types of opportunities. Provided types have to be separated by commas.
*--download*, *--no-download*::
Enable or disable updating the cache when it is present.
The cache is updated by default and when it is missing.
PROXY SUPPORT
-------------
*how-can-i-help* uses the HTTP_PROXY (or http_proxy) environment variable as
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment