forked from Jrohy/multi-v2ray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.py
32 lines (28 loc) · 941 Bytes
/
loader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import pickle
from config import Config
from profile import Profile
class Loader:
def __init__(self):
config = Config()
self.config_path = config.get_path("config_path")
self.path = config.get_path("data_path")
self.profile = None
self.load_profile()
def load_profile(self):
try:
if os.path.exists(self.path):
with open(self.path, 'rb') as reader:
self.profile = pickle.load(reader)
if os.path.getmtime(self.profile.path) != self.profile.modify_time:
raise ValueError
else:
raise FileNotFoundError
except Exception:
self.profile = Profile()
self.save_profile()
def save_profile(self):
with open(self.path, 'wb') as writer:
pickle.dump(self.profile, writer)