diff options
| author | B. Watson <urchlay@slackware.uk> | 2026-10-16 20:00:30 -0400 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2026-10-16 20:00:30 -0400 |
| commit | 0f18242a1e0bc01c4286c3ec58a6746c21d4b0d7 (patch) | |
| tree | 5b8a34a0f5ebbf717a2d3982d5b4abb2b60e1f8a | |
| parent | ab5be5bcdca38952de7e3dac383828faaf6b03a8 (diff) | |
| download | greypool-0f18242a1e0bc01c4286c3ec58a6746c21d4b0d7.tar.gz | |
Improve the repo selection in interactive config.
| -rw-r--r-- | TODO | 4 | ||||
| -rwxr-xr-x | greypool | 48 |
2 files changed, 43 insertions, 9 deletions
@@ -4,9 +4,7 @@ TODO list for greypool - improve the interactive config: - cache the repo list? - - better UI for choosing a repo - possibly use dialog? - - search for repos by partial name - there's a bug I haven't looked for yet that causes the list to be incomplete occasionally. Pretty sure this happens if an ignored @@ -17,7 +15,7 @@ TODO list for greypool - de-uglify and refactor the code. it's a mess. -- style the HTML output a bit. +- HTML: allow setting font and font size in config file - allow user-specified stylesheet for HTML. I am not a web designer, nor do I want to be. @@ -137,28 +137,63 @@ sub mkdir_p { # the API doesn't seem to have a way to just get a list of repos # from repology, so this does traditional HTML scraping. Yuck. sub get_repo_list { + my $count = 0; print "Getting repo list\n"; open my $f, "wget --config=$wgetrc -qO- " . 'https://repology.org/repositories/statistics' . '|'; fatal "failed to run wget: $!\n" unless $f; - my $ok = 0; while(<$f>) { - $ok = 1; if(m,<a\s*href="/repository/([^"/]+)">([^<]+)</a>,) { $repo_list{$1} = $2; + $count++; } } close $f; - if(!$ok) { + + if($count) { + print "Found $count repos at repology.org\n"; + } else { warning "couldn't get repo list from repology.org"; } } sub show_repo_list { + my @res; + my $regex = shift || '.*'; + for(sort keys %repo_list) { + if(/$regex/) { + print "$_ ($repo_list{$_})\n"; + push @res, $_; + } + } + return @res; +} + +sub choose_repo { + my $dflt = shift || "L"; get_repo_list() unless %repo_list; - print "$_ ($repo_list{$_})\n" for sort keys %repo_list; + + while(1) { + my $got = prompt("Repo or 'l <substring>' to list", $dflt); + $got = lc $got; + if($got =~ /^l(?:\s+(\S+))?/) { + my $term = $1; + @list = show_repo_list($term); + if(!@list) { + print "No repos matching '$term'\n"; + } elsif(@list == 1) { + $dflt = $list[0]; + } + } else { + if($repo_list{$got}) { + return $got; + } else { + print "No such repository '$got'\n"; + } + } + } } sub prompt { @@ -185,8 +220,9 @@ sub create_default_config { while(!$ok) { $email = prompt("Your email address", $email); redo if $email =~ /^\s*$/; - show_repo_list(); - $repo = prompt("What repo is this config file for", $repo); + #show_repo_list(); + #$repo = prompt("What repo is this config file for", $repo); + $repo = choose_repo($repo); redo if $repo =~ /^\s*$/; my $yn = prompt(<<EOF, "Y"); |
