Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
giterlizzi committed May 22, 2017
2 parents 0b32dac + 4d0a1e6 commit 35d101b
Show file tree
Hide file tree
Showing 15 changed files with 217 additions and 154 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ update Slackware packages from a standard Slackware repository (official and 3th

## Installation

**INSTALL.md** file provide instructions on how to install SlackMan.
**[INSTALL.md](INSTALL.md)** file provide instructions on how to install SlackMan.

## Supported Repository

Expand Down Expand Up @@ -136,7 +136,7 @@ Enable a repository:

Bash Completion:

# slackman repo info sla<TAB> <TAB>
# slackman repo info sla<TAB><TAB>
slackware:extra slackware:multilib slackware:packages
slackware:pasture slackware:patches slackware:testing

Expand Down
10 changes: 10 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# TODO

- [ ] Number of installed packages in `slackman repo info REPOSITORY` command
- [ ] D-BUS notification of avaiable packages update
- [ ] Crontab script (send mail for new updates, download packages, etc)
- [x] Makefile for automate build of package
- [ ] Speedup slackman bootstrap
- [ ] Installed packages by repo `slackman list installed --repo REPOSITORY`
- [x] List packages by repo `slackman list packages --repo REPOSITORY`

3 changes: 0 additions & 3 deletions bin/slackman
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ use warnings;

use 5.010;

use File::Basename;
use lib dirname(__FILE__)."/../lib";

use Slackware::SlackMan::Command qw(run);
exit run;

Expand Down
4 changes: 2 additions & 2 deletions etc/repos.d/extra/ktown.repo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[latest]
name=ktown latest
[packages]
name=KDE5 ktown packages
enabled=false
mirror=http://bear.alienbase.nl/mirrors/alien-kde/$release/latest/$arch.family/
changelog=http://bear.alienbase.nl/mirrors/alien-kde/ChangeLog.txt
Expand Down
2 changes: 1 addition & 1 deletion lib/Slackware/SlackMan.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ BEGIN {

@ISA = qw(Exporter);

$VERSION = 'v1.0.0';
$VERSION = 'v1.0.1';

@EXPORT_OK = (
@Slackware::SlackMan::Utils::EXPORT_OK,
Expand Down
104 changes: 55 additions & 49 deletions lib/Slackware/SlackMan/Command.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ BEGIN {

require Exporter;

$VERSION = 'v1.0.0';
$VERSION = 'v1.0.1';
@ISA = qw(Exporter);
@EXPORT_OK = qw(run);
%EXPORT_TAGS = (
Expand Down Expand Up @@ -42,20 +42,10 @@ use Slackware::SlackMan::Config qw(:all);

my $lock_check = get_lock_pid();

my $opts = {};
exit _show_help() if $slackman_opts->{'help'};
exit _show_version() if $slackman_opts->{'version'};

GetOptions( $opts,
'help|h', 'man', 'version', 'root=s', 'repo=s', 'exclude|x=s', 'limit=i',
'yes|y', 'no|n', 'quiet', 'no-excludes', 'no-priority', 'config=s',
'download-only', 'new-packages', 'obsolete-packages', 'summary', 'show-files',
);

$opts->{'limit'} ||= 50;

exit _show_help() if $opts->{'help'};
exit _show_version() if $opts->{'version'};

pod2usage(-exitval => 0, -verbose => 2) if $opts->{'man'};
pod2usage(-exitval => 0, -verbose => 2) if $slackman_opts->{'man'};

# Force exit on CTRL-C
$SIG{INT} = sub {
Expand Down Expand Up @@ -83,6 +73,8 @@ sub run {

_show_help() unless ($command);

logger->debug(sprintf('Call %s command (cmd: slackman %s)', $command, join(' ', @ARGV)));

if ($lock_check) {

print "Another instance of slackman is running (pid: $lock_check) If this is not correct,\n" .
Expand All @@ -103,7 +95,7 @@ sub run {
when('reinstall') { _call_package_reinstall(@arguments) }
when('remove') { _call_package_remove(@arguments) }
when('upgrade') { _call_package_update(@arguments) }
when('check-update') { $opts->{'no'} = 1 ; _call_package_update(@arguments) }
when('check-update') { $slackman_opts->{'no'} = 1 ; _call_package_update(@arguments) }
when('info') { _call_package_info($ARGV[1]) }
when('history') { _call_package_history($ARGV[1]) }

Expand Down Expand Up @@ -272,7 +264,6 @@ sub _show_db_help {

}


sub _show_version {
print sprintf("SlackMan - Slackware Package Manager %s\n\n", $VERSION);
exit(0);
Expand Down Expand Up @@ -497,14 +488,17 @@ sub _call_package_info {

push @installed, $row->{name};

my $pkg_dependency = $dbh->selectrow_hashref('SELECT * FROM packages WHERE package LIKE ?', undef, $row->{'package'}.'%');

print sprintf("%-10s : %s\n", 'Name', $row->{name});
print sprintf("%-10s : %s\n", 'Arch', $row->{arch});
print sprintf("%-10s : %s\n", 'Tag', $row->{tag}) if ($row->{tag});
print sprintf("%-10s : %s\n", 'Version', $row->{version});
print sprintf("%-10s : %.1f M\n", 'Size', ($row->{size_uncompressed}/1024));
print sprintf("%-10s : %s\n", 'Require', $pkg_dependency->{'required'}) if ($pkg_dependency);
print sprintf("%-10s : %s\n", 'Summary', $row->{description});

if ($opts->{'show-files'}) {
if ($slackman_opts->{'show-files'}) {

print sprintf("\n%-10s :\n", 'File lists');

Expand Down Expand Up @@ -543,10 +537,11 @@ sub _call_package_info {
print sprintf("%-10s : %s\n", 'Category', $row->{category}) if ($row->{category});
print sprintf("%-10s : %s\n", 'Version', $row->{version});
print sprintf("%-10s : %.1f M\n", 'Size', ($row->{size_uncompressed}/1024));
print sprintf("%-10s : %s\n", 'Require', $row->{required}) if ($row->{required});
print sprintf("%-10s : %s\n", 'Repo', $row->{repository});
print sprintf("%-10s : %s\n", 'Summary', $row->{description});

if ($opts->{'show-files'}) {
if ($slackman_opts->{'show-files'}) {

print sprintf("\n%-10s :\n", 'File lists');

Expand Down Expand Up @@ -610,9 +605,10 @@ sub _call_package_search {
p1.repository,
(SELECT "installed"
FROM history h1
WHERE h1.name = p1.name
WHERE h1.name = p1.name
AND h1.version = p1.version
AND h1.status = "installed") AS status
AND h1.tag = p1.tag
AND h1.status = "installed") AS status
FROM packages p1
WHERE ( p1.name LIKE ?
OR p1.summary LIKE ? )
Expand All @@ -629,8 +625,9 @@ sub _call_package_search {
OR h2.summary LIKE ?)
AND NOT EXISTS (SELECT 1
FROM packages p2
WHERE p2.name = h2.name
AND p2.version = h2.version)';
WHERE p2.name = h2.name
AND p2.version = h2.version
AND p2.tag = h2.tag)';

my $sth = $dbh->prepare($query);
$sth->execute($search, $search, $search, $search);
Expand Down Expand Up @@ -753,8 +750,8 @@ sub _call_package_update {

my $arch = get_arch();

my $option_repo = $opts->{'repo'};
my $option_exclude = $opts->{'exclude'};
my $option_repo = $slackman_opts->{'repo'};
my $option_exclude = $slackman_opts->{'exclude'};

my @filters;

Expand All @@ -770,7 +767,7 @@ sub _call_package_update {
push(@filters, 'packages.repository IN ("' . join('", "', get_enabled_repositories()) . '")');
}

push(@filters, 'packages.excluded = 0') unless ($opts->{'no-excludes'});
push(@filters, 'packages.excluded = 0') unless ($slackman_opts->{'no-excludes'});
push(@filters, 'packages.repository NOT IN ("' . join('", "', get_disabled_repositories()) . '")');

@update_package = map { parse_module_name($_) } @update_package if (@update_package);
Expand Down Expand Up @@ -822,7 +819,7 @@ sub _call_package_update {
callback_spinner($spinner);
$spinner++;

next if (($row->{old_priority} > $row->{new_priority}) && ! $opts->{'no-priority'});
next if (($row->{old_priority} > $row->{new_priority}) && ! $slackman_opts->{'no-priority'});

$update_pkgs->{$row->{name}} = $row;

Expand All @@ -834,7 +831,7 @@ sub _call_package_update {
my $updatable_pkg_required_row = package_available_update($pkg_required, $option_repo);

next unless($updatable_pkg_required_row);
next if (($updatable_pkg_required_row->{old_priority} > $updatable_pkg_required_row->{new_priority}) && ! $opts->{'no-priority'});
next if (($updatable_pkg_required_row->{old_priority} > $updatable_pkg_required_row->{new_priority}) && ! $slackman_opts->{'no-priority'});

$update_pkgs->{$updatable_pkg_required_row->{name}} = $updatable_pkg_required_row;

Expand Down Expand Up @@ -915,11 +912,11 @@ sub _call_package_update {
print sprintf("%-20s %.1f M\n", 'Installed size', $total_uncompressed_size/1024);
print "\n\n";

exit(0) if ($opts->{'no'});
exit(0) if ($slackman_opts->{'no'} || $slackman_opts->{'summary'});

if (@downloads) {

unless ($opts->{'yes'} || $opts->{'download-only'}) {
unless ($slackman_opts->{'yes'} || $slackman_opts->{'download-only'}) {
exit(0) unless(confirm("Perform update of selected packages? [Y/N] "));
}

Expand All @@ -938,7 +935,7 @@ sub _call_package_update {

}

exit(0) if ($opts->{'download-only'});
exit(0) if ($slackman_opts->{'download-only'});

unless ($< == 0) {
warn "\nPackage update requires root privileges!\n";
Expand Down Expand Up @@ -1005,7 +1002,7 @@ sub _call_list_repo {
sub _call_changelog {

my $query = 'SELECT * FROM changelogs WHERE %s ORDER BY timestamp DESC LIMIT %s';
my $option_repo = $opts->{'repo'};
my $option_repo = $slackman_opts->{'repo'};

my @repositories = get_enabled_repositories();
my @filters = ();
Expand All @@ -1028,7 +1025,7 @@ sub _call_changelog {
# Filter disabled repository
push(@filters, sprintf('repository NOT IN ("%s")', join('","', get_disabled_repositories())));

my $sth = $dbh->prepare(sprintf($query, join(' AND ', @filters), $opts->{'limit'}));
my $sth = $dbh->prepare(sprintf($query, join(' AND ', @filters), $slackman_opts->{'limit'}));
$sth->execute();

print sprintf("%-60s %-15s %-25s %s\n", "Package", "Status", "Timestamp", "Repository");
Expand Down Expand Up @@ -1102,7 +1099,7 @@ sub _call_repo_info {

sub _call_list_obsoletes {

my $obsolete_rows = package_list_obsoletes($opts->{'repo'});
my $obsolete_rows = package_list_obsoletes($slackman_opts->{'repo'});
my $num_rows = scalar keys %$obsolete_rows;

print "\nObsolete package(s)\n\n";
Expand Down Expand Up @@ -1140,7 +1137,7 @@ sub _call_package_reinstall {

my @packages = @_;
my @is_installed = ();
my $option_repo = $opts->{'repo'};
my $option_repo = $slackman_opts->{'repo'};

unless (@packages) {
warn "Specify package!\n";
Expand Down Expand Up @@ -1169,7 +1166,7 @@ sub _call_package_reinstall {

print "\n\n";

unless ($opts->{'yes'}) {
unless ($slackman_opts->{'yes'}) {
exit(0) unless(confirm("Are you sure? [Y/N] "));
}

Expand Down Expand Up @@ -1211,7 +1208,7 @@ sub _call_package_reinstall {

}

exit(0) if ($opts->{'download-only'});
exit(0) if ($slackman_opts->{'download-only'});

unless ($< == 0) {
warn "\nPackage reinstall requires root privileges!\n";
Expand Down Expand Up @@ -1254,7 +1251,7 @@ sub _call_package_remove {
my @packages = @_;
my @is_installed = ();

if ($opts->{'obsolete-packages'}) {
if ($slackman_opts->{'obsolete-packages'}) {

# Get list from "slackman list obsoletes"
@is_installed = _call_list_obsoletes();
Expand Down Expand Up @@ -1290,9 +1287,9 @@ sub _call_package_remove {
}

exit(0) unless(@is_installed);
exit(0) if ($opts->{'no'});
exit(0) if ($slackman_opts->{'no'});

unless ($opts->{'yes'}) {
unless ($slackman_opts->{'yes'}) {
exit(0) unless(confirm("Are you sure? [Y/N] "));
}

Expand All @@ -1314,8 +1311,8 @@ sub _call_package_install {

my @packages = @_;
my $arch = get_arch();
my $option_repo = $opts->{'repo'};
my $option_exclude = $opts->{'exclude'};
my $option_repo = $slackman_opts->{'repo'};
my $option_exclude = $slackman_opts->{'exclude'};

my $check = $dbh->selectrow_array(sprintf('SELECT COUNT(*) FROM history WHERE name IN (%s) AND status = "installed"', '"' . join('","', @packages) . '"'), undef);

Expand Down Expand Up @@ -1375,7 +1372,7 @@ sub _call_package_install {
push(@filters, qq/( packages.repository != "$repository" )/);
}

push(@filters, 'packages.excluded = 0') unless ($opts->{'no-excludes'});
push(@filters, 'packages.excluded = 0') unless ($slackman_opts->{'no-excludes'});

my $query_packages = qq/SELECT *
FROM packages
Expand Down Expand Up @@ -1410,7 +1407,7 @@ sub _call_package_install {
AND repository = ?
AND arch IN (?, "noarch")/;

if ($opts->{'new-packages'}) {
if ($slackman_opts->{'new-packages'}) {
$query_packages = $query_new_packages;
}

Expand Down Expand Up @@ -1473,10 +1470,10 @@ sub _call_package_install {

print "\n\n";

exit(0) if ($opts->{'no'});
exit(0) if ($slackman_opts->{'no'});
exit(0) unless (@install);

unless ($opts->{'yes'} || $opts->{'download-only'}) {
unless ($slackman_opts->{'yes'} || $slackman_opts->{'download-only'}) {
exit(0) unless(confirm("Install selected packages? [Y/N] "));
}

Expand All @@ -1498,7 +1495,7 @@ sub _call_package_install {
package_download($install, \@pkg_install, \@errors);
}

exit(0) if ($opts->{'download-only'});
exit(0) if ($slackman_opts->{'download-only'});

unless ($< == 0) {
warn "\nPackage update requires root privileges!\n";
Expand Down Expand Up @@ -1614,8 +1611,17 @@ sub _call_list_packages {
print sprintf("%-40s %-10s\t%-25s %-10s %s\n", "Name", "Arch", "Version", "Tag", "Repository");
print sprintf("%s\n", "-"x132);

my $query = 'SELECT * FROM packages WHERE repository IN (%s) ORDER BY name';
$query = sprintf($query, '"' . join('", "', get_enabled_repositories()) . '"');
my $option_repo = $slackman_opts->{'repo'};

if ($option_repo) {
$option_repo .= ":%" unless ($option_repo =~ m/\:/);
}

my $active_repositories = sprintf('IN ("%s")', join('", "', get_enabled_repositories()));
$active_repositories = sprintf('LIKE "%s"', $option_repo) if ($option_repo);

my $query = 'SELECT * FROM packages WHERE repository %s ORDER BY name';
$query = sprintf($query, $active_repositories);

my $sth = $dbh->prepare($query);
$sth->execute();
Expand All @@ -1641,7 +1647,7 @@ sub _fork_update_history {
delete_lock();

# Call update history command in background and set ROOT environment
my $update_history_cmd = "perl $0 update history";
my $update_history_cmd = "slackman update history";
$update_history_cmd .= sprintf(" --root %s", $ENV{ROOT}) if ($ENV{ROOT});
$update_history_cmd .= " > /dev/null &";

Expand Down
Loading

0 comments on commit 35d101b

Please sign in to comment.