Skip to content

Commit

Permalink
issue #19 check new gem version periodically (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent-martin authored Mar 9, 2021
1 parent c5d731f commit 500db78
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 8 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ To upgrade to the latest version:
# gem update aspera-cli
```

`ascli` checks every week if a new version is available and notify the user in a WARN log. To de-activate this feature set the option `version_check_days` to `0`, or specify a different period in days.

To check manually:

```
# ascli conf check_update
```



## <a name="fasp_prot"></a>FASP Protocol

Most file transfers will be done using the FASP protocol. Only two additional files are required to perform
Expand Down Expand Up @@ -1345,6 +1355,7 @@ ascli config ascp info
ascli config ascp install
ascli config ascp products list
ascli config ascp show
ascli config check_update
ascli config email_test [email protected]
ascli config export
ascli config genkey mykey
Expand Down Expand Up @@ -1513,7 +1524,7 @@ OPTIONS: global
--once-only=ENUM process only new items (some commands): yes, no

COMMAND: config
SUBCOMMANDS: gem_path genkey plugins flush_tokens list overview open echo id documentation wizard export_to_cli detect coffee ascp email_test smtp_settings proxy_check folder file
SUBCOMMANDS: gem_path genkey plugins flush_tokens list overview open echo id documentation wizard export_to_cli detect coffee ascp email_test smtp_settings proxy_check folder file check_update
OPTIONS:
--value=VALUE extended value for create, update, list filter
--property=VALUE name of property to set
Expand All @@ -1532,6 +1543,7 @@ OPTIONS:
--secret=VALUE access key secret for node
--secrets=VALUE access key secret for node
--test-mode=ENUM skip user validation in wizard mode: yes, no
--version-check-days=VALUE period to check neew version in days (zero to disable)
--ts=VALUE override transfer spec values (Hash, use @json: prefix), current={"create_dir"=>true}
--local-resume=VALUE set resume policy (Hash, use @json: prefix), current=
--to-folder=VALUE destination folder for downloaded files
Expand Down
10 changes: 10 additions & 0 deletions docs/README.erb.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ To upgrade to the latest version:
# gem update <%= gemspec.name %>
```

<%=tool%> checks every week if a new version is available and notify the user in a WARN log. To de-activate this feature set the option `version_check_days` to `0`, or specify a different period in days.

To check manually:

```
# <%=cmd%> conf check_update
```



## <a name="fasp_prot"></a>FASP Protocol

Most file transfers will be done using the FASP protocol. Only two additional files are required to perform
Expand Down
3 changes: 2 additions & 1 deletion lib/aspera/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def self.result_transfer(statuses)
return Main.result_nothing
end

def options;@opt_mgr;end
#def options;@opt_mgr;end

def program_name;PROGRAM_NAME;end

Expand All @@ -232,6 +232,7 @@ def process_command_line
raise CliError,"Another instance is already running (lock port=#{lock_port})."
end
end
@plugin_env[:config].periodic_check_newer_gem_version
if @option_show_config and @opt_mgr.command_or_arg_empty?
command_sym=Plugins::Config::CONF_PLUGIN_SYM
else
Expand Down
10 changes: 6 additions & 4 deletions lib/aspera/cli/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ def entity_action(rest_api,res_class_path,display_fields,id_symb,id_default=nil,
return entity_command(command,rest_api,res_class_path,display_fields,id_symb,id_default,subkey)
end

def options;@agents[:options];end
def options; return @agents[:options];end

def transfer;@agents[:transfer];end
def transfer; return @agents[:transfer];end

def config;return @agents[:config];end
def config; return @agents[:config];end

def format;return @agents[:formater];end
def format; return @agents[:formater];end

def persistency; return @agents[:persistency];end

end # Plugin
end # Cli
Expand Down
50 changes: 49 additions & 1 deletion lib/aspera/cli/plugins/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
require 'aspera/proxy_auto_config'
require 'aspera/uri_reader'
require 'aspera/rest'
require 'aspera/persistency_action_once'
require 'xmlsimple'
require 'base64'
require 'net/smtp'
require 'open3'
require 'date'

module Aspera
module Cli
Expand Down Expand Up @@ -106,8 +108,10 @@ def initialize(env,tool_name,help_url,version)
self.options.add_opt_simple(:secret,"access key secret for node")
self.options.add_opt_simple(:secrets,"access key secret for node")
self.options.add_opt_boolean(:test_mode,"skip user validation in wizard mode")
self.options.add_opt_simple(:version_check_days,Integer,"period to check neew version in days (zero to disable)")
self.options.set_option(:use_generic_client,true)
self.options.set_option(:test_mode,false)
self.options.set_option(:version_check_days,7)
self.options.parse_options!
raise CliBadArgument,"secrets shall be Hash" unless @option_secrets.is_a?(Hash)
end
Expand All @@ -122,6 +126,48 @@ def get_secrets
return @option_secrets
end

def check_gem_version
this_gem_name=File.basename(File.dirname(self.class.gem_root)).gsub(/-[0-9].*$/,'')
latest_version=begin
Rest.new(base_url: "https://rubygems.org/api/v1").read("versions/#{this_gem_name}/latest.json")[:data]['version']
rescue
nil
end
return {name: this_gem_name,current: Aspera::Cli::VERSION, latest: latest_version, need_update: Gem::Version.new(Aspera::Cli::VERSION) < Gem::Version.new(latest_version)}
end

def periodic_check_newer_gem_version
# get verification period
delay_days=options.get_option(:version_check_days,:mandatory)
Log.log.info("check days: #{delay_days}")
# check only if not zero day
if !delay_days.eql?(0)
# get last date from persistency
last_check_array=[]
check_date_persist=PersistencyActionOnce.new(
manager: persistency,
data: last_check_array,
ids: ['version_last_check'])
# get persisted date or nil
last_check_date = begin
Date.strptime(last_check_array.first, "%Y/%m/%d")
rescue
nil
end
current_date=Date.today
Log.log.info("last check: #{last_check_date.class}")
if last_check_date.nil? or (current_date - last_check_date) > delay_days
Log.log.info("days elapsed #{last_check_date.is_a?(Date) ? current_date - last_check_date : last_check_date.class.name}")
last_check_array[0]=current_date.strftime("%Y/%m/%d")
check_date_persist.save
check_data=check_gem_version
if check_data[:need_update]
Log.log.warn("A new version is available: #{check_data[:latest]}. You have #{check_data[:current]}. Upgrade with: gem update #{check_data[:nname]}")
end
end
end
end

# retrieve structure from cloud (CDN) with all versions available
def connect_versions
if @connect_versions.nil?
Expand Down Expand Up @@ -484,7 +530,7 @@ def execute_action_ascp
raise "unexpected case: #{command}"
end

ACTIONS=[:gem_path, :genkey,:plugins,:flush_tokens,:list,:overview,:open,:echo,:id,:documentation,:wizard,:export_to_cli,:detect,:coffee,:ascp,:email_test,:smtp_settings,:proxy_check,:folder,:file]
ACTIONS=[:gem_path, :genkey,:plugins,:flush_tokens,:list,:overview,:open,:echo,:id,:documentation,:wizard,:export_to_cli,:detect,:coffee,:ascp,:email_test,:smtp_settings,:proxy_check,:folder,:file,:check_update]

# "config" plugin
def execute_action
Expand Down Expand Up @@ -764,6 +810,8 @@ def execute_action
pac_url=self.options.get_option(:fpac,:mandatory)
server_url=self.options.get_next_argument("server url")
return Main.result_status(Aspera::ProxyAutoConfig.new(UriReader.read(pac_url)).get_proxy(server_url))
when :check_update
return {:type=>:single_object, :data=>check_gem_version}
else raise "error"
end
end
Expand Down
6 changes: 5 additions & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,11 @@ $(T)conf_pac: $(T).exists
@echo $@
$(EXE_MAN) config proxy_check --fpac=file:///$(DIR_TOP)examples/proxy.pac https://eudemo.asperademo.com
@touch $@
tconf: $(T)conf_id_1 $(T)conf_id_2 $(T)conf_id_3 $(T)conf_id_4 $(T)conf_id_5 $(T)conf_id_6 $(T)conf_open $(T)conf_list $(T)conf_over $(T)conf_help $(T)conf_open_err $(T)conf_plugins $(T)conf_export $(T)conf_wizard_org $(T)conf_wizard_gen $(T)conf_genkey $(T)conf_smtp $(T)conf_pac
$(T)conf_check_gem: $(T).exists
@echo $@
$(EXE_MAN) config check_update
@touch $@
tconf: $(T)conf_id_1 $(T)conf_id_2 $(T)conf_id_3 $(T)conf_id_4 $(T)conf_id_5 $(T)conf_id_6 $(T)conf_open $(T)conf_list $(T)conf_over $(T)conf_help $(T)conf_open_err $(T)conf_plugins $(T)conf_export $(T)conf_wizard_org $(T)conf_wizard_gen $(T)conf_genkey $(T)conf_smtp $(T)conf_pac $(T)conf_check_gem

$(T)shar2_1: $(T).exists
@echo $@
Expand Down

0 comments on commit 500db78

Please sign in to comment.