From d34983cb57388f41217a4215e24c737dba352d3c Mon Sep 17 00:00:00 2001 From: dslackw Date: Wed, 23 Jul 2014 17:00:54 +0300 Subject: [PATCH] added: slack upgrade --- slpkg/slack/__init__.py | 0 slpkg/slack/dir_patches.py | 25 +++++++++++++++++ slpkg/slack/mirrors.py | 17 ++++++++++++ slpkg/slack/patches.py | 26 ++++++++++++++++++ slpkg/slack/slack_version.py | 10 +++++++ slpkg/slack/upgrade.py | 52 ++++++++++++++++++++++++++++++++++++ 6 files changed, 130 insertions(+) create mode 100644 slpkg/slack/__init__.py create mode 100755 slpkg/slack/dir_patches.py create mode 100755 slpkg/slack/mirrors.py create mode 100755 slpkg/slack/patches.py create mode 100755 slpkg/slack/slack_version.py create mode 100755 slpkg/slack/upgrade.py diff --git a/slpkg/slack/__init__.py b/slpkg/slack/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/slpkg/slack/dir_patches.py b/slpkg/slack/dir_patches.py new file mode 100755 index 00000000..3d65b6d3 --- /dev/null +++ b/slpkg/slack/dir_patches.py @@ -0,0 +1,25 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import re +from functions import get_to +from url_read import url_read + +def dir_patches(http): + ''' + Found directories from patches + ''' + link = url_read(http) + folders = [] + patch_dir = [] + dirs = '' + for line in link.splitlines(): + if re.findall("folder", line): + folders.append(line) + for dirs in folders: + folders = dirs.split() + for folder in folders: + if re.findall("href", folder): + folder = folder.replace("href=\"", "") + patch_dir.append(get_to(folder, "/")) + return patch_dir diff --git a/slpkg/slack/mirrors.py b/slpkg/slack/mirrors.py new file mode 100755 index 00000000..8839f402 --- /dev/null +++ b/slpkg/slack/mirrors.py @@ -0,0 +1,17 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +from __metadata__ import uname, arch + +def mirrors(name): + ''' + Choose Slackware mirror based + architecture + ''' + if arch == "x86_64": + http = "http://mirrors.slackware.com/slackware/slackware64-14.1/patches/packages/" + name + else: + http = "http://mirrors.slackware.com/slackware/slackware-14.1/patches/packages/" + name + return http + + diff --git a/slpkg/slack/patches.py b/slpkg/slack/patches.py new file mode 100755 index 00000000..60b7770b --- /dev/null +++ b/slpkg/slack/patches.py @@ -0,0 +1,26 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import re +import os + +from functions import get_to +from url_read import url_read + + +def patches(http): + ''' + Find patches from oficial Slackware mirrors + ''' + link = url_read(http) + patches = [] + pkg_patches = [] + for line in link.split(): + if line.startswith("href"): + line = line.replace("href=\"", "") + txz = re.findall(".txz", line) + if txz: + slack = get_to(line, "\"") + if slack.endswith(".txz"): + patches.append(slack) + return patches diff --git a/slpkg/slack/slack_version.py b/slpkg/slack/slack_version.py new file mode 100755 index 00000000..22d1d714 --- /dev/null +++ b/slpkg/slack/slack_version.py @@ -0,0 +1,10 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import re + +def slack_ver(): + f = open('/etc/slackware-version', 'r') + sv = f.read() + f.close() + return '.'.join(re.findall(r'\d+', sv)) diff --git a/slpkg/slack/upgrade.py b/slpkg/slack/upgrade.py new file mode 100755 index 00000000..bb63aa68 --- /dev/null +++ b/slpkg/slack/upgrade.py @@ -0,0 +1,52 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import sys +from dir_patches import dir_patches +from patches import patches +from slack_version import slack_ver +from __metadata__ import arch, packages +from pkg.find import find_package +from colors import colors +from url_read import url_read +from mirrors import mirrors + + +def upgrade_all(): + upgrades = [] + sum_upgrades = [] + dirs = dir_patches(mirrors(name = '')) + upgrades.append((patches(mirrors(name = '')))) + version = slack_ver() + tag = "slack" + ftype = ".txz" + updates = [] + slack_type_len = len(arch + tag + version + ftype) + 4 + ftype_len = len(ftype) + + if dirs: + for d in dirs: + http = mirrors(d) + "/" + upgrades.append((patches(http))) + + for i in range(len(upgrades)): + for j in range(len(upgrades[i])): + sum_upgrades.append(upgrades[i][j]) + + + for patch in sum_upgrades: + print patch + patch_name = patch[:-ftype_len] + pkg = ''.join(find_package(patch_name, packages)) + patch = patch.replace(ftype, '') + if patch > pkg: + updates.append(patch + ftype) + if updates != []: + print ("\nThese packages need upgrading:") + for update in updates: + print ("{0}update -->{1} {2}".format(colors.RED, colors.ENDC, update)) + read = raw_input("\nWould you like to upgrade ? [Y/y] ") + if read == "Y" or read == "y": + os.system("wget -N " + http + ''.join(updates)) + else: + print ("Your Slackware system is up to date")