2014-09-27 22:54:30 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# downloader.py file is part of slpkg.
|
|
|
|
|
|
|
|
# Copyright 2014 Dimitris Zlatanidis <d.zlatanidis@gmail.com>
|
|
|
|
# All rights reserved.
|
|
|
|
|
2014-12-19 05:57:56 +01:00
|
|
|
# Slpkg is a user-friendly package manager for Slackware installations
|
2014-09-27 22:54:30 +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-01-30 23:04:51 +01:00
|
|
|
import os
|
2014-10-06 21:44:44 +02:00
|
|
|
import sys
|
2014-09-27 22:54:30 +02:00
|
|
|
import subprocess
|
|
|
|
|
2015-01-30 23:04:51 +01:00
|
|
|
from messages import Msg
|
2015-01-24 16:19:06 +01:00
|
|
|
from __metadata__ import MetaData as _m
|
2014-09-27 22:54:30 +02:00
|
|
|
|
2014-10-06 21:44:44 +02:00
|
|
|
|
|
|
|
class Download(object):
|
|
|
|
|
|
|
|
def __init__(self, path, url):
|
|
|
|
self.path = path
|
|
|
|
self.url = url
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
'''
|
|
|
|
Download files usign wget.
|
|
|
|
'''
|
2014-12-03 02:42:55 +01:00
|
|
|
for dwn in self.url:
|
2015-01-30 23:04:51 +01:00
|
|
|
self.file_name = dwn.split("/")[-1]
|
2015-01-24 16:19:06 +01:00
|
|
|
print("\n[ {0}Download{1} ] -->{1} {2}\n".format(_m.color['GREEN'],
|
|
|
|
_m.color['ENDC'],
|
2015-01-30 23:04:51 +01:00
|
|
|
self.file_name))
|
2014-12-03 02:42:55 +01:00
|
|
|
try:
|
2015-01-07 08:25:48 +01:00
|
|
|
subprocess.call("wget {0} --directory-prefix={1} {2}".format(
|
2015-01-24 16:19:06 +01:00
|
|
|
_m.wget_option, self.path, dwn), shell=True)
|
2015-01-30 23:04:51 +01:00
|
|
|
self.check()
|
2014-12-03 02:42:55 +01:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
print # new line at cancel
|
|
|
|
sys.exit(0)
|
2015-01-30 23:04:51 +01:00
|
|
|
|
|
|
|
def check(self):
|
|
|
|
if not os.path.isfile(self.path + self.file_name):
|
|
|
|
Msg().template(78)
|
|
|
|
print("| Download '{0}' file {1}[ FAILED ]{2}".format(
|
|
|
|
self.file_name, _m.color['RED'], _m.color['ENDC']))
|
|
|
|
Msg().template(78)
|