Updated installing over setup.py file

Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
Dimitris Zlatanidis 2018-03-18 18:01:04 +01:00
parent eb7dd6d1e0
commit e62ad0b8e4
4 changed files with 49 additions and 113 deletions

106
setup.py
View file

@ -24,7 +24,6 @@
import os
import sys
import gzip
import time
import shutil
from slpkg.md5sum import md5
@ -46,13 +45,40 @@ OPTIONAL_REQUIREMENTS = [
# Non-Python/non-PyPI optional dependencies:
# ascii diagram: graph-easy (available from SBo repository)
if "--install" not in sys.argv:
logo_fname = os.path.join(os.path.dirname(__file__), 'logo.txt')
with open(logo_fname, 'rb') as f:
logo = f.read().decode('utf-8')
print(logo)
time.sleep(1)
def print_logo():
if "--install" not in sys.argv:
logo_fname = os.path.join(os.path.dirname(__file__), 'logo.txt')
with open(logo_fname, 'rb') as f:
logo = f.read().decode('utf-8')
print(logo)
time.sleep(1)
def setup_configurations():
conf_file = [
"conf/slpkg.conf",
"conf/repositories.conf",
"conf/blacklist",
"conf/slackware-mirrors",
"conf/default-repositories",
"conf/custom-repositories",
"conf/rlworkman.deps",
"conf/pkg_security"
]
if not os.path.exists(_meta_.conf_path):
os.makedirs(_meta_.conf_path)
for conf in conf_file:
filename = conf.split("/")[-1]
if os.path.isfile(_meta_.conf_path + filename):
old = md5(_meta_.conf_path + filename)
new = md5(conf)
if old != new:
shutil.copy2(_meta_.conf_path + filename,
_meta_.conf_path + filename + ".old")
print_logo()
setup_configurations()
setup(
name="slpkg",
@ -68,6 +94,17 @@ setup(
url="https://github.com/dslackw/slpkg",
package_data={"": ["LICENSE", "README.rst", "CHANGELOG"]},
install_requires=INSTALLATION_REQUIREMENTS,
data_files=[("man/man8", ["man/slpkg.8"]),
("/etc/bash_completion.d", ["conf/slpkg.bash-completion"]),
("/etc/fish/completions", ["conf/slpkg.fish"]),
(_meta_.conf_path, ["conf/slpkg.conf"]),
(_meta_.conf_path, ["conf/repositories.conf"]),
(_meta_.conf_path, ["conf/blacklist"]),
(_meta_.conf_path, ["conf/slackware-mirrors"]),
(_meta_.conf_path, ["conf/default-repositories"]),
(_meta_.conf_path, ["conf/custom-repositories"]),
(_meta_.conf_path, ["conf/rlworkman.deps"]),
(_meta_.conf_path, ["conf/pkg_security"])],
extras_require={
"optional": OPTIONAL_REQUIREMENTS,
"docs": DOCS_REQUIREMENTS,
@ -89,58 +126,3 @@ setup(
"Topic :: Utilities"],
long_description=open("README.rst").read()
)
# Install man page and configuration files with pip.
if "install" in sys.argv:
man_path = "/usr/man/man8/"
if not os.path.exists(man_path):
os.makedirs(man_path)
man_page = "man/slpkg.8"
gzip_man = "man/slpkg.8.gz"
print("Installing '{0}' man pages".format(gzip_man.split("/")[1]))
f_in = open(man_page, "rb")
f_out = gzip.open(gzip_man, "wb")
f_out.writelines(f_in)
f_out.close()
f_in.close()
shutil.copy2(gzip_man, man_path)
bash_completion = "/etc/bash_completion.d/"
fish_completion = "/etc/fish/completions/"
completion_file = [
"conf/slpkg.bash-completion",
"conf/slpkg.fish"
]
if not os.path.exists(bash_completion):
os.makedirs(bash_completion)
print("Installing '{0}' file".format(completion_file[0].split("/")[1]))
shutil.copy2(completion_file[0], bash_completion)
os.chmod(bash_completion + completion_file[0].split("/")[1], 744)
if os.path.exists(fish_completion):
print("Installing '{0}' file".format(completion_file[1].split("/")[1]))
shutil.copy2(completion_file[1], fish_completion)
os.chmod(fish_completion + completion_file[1].split("/")[1], 744)
conf_file = [
"conf/slpkg.conf",
"conf/repositories.conf",
"conf/blacklist",
"conf/slackware-mirrors",
"conf/default-repositories",
"conf/custom-repositories",
"conf/rlworkman.deps",
"conf/pkg_security"
]
if not os.path.exists(_meta_.conf_path):
os.makedirs(_meta_.conf_path)
for conf in conf_file:
filename = conf.split("/")[-1]
print("Installing '{0}' file".format(filename))
if os.path.isfile(_meta_.conf_path + filename):
old = md5(_meta_.conf_path + filename)
new = md5(conf)
if old != new:
shutil.copy2(conf, _meta_.conf_path + filename + ".new")
else:
shutil.copy2(conf, _meta_.conf_path)
shutil.copy2(conf_file[0],
_meta_.conf_path + conf_file[0].split("/")[-1] + ".orig")

View file

@ -1,19 +0,0 @@
config() {
NEW="$1"
OLD="$(dirname $NEW)/$(basename $NEW .new)"
if [ ! -r $OLD ]; then
mv $NEW $OLD
elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then
rm $NEW
fi
}
CONFIGS="slpkg.conf repositories.conf blacklist slackware-mirrors default-repositories \
custom-repositories rlworkman.deps pkg_security"
for file in $CONFIGS; do
config etc/slpkg/${file}.new
done
if [ -x /usr/bin/update-desktop-database ]; then
/usr/bin/update-desktop-database -q usr/share/applications >/dev/null 2>&1
fi

View file

@ -80,10 +80,7 @@ find -L . \
\( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
-o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;
# avoid install man page and configuration files over setup.py
sed -i 's/if "install"/if ""/' setup.py
# Python 3 support temporarily is out until new Slackware version
# Python 3 support temporarily is out until new Slackware version release
# will be release
# if [ "$PYTHON3" = "yes" ]; then
# sh convert-py3k
@ -95,33 +92,6 @@ $PYTHON setup.py install --root=$PKG
find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \
| cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
mkdir -p $PKG/etc/slpkg
# install configurations files
CONFIGS="slpkg.conf repositories.conf blacklist slackware-mirrors default-repositories \
custom-repositories rlworkman.deps pkg_security"
for file in $CONFIGS; do
install -D -m0644 conf/$file $PKG/etc/slpkg/${file}.new
done
# keep original configuration file for reset
cp -p conf/slpkg.conf $PKG/etc/slpkg/slpkg.conf.orig
# install bash completion file
mkdir -p $PKG/etc/bash_completion.d
install -D -m0744 conf/${PRGNAM}.bash-completion \
$PKG/etc/bash_completion.d/${PRGNAM}.bash-completion
# install fish completion file
if [ -d "/etc/fish/completions" ]; then
install -D -m0744 conf/${PRGNAM}.fish \
$PKG/etc/fish/completions/${PRGNAM}.fish
fi
# install man page
mkdir -p $PKG/usr/man/man8
gzip -9 man/$PRGNAM.8
install -D -m0644 man/$PRGNAM.8.gz $PKG/usr/man/man8/$PRGNAM.8.gz
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a README.rst ChangeLog.txt LICENSE TESTING ISSUES KNOWN_ISSUES REPOSITORIES \
requirements.txt $PKG/usr/doc/$PRGNAM-$VERSION

View file

@ -21,6 +21,7 @@
# 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
from slpkg.utils import Utils
from slpkg.splitting import split_package
@ -34,7 +35,9 @@ class BlackList(object):
self.meta = _meta_
self.quit = False
self.blackfile = "/etc/slpkg/blacklist"
self.black_conf = Utils().read_file(self.blackfile)
self.black_conf = ""
if os.path.isfile(self.blackfile):
self.black_conf = Utils().read_file(self.blackfile)
def get_black(self):
"""Return blacklist packages from /etc/slpkg/blacklist