diff options
author | spoob <spoob@gmx.de> | 2009-05-14 18:04:09 +0200 |
---|---|---|
committer | spoob <spoob@gmx.de> | 2009-05-14 18:04:09 +0200 |
commit | efd6b47d534a99986e56a1a347339019e63b387e (patch) | |
tree | 95358724350e24c16772d5b61de0e96d3ae92f90 | |
parent | Py_load_File in own file (diff) | |
download | pyload-efd6b47d534a99986e56a1a347339019e63b387e.tar.xz |
new plugin system in Core
-rw-r--r-- | Core.py | 83 | ||||
-rw-r--r-- | Plugins/UploadedTo.py | 75 |
2 files changed, 151 insertions, 7 deletions
@@ -23,13 +23,14 @@ CURRENT_VERSION = '0.1' import ConfigParser from glob import glob from string import find, split -from os import sep, chdir, mkdir, curdir, name, system +from os import sep, chdir, mkdir, curdir, name, system, remove from os.path import exists, abspath, dirname, basename from sys import path, exit from logging import warning, basicConfig import urllib2 import re from time import sleep +import pickle #my imports from download_thread import Download_Thread @@ -44,6 +45,9 @@ class Core(object): def __init__(self): self.download_folder = "" self.link_file = "links.txt" + self.plugin_index = "plugin_index.txt" + self.plugins_avaible = {} + self.plugins_needed = {} #self.applicationPath = "" self.search_updates = False self.plugins_folder = "" @@ -64,19 +68,84 @@ class Core(object): self.search_updates = config.get('updates', 'searchUpdates') self.plugins_folder = 'Plugins' path.append(self.plugins_folder) + +#################################################################################################### + + def import_plugins(self): + self.check_temp_file() + self.check_needed_plugins() + self.import_needed_plugins() + + def check_temp_file(self): + if not exists(self.plugin_index): + self.create_plugin_index() + + elif len(pickle.load(open(self.plugin_index, "r")).keys()) != len(glob(self.plugins_folder + sep + '*.py')) - 1: # without Plugin.py + remove(self.plugin_index) + self.create_plugin_index() + + def create_plugin_index(self): + for file in glob(self.plugins_folder + sep + '*.py'): + if file != self.plugins_folder + sep + "Plugin.py": + plugin_pattern = "" + plugin_file = basename(file).replace('.py', '') + for line in open(file, "r").readlines(): + try: + plugin_pattern = re.search(r"self.plugin_pattern = r\"(.*)\"", line).group(1) + break + print line + except: + pass + if plugin_pattern != "": + self.plugins_avaible[plugin_file] = plugin_pattern + print plugin_file, "hinzugefuegt" + pickle.dump(self.plugins_avaible, open(self.plugin_index, "w")) + print "Index der Plugins erstellt" + + def check_needed_plugins(self): + links = open(self.link_file, 'r').readlines() + plugins_indexed = pickle.load(open(self.plugin_index, "r")) + for link in links: + link = link.replace("\n", "") + for plugin_file in plugins_indexed.keys(): + if re.search(plugins_indexed[plugin_file], link) != None: + self.plugins_needed[plugin_file] = plugins_indexed[plugin_file] + print "Benoetigte Plugins: " + str(self.plugins_needed) + + def import_needed_plugins(self): + for needed_plugin in self.plugins_needed.keys(): + self.import_plugin(needed_plugin) + + def import_plugin(self, needed_plugin): + try: + new_plugin = __import__(needed_plugin) + #if new_plugin.plugin_type in "hoster" or new_plugin.plugin_type in "container": + # print "Plugin geladen: " + new_plugin.plugin_name + #plugins[plugin_file] = __import__(plugin_file) + except: + print "Fehlerhaftes Plugin: " + needed_plugin + + +#################################################################################################### + def get_avial_plugins(self, plugin_folder): """ searches the plugin-folder for plugins """ for file in glob(plugin_folder + "/" + '*.py'): - if file.endswith('.py'): + print file + if file.endswith('.py') and file != plugin_folder + sep + "Plugin.py": self.plugin_file = basename(file).replace('.py', '') print self.plugin_file + self.new_plugin = __import__(self.plugin_file) + print dir(self.new_plugin)[1].plugin_pattern try: - self.new_plugin = __import__(self.plugin_file) - if self.new_plugin.plugin_type in "hoster" or self.new_plugin.plugin_type in "container": - print "Plugin geladen: " + self.new_plugin.plugin_name - self.plugins[self.plugin_file] = __import__(self.plugin_file) + pass + #self.new_plugin = __import__(self.plugin_file) + #print self.new_plugin + #if self.new_plugin.plugin_type in "hoster" or self.new_plugin.plugin_type in "container": + # print "Plugin geladen: " + self.new_plugin.plugin_name + # self.plugins[self.plugin_file] = __import__(self.plugin_file) except: print "Fehlerhaftes Plugin: " + self.plugin_file #plugindict = {} @@ -184,4 +253,4 @@ class Core(object): break testLoader = Core() -testLoader.get_avial_plugins('Plugins') +testLoader.import_plugins() diff --git a/Plugins/UploadedTo.py b/Plugins/UploadedTo.py new file mode 100644 index 000000000..0a3b7ef71 --- /dev/null +++ b/Plugins/UploadedTo.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python + +import urllib2 +import re +from Plugin import Plugin + +class UploadedTo(Plugin): + + def __init__(self, parent): + self.plugin_name = "Uploaded.to" + self.plugin_pattern = r"http://(www\.)?uploaded.to/" + self.plugin_type = "hoster" + self.plugin_config = {} + pluginProp = {} + pluginProp ['name'] = "UploadedTo" + pluginProp ['version'] = "0.1" + pluginProp ['format'] = "*.py" + pluginProp ['description'] = """Uploaded Plugin""" + pluginProp ['author'] = "spoob" + pluginProp ['author_email'] = "spoob@gmx.de" + self.pluginProp = pluginProp + self.parent = parent + self.html = "" + self.html_old = None #time() where loaded the HTML + self.time_plus_wait = None #time() + wait in seconds + + def set_parent_status(self): + """ sets all available Statusinfos about a File in self.parent.status + """ + if self.html == None: + self.download_html() + self.parent.status.filename = self.get_file_name() + self.parent.status.url = self.get_file_url() + self.parent.status.wait = self.wait_until() + + def download_html(self): + url = self.parent.url + html = urllib2.urlopen(url).read() + try: + wait_minutes = re.search(r"Or wait (\d+) minutes", self.html).group(1) + self.time_plus_wait = time() + 60 * wait_minutes + except: + self.time_plus_wait = 0 + + def get_file_url(self): + """ returns the absolute downloadable filepath + """ + if self.html == None: + self.download_html() + file_url_pattern = r".*<form name=\"download_form\" method=\"post\" action=\"(.*)\">" + return re.search(file_url_pattern, self.html).group(1) + + def get_file_name(self): + if self.html == None: + self.download_html() + file_name_pattern = r"<title>\s*(.*?)\s+\.\.\." + return re.search(file_name_pattern, self.html).group(1) + + def file_exists(self): + """ returns True or False + """ + if self.html == None: + self.download_html() + if re.search(r"(File doesn't exist .*)", self.html) != None: + return False + else: + return True + + def wait_until(self): + if self.html == None: + self.download_html() + return self.time_plus_wait + + def __call__(self): + return self.plugin_name |