-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
45 lines (33 loc) · 827 Bytes
/
utils.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
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
import os
import time
instances = {}
def Singleton(cls, *args, **kw):
"""
Singleton decorator
"""
global instances
def _singleton(*args, **kw):
if cls.__name__ not in instances:
instances[cls.__name__] = cls(*args, **kw)
return instances[cls.__name__]
return _singleton
def list_files(path):
"""
list files under path
"""
fs = os.walk(path)
files = []
for x in fs:
if x[2]:
files += [os.path.join(x[0], _) for _ in x[2]]
return files
def format_time(fmt='%Y-%m-%d %H:%M:%S'):
return time.strftime(fmt, time.localtime(time.time()))
def exec_cmd(cmd):
"""
exec system command
"""
with os.popen(cmd, 'r') as msg:
for line in msg:
print(line.rstrip())