-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
71 lines (70 loc) · 3.18 KB
/
script.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
/***************************************************************************
Wordpress_actions
GitHub repo : https://github.com/npltr62/OC_projet6
-------------------
Date : 01.03.2022
Author : @npltr62
***************************************************************************/
/***************************************************************************
* *
* This program is usefull to automate some actions of your wordpress site *
* Initialize a Wordpress configuration *
* Backup a site and upload to remote server *
* Hard reset a Wordpress configuration *
* Download a backup from a remote server and restore it *
* Schedule a backup job *
***************************************************************************/
"""
import logging #import librairie logging permettant de logger les étapes du script
from time import strftime #call time module
import fnct #call functions
fnct.run('mkdir -p logs') #create logs folder
time = strftime('%T')
date = strftime('%Y_%m_%d') #create logs folder
logfileinfo = f'./logs/{date}.log' #logfile name
logformat = '%(asctime)s %(levelname)s %(message)s' #logformat
logging.basicConfig(filename=logfileinfo, level=logging.INFO, format=logformat) #log config
logging.info(f'*----------START SCRIPT AT {time}----------*')
def main():
package= fnct.distrib() #detect witch installing package should be used
cmd1= f'sudo {package} update'
cmd2= f'sudo {package} install python3-distro python3-yaml -y'
fnct.run(cmd1) #check updates
fnct.run(cmd2) #install distro and yaml packages
print("""
1.Init wordpress
2.Backup and upload to ftp server
3.Hardreset wordpress
4.Restore last backup
5.Schedule a backup job
""")
choice= input("What would you like to do? ")
if choice=="1":
logging.info('***init wordpress***')
print("\n Launch install")
exec(open("Case1.py").read())
logging.info(f'*----------END SCRIPT AT {time}----------*')
elif choice=="2":
logging.info('***backup and upload ftp server***')
print("\n Launch backup")
exec(open("Case2.py").read())
logging.info('*----------END SCRIPT----------*')
elif choice=="3":
logging.info('***hardreset wordpress***')
print("\n Launch reset")
exec(open("Case3.py").read())
logging.info('*----------END SCRIPT----------*')
elif choice=="4":
logging.info('***restore last backup***')
print("\n Launch restore")
exec(open("Case4.py").read())
logging.info('*----------END SCRIPT----------*')
elif choice=="5":
logging.info('***run crontab***')
print("\n Launch cronjob")
exec(open("Case5.py").read())
logging.info('*----------END SCRIPT----------*')
else:
print("\n Choose an option, try again!")
main()