36 lines
830 B
Python
36 lines
830 B
Python
import os
|
|
import shutil
|
|
|
|
def save_file(name, data):
|
|
temp_path = os.path.join(os.path.dirname(__file__), 'temp')
|
|
check_dir(temp_path)
|
|
with open(os.path.join(temp_path, name), 'wb') as code:
|
|
code.write(data)
|
|
|
|
def remove_file(path):
|
|
if len(path) > 0:
|
|
try:
|
|
os.remove(path)
|
|
except:
|
|
pass
|
|
|
|
def clear_dir():
|
|
temp_path = os.path.join(os.path.dirname(__file__), 'temp')
|
|
check_dir(temp_path)
|
|
flag = True
|
|
for files in os.listdir(temp_path):
|
|
path = os.path.join(temp_path, files)
|
|
|
|
try:
|
|
shutil.rmtree(path)
|
|
except OSError:
|
|
os.remove(path)
|
|
|
|
print('Info: temp dir is cleared')
|
|
|
|
def check_dir(path):
|
|
is_exists = os.path.exists(path)
|
|
if not(is_exists):
|
|
os.mkdir(path.encode('utf-8'))
|
|
return
|
|
|