MCPcopy Create free account
hub / github.com/pyload/pyload / loadAccounts

Method loadAccounts

module/plugins/AccountManager.py:74–120  ·  view source on GitHub ↗

loads all accounts available

(self)

Source from the content-addressed store, hash-verified

72 return plugins
73 #----------------------------------------------------------------------
74 def loadAccounts(self):
75 """loads all accounts available"""
76
77 if not exists("accounts.conf"):
78 f = open("accounts.conf", "wb")
79 f.write("version: " + str(ACC_VERSION))
80 f.close()
81
82 f = open("accounts.conf", "rb")
83 content = f.readlines()
84 version = content[0].split(":")[1].strip() if content else ""
85 f.close()
86
87 if not version or int(version) < ACC_VERSION:
88 copy("accounts.conf", "accounts.backup")
89 f = open("accounts.conf", "wb")
90 f.write("version: " + str(ACC_VERSION))
91 f.close()
92 self.core.log.warning(_("Account settings deleted, due to new config format."))
93 return
94
95
96
97 plugin = ""
98 name = ""
99
100 for line in content[1:]:
101 line = line.strip()
102
103 if not line: continue
104 if line.startswith("#"): continue
105 if line.startswith("version"): continue
106
107 if line.endswith(":") and line.count(":") == 1:
108 plugin = line[:-1]
109 self.accounts[plugin] = {}
110
111 elif line.startswith("@"):
112 try:
113 option = line[1:].split()
114 self.accounts[plugin][name]["options"][option[0]] = [] if len(option) < 2 else ([option[1]] if len(option) < 3 else option[1:])
115 except:
116 pass
117
118 elif ":" in line:
119 name, sep, pw = line.partition(":")
120 self.accounts[plugin][name] = {"password": pw, "options": {}, "valid": True}
121 #----------------------------------------------------------------------
122 def saveAccounts(self):
123 """save all account information"""

Callers 1

initPluginsMethod · 0.95

Calls 6

existsFunction · 0.85
readlinesMethod · 0.80
splitMethod · 0.80
_Function · 0.50
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected