text
stringlengths
0
834k
}
elsif ($cmd eq ""init"") {
$USAGE = ""area init <area>"";
usage() unless @ARGV == 1;
my $name = shift(@ARGV);
$ppm->area($name)->initialize;
}
elsif ($cmd eq ""sync"") {
$USAGE = ""area sync [<area>...]"";
for my $area (map $ppm->area($_), @ARGV ? @ARGV : $ppm->areas) {
$area->sync_db;
}
}
else {
$cmd = _try_abbrev(""area"", $cmd, qw(list sync init));
goto AGAIN;
}
}
sub _try_abbrev {
my $cmd = shift;
my $subcmd = shift;
require Text::Abbrev;
if (my $full_cmd = Text::Abbrev::abbrev(@_)->{$subcmd}) {
return $full_cmd;
}
$USAGE = ""$cmd <cmd> <args>"";
require Text::Wrap;
usage(Text::Wrap::wrap("""", "" "",
""The $cmd command '$subcmd' isn't recognized; try one of "" .
join_with(""or"", sort @_)
)
);
}
sub do_list {
my $area_name;
my $matching;
my $show_header = 1;
my $csv;
my @fields;
if (@ARGV) {
$USAGE = ""list [<area>] [--field <field>] [--matching <pattern>] [--csv]"";
require Getopt::Long;
Getopt::Long::GetOptions(
'matching=s' => \$matching,
'header!' => \$show_header,
'fields:s' => sub { push(@fields, split(/\s*,\s*/, $_[1])) },
'csv:s' => \$csv,
) || usage();
$area_name = shift(@ARGV) if @ARGV;
usage() if @ARGV;
}
my $matching_re = glob2re($matching) if defined($matching);
$matching = (defined $matching) ? "" matching '$matching'"" : """";
unless (@fields) {
# fields to show by default
push(@fields, ""version"", ""files"", ""size"");
push(@fields, ""area"") unless $area_name;
}
unshift(@fields, ""name"") unless grep $_ eq ""name"", @fields;
my @areas = ($area_name ? ($area_name) : $ppm->areas);
my $in = $area_name ? "" in '$area_name' area"" : """";
if (@fields == 1) {
# just list the names
my @pkgs = map $_->packages, map $ppm->area($_), @areas;
@pkgs = grep $_ =~ $matching_re, @pkgs if $matching_re;
goto NO_PKG_INSTALLED unless @pkgs;
print ""$_\n"" for sort @pkgs;
}
else {
require ActiveState::Table;
my $tab = ActiveState::Table->new;
$tab->add_field($_) for @fields;
my %field = map { $_ => 1 } @fields;
my %db_column = map { $_ => 1 } qw(id name version release_date abstract author ppd_uri);
my @db_fields = grep $db_column{$_}, @fields;
unshift(@db_fields, ""id"") if !$field{id} && $field{files} || $field{size};
for my $area (map $ppm->area($_), @areas) {
for my $pkg ($area->packages(@db_fields)) {
my %row = map {$_ => shift(@$pkg)} @db_fields;
next if $matching_re && $row{name} !~ $matching_re;
if ($row{release_date}) {
$row{release_date} =~ s/[T ].*//; # drop time
}
if ($field{files} || $field{size}) {
if ($field{size}) {
my @files = $area->package_files($row{id});
$row{files} = @files if $field{files};
require ActiveState::DiskUsage;
my $size = 0;
$size += ActiveState::DiskUsage::du($_) for @files;
$size = sprintf ""%.0f KB"", $size / 1024 unless defined($csv);