gget r103 - trunk/gget
- From: johans svn gnome org
- To: svn-commits-list gnome org
- Subject: gget r103 - trunk/gget
- Date: Thu, 21 Aug 2008 11:30:48 +0000 (UTC)
Author: johans
Date: Thu Aug 21 11:30:48 2008
New Revision: 103
URL: http://svn.gnome.org/viewvc/gget?rev=103&view=rev
Log:
Added:
trunk/gget/download_manager.py
Removed:
trunk/gget/DownloadManager.py
Modified:
trunk/gget/Download.py
trunk/gget/Makefile.am
trunk/gget/application.py
trunk/gget/dbus_service.py
trunk/gget/dialogs.py
trunk/gget/notify.py
trunk/gget/utils.py
Modified: trunk/gget/Download.py
==============================================================================
--- trunk/gget/Download.py (original)
+++ trunk/gget/Download.py Thu Aug 21 11:30:48 2008
@@ -27,11 +27,11 @@
import gobject
import gnomevfs
-import DBusService
+import config
+import dbus_service
import gui
import utils
import metalink
-from config import Configuration
from notify import Notification
from gget import NAME
@@ -63,8 +63,8 @@
def __init__(self, uri, path, date_started="", date_completed=""):
gobject.GObject.__init__(self)
- self.config = Configuration()
- self.dbus_service = DBusService.DBusService()
+ self.config = config.Configuration()
+ self.dbus_service = dbus_service.DBusService()
self.uri = gnomevfs.make_uri_from_shell_arg(uri)
self.file_name = os.path.basename(self.uri)
Modified: trunk/gget/Makefile.am
==============================================================================
--- trunk/gget/Makefile.am (original)
+++ trunk/gget/Makefile.am Thu Aug 21 11:30:48 2008
@@ -6,7 +6,7 @@
dialogs.py \
Download.py \
download_list.py \
- DownloadManager.py \
+ download_manager.py \
gui.py \
__init__.py \
metalink.py \
Modified: trunk/gget/application.py
==============================================================================
--- trunk/gget/application.py (original)
+++ trunk/gget/application.py Thu Aug 21 11:30:48 2008
@@ -35,7 +35,7 @@
import gui
from dialogs import AddDownloadDialog
from download_list import DownloadList
-from DownloadManager import DownloadManager
+from download_manager import DownloadManager
from window import MainWindow
from status_icon import TrayIcon
from gget import NAME, VERSION, LOCALE_DIR
Modified: trunk/gget/dbus_service.py
==============================================================================
--- trunk/gget/dbus_service.py (original)
+++ trunk/gget/dbus_service.py Thu Aug 21 11:30:48 2008
@@ -26,7 +26,6 @@
import config
import dialogs
import utils
-from dialogs import AddDownloadDialog
from gget import NAME
try:
@@ -164,7 +163,7 @@
r = ""
if self.config.ask_for_location:
gtk.gdk.threads_enter()
- add = AddDownloadDialog.AddDownloadDialog(uri)
+ add = dialogs.AddDownloadDialog(uri)
if add.dialog.run() == 1:
download = add.download
if download:
Modified: trunk/gget/dialogs.py
==============================================================================
--- trunk/gget/dialogs.py (original)
+++ trunk/gget/dialogs.py Thu Aug 21 11:30:48 2008
@@ -33,7 +33,7 @@
import Download
import utils
from download_list import DownloadList
-from DownloadManager import DownloadManager
+from download_manager import DownloadManager
from status_icon import TrayIcon
from gget import NAME, VERSION
Added: trunk/gget/download_manager.py
==============================================================================
--- (empty file)
+++ trunk/gget/download_manager.py Thu Aug 21 11:30:48 2008
@@ -0,0 +1,156 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2008 Johan Svedberg <johan svedberg com>
+
+# This file is part of GGet.
+
+# GGet 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 2 of the License, or
+# (at your option) any later version.
+
+# GGet 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 GGet; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+
+import os.path
+import sys
+import thread
+from gettext import gettext as _
+
+import gtk
+import gobject
+
+import metalink
+
+import config
+import Download
+import utils
+from download_list import DownloadList
+from gget import NAME, VERSION
+
+class DownloadManager(gobject.GObject):
+ """Singleton handling the downloads"""
+
+ __gsignals__ = {"download-started": (gobject.SIGNAL_RUN_LAST, None,
+ (object,))}
+
+ instance = None
+
+ def __new__(type, *args):
+ if DownloadManager.instance is None:
+ DownloadManager.instance = gobject.GObject.__new__(type)
+ DownloadManager.instance.__init(*args)
+ return DownloadManager.instance
+
+ def __init(self, *args):
+ gobject.GObject.__init__(self)
+ self.config = config.Configuration()
+ self.download_list = DownloadList()
+ self.download_list.connect("download-added", self.__download_added)
+
+ metalink.USER_AGENT = "%s %s" % (NAME, VERSION)
+
+ self.__set_proxies()
+
+ def __set_proxies(self):
+ if self.config.proxy_mode == "gnome":
+ if self.config.use_http_proxy:
+ if self.config.use_http_proxy_auth:
+ self.set_proxy("http", "http://%s:%s %s:%s" % \
+ (self.config.http_proxy_user,
+ self.config.http_proxy_pass,
+ self.config.http_proxy_host,
+ self.config.http_proxy_port))
+ if self.config.use_same_proxy:
+ self.set_proxy("https", "https://%s:%s %s:%s" % \
+ (self.config.http_proxy_user,
+ self.config.http_proxy_pass,
+ self.config.proxy_https_host,
+ self.config.proxy_https_port))
+ self.set_proxy("ftp", "ftp://%s:%s %s:%s" % \
+ (self.config.http_proxy_user,
+ self.config.http_proxy_pass,
+ self.config.proxy_ftp_host,
+ self.config.proxy_ftp_port))
+ else:
+ self.set_proxy("http", "http://%s:%s" % \
+ (self.config.http_proxy_host,
+ self.config.http_proxy_port))
+ self.set_proxy("https", "https://%s:%s" % \
+ (self.config.proxy_https_host,
+ self.config.proxy_https_port))
+ self.set_proxy("ftp", "ftp://%s:%s" % \
+ (self.config.proxy_ftp_host,
+ self.config.proxy_ftp_port))
+ elif self.config.proxy_mode == "manual":
+ if self.config.proxy_auth:
+ self.set_proxy("http", "http://%s:%s %s:%s" % \
+ (self.config.proxy_user,
+ self.config.proxy_password,
+ self.config.proxy_host,
+ self.config.proxy_port))
+ else:
+ self.set_proxy("http", "http://%s:%s" % \
+ (self.config.proxy_host, self.config.proxy_port))
+
+ def __download_added(self, download_list, download):
+ """Called when a new download is added to DownloadList. Starts the
+ download if its not already completed."""
+ download.connect("status-changed", self.__status_changed)
+
+ if not download.status in [Download.COMPLETED, Download.CANCELED]:
+ self.start_download(download)
+
+ def __status_changed(self, download, status):
+ """Called when the status of a download changes. If a canceled download
+ is resumed we need to start the download again."""
+ if status == Download.DOWNLOADING and \
+ download.old_status == Download.CANCELED:
+ self.start_download(download)
+
+ def start_download(self, download):
+ """Starts a download in a new thread."""
+ utils.debug_print("Starting download %s" % download)
+ thread.start_new_thread(self.__start_download, (download,))
+ self.emit("download-started", (download))
+
+ def __start_download(self, download):
+ # Python 2.5 seems to have a bug: sys.excepthook is not call from code
+ # in a thread, see http://spyced.blogspot.com/2007/06/workaround-for-sysexcepthook-bug.html
+ # sys.excepthook(*sys.exc_info())
+
+ if download.status in [-1, Download.DOWNLOADING]:
+ download.set_status(Download.CONNECTING)
+ try:
+ result = metalink.get(download.uri, download.path,
+ handlers={"status": download.update,
+ "bitrate": download.bitrate,
+ "cancel": download.is_canceled,
+ "pause": download.is_paused})
+
+ if not result:
+ download.set_status(Download.ERROR)
+ print "Failed downloading of file %s" % download.uri
+
+ except Exception, e:
+ print "Exception caught in DownloadManager.__start_download: " + e
+
+ def set_proxy(self, protocol, proxy):
+ """Sets the proxy to use for the specified protocol."""
+ if protocol == "http":
+ metalink.HTTP_PROXY = proxy
+ utils.debug_print("HTTP proxy: %s" % metalink.HTTP_PROXY)
+ elif protocol == "https":
+ metalink.HTTPS_PROXY = proxy
+ utils.debug_print("HTTPS proxy: %s" % metalink.HTTPS_PROXY)
+ elif protocol == "ftp":
+ metalink.FTP_PROXY = proxy
+ utils.debug_print("FTP proxy: %s" % metalink.FTP_PROXY)
+
+# vim: set sw=4 et sts=4 tw=79 fo+=l:
Modified: trunk/gget/notify.py
==============================================================================
--- trunk/gget/notify.py (original)
+++ trunk/gget/notify.py Thu Aug 21 11:30:48 2008
@@ -24,10 +24,10 @@
import gobject
import gnomevfs
+import config
import gui
import dialogs
from status_icon import TrayIcon
-from config import Configuration
from gget import NAME
try:
@@ -45,7 +45,7 @@
def __init__(self, download):
self.download = download
- self.config = Configuration()
+ self.config = config.Configuration()
self.status_icon = TrayIcon()
pynotify.init(NAME)
Modified: trunk/gget/utils.py
==============================================================================
--- trunk/gget/utils.py (original)
+++ trunk/gget/utils.py Thu Aug 21 11:30:48 2008
@@ -29,7 +29,7 @@
import dbus
import dbus.glib
-from config import Configuration
+import config
def runned_from_source():
path = os.path.join(os.path.dirname(__file__), "..")
@@ -106,16 +106,15 @@
return "%ds" % secs
def debug_print(message):
- config = Configuration()
- if config.debug:
+ cfg = config.Configuration()
+ if cfg.debug:
print("[%s] %s" % (time.strftime("%Y/%m/%d %H:%M:%S", time.localtime()),
- message))
+ message))
def get_folder_for_extension(uri):
- config = Configuration()
- if config.check_extensions:
- for extension, folder in zip(config.extensions,
- config.extension_folders):
+ cfg = config.Configuration()
+ if cfg.check_extensions:
+ for extension, folder in zip(cfg.extensions, cfg.extension_folders):
if fnmatch.fnmatch(os.path.basename(uri), extension):
return folder
return None
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]