improve code quality according to codacy
This commit is contained in:
@@ -41,7 +41,8 @@ class WOInfoController(CementBaseController):
|
|||||||
@expose(hide=True)
|
@expose(hide=True)
|
||||||
def info_nginx(self):
|
def info_nginx(self):
|
||||||
"""Display Nginx information"""
|
"""Display Nginx information"""
|
||||||
version = os.popen("/usr/sbin/nginx -v 2>&1 | awk -F '/' '{print $2}' | "
|
version = os.popen("/usr/sbin/nginx -v 2>&1 | "
|
||||||
|
"awk -F '/' '{print $2}' | "
|
||||||
"awk -F ' ' '{print $1}' | tr '\n' ' '").read()
|
"awk -F ' ' '{print $1}' | tr '\n' ' '").read()
|
||||||
allow = os.popen("grep ^allow /etc/nginx/common/acl.conf | "
|
allow = os.popen("grep ^allow /etc/nginx/common/acl.conf | "
|
||||||
"cut -d' ' -f2 | cut -d';' -f1 | tr '\n' ' '").read()
|
"cut -d' ' -f2 | cut -d';' -f1 | tr '\n' ' '").read()
|
||||||
@@ -66,7 +67,8 @@ class WOInfoController(CementBaseController):
|
|||||||
@expose(hide=True)
|
@expose(hide=True)
|
||||||
def info_php(self):
|
def info_php(self):
|
||||||
"""Display PHP information"""
|
"""Display PHP information"""
|
||||||
version = os.popen("/usr/bin/php7.2 -v 2>/dev/null | head -n1 | cut -d' ' -f2 |"
|
version = os.popen("/usr/bin/php7.2 -v 2>/dev/null | "
|
||||||
|
"head -n1 | cut -d' ' -f2 |"
|
||||||
" cut -d'+' -f1 | tr -d '\n'").read
|
" cut -d'+' -f1 | tr -d '\n'").read
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read('/etc/{0}/fpm/php.ini'.format("php/7.2"))
|
config.read('/etc/{0}/fpm/php.ini'.format("php/7.2"))
|
||||||
@@ -140,7 +142,8 @@ class WOInfoController(CementBaseController):
|
|||||||
@expose(hide=True)
|
@expose(hide=True)
|
||||||
def info_php73(self):
|
def info_php73(self):
|
||||||
"""Display PHP information"""
|
"""Display PHP information"""
|
||||||
version = os.popen("/usr/bin/php7.3 -v 2>/dev/null | head -n1 | cut -d' ' -f2 |"
|
version = os.popen("/usr/bin/php7.3 -v 2>/dev/null | "
|
||||||
|
"head -n1 | cut -d' ' -f2 |"
|
||||||
" cut -d'+' -f1 | tr -d '\n'").read
|
" cut -d'+' -f1 | tr -d '\n'").read
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read('/etc/php/7.3/fpm/php.ini')
|
config.read('/etc/php/7.3/fpm/php.ini')
|
||||||
@@ -214,23 +217,29 @@ class WOInfoController(CementBaseController):
|
|||||||
@expose(hide=True)
|
@expose(hide=True)
|
||||||
def info_mysql(self):
|
def info_mysql(self):
|
||||||
"""Display MySQL information"""
|
"""Display MySQL information"""
|
||||||
version = os.popen("/usr/bin/mysql -V | awk '{print($5)}' | cut -d ',' "
|
version = os.popen("/usr/bin/mysql -V | awk '{print($5)}' | "
|
||||||
|
"cut -d ',' "
|
||||||
"-f1 | tr -d '\n'").read()
|
"-f1 | tr -d '\n'").read()
|
||||||
host = "localhost"
|
host = "localhost"
|
||||||
port = os.popen("/usr/bin/mysql -e \"show variables\" | grep ^port | awk "
|
port = os.popen("/usr/bin/mysql -e \"show variables\" | "
|
||||||
|
"grep ^port | awk "
|
||||||
"'{print($2)}' | tr -d '\n'").read()
|
"'{print($2)}' | tr -d '\n'").read()
|
||||||
wait_timeout = os.popen("/usr/bin/mysql -e \"show variables\" | grep "
|
wait_timeout = os.popen("/usr/bin/mysql -e \"show variables\" | grep "
|
||||||
"^wait_timeout | awk '{print($2)}' | "
|
"^wait_timeout | awk '{print($2)}' | "
|
||||||
"tr -d '\n'").read()
|
"tr -d '\n'").read()
|
||||||
interactive_timeout = os.popen("/usr/bin/mysql -e \"show variables\" | grep "
|
interactive_timeout = os.popen("/usr/bin/mysql -e "
|
||||||
|
"\"show variables\" | grep "
|
||||||
"^interactive_timeout | awk "
|
"^interactive_timeout | awk "
|
||||||
"'{print($2)}' | tr -d '\n'").read()
|
"'{print($2)}' | tr -d '\n'").read()
|
||||||
max_used_connections = os.popen("/usr/bin/mysql -e \"show global status\" | "
|
max_used_connections = os.popen("/usr/bin/mysql -e "
|
||||||
|
"\"show global status\" | "
|
||||||
"grep Max_used_connections | awk "
|
"grep Max_used_connections | awk "
|
||||||
"'{print($2)}' | tr -d '\n'").read()
|
"'{print($2)}' | tr -d '\n'").read()
|
||||||
datadir = os.popen("/usr/bin/mysql -e \"show variables\" | grep datadir | awk"
|
datadir = os.popen("/usr/bin/mysql -e \"show variables\" | "
|
||||||
|
"grep datadir | awk"
|
||||||
" '{print($2)}' | tr -d '\n'").read()
|
" '{print($2)}' | tr -d '\n'").read()
|
||||||
socket = os.popen("/usr/bin/mysql -e \"show variables\" | grep \"^socket\" | "
|
socket = os.popen("/usr/bin/mysql -e \"show variables\" | "
|
||||||
|
"grep \"^socket\" | "
|
||||||
"awk '{print($2)}' | tr -d '\n'").read()
|
"awk '{print($2)}' | tr -d '\n'").read()
|
||||||
data = dict(version=version, host=host, port=port,
|
data = dict(version=version, host=host, port=port,
|
||||||
wait_timeout=wait_timeout,
|
wait_timeout=wait_timeout,
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ class WORepo():
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if repo_url is not None:
|
if repo_url is not None:
|
||||||
repo_file_path = ("/etc/apt/sources.list.d/"
|
repo_file_path = ("/etc/apt/sources.list.d/" +
|
||||||
+ WOVariables().wo_repo_file)
|
WOVariables().wo_repo_file)
|
||||||
try:
|
try:
|
||||||
if not os.path.isfile(repo_file_path):
|
if not os.path.isfile(repo_file_path):
|
||||||
with open(repo_file_path,
|
with open(repo_file_path,
|
||||||
@@ -62,8 +62,8 @@ class WORepo():
|
|||||||
"--remove '{ppa_name}'"
|
"--remove '{ppa_name}'"
|
||||||
.format(ppa_name=ppa))
|
.format(ppa_name=ppa))
|
||||||
elif repo_url:
|
elif repo_url:
|
||||||
repo_file_path = ("/etc/apt/sources.list.d/"
|
repo_file_path = ("/etc/apt/sources.list.d/" +
|
||||||
+ WOVariables().wo_repo_file)
|
WOVariables().wo_repo_file)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
repofile = open(repo_file_path, "w+")
|
repofile = open(repo_file_path, "w+")
|
||||||
@@ -84,8 +84,8 @@ class WORepo():
|
|||||||
"""
|
"""
|
||||||
WOShellExec.cmd_exec(self, "gpg --keyserver {serv}"
|
WOShellExec.cmd_exec(self, "gpg --keyserver {serv}"
|
||||||
.format(serv=(keyserver or
|
.format(serv=(keyserver or
|
||||||
"hkp://keyserver.ubuntu.com"))
|
"hkp://keyserver.ubuntu.com")) +
|
||||||
+ " --recv-keys {key}".format(key=keyids))
|
" --recv-keys {key}".format(key=keyids))
|
||||||
WOShellExec.cmd_exec(self, "gpg -a --export --armor {0}"
|
WOShellExec.cmd_exec(self, "gpg -a --export --armor {0}"
|
||||||
.format(keyids)
|
.format(keyids) +
|
||||||
+ " | apt-key add - ")
|
" | apt-key add - ")
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ class WOAptGet():
|
|||||||
Log.info(self, Log.FAIL +
|
Log.info(self, Log.FAIL +
|
||||||
"Whoops, something went wrong...")
|
"Whoops, something went wrong...")
|
||||||
Log.error(self, "Check the WordOps log for more details "
|
Log.error(self, "Check the WordOps log for more details "
|
||||||
"`tail /var/log/wo/wordops.log` and please try again...")
|
"`tail /var/log/wo/wordops.log` "
|
||||||
|
"and please try again...")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Log.error(self, "apt-get update exited with error")
|
Log.error(self, "apt-get update exited with error")
|
||||||
@@ -98,7 +99,8 @@ class WOAptGet():
|
|||||||
Log.info(self, Log.FAIL + "Oops Something went "
|
Log.info(self, Log.FAIL + "Oops Something went "
|
||||||
"wrong!!")
|
"wrong!!")
|
||||||
Log.error(self, "Check the WordOps log for more details "
|
Log.error(self, "Check the WordOps log for more details "
|
||||||
"`tail /var/log/wo/wordops.log` and please try again...")
|
"`tail /var/log/wo/wordops.log` "
|
||||||
|
"and please try again...")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Log.error(self, "Error while installing packages, "
|
Log.error(self, "Error while installing packages, "
|
||||||
"apt-get exited with error")
|
"apt-get exited with error")
|
||||||
@@ -124,13 +126,15 @@ class WOAptGet():
|
|||||||
Log.info(self, Log.FAIL + "Oops Something went "
|
Log.info(self, Log.FAIL + "Oops Something went "
|
||||||
"wrong!!")
|
"wrong!!")
|
||||||
Log.error(self, "Check the WordOps log for more details "
|
Log.error(self, "Check the WordOps log for more details "
|
||||||
"`tail /var/log/wo/wordops.log` and please try again...")
|
"`tail /var/log/wo/wordops.log` "
|
||||||
|
"and please try again...")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Log.info(self, Log.FAIL + "Oops Something went "
|
Log.info(self, Log.FAIL + "Oops Something went "
|
||||||
"wrong!!")
|
"wrong!!")
|
||||||
Log.error(self, "Check the WordOps log for more details "
|
Log.error(self, "Check the WordOps log for more details "
|
||||||
"`tail /var/log/wo/wordops.log` and please try again...")
|
"`tail /var/log/wo/wordops.log` "
|
||||||
|
"and please try again...")
|
||||||
|
|
||||||
def remove(self, packages, auto=False, purge=False):
|
def remove(self, packages, auto=False, purge=False):
|
||||||
all_packages = ' '.join(packages)
|
all_packages = ' '.join(packages)
|
||||||
@@ -153,7 +157,8 @@ class WOAptGet():
|
|||||||
Log.info(self, Log.FAIL + "Oops Something went "
|
Log.info(self, Log.FAIL + "Oops Something went "
|
||||||
"wrong!!")
|
"wrong!!")
|
||||||
Log.error(self, "Check the WordOps log for more details "
|
Log.error(self, "Check the WordOps log for more details "
|
||||||
"`tail /var/log/wo/wordops.log` and please try again...")
|
"`tail /var/log/wo/wordops.log` "
|
||||||
|
"and please try again...")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Log.error(self, "Error while installing packages, "
|
Log.error(self, "Error while installing packages, "
|
||||||
@@ -186,7 +191,8 @@ class WOAptGet():
|
|||||||
|
|
||||||
def is_installed(self, package_name):
|
def is_installed(self, package_name):
|
||||||
"""
|
"""
|
||||||
Checks if package is available in cache and is installed or not
|
Checks if package is available in cache "
|
||||||
|
"and is installed or not
|
||||||
returns True if installed otherwise returns False
|
returns True if installed otherwise returns False
|
||||||
"""
|
"""
|
||||||
apt_cache = apt.cache.Cache()
|
apt_cache = apt.cache.Cache()
|
||||||
@@ -209,7 +215,8 @@ class WOAptGet():
|
|||||||
WORepo.add(self, repo_url=repo_url)
|
WORepo.add(self, repo_url=repo_url)
|
||||||
if repo_key is not None:
|
if repo_key is not None:
|
||||||
WORepo.add_key(self, repo_key)
|
WORepo.add_key(self, repo_key)
|
||||||
proc = subprocess.Popen("apt-get update && DEBIAN_FRONTEND=noninteractive "
|
proc = subprocess.Popen("apt-get update && "
|
||||||
|
"DEBIAN_FRONTEND=noninteractive "
|
||||||
"apt-get install -o "
|
"apt-get install -o "
|
||||||
"Dpkg::Options::=\"--force-confdef\""
|
"Dpkg::Options::=\"--force-confdef\""
|
||||||
" -o "
|
" -o "
|
||||||
@@ -224,7 +231,8 @@ class WOAptGet():
|
|||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
Log.error(
|
Log.error(
|
||||||
self, "Error in fetching dpkg package.\nReverting changes ..", False)
|
self, "Error in fetching dpkg package.\n"
|
||||||
|
"Reverting changes ..", False)
|
||||||
if repo_url is not None:
|
if repo_url is not None:
|
||||||
WORepo.remove(self, repo_url=repo_url)
|
WORepo.remove(self, repo_url=repo_url)
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -100,20 +100,22 @@ class WOMysql():
|
|||||||
'/var/wo-mysqlbackup')
|
'/var/wo-mysqlbackup')
|
||||||
os.makedirs('/var/wo-mysqlbackup')
|
os.makedirs('/var/wo-mysqlbackup')
|
||||||
|
|
||||||
db = subprocess.check_output(["mysql -Bse \'show databases\'"],
|
db = subprocess.check_output(["/usr/bin/mysql "
|
||||||
|
"-Bse \'show databases\'"],
|
||||||
universal_newlines=True,
|
universal_newlines=True,
|
||||||
shell=True).split('\n')
|
shell=True).split('\n')
|
||||||
for dbs in db:
|
for dbs in db:
|
||||||
if dbs == "":
|
if dbs == "":
|
||||||
continue
|
continue
|
||||||
Log.info(self, "Backing up {0} database".format(dbs))
|
Log.info(self, "Backing up {0} database".format(dbs))
|
||||||
p1 = subprocess.Popen("mysqldump {0}"
|
p1 = subprocess.Popen("/usr/bin/mysqldump {0}"
|
||||||
" --max_allowed_packet=1024M"
|
" --max_allowed_packet=1024M"
|
||||||
" --single-transaction".format(dbs),
|
" --single-transaction".format(dbs),
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE, shell=True)
|
stderr=subprocess.PIPE, shell=True)
|
||||||
p2 = subprocess.Popen("pigz -c > /var/wo-mysqlbackup/{0}{1}.s"
|
p2 = subprocess.Popen("/usr/bin/pigz -c > "
|
||||||
"ql.gz".format(dbs, WOVariables.wo_date),
|
"/var/wo-mysqlbackup/{0}{1}.sql.gz"
|
||||||
|
.format(dbs, WOVariables.wo_date),
|
||||||
stdin=p1.stdout,
|
stdin=p1.stdout,
|
||||||
shell=True)
|
shell=True)
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ class SSL:
|
|||||||
|
|
||||||
current_date = WOShellExec.cmd_exec_stdout(self, "date -d \"now\" +%s")
|
current_date = WOShellExec.cmd_exec_stdout(self, "date -d \"now\" +%s")
|
||||||
expiration_date = WOShellExec.cmd_exec_stdout(self, "date -d \""
|
expiration_date = WOShellExec.cmd_exec_stdout(self, "date -d \""
|
||||||
"`openssl x509 -in "
|
"`/usr/bin/openssl "
|
||||||
|
"x509 -in "
|
||||||
"/etc/letsencrypt/live/"
|
"/etc/letsencrypt/live/"
|
||||||
"{0}/cert.pem"
|
"{0}/cert.pem"
|
||||||
" -text -noout|grep "
|
" -text -noout|grep "
|
||||||
@@ -45,7 +46,8 @@ class SSL:
|
|||||||
"`tail /var/log/wo/wordops.log` and please try again...")
|
"`tail /var/log/wo/wordops.log` and please try again...")
|
||||||
|
|
||||||
expiration_date = WOShellExec.cmd_exec_stdout(self, "date -d "
|
expiration_date = WOShellExec.cmd_exec_stdout(self, "date -d "
|
||||||
"\"`openssl x509 -in "
|
"\"`/usr/bin/openssl "
|
||||||
|
"x509 -in "
|
||||||
"/etc/letsencrypt/live/"
|
"/etc/letsencrypt/live/"
|
||||||
"{0}/cert.pem"
|
"{0}/cert.pem"
|
||||||
" -text -noout|grep "
|
" -text -noout|grep "
|
||||||
|
|||||||
@@ -69,8 +69,9 @@ class WOVariables():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
wo_user = input("Enter your name: ")
|
wo_user = input("Enter your name: ")
|
||||||
wo_email = input("Enter your email: ")
|
wo_email = input("Enter your email: ")
|
||||||
os.system("git config --global user.name {0}".format(wo_user))
|
os.system("/usr/bin/git config --global user.name {0}".format(wo_user))
|
||||||
os.system("git config --global user.email {0}".format(wo_email))
|
os.system(
|
||||||
|
"/usr/bin/git config --global user.email {0}".format(wo_email))
|
||||||
|
|
||||||
# Get System RAM and SWAP details
|
# Get System RAM and SWAP details
|
||||||
wo_ram = psutil.virtual_memory().total / (1024 * 1024)
|
wo_ram = psutil.virtual_memory().total / (1024 * 1024)
|
||||||
|
|||||||
Reference in New Issue
Block a user