added: slack upgrade

This commit is contained in:
dslackw 2014-07-23 17:00:54 +03:00
parent ca64f0f743
commit d34983cb57
6 changed files with 130 additions and 0 deletions

0
slpkg/slack/__init__.py Normal file
View file

25
slpkg/slack/dir_patches.py Executable file
View file

@ -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

17
slpkg/slack/mirrors.py Executable file
View file

@ -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

26
slpkg/slack/patches.py Executable file
View file

@ -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

10
slpkg/slack/slack_version.py Executable file
View file

@ -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))

52
slpkg/slack/upgrade.py Executable file
View file

@ -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")