summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-07-10 21:45:09 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-07-10 21:45:09 +0200
commitd0c21a999ba8ddf0c1956415a27f215baa2f727d (patch)
tree07feeb37a12e95b45b91f5e1faaea19d1b5da613 /module
parentshow queue in webif (diff)
downloadpyload-d0c21a999ba8ddf0c1956415a27f215baa2f727d.tar.xz
more documentation, some fixes
Diffstat (limited to 'module')
-rw-r--r--module/Api.py2
-rw-r--r--module/HookManager.py8
-rw-r--r--module/Progress.py5
-rw-r--r--module/database/FileDatabase.py8
-rw-r--r--module/plugins/hooks/UnRar.py63
5 files changed, 69 insertions, 17 deletions
diff --git a/module/Api.py b/module/Api.py
index 15052e83a..975b43709 100644
--- a/module/Api.py
+++ b/module/Api.py
@@ -152,9 +152,11 @@ class Api(Iface):
return serverStatus
def freeSpace(self):
+ """Available free space at download directory in bytes"""
return freeSpace(self.core.config["general"]["download_folder"])
def getServerVersion(self):
+ """pyLoad Core version """
return self.core.version
def kill(self):
diff --git a/module/HookManager.py b/module/HookManager.py
index 393db2de6..94faaba6e 100644
--- a/module/HookManager.py
+++ b/module/HookManager.py
@@ -34,18 +34,18 @@ class HookManager:
but some very usefull events are called by the Core.
Contrary to overwriting hook methods you can use event listener,
which provides additional entry point in the control flow.
- Only use very short tasks or use threads.
+ Only do very short tasks or use threads.
*Known Events:*
All hook methods exists as events.
downloadPreparing: A download was just queued and will be prepared now.
- Argument: fid
+ Argument: fid
downloadStarts: A file will immediately starts the download afterwards.
- Argument: fid
+ Argument: fid
linksAdded: Someone just added links, you are able to modify the links.
- Arguments: links, pid
+ Arguments: links, pid
allDownloadsProcessed: Every link was handled, pyload would idle afterwards.
diff --git a/module/Progress.py b/module/Progress.py
index e12786da8..1ce4903a4 100644
--- a/module/Progress.py
+++ b/module/Progress.py
@@ -34,4 +34,7 @@ class Progress:
self.notify()
def getPercent(self):
- return self.value
+ try:
+ return int(self.value)
+ except:
+ return 0
diff --git a/module/database/FileDatabase.py b/module/database/FileDatabase.py
index 96b505fe0..3e2f37976 100644
--- a/module/database/FileDatabase.py
+++ b/module/database/FileDatabase.py
@@ -95,8 +95,8 @@ class FileHandler:
data = self.db.getAllLinks(queue)
packs = self.db.getAllPackages(queue)
- data.update([(str(x.id), x.toDbDict()[x.id]) for x in self.cache.itervalues()])
- packs.update([(str(x.id), x.toDict()[x.id]) for x in self.packageCache.itervalues() if x.queue == queue])
+ data.update([(str(x.id), x.toDbDict()[x.id]) for x in self.cache.values()])
+ packs.update([(str(x.id), x.toDict()[x.id]) for x in self.packageCache.values() if x.queue == queue])
for key, value in data.iteritems():
if packs.has_key(str(value["package"])):
@@ -351,9 +351,10 @@ class FileHandler:
"""checks if all files are finished and dispatch event"""
if not self.getQueueCount(True):
- #hope its not called twice
+ #hope its not called together with all DownloadsProcessed
self.core.hookManager.dispatchEvent("allDownloadsProcessed")
self.core.hookManager.dispatchEvent("allDownloadsFinished")
+ self.core.log.debug("All downloads finished")
return True
return False
@@ -365,6 +366,7 @@ class FileHandler:
if not self.db.processcount(1):
self.core.hookManager.dispatchEvent("allDownloadsProcessed")
+ self.core.log.debug("All downloads processed")
return True
return False
diff --git a/module/plugins/hooks/UnRar.py b/module/plugins/hooks/UnRar.py
index 751c03987..6dfe2c195 100644
--- a/module/plugins/hooks/UnRar.py
+++ b/module/plugins/hooks/UnRar.py
@@ -24,13 +24,14 @@ from module.plugins.Hook import Hook
from module.lib.pyunrar import Unrar, WrongPasswordError, CommandError, UnknownError, LowRamError
from traceback import print_exc
-from os.path import exists, join, isabs
-from os import remove
+from os.path import exists, join, isabs, isdir
+from os import remove, makedirs, rmdir, listdir, chown, chmod
+from pwd import getpwnam
import re
class UnRar(Hook):
__name__ = "UnRar"
- __version__ = "0.1"
+ __version__ = "0.11"
__description__ = """unrar"""
__config__ = [ ("activated", "bool", "Activated", False),
("fullpath", "bool", "extract full path", True),
@@ -70,7 +71,31 @@ class UnRar(Hook):
self.ram = 0
self.ram /= 1024
-
+
+ def setOwner(self,d,uid,gid,mode):
+ if not exists(d):
+ self.core.log.debug(_("Directory %s does not exist!") % d)
+ return
+ fileList=listdir(d)
+ for fileEntry in fileList:
+ fullEntryName=join(d,fileEntry)
+ if isdir(fullEntryName):
+ self.setOwner(fullEntryName,uid,gid,mode)
+ try:
+ chown(fullEntryName,uid,gid)
+ chmod(fullEntryName,mode)
+ except:
+ self.core.log.debug(_("Chown/Chmod for %s failed") % fullEntryName)
+ self.core.log.debug(_("Exception: %s") % sys.exc_info()[0])
+ continue
+ try:
+ chown(d,uid,gid)
+ chmod(d,mode)
+ except:
+ self.core.log.debug(_("Chown/Chmod for %s failed") % d)
+ self.core.log.debug(_("Exception: %s") % sys.exc_info()[0])
+ return
+
def addPassword(self, pws):
if not type(pws) == list: pws = [pws]
pws.reverse()
@@ -123,14 +148,15 @@ class UnRar(Hook):
pyfile.progress.setRange(0, 100)
def s(p):
pyfile.progress.setValue(p)
-
+
download_folder = self.core.config['general']['download_folder']
-
+ self.core.log.debug(_("download folder %s") % download_folder)
+
if self.core.config['general']['folder_per_package']:
folder = join(download_folder, pack.folder.decode(sys.getfilesystemencoding()))
else:
folder = download_folder
-
+
destination = folder
if self.getConfig("unrar_destination") and not self.getConfig("unrar_destination").lower() == "none":
destination = self.getConfig("unrar_destination")
@@ -141,7 +167,12 @@ class UnRar(Hook):
destination = join(destination, sub)
else:
destination = join(folder, destination, sub)
-
+
+ self.core.log.debug(_("Destination folder %s") % destination)
+ if not exists(destination):
+ self.core.log.info(_("Creating destination folder %s") % destination)
+ makedirs(destination)
+
u = Unrar(join(folder, fname), tmpdir=join(folder, "tmp"), ramSize=(self.ram if self.getConfig("ramwarning") else 0), cpu=self.getConfig("renice"))
try:
success = u.crackPassword(passwords=self.passwords, statusFunction=s, overwrite=True, destination=destination, fullPath=self.getConfig("fullpath"))
@@ -175,9 +206,23 @@ class UnRar(Hook):
if success:
self.core.log.info(_("Unrar of %s ok") % fname)
self.removeFiles(pack, fname)
+ if self.core.config['general']['folder_per_package']:
+ if self.getConfig("deletearchive"):
+ self.core.log.debug(_("Deleting package directory %s...") % folder)
+ rmdir(folder)
+ self.core.log.debug(_("Package directory %s has been deleted.") % folder)
+ ownerUser=self.core.config['permission']['user']
+ uinfo=getpwnam(ownerUser)
+ fileMode=int(self.core.config['permission']['file'],8)
+ self.core.log.debug(_("Setting destination file/directory owner to %s.") % ownerUser)
+ self.core.log.debug(_("Setting destination file/directory mode to %s.") % fileMode)
+ self.core.log.debug(_("Uid is %s.") % uinfo.pw_uid)
+ self.core.log.debug(_("Gid is %s.") % uinfo.pw_gid)
+ self.setOwner(destination,uinfo.pw_uid,uinfo.pw_gid,fileMode)
+ self.core.log.debug(_("The owner/rights have been successfully changed."))
self.core.hookManager.unrarFinished(folder, fname)
else:
- self.core.log.info(_("Unrar of %s failed (wrong password)") % fname)
+ self.core.log.info(_("Unrar of %s failed (wrong password or bad parts)") % fname)
finally:
pyfile.progress.setValue(100)
pyfile.setStatus("finished")