| 1 | package Sparrow::Commands::Index; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | use base 'Exporter'; | ||
| 6 | |||
| 7 | use Sparrow::Constants; | ||
| 8 | use Sparrow::Misc; | ||
| 9 | |||
| 10 | use Carp; | ||
| 11 | |||
| 12 | our @EXPORT = qw{ | ||
| 13 | |||
| 14 | update_index | ||
| 15 | update_custom_index | ||
| 16 | index_summary | ||
| 17 | |||
| 18 | }; | ||
| 19 | |||
| 20 | |||
| 21 | sub update_index { | ||
| 22 | |||
| 23 | my $data = get_http_resource(sparrow_hub_api_url().'/api/v1/index'); | ||
| 24 | open my $fh, ">", spi_file() or die "can't open ".(spci_file())." to write"; | ||
| 25 | print $fh $data; | ||
| 26 | close $fh; | ||
| 27 | print spi_file()." updated OK from ".sparrow_hub_api_url()."\n"; | ||
| 28 | }; | ||
| 29 | |||
| 30 | sub update_custom_index { | ||
| 31 | |||
| 32 | my $repo = sparrow_config()->{repo}; | ||
| 33 | |||
| 34 | if ($repo){ | ||
| 35 | print "get index updates from custom repo $repo ... "; | ||
| 36 | my $data = get_http_resource($repo); | ||
| 37 | open my $fh, ">", spci_file() or die "can't open ".(spci_file())." to write"; | ||
| 38 | print $fh $data; | ||
| 39 | close $fh; | ||
| 40 | print "OK\n"; | ||
| 41 | } | ||
| 42 | |||
| 43 | }; | ||
| 44 | |||
| 45 | sub index_summary { | ||
| 46 | |||
| 47 | print "[sparrow index summary]\n\n"; | ||
| 48 | execute_shell_command("ls -l ".spi_file); | ||
| 49 | execute_shell_command("ls -l ".spci_file); | ||
| 50 | execute_shell_command("ls -l ".spl_file); | ||
| 51 | |||
| 52 | }; | ||
| 53 | |||
| 54 | 1; |