summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-08-21 18:23:28 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-08-21 18:23:28 +0200
commit6725cbd7f7e52741ee13f79ea030b908691232bf (patch)
tree25dec00afba7d03e938ec370a0d5570a22b1f74f /module
parentadaptions for win build (diff)
downloadpyload-6725cbd7f7e52741ee13f79ea030b908691232bf.tar.xz
removed tempfile, win fixes
Diffstat (limited to 'module')
-rw-r--r--module/PluginThread.py2
-rw-r--r--module/plugins/Plugin.py7
-rw-r--r--module/plugins/captcha/LinksaveIn.py1
-rw-r--r--module/plugins/captcha/MegauploadCom.py1
-rw-r--r--module/plugins/captcha/NetloadIn.py1
-rw-r--r--module/plugins/captcha/ShareonlineBiz.py2
-rw-r--r--module/plugins/captcha/captcha.py37
7 files changed, 39 insertions, 12 deletions
diff --git a/module/PluginThread.py b/module/PluginThread.py
index 623227061..ee5ebb0d5 100644
--- a/module/PluginThread.py
+++ b/module/PluginThread.py
@@ -92,7 +92,7 @@ class PluginThread(Thread):
- dump_name = "debug_%s_%s.txt" % (pyfile.pluginname, strftime("%d-%m-%Y_%H:%M:%S"))
+ dump_name = "debug_%s_%s.txt" % (pyfile.pluginname, strftime("%d-%m-%Y_%H-%M-%S"))
self.m.core.log.info("Debug Report written to %s" % dump_name)
f = open(dump_name, "wb")
diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py
index 31aae2ee9..42809b248 100644
--- a/module/plugins/Plugin.py
+++ b/module/plugins/Plugin.py
@@ -204,7 +204,7 @@ class Plugin(object):
content = self.load(url, get=get, post=post, cookies=cookies)
temp = NamedTemporaryFile()
- temp = open("tmpCaptcha_%s" % self.__name__, "wb")
+ temp = open(join("tmp","tmpCaptcha_%s" % self.__name__ ), "wb")
temp.write(content)
temp.close()
@@ -232,9 +232,10 @@ class Plugin(object):
sleep(1)
result = task.getResult()
task.removeTask()
+
+ if not self.core.debug:
+ remove(temp.name)
- remove(temp.name)
- #temp.unlink(temp.name)
return result
diff --git a/module/plugins/captcha/LinksaveIn.py b/module/plugins/captcha/LinksaveIn.py
index ff6bbebba..3ad7b265a 100644
--- a/module/plugins/captcha/LinksaveIn.py
+++ b/module/plugins/captcha/LinksaveIn.py
@@ -7,6 +7,7 @@ from glob import glob
class LinksaveIn(OCR):
+ __name__ = "LinksaveIn"
def __init__(self):
OCR.__init__(self)
self.data_dir = dirname(abspath(__file__)) + sep + "LinksaveIn" + sep
diff --git a/module/plugins/captcha/MegauploadCom.py b/module/plugins/captcha/MegauploadCom.py
index da8ab2cb9..469ee4094 100644
--- a/module/plugins/captcha/MegauploadCom.py
+++ b/module/plugins/captcha/MegauploadCom.py
@@ -1,6 +1,7 @@
from captcha import OCR
class MegauploadCom(OCR):
+ __name__ = "MegauploadCom"
def __init__(self):
OCR.__init__(self)
diff --git a/module/plugins/captcha/NetloadIn.py b/module/plugins/captcha/NetloadIn.py
index 75f3f2e8b..7f2e6a8d1 100644
--- a/module/plugins/captcha/NetloadIn.py
+++ b/module/plugins/captcha/NetloadIn.py
@@ -1,6 +1,7 @@
from captcha import OCR
class NetloadIn(OCR):
+ __name__ = "NetloadIn"
def __init__(self):
OCR.__init__(self)
diff --git a/module/plugins/captcha/ShareonlineBiz.py b/module/plugins/captcha/ShareonlineBiz.py
index 7bd5d7960..b07fb9b0f 100644
--- a/module/plugins/captcha/ShareonlineBiz.py
+++ b/module/plugins/captcha/ShareonlineBiz.py
@@ -20,6 +20,8 @@
from captcha import OCR
class ShareonlineBiz(OCR):
+ __name__ = "ShareonlineBiz"
+
def __init__(self):
OCR.__init__(self)
diff --git a/module/plugins/captcha/captcha.py b/module/plugins/captcha/captcha.py
index b4a6b0a37..60705f9e8 100644
--- a/module/plugins/captcha/captcha.py
+++ b/module/plugins/captcha/captcha.py
@@ -20,9 +20,10 @@
from __future__ import with_statement
import os
from os.path import join
+from os.path import abspath
import logging
import subprocess
-import tempfile
+#import tempfile
import threading
import Image
@@ -54,6 +55,9 @@ class RunThread(threading.Thread):
self.result = outputdata
class OCR(object):
+
+ __name__ = "OCR"
+
def __init__(self):
self.logger = logging.getLogger("log")
@@ -85,22 +89,30 @@ class OCR(object):
def run_tesser(self, subset=False, digits=True, lowercase=True, uppercase=True):
#self.logger.debug("create tmp tif")
- tmp = tempfile.NamedTemporaryFile(suffix=".tif")
+
+
+ #tmp = tempfile.NamedTemporaryFile(suffix=".tif")
+ tmp = open(join("tmp", "tmpTif_%s.tif" % self.__name__), "wb")
+ tmp.close()
#self.logger.debug("create tmp txt")
- tmpTxt = tempfile.NamedTemporaryFile(suffix=".txt")
+ #tmpTxt = tempfile.NamedTemporaryFile(suffix=".txt")
+ tmpTxt = open(join("tmp", "tmpTxt_%s.txt" % self.__name__), "wb")
+ tmpTxt.close()
+
self.logger.debug("save tiff")
self.image.save(tmp.name, 'TIFF')
if os.name == "nt":
- tessparams = [join(pydir,"tesseract","tesseract.exe")]
+ tessparams = [join(pypath,"tesseract","tesseract.exe")]
else:
tessparams = ['tesseract']
- tessparams.extend( [tmp.name, tmpTxt.name.replace(".txt", "")] )
+ tessparams.extend( [abspath(tmp.name), abspath(tmpTxt.name).replace(".txt", "")] )
if subset and (digits or lowercase or uppercase):
#self.logger.debug("create temp subset config")
- tmpSub = tempfile.NamedTemporaryFile(suffix=".subset")
+ #tmpSub = tempfile.NamedTemporaryFile(suffix=".subset")
+ tmpSub = open(join("tmp", "tmpSub_%s.subset" % self.__name__), "wb")
tmpSub.write("tessedit_char_whitelist ")
if digits:
tmpSub.write("0123456789")
@@ -110,8 +122,8 @@ class OCR(object):
tmpSub.write("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
tmpSub.write("\n")
tessparams.append("nobatch")
- tessparams.append(tmpSub.name)
- tmpSub.flush()
+ tessparams.append(abspath(tmpSub.name))
+ tmpSub.close()
self.logger.debug("run tesseract")
self.run(tessparams)
@@ -121,6 +133,15 @@ class OCR(object):
self.result_captcha = f.read().replace("\n", "")
self.logger.debug(self.result_captcha)
+
+ try:
+ os.remove(tmp.name)
+ os.remove(tmpTxt.name)
+ if subset and (digits or lowercase or uppercase):
+ os.remove(tmpSub.name)
+ except:
+ pass
+
def get_captcha(self):
raise NotImplementedError