diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-06-08 12:23:28 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-06-08 12:23:28 +0200 |
commit | 7b6a6cb94c8c2abc449351a1238227f9b10b0872 (patch) | |
tree | cc419ba50b1cbab369949c0be45ccc2e82c57dba | |
parent | Fixed the YouPorn.com Plugin (diff) | |
download | pyload-7b6a6cb94c8c2abc449351a1238227f9b10b0872.tar.xz |
core able to push data to gui, proxy support: closed #1
-rw-r--r-- | Core.py | 33 | ||||
-rw-r--r-- | config | 4 | ||||
-rw-r--r-- | module/Py_Load_File.py | 5 | ||||
-rwxr-xr-x | module/network/Request.py | 13 | ||||
-rw-r--r-- | module/remote/RequestHandler.py | 4 | ||||
-rw-r--r-- | module/remote/RequestObject.py | 3 | ||||
-rw-r--r-- | module/remote/SocketServer.py | 17 | ||||
-rwxr-xr-x | pyMainGui.py | 21 |
8 files changed, 72 insertions, 28 deletions
@@ -19,10 +19,8 @@ ### CURRENT_VERSION = '0.1' -import gettext - -#python imports import ConfigParser +import gettext import logging import logging.handlers import time @@ -38,6 +36,7 @@ from sys import stdout from time import sleep from module.Py_Load_File import PyLoadFile +from module.remote.RequestObject import RequestObject from module.remote.SocketServer import ServerThread from module.thread_list import Thread_List @@ -71,6 +70,8 @@ class Core(object): path.append(self.config['plugin_folder']) self.create_plugin_index() + + self.init_server() def read_config(self): """ read config and sets preferences @@ -105,7 +106,7 @@ class Core(object): def append_link(self, link): if link not in self.thread_list.get_loaded_urls(): - self.__new_py_load_file(link.replace("\n","")) + self.__new_py_load_file(link.replace("\n", "")) def extend_links(self, links): for link in links: @@ -120,7 +121,7 @@ class Core(object): elif CURRENT_VERSION == newst_version: self.logger.info(_("newst version %s in use:") % CURRENT_VERSION) #using newst version else: - self.logger.info( _("beta version %s in use:") % CURRENT_VERSION) #using beta version + self.logger.info(_("beta version %s in use:") % CURRENT_VERSION) #using beta version def check_create(self, check_name, legend, folder=True): if not exists(check_name): @@ -194,6 +195,7 @@ class Core(object): return _("%i seconds") % seconds def _test_print_status(self): + if self.thread_list.py_downloading: for pyfile in self.thread_list.py_downloading: @@ -210,17 +212,24 @@ class Core(object): while True: #self.thread_list.status() self._test_print_status() + self.server_test() sleep(2) if len(self.thread_list.threads) == 0: pass #break + def server_test(self): + obj = RequestObject() + obj.command = "update" + obj.data = self.get_downloads() + + self.server.push_all(obj) + + def init_server(self): + print _("Server Mode") + self.server = ServerThread(self) + self.server.start() + if __name__ == "__main__": - testLoader = Core() - #if testLoader.config['remote_activated']: - #@spoob: lass den server an - print _("Server Mode") - server = ServerThread(testLoader) - server.start() - + testLoader = Core() testLoader.start() @@ -18,3 +18,7 @@ end = 24:00 [remote] port = 7272 remotePassword = pwhere +[proxy] +useproxy = False +proxyProtocol = http +proxyAdress = http://localhost:8080
\ No newline at end of file diff --git a/module/Py_Load_File.py b/module/Py_Load_File.py index 9fcd554a5..d0a4c4591 100644 --- a/module/Py_Load_File.py +++ b/module/Py_Load_File.py @@ -26,6 +26,11 @@ class PyLoadFile: return "Plugin" def prepareDownload(self): + + if self.parent.config['useproxy']: + self.plugin.req.add_proxy(self.parent.config['proxyprotocol'], self.parent.config['proxyadress']) + + self.status.exists = self.plugin.file_exists() if self.status.exists: self.status.filename = self.plugin.get_file_name() diff --git a/module/network/Request.py b/module/network/Request.py index 8e2b6ae02..de9000ab3 100755 --- a/module/network/Request.py +++ b/module/network/Request.py @@ -59,12 +59,12 @@ class Request: if post: post = urllib.urlencode(post) else: - post = None + post = None if get: - get = urllib.urlencode(get) + get = urllib.urlencode(get) else: - get = "" + get = "" url = url + get req = urllib2.Request(url, data=post) @@ -100,11 +100,16 @@ class Request: def add_cookies(self, req): cookie_head = "" for cookie in self.cookies: - cookie_head += cookie.name+"="+cookie.value+"; " + cookie_head += cookie.name + "=" + cookie.value + "; " req.add_header("Cookie", cookie_head) #def download(url, filename, reporthook = None, data = None): #default von urlretrieve auch None? # return self.downloader.urlretrieve(url, filename, reporthook, data) + def add_proxy(self, protocol, adress): + handler = urllib2.ProxyHandler({protocol: adress}) + self.opener.add_handler(handler) + self.downloader.add_handler(handler) + def download(self, url, filename, post={}): if post: diff --git a/module/remote/RequestHandler.py b/module/remote/RequestHandler.py index f7623d27b..2f6f248bd 100644 --- a/module/remote/RequestHandler.py +++ b/module/remote/RequestHandler.py @@ -28,7 +28,7 @@ class RequestHandler: if obj.command == "exec": func = getattr(self.core, obj.function) - obj.response = func(*obj.args) + obj.response = func( * obj.args) else: obj.response = "error happend" @@ -54,7 +54,7 @@ class RequestHandler: p_str = "" for i in range(padding - 1): - p_str += random.choice(string.letters + string.digits) + p_str += random.choice(string.letters + string.digits + string.punctuation) p_str += hex(len(p_str)).replace("0x", "") enc_str += p_str diff --git a/module/remote/RequestObject.py b/module/remote/RequestObject.py index 7080a6faf..c5786061b 100644 --- a/module/remote/RequestObject.py +++ b/module/remote/RequestObject.py @@ -13,4 +13,5 @@ class RequestObject(object): self.command = None self.function = "" self.args = [] - self.response = ""
\ No newline at end of file + self.response = None + self.data = None
\ No newline at end of file diff --git a/module/remote/SocketServer.py b/module/remote/SocketServer.py index c519d8a3b..e5932bb6e 100644 --- a/module/remote/SocketServer.py +++ b/module/remote/SocketServer.py @@ -24,6 +24,20 @@ class ServerThread(threading.Thread): asyncore.loop() print "loop closed" + def sockets(self): + """returns all connected sockets in a list""" + sockets = [] + for value in asyncore.socket_map.values(): + if SecondaryServerSocket == value.__class__: + sockets.append(value) + + return sockets + + def push_all(self, obj): + """push obj to all sockets""" + for socket in self.sockets(): + socket.push_obj(obj) + class MainServerSocket(asyncore.dispatcher): def __init__(self, port, pycore): @@ -61,3 +75,6 @@ class SecondaryServerSocket(asynchat.async_chat): def handle_close(self): print "Disconnected from", self.getpeername() self.close() + def push_obj(self, obj): + obj = self.handler.encrypt(obj) + self.push(obj) diff --git a/pyMainGui.py b/pyMainGui.py index a966992b2..440e40471 100755 --- a/pyMainGui.py +++ b/pyMainGui.py @@ -23,8 +23,8 @@ from os.path import abspath from os.path import dirname import wx +import wx.lib.newevent import wx.lib.sized_controls as sized_control -import wx.lib.newevent from module.remote.ClientSocket import SocketThread (DataArrived, EVT_DATA_ARRIVED) = wx.lib.newevent.NewEvent() @@ -83,7 +83,7 @@ class Pyload_Main_Gui(wx.Frame): app_path = dirname(abspath(__file__)) + sep - # socket + # socket self.thread = SocketThread("localhost", 7272, "pwhere", self) @@ -110,7 +110,7 @@ class Pyload_Main_Gui(wx.Frame): splitter = wx.SplitterWindow(self) panel_up = _Upper_Panel(splitter) panel_down = _Lower_Panel(splitter) - splitter.SplitHorizontally(panel_up,panel_down,300) + splitter.SplitHorizontally(panel_up, panel_down, 300) # Binds self.Bind(wx.EVT_MENU, self.exit_button_clicked, submenu_exit) @@ -134,17 +134,20 @@ class Pyload_Main_Gui(wx.Frame): def show_links(self, links): for link in links: - wx.CallAfter(wx.MessageDialog(self, str(link), 'info', style=wx.OK).ShowModal()) + wx.MessageDialog(self, str(link), 'info', style=wx.OK).ShowModal() def data_arrived(self, rep): - evt = DataArrived(obj = rep) + evt = DataArrived(obj=rep) wx.PostEvent(self, evt) - def onUpdate(self, data): + def onUpdate(self, evt): - if data.obj.function == "get_downloads": - self.show_links(data.obj.response) + if evt.obj.function == "get_downloads": + self.show_links(evt.obj.response) + + if evt.obj.command == "update": + self.show_links(evt.obj.data) app = wx.App() -Pyload_Main_Gui(None,-1) +Pyload_Main_Gui(None, -1) app.MainLoop() |