summaryrefslogtreecommitdiffstats
path: root/module/plugins/AccountManager.py
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2014-11-09 21:51:02 +0100
committerGravatar Walter Purcaro <vuolter@gmail.com> 2014-11-09 21:51:02 +0100
commitaf98b90aee3d0d726a03be3d0b55485daf10926e (patch)
tree6b6436336b71b99e0f2620f514e030ada7ba172a /module/plugins/AccountManager.py
parent[Plugin] Update and bugfix (diff)
downloadpyload-af98b90aee3d0d726a03be3d0b55485daf10926e.tar.xz
[AccountManager] I/O error handling
Diffstat (limited to 'module/plugins/AccountManager.py')
-rw-r--r--module/plugins/AccountManager.py58
1 files changed, 30 insertions, 28 deletions
diff --git a/module/plugins/AccountManager.py b/module/plugins/AccountManager.py
index d9888ec8b..b2010019b 100644
--- a/module/plugins/AccountManager.py
+++ b/module/plugins/AccountManager.py
@@ -59,22 +59,21 @@ class AccountManager():
def loadAccounts(self):
"""loads all accounts available"""
- if not exists("accounts.conf"):
- f = open("accounts.conf", "wb")
- f.write("version: " + str(ACC_VERSION))
- f.close()
-
- f = open("accounts.conf", "rb")
- content = f.readlines()
- version = content[0].split(":")[1].strip() if content else ""
- f.close()
-
- if not version or int(version) < ACC_VERSION:
- copy("accounts.conf", "accounts.backup")
- f = open("accounts.conf", "wb")
- f.write("version: " + str(ACC_VERSION))
- f.close()
- self.core.log.warning(_("Account settings deleted, due to new config format"))
+ try:
+ with open("accounts.conf", "a+") as f:
+ content = f.readlines()
+ version = content[0].split(":")[1].strip() if content else ""
+
+ if not version or int(version) < ACC_VERSION:
+ copy("accounts.conf", "accounts.backup")
+ f.seek(0)
+ f.write("version: " + str(ACC_VERSION))
+
+ self.core.log.warning(_("Account settings deleted, due to new config format"))
+ return
+
+ except IOError, e:
+ self.logError(str(e))
return
plugin = ""
@@ -107,21 +106,24 @@ class AccountManager():
def saveAccounts(self):
"""save all account information"""
- f = open("accounts.conf", "wb")
- f.write("version: " + str(ACC_VERSION) + "\n")
+ try:
+ with open("accounts.conf", "wb") as f:
+ f.write("version: " + str(ACC_VERSION) + "\n")
+
+ for plugin, accounts in self.accounts.iteritems():
+ f.write("\n")
+ f.write(plugin+":\n")
- for plugin, accounts in self.accounts.iteritems():
- f.write("\n")
- f.write(plugin+":\n")
+ for name,data in accounts.iteritems():
+ f.write("\n\t%s:%s\n" % (name,data['password']) )
+ if data['options']:
+ for option, values in data['options'].iteritems():
+ f.write("\t@%s %s\n" % (option, " ".join(values)))
- for name,data in accounts.iteritems():
- f.write("\n\t%s:%s\n" % (name,data['password']) )
- if data['options']:
- for option, values in data['options'].iteritems():
- f.write("\t@%s %s\n" % (option, " ".join(values)))
+ chmod(f.name, 0600)
- f.close()
- chmod(f.name, 0600)
+ except Exception, e:
+ self.logError(str(e))
#----------------------------------------------------------------------