-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.py
executable file
·46 lines (36 loc) · 1.31 KB
/
delete.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
45
46
#import library
import os
from app_logs import app_logs as app
from credential import ftp_push
#clear logs
def delete_logs():
logger = app('deletelogs')
logger.info('Delete logs function execution starting')
try:
#local path
path = './logs/'
sftp_logs = sorted(list(os.listdir(path)),reverse=True)
for item in sftp_logs:
os.remove(path+item)
logger.info(item+' File is removed successfully')
except:
logger.error('Please check your path!')
logger.info('Delete logs function execution finished')
#delete backup files
def delete_files():
credential = ftp_push()
logger = app('deletefiles')
logger.info('Delete file function execution starting')
try:
#local path
pushed_files = os.listdir(credential['local_move_path'])
if(len(pushed_files)>30):
for item in pushed_files:
os.remove(credential['local_move_path']+item)
logger.info(item+' File is removed successfully')
else:
logger.warning('Could not delete files!,because files are less than 30 days')
except:
logger.error('Please check your path!')
logger.info('Delete files function execution finished')
delete_files()