toxygen/toxygen/util.py

50 lines
1016 B
Python
Raw Normal View History

import os
2016-02-26 14:32:36 +00:00
import time
2016-07-07 10:54:02 +00:00
import shutil
2016-02-19 21:10:24 +00:00
2016-08-08 11:07:18 +00:00
program_version = '0.2.5'
2016-02-19 21:10:24 +00:00
def log(data):
2016-03-30 18:05:21 +00:00
with open(curr_directory() + '/logs.log', 'a') as fl:
fl.write(str(data) + '\n')
2016-02-19 21:10:24 +00:00
2016-02-20 08:06:24 +00:00
def curr_directory():
return os.path.dirname(os.path.realpath(__file__))
2016-02-26 14:32:36 +00:00
def curr_time():
2016-03-13 12:06:06 +00:00
return time.strftime('%H:%M')
2016-07-07 10:54:02 +00:00
def copy(src, dest):
if not os.path.exists(dest):
os.makedirs(dest)
src_files = os.listdir(src)
for file_name in src_files:
full_file_name = os.path.join(src, file_name)
if os.path.isfile(full_file_name):
shutil.copy(full_file_name, dest)
else:
copy(full_file_name, os.path.join(dest, file_name))
2016-03-13 12:06:06 +00:00
def convert_time(t):
sec = int(t) - time.timezone
m, s = divmod(sec, 60)
h, m = divmod(m, 60)
d, h = divmod(h, 24)
return '%02d:%02d' % (h, m)
2016-02-26 14:32:36 +00:00
2016-06-21 11:58:11 +00:00
class Singleton:
_instance = None
2016-06-22 11:35:22 +00:00
def __init__(self):
self.__class__._instance = self
2016-03-03 19:19:09 +00:00
@classmethod
def get_instance(cls):
return cls._instance