2014-09-29 07:41:57 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# blacklist.py file is part of slpkg.
|
|
|
|
|
2015-05-21 01:00:07 +02:00
|
|
|
# Copyright 2014-2015 Dimitris Zlatanidis <d.zlatanidis@gmail.com>
|
2014-09-29 07:41:57 +02:00
|
|
|
# All rights reserved.
|
|
|
|
|
2014-12-19 05:57:56 +01:00
|
|
|
# Slpkg is a user-friendly package manager for Slackware installations
|
2014-09-29 07:41:57 +02:00
|
|
|
|
|
|
|
# https://github.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/>.
|
|
|
|
|
2015-05-28 05:07:13 +02:00
|
|
|
|
2015-01-31 01:47:36 +01:00
|
|
|
from utils import Utils
|
2015-06-07 07:26:42 +02:00
|
|
|
from __metadata__ import MetaData as _meta_
|
2014-09-29 07:41:57 +02:00
|
|
|
|
2014-10-06 21:44:44 +02:00
|
|
|
|
2014-10-04 00:44:18 +02:00
|
|
|
class BlackList(object):
|
2015-06-05 13:42:52 +02:00
|
|
|
"""
|
2014-10-04 00:44:18 +02:00
|
|
|
Blacklist class to add, remove or listed packages
|
|
|
|
in blacklist file.
|
2015-06-05 13:42:52 +02:00
|
|
|
"""
|
2014-10-04 00:44:18 +02:00
|
|
|
def __init__(self):
|
2015-06-08 05:28:49 +02:00
|
|
|
self.meta = _meta_
|
2014-10-21 07:50:59 +02:00
|
|
|
self.quit = False
|
2014-11-22 11:01:32 +01:00
|
|
|
self.blackfile = "/etc/slpkg/blacklist"
|
2015-01-31 01:47:36 +01:00
|
|
|
self.black_conf = Utils().read_file(self.blackfile)
|
2014-10-16 04:10:24 +02:00
|
|
|
|
2014-10-04 00:44:18 +02:00
|
|
|
def packages(self):
|
2015-06-05 13:42:52 +02:00
|
|
|
"""
|
2014-10-14 05:01:38 +02:00
|
|
|
Return blacklist packages from /etc/slpkg/blacklist
|
2014-10-04 00:44:18 +02:00
|
|
|
configuration file.
|
2015-06-05 13:42:52 +02:00
|
|
|
"""
|
2014-10-04 00:44:18 +02:00
|
|
|
blacklist = []
|
2014-10-16 04:10:24 +02:00
|
|
|
for read in self.black_conf.splitlines():
|
|
|
|
read = read.lstrip()
|
|
|
|
if not read.startswith("#"):
|
|
|
|
blacklist.append(read.replace("\n", ""))
|
2014-10-04 00:44:18 +02:00
|
|
|
return blacklist
|
2014-09-29 07:41:57 +02:00
|
|
|
|
2014-10-04 00:44:18 +02:00
|
|
|
def listed(self):
|
2015-06-05 13:42:52 +02:00
|
|
|
"""
|
2014-10-04 00:44:18 +02:00
|
|
|
Print blacklist packages
|
2015-06-05 13:42:52 +02:00
|
|
|
"""
|
2014-10-04 00:44:18 +02:00
|
|
|
print("\nPackages in blacklist:\n")
|
|
|
|
for black in self.packages():
|
|
|
|
if black:
|
2015-06-08 05:28:49 +02:00
|
|
|
print("{0}{1}{2}".format(self.meta.color["GREEN"], black,
|
|
|
|
self.meta.color["ENDC"]))
|
2014-10-21 07:50:59 +02:00
|
|
|
self.quit = True
|
|
|
|
if self.quit:
|
2014-11-13 12:32:40 +01:00
|
|
|
print("") # new line at exit
|
2014-09-29 07:41:57 +02:00
|
|
|
|
2014-10-04 00:44:18 +02:00
|
|
|
def add(self, pkgs):
|
2015-06-05 13:42:52 +02:00
|
|
|
"""
|
2014-10-04 00:44:18 +02:00
|
|
|
Add blacklist packages if not exist
|
2015-06-05 13:42:52 +02:00
|
|
|
"""
|
2014-10-04 00:44:18 +02:00
|
|
|
blacklist = self.packages()
|
2014-10-11 04:06:04 +02:00
|
|
|
pkgs = set(pkgs)
|
2014-10-04 00:44:18 +02:00
|
|
|
print("\nAdd packages in blacklist:\n")
|
|
|
|
with open(self.blackfile, "a") as black_conf:
|
|
|
|
for pkg in pkgs:
|
|
|
|
if pkg not in blacklist:
|
2015-06-08 05:28:49 +02:00
|
|
|
print("{0}{1}{2}".format(self.meta.color["GREEN"], pkg,
|
|
|
|
self.meta.color["ENDC"]))
|
2014-10-04 00:44:18 +02:00
|
|
|
black_conf.write(pkg + "\n")
|
2014-10-21 07:50:59 +02:00
|
|
|
self.quit = True
|
2014-10-11 04:06:04 +02:00
|
|
|
black_conf.close()
|
2014-10-21 07:50:59 +02:00
|
|
|
if self.quit:
|
2014-11-13 12:32:40 +01:00
|
|
|
print("") # new line at exit
|
2014-10-04 00:44:18 +02:00
|
|
|
|
|
|
|
def remove(self, pkgs):
|
2015-06-05 13:42:52 +02:00
|
|
|
"""
|
2014-10-04 00:44:18 +02:00
|
|
|
Remove packages from blacklist
|
2015-06-05 13:42:52 +02:00
|
|
|
"""
|
2014-10-04 00:44:18 +02:00
|
|
|
print("\nRemove packages from blacklist:\n")
|
2014-10-16 04:10:24 +02:00
|
|
|
with open(self.blackfile, "w") as remove:
|
|
|
|
for line in self.black_conf.splitlines():
|
2014-10-04 00:44:18 +02:00
|
|
|
if line not in pkgs:
|
2014-10-16 04:10:24 +02:00
|
|
|
remove.write(line + "\n")
|
2014-10-04 00:44:18 +02:00
|
|
|
else:
|
2015-06-08 05:28:49 +02:00
|
|
|
print("{0}{1}{2}".format(self.meta.color["RED"], line,
|
|
|
|
self.meta.color["ENDC"]))
|
2014-10-21 07:50:59 +02:00
|
|
|
self.quit = True
|
2014-10-16 04:10:24 +02:00
|
|
|
remove.close()
|
2014-10-21 07:50:59 +02:00
|
|
|
if self.quit:
|
2014-11-13 12:32:40 +01:00
|
|
|
print("") # new line at exit
|