2
# -*- coding: iso-8859-15 -*-
3
######################################################
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published
7
# by the Free Software Foundation; version 2 only.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
######################################################
18
# Author: Alfredo Jr. <junix>
19
# Creation: 28/10/2006
20
# Changed: 08/12/2006 by Laudeci Oliveira <laudeci@gmail.com>
21
# Purpose: Download Class
23
######################################################
31
(PACKAGE, VERSION, FILENAME, SIZE, DEBFILENAME,REMOTEFILEPATH,SECTION) = range(7)
33
def getRemoteFileSize(url):
35
instream=urllib2.urlopen(url, None)
36
return instream.info().getheader("Content-Length")
40
class Download(gobject.GObject):
42
__gsignals__ = dict(download_status=(gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_STRING, gobject.TYPE_FLOAT,gobject.TYPE_FLOAT, gobject.TYPE_INT)))
44
def __init__(self, url = "", filepath = ""):
45
gobject.GObject.__init__(self)
49
self.Folder = filepath
53
def cancelDownload(self):
56
def getDownloadSize(self):
57
return self.downloadSize
60
name = "%s%s%s" % ( self.Folder, os.sep, self.url.split("/")[-1] )
63
def createDownload(self):
64
instream=urllib2.urlopen(self.url, None)
65
#self.initialtime = time.time()
66
return (instream, instream.info().getheader("Content-Length"))
68
def download(self, progressgui = False):
74
outfile=open( self.getURLName(), "wb")
75
url, length = self.createDownload()
76
fileName=outfile.name.split(os.sep)[-1]
77
self.FileName = fileName
88
bytes = url.read(int(self.downSize))
89
bytesRead+= len(bytes)
90
fraction = float((100 * bytesRead) / length)
93
self.emit('download_status',fileName, length, len(bytes) , (fraction))
101
os.remove(self.getURLName())
111
# print "Error downloading %s" % (self.url)
114
gobject.type_register(Download)