summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-08-05 12:38:49 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-08-05 12:38:49 +0200
commit3ff84e841db60c275df2df4256505a26b8c2ee08 (patch)
tree349e8723c964b0de4c64769ae2f9ab532661bdba
parentsingle file abort (diff)
downloadpyload-3ff84e841db60c275df2df4256505a26b8c2ee08.tar.xz
file version check, delete old configs!
-rw-r--r--module/ConfigParser.py29
-rw-r--r--module/FileDatabase.py31
-rw-r--r--module/config/default.conf4
3 files changed, 58 insertions, 6 deletions
diff --git a/module/ConfigParser.py b/module/ConfigParser.py
index e3d1e038e..49401416b 100644
--- a/module/ConfigParser.py
+++ b/module/ConfigParser.py
@@ -5,8 +5,11 @@ from pprint import pprint
from os.path import exists
from os.path import join
from shutil import copy
+from os import remove
+CONF_VERSION = 1
+
########################################################################
class ConfigParser:
"""
@@ -53,9 +56,29 @@ class ConfigParser:
if not exists("plugin.conf"):
f = open("plugin.conf", "wb")
+ f.write("version: "+str(CONF_VERSION))
f.close()
- #@TODO: testing conf file version
+ f = open("pyload.conf", "rb")
+ v = f.readline()
+ f.close()
+ v = v[v.find(":")+1:].strip()
+
+ if int(v) < CONF_VERSION:
+ copy(join(pypath,"module", "config", "default.conf"), "pyload.conf")
+ print "Old version of config was replaced"
+
+ f = open("plugin.conf", "rb")
+ v = f.readline()
+ f.close()
+ v = v[v.find(":")+1:].strip()
+
+ if int(v) < CONF_VERSION:
+ f = open("plugin.conf", "wb")
+ f.write("version: "+str(CONF_VERSION))
+ f.close()
+ print "Old version of config was replaced"
+
#----------------------------------------------------------------------
def readConfig(self):
@@ -87,7 +110,7 @@ class ConfigParser:
config = f.read()
- config = config.split("\n")
+ config = config.split("\n")[1:]
conf = {}
@@ -192,7 +215,7 @@ class ConfigParser:
def saveConfig(self, config, filename):
"""saves config to filename"""
with open(filename, "wb") as f:
-
+ f.write("config: %i \n" % CONF_VERSION)
for section in config.iterkeys():
f.write('\n%s - "%s":\n' % (section, config[section]["desc"]))
diff --git a/module/FileDatabase.py b/module/FileDatabase.py
index fe1bb9f8f..990f7cab4 100644
--- a/module/FileDatabase.py
+++ b/module/FileDatabase.py
@@ -23,9 +23,14 @@ from threading import RLock
from time import sleep
from time import time
import traceback
+from os.path import exists
+from os import remove
from module.PullEvents import UpdateEvent, RemoveEvent, InsertEvent
+
+DB_VERSION = 1
+
statusMap = {
"finished": 0,
"offline": 1,
@@ -339,13 +344,14 @@ class FileHandler:
@change
def setPackageLocation(self, id, queue):
"""push package to queue"""
- pack = self.db.getPackage(id)
+ pack = self.getPackage(id)
e = RemoveEvent("pack", id, "collector" if not pack.queue else "queue")
self.core.pullManager.addEvent(e)
pack.queue = queue
- self.db.updatePackage(pack)
+ pack.sync()
+ self.db.commit()
e = InsertEvent("pack", id, -1, "collector" if not pack.queue else "queue")
self.core.pullManager.addEvent(e)
@@ -365,6 +371,8 @@ class FileDatabaseBackend(Thread):
self.jobs = Queue() # queues for jobs
self.res = Queue()
+ self._checkVersion()
+
self.start()
@@ -406,6 +414,25 @@ class FileDatabaseBackend(Thread):
self.save()
self.jobs.put(("quit", "", 0))
+ def _checkVersion(self):
+ """ check db version and delete it if needed"""
+ if not exists("files.version"):
+ f = open("files.version" , "wb")
+ f.write(str(DB_VERSION))
+ f.close()
+ return
+
+ f = open("files.version" , "rb")
+ v = int(f.read().strip())
+ f.close()
+ if v < DB_VERSION:
+ self.manager.core.log.warning(_("Filedatabase was deleted due to incompatible version."))
+ remove("files.version")
+ remove("files.db")
+ f = open("files.version" , "wb")
+ f.write(str(DB_VERSION))
+ f.close()
+
def _createTables(self):
"""create tables for database"""
diff --git a/module/config/default.conf b/module/config/default.conf
index c71005bd3..4d0d588df 100644
--- a/module/config/default.conf
+++ b/module/config/default.conf
@@ -1,3 +1,5 @@
+version: 1
+
remote - "Remote":
int port : "Port" = 7227
ip listenaddr : "Adress" = 0.0.0.0
@@ -49,4 +51,4 @@ downloadTime - "Download Time":
proxy - "Proxy":
bool activated : "Activated" = False
str adress : "Adress" = http://localhost:8080
- str protocol : "Protocol" = http \ No newline at end of file
+ str protocol : "Protocol" = http