Skip to content

Instantly share code, notes, and snippets.

@leque
Last active January 29, 2020 13:08
Show Gist options
  • Save leque/f8f54b9cfb44e38c8a8cc9b540d4f42b to your computer and use it in GitHub Desktop.
Save leque/f8f54b9cfb44e38c8a8cc9b540d4f42b to your computer and use it in GitHub Desktop.
# cd opam-repository
# ruby hoge.rb packages/*
def ocaml_ver_lower_bound(dir)
File.read(File.join(dir, 'opam')).lines.collect {|line|
/ *"ocaml" {>= "([^"]*)".*$/.match(line){|m| m[1] }
}.detect{|x| x }
end
def latest_dir(package)
Dir.children(package).collect {|path|
ver = /(?:\.[0-9]+){1,3}(?:[a-z]|[-+][0-9])?$/.match(File.basename(path)) {|m| m[0] }
[path, ver || path]
}.sort_by{|(_, ver)| ver }.first
end
ARGV.collect_concat {|d|
(dir, ver) = latest_dir(d)
return [] unless dir
Dir.chdir(d) do
[[ocaml_ver_lower_bound(dir) || "", File.basename(d)]]
# [[(ocaml_ver_lower_bound(dir) || "")[0..3], File.basename(d)]]
end
}.group_by{|x|
x[0]
}.collect{|k, v|
[k, v.length]
}.sort_by{|x|
x[0]
}.each do |(ver, n)|
printf "% 6s %s\n", ver, '*' * n
end
****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
3.08 *
3.10 **
3.11 **
3.11.0 **
3.12 *************
3.12.0 ***************
3.12.1 *****************
4.0 *
4.0.0 *****
4.0.1 *
4.00 *****
4.00.0 *******************************************************************************
4.00.1 **************************
4.01 **************
4.01.0 ****************************************************************************************************************************************************************************************
4.02 **********************************************
4.02.0 ********************************************************************************************************************************************************
4.02.1 *****************************
4.02.2 *************
4.02.3 *********************************************************************************************
4.03 ******************************************************
4.03.0 *******************************************************************************************************************************************************************************************************************************************************************
4.04 ********************
4.04.0 ****************************************************
4.04.1 ********************************************************************************************************
4.04.2 **********************
4.05 ***********
4.05.0 ******************************
4.06 ************
4.06.0 **************************************
4.06.1 **
4.07 ********
4.07.0 *********************
4.07.1 *
4.08 ***
4.08.0 ********************
4.09 *
****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
3.08 *
3.10 **
3.11 ****
3.12 *********************************************
4.0 *
4.0. ******
4.00 **************************************************************************************************************
4.01 ******************************************************************************************************************************************************************************************************
4.02 *********************************************************************************************************************************************************************************************************************************************************************************************************************************************
4.03 *************************************************************************************************************************************************************************************************************************************************************************************************************************
4.04 ******************************************************************************************************************************************************************************************************
4.05 *****************************************
4.06 ****************************************************
4.07 ******************************
4.08 ***********************
4.09 *
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment