Added command clean

Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
Dimitris Zlatanidis 2019-01-22 17:55:05 +01:00
parent f023925dd1
commit 8ab15075a4
5 changed files with 71 additions and 1 deletions

View file

@ -5,6 +5,8 @@ Updated:
- Merge sbo/remove.py in the slpkg/remove.py file
Fixed:
- Bugfix: update slpkg itself from gitlab repository
Added:
- Command clean to remove the packages and the sources from /tmp/slpkg/ directory
3.3.9 - 14/01/2019
Updated:

View file

@ -29,6 +29,7 @@ Usage: slpkg [COMMANDS|OPTIONS] {repository|package...}
[health, --silent]
[deps-status, --tree, --graph=[type]]
[new-config]
[clean]
Optional arguments:
[-h] [-v]
@ -152,6 +153,11 @@ Additional options:
This command searches for .new configuration files in /etc/ path and ask the user what todo with those
files.
.SS clean, the tmp/ directory
\fBslpkg\fP \fBclean\fP
.PP
Clean the /tmp/slpkg/ directory from downloaded packages and sources.
.SH OPTIONS
.PP
The following arguments are available.

View file

@ -78,6 +78,8 @@ Commands:
new-config Manage .new configuration files.
clean Clean the tmp/ directory from
downloaded packages and sources.
Optional arguments:
-h | --help Print this help message and exit.
@ -184,6 +186,7 @@ def usage(repo):
[health, --silent]
[deps-status, --tree, --graph=[type]]
[new-config]
[clean]
Optional arguments:
[-h] [-v]

49
slpkg/clean.py Normal file
View file

@ -0,0 +1,49 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# clean.py file is part of slpkg.
# Copyright 2014-2019 Dimitris Zlatanidis <d.zlatanidis@gmail.com>
# All rights reserved.
# Slpkg is a user-friendly package manager for Slackware installations
# https://gitlab.com/dslackw/slpkg
# Slpkg is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import shutil
from slpkg.__metadata__ import MetaData as _meta_
def clean_tmp():
"""Delete packages and sources from tmp/ directory
"""
tmps = [_meta_.tmp_path, # /tmp/slpkg/
_meta_.build_path, # /tmp/slpkg/build/
_meta_.slpkg_tmp_packages, # /tmp/slpkg/packages/
_meta_.slpkg_tmp_patches # /tmp/slpkg/patches/
]
# Delete a whole slpkg folder from the tmp directory
if os.path.exists(tmps[0]):
shutil.rmtree(tmps[0])
print("All packages and sources were deleted from: {0}".format(
tmps[0]))
# Recreate the paths again
if not os.path.exists(tmps[0]):
for tmp in tmps:
print("Create directory: {0}".format(tmp))
os.mkdir(tmp)
print("Done!")

View file

@ -25,6 +25,7 @@
import os
import sys
from slpkg.clean import clean_tmp
from slpkg.load import Regex
from slpkg.desc import PkgDesc
from slpkg.messages import Msg
@ -82,7 +83,8 @@ class ArgParse(object):
"update-slpkg",
"health",
"deps-status",
"new-config"
"new-config",
"clean"
]
# checking if repositories exists
@ -239,6 +241,13 @@ class ArgParse(object):
else:
usage("")
def command_clean(self):
"""Clean all downloaded packages and sources"""
if len(self.args) == 1 and self.args[0] == "clean":
clean_tmp()
else:
usage("")
def auto_build(self):
"""Auto built tool
"""
@ -806,6 +815,7 @@ def main():
"health": argparse.command_health,
"deps-status": argparse.command_deps_status,
"new-config": argparse.command_new_config,
"clean": argparse.command_clean,
"-a": argparse.auto_build,
"--autobuild": argparse.auto_build,
"-l": argparse.pkg_list,