Bugfix: Slackware-current from Alien Bob 20191130 #119

Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
Dimitris Zlatanidis 2019-12-10 23:22:58 +01:00
parent c130631404
commit e583ffdbc6
4 changed files with 31 additions and 19 deletions

View file

@ -23,7 +23,7 @@
import os
import requests
import urllib3
class FileSize:
@ -31,15 +31,15 @@ class FileSize:
"""
def __init__(self, registry):
self.registry = registry
self.http = urllib3.PoolManager()
def server(self):
"""Returns the size of remote files
"""
try:
r = requests.head(self.registry)
r = self.http.request("GET", self.registry)
return int(r.headers["Content-Length"])
except (requests.exceptions.Timeout,
requests.exceptions.ConnectionError):
except urllib3.exceptions.NewConnectionError:
return " "
def local(self):

View file

@ -25,6 +25,7 @@
import os
import shutil
from slpkg.utils import Utils
from slpkg.repositories import Repo
from slpkg.file_size import FileSize
from slpkg.downloader import Download
@ -701,10 +702,13 @@ class Initialization:
def merge(self, path, outfile, infiles):
"""Merge files
"""
with open(path + outfile, 'w') as out_f:
for i in infiles:
if os.path.isfile("{0}{1}".format(path, i)):
with open(path + i, "r") as in_f:
code = "utf-8"
with open(path + outfile, 'w', encoding=code) as out_f:
for f in infiles:
if os.path.isfile("{0}{1}".format(path, f)):
# checking the encoding before read the file
code = Utils.check_encoding(path, f)
with open(path + f, "r", encoding=code) as in_f:
for line in in_f:
out_f.write(line)
@ -770,12 +774,10 @@ class Update(object):
if check_for_local_repos(repo) is True:
continue
print("{0}Check repository [{1}{2}{3}] ... "
"{4}".format(
self.meta.color["GREY"],
self.meta.color["CYAN"], repo,
self.meta.color["GREY"],
self.meta.color["ENDC"]), end="")
print(end="", flush=True)
"{4}".format(self.meta.color["GREY"],
self.meta.color["CYAN"], repo,
self.meta.color["GREY"],
self.meta.color["ENDC"]), end="", flush=True)
if repo in default:
exec("{0}.{1}()".format(self._init, repo))
print(self.done, end="")

View file

@ -22,7 +22,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import requests
import urllib3
from slpkg.__metadata__ import MetaData as _meta_
@ -33,15 +33,15 @@ class URL:
def __init__(self, link):
self.link = link
self.meta = _meta_
self.http = urllib3.PoolManager()
def reading(self):
"""Open url and read
"""
try:
f = requests.get(self.link)
return f.text
except (requests.exceptions.Timeout,
requests.exceptions.ConnectionError):
f = self.http.request('GET', self.link)
return f.data.decode("utf-8")
except urllib3.exceptions.NewConnectionError:
print("\n{0}Can't read the file '{1}'{2}".format(
self.meta.color["RED"], self.link.split("/")[-1],
self.meta.color["ENDC"]))

View file

@ -102,6 +102,16 @@ class Utils:
else:
return file_name
@staticmethod
def check_encoding(path, f):
"""Checking the file encoding default is utf-8
"""
try:
with open(path + f, "r") as ftest:
ftest.read()
except UnicodeDecodeError:
return "ISO-8859-1"
def debug(self, test):
"""Function used for print some stuff for debugging
"""