@cached
This commit is contained in:
parent
47ce9252b7
commit
4f77e2c105
3 changed files with 22 additions and 3 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
|
||||||
from sqlite3 import connect
|
from sqlite3 import connect
|
||||||
import settings
|
import settings
|
||||||
from os import chdir
|
from os import chdir
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from loginscreen import LoginScreen
|
from loginscreen import LoginScreen
|
||||||
import profile
|
import profile
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -7,11 +9,25 @@ import re
|
||||||
program_version = '0.2.8'
|
program_version = '0.2.8'
|
||||||
|
|
||||||
|
|
||||||
|
def cached(func):
|
||||||
|
saved_result = None
|
||||||
|
|
||||||
|
def wrapped_func():
|
||||||
|
nonlocal saved_result
|
||||||
|
if saved_result is None:
|
||||||
|
saved_result = func()
|
||||||
|
|
||||||
|
return saved_result
|
||||||
|
|
||||||
|
return wrapped_func
|
||||||
|
|
||||||
|
|
||||||
def log(data):
|
def log(data):
|
||||||
with open(curr_directory() + '/logs.log', 'a') as fl:
|
with open(curr_directory() + '/logs.log', 'a') as fl:
|
||||||
fl.write(str(data) + '\n')
|
fl.write(str(data) + '\n')
|
||||||
|
|
||||||
|
|
||||||
|
@cached
|
||||||
def curr_directory():
|
def curr_directory():
|
||||||
return os.path.dirname(os.path.realpath(__file__))
|
return os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
|
@ -46,9 +62,8 @@ def convert_time(t):
|
||||||
return '%02d:%02d' % (h, m)
|
return '%02d:%02d' % (h, m)
|
||||||
|
|
||||||
|
|
||||||
|
@cached
|
||||||
def time_offset():
|
def time_offset():
|
||||||
if hasattr(time_offset, 'offset'):
|
|
||||||
return time_offset.offset
|
|
||||||
hours = int(time.strftime('%H'))
|
hours = int(time.strftime('%H'))
|
||||||
minutes = int(time.strftime('%M'))
|
minutes = int(time.strftime('%M'))
|
||||||
sec = int(time.time()) - time.timezone
|
sec = int(time.time()) - time.timezone
|
||||||
|
@ -56,7 +71,6 @@ def time_offset():
|
||||||
h, m = divmod(m, 60)
|
h, m = divmod(m, 60)
|
||||||
d, h = divmod(h, 24)
|
d, h = divmod(h, 24)
|
||||||
result = hours * 60 + minutes - h * 60 - m
|
result = hours * 60 + minutes - h * 60 - m
|
||||||
time_offset.offset = result
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue