WIP
This commit is contained in:
parent
d09e1f8757
commit
e8da744744
3 changed files with 14 additions and 6 deletions
|
@ -35,8 +35,9 @@ class User(object):
|
|||
# Save to data/users.json
|
||||
@util.Noparallel(queue=True, ignore_class=True)
|
||||
def save(self):
|
||||
users_json = f'{config.private_dir}/users.json'
|
||||
s = time.time()
|
||||
users = json.load(open("%s/users.json" % config.data_dir))
|
||||
users = json.load(open(users_json))
|
||||
if self.master_address not in users:
|
||||
users[self.master_address] = {} # Create if not exist
|
||||
user_data = users[self.master_address]
|
||||
|
@ -45,7 +46,7 @@ class User(object):
|
|||
user_data["sites"] = self.sites
|
||||
user_data["certs"] = self.certs
|
||||
user_data["settings"] = self.settings
|
||||
helper.atomicWrite("%s/users.json" % config.data_dir, helper.jsonDumps(users).encode("utf8"))
|
||||
helper.atomicWrite(users_json, helper.jsonDumps(users).encode("utf8"))
|
||||
self.log.debug("Saved in %.3fs" % (time.time() - s))
|
||||
self.delayed_save_thread = None
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ class UserManager(object):
|
|||
self.users = {}
|
||||
self.log = logging.getLogger("UserManager")
|
||||
|
||||
# Load all user from data/users.json
|
||||
# Load all user from users.json
|
||||
def load(self):
|
||||
if not self.users:
|
||||
self.users = {}
|
||||
|
@ -25,7 +25,7 @@ class UserManager(object):
|
|||
s = time.time()
|
||||
# Load new users
|
||||
try:
|
||||
json_path = "%s/users.json" % config.data_dir
|
||||
json_path = f'{config.private_dir}/users.json'
|
||||
data = json.load(open(json_path))
|
||||
except Exception as err:
|
||||
raise Exception("Unable to load %s: %s" % (json_path, err))
|
||||
|
@ -57,7 +57,7 @@ class UserManager(object):
|
|||
user.saveDelayed()
|
||||
return user
|
||||
|
||||
# List all users from data/users.json
|
||||
# List all users
|
||||
# Return: {"usermasteraddr": User}
|
||||
def list(self):
|
||||
if self.users == {}: # Not loaded yet
|
||||
|
|
|
@ -72,6 +72,13 @@ def init_dirs():
|
|||
and not config.offline
|
||||
and (not data_dir.is_dir() or not (data_dir / 'sites.json').is_file()))
|
||||
|
||||
old_users_json = data_dir / 'users.json'
|
||||
if old_users_json.is_file():
|
||||
print('Migrating existing users.json file to private/')
|
||||
old_sites_json = data_dir / 'sites.json'
|
||||
if old_sites_json.is_file():
|
||||
print('Migrating existing sites.json file to private/')
|
||||
|
||||
if not data_dir.is_dir():
|
||||
data_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
@ -94,7 +101,7 @@ def init_dirs():
|
|||
if not os.path.isfile(sites_json):
|
||||
with open(sites_json, "w") as f:
|
||||
f.write("{}")
|
||||
users_json = f"{data_dir}/users.json"
|
||||
users_json = f"{private_dir_dir}/users.json"
|
||||
if not os.path.isfile(users_json):
|
||||
with open(users_json, "w") as f:
|
||||
f.write("{}")
|
||||
|
|
Loading…
Reference in a new issue