reformat code
This commit is contained in:
@@ -86,7 +86,8 @@ def main():
|
|||||||
|
|
||||||
# if not root...kick out
|
# if not root...kick out
|
||||||
if not os.geteuid() == 0:
|
if not os.geteuid() == 0:
|
||||||
print("\nNon-privileged users cant use WordOps. Switch to root or invoke sudo.\n")
|
print("\nNon-privileged users cant use WordOps. "
|
||||||
|
"Switch to root or invoke sudo.\n")
|
||||||
app.close(1)
|
app.close(1)
|
||||||
|
|
||||||
# Setup the application
|
# Setup the application
|
||||||
@@ -130,5 +131,6 @@ def get_test_app(**kw):
|
|||||||
app = WOApp(**kw)
|
app = WOApp(**kw)
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"""Stack Plugin for WordOps"""
|
"""Stack Plugin for WordOps"""
|
||||||
|
|
||||||
from cement.core.controller import CementBaseController, expose
|
from cement.core.controller import CementBaseController, expose
|
||||||
from cement.core import handler, hook
|
from cement.core import handler
|
||||||
from wo.cli.plugins.site_functions import *
|
from wo.cli.plugins.site_functions import *
|
||||||
from wo.core.variables import WOVariables
|
from wo.core.variables import WOVariables
|
||||||
from wo.core.aptget import WOAptGet
|
from wo.core.aptget import WOAptGet
|
||||||
@@ -20,7 +20,6 @@ from wo.core.variables import WOVariables
|
|||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
import configparser
|
import configparser
|
||||||
import time
|
|
||||||
import shutil
|
import shutil
|
||||||
import os
|
import os
|
||||||
import pwd
|
import pwd
|
||||||
|
|||||||
@@ -100,8 +100,8 @@ class WOStackMigrateController(CementBaseController):
|
|||||||
Log.error(
|
Log.error(
|
||||||
self, "Remote MySQL server in use, skipping local install")
|
self, "Remote MySQL server in use, skipping local install")
|
||||||
|
|
||||||
if WOShellExec.cmd_exec(self, "mysqladmin ping") and (not
|
if (WOShellExec.cmd_exec(self, "mysqladmin ping") and
|
||||||
WOAptGet.is_installed(self, 'mariadb-server')):
|
(not WOAptGet.is_installed(self, 'mariadb-server'))):
|
||||||
|
|
||||||
Log.info(self, "If your database size is big, "
|
Log.info(self, "If your database size is big, "
|
||||||
"migration may take some time.")
|
"migration may take some time.")
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ class WOAptGet():
|
|||||||
for single_error in error_list:
|
for single_error in error_list:
|
||||||
if "NO_PUBKEY" in single_error:
|
if "NO_PUBKEY" in single_error:
|
||||||
key = single_error.rsplit(None, 1)[-1]
|
key = single_error.rsplit(None, 1)[-1]
|
||||||
WORepo.add_key(self, key, keyserver="hkp://pgp.mit.edu")
|
WORepo.add_key(
|
||||||
|
self, key, keyserver="hkp://pgp.mit.edu")
|
||||||
|
|
||||||
proc = subprocess.Popen('apt-get update',
|
proc = subprocess.Popen('apt-get update',
|
||||||
shell=True,
|
shell=True,
|
||||||
@@ -47,7 +48,8 @@ class WOAptGet():
|
|||||||
if proc.returncode == 0:
|
if proc.returncode == 0:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
Log.info(self, Log.FAIL + "Whoops, something went wrong...")
|
Log.info(self, Log.FAIL +
|
||||||
|
"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...")
|
||||||
|
|
||||||
@@ -60,7 +62,7 @@ class WOAptGet():
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
check_update = subprocess.Popen(['apt-get upgrade -s | grep '
|
check_update = subprocess.Popen(['apt-get upgrade -s | grep '
|
||||||
'\"^Inst\" | wc -l'],
|
'\"^Inst\" | wc -l'],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
shell=True).communicate()[0]
|
shell=True).communicate()[0]
|
||||||
if check_update == b'0\n':
|
if check_update == b'0\n':
|
||||||
@@ -190,13 +192,13 @@ class WOAptGet():
|
|||||||
apt_cache = apt.cache.Cache()
|
apt_cache = apt.cache.Cache()
|
||||||
apt_cache.open()
|
apt_cache.open()
|
||||||
if (package_name.strip() in apt_cache and
|
if (package_name.strip() in apt_cache and
|
||||||
apt_cache[package_name.strip()].is_installed):
|
apt_cache[package_name.strip()].is_installed):
|
||||||
# apt_cache.close()
|
# apt_cache.close()
|
||||||
return True
|
return True
|
||||||
# apt_cache.close()
|
# apt_cache.close()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def download_only(self,package_name,repo_url=None,repo_key=None):
|
def download_only(self, package_name, repo_url=None, repo_key=None):
|
||||||
"""
|
"""
|
||||||
Similar to `apt-get install --download-only PACKAGE_NAME`
|
Similar to `apt-get install --download-only PACKAGE_NAME`
|
||||||
"""
|
"""
|
||||||
@@ -221,11 +223,11 @@ class WOAptGet():
|
|||||||
if proc.returncode == 0:
|
if proc.returncode == 0:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
Log.error(self,"Error in fetching dpkg package.\nReverting changes ..",False)
|
Log.error(
|
||||||
|
self, "Error in fetching dpkg package.\nReverting 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
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Log.error(self, "Error while downloading packages, "
|
Log.error(self, "Error while downloading packages, "
|
||||||
"apt-get exited with error")
|
"apt-get exited with error")
|
||||||
|
|
||||||
|
|||||||
@@ -5,28 +5,27 @@ from wo.core.logging import Log
|
|||||||
Set CRON on LINUX system.
|
Set CRON on LINUX system.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class WOCron():
|
class WOCron():
|
||||||
def setcron_weekly(self,cmd,comment='Cron set by WordOps',user='root',min=0,hour=12):
|
def setcron_weekly(self, cmd, comment='Cron set by WordOps', user='root', min=0, hour=12):
|
||||||
if not WOShellExec.cmd_exec(self, "crontab -l | grep -q \'{0}\'".format(cmd)):
|
if not WOShellExec.cmd_exec(self, "crontab -l | grep -q \'{0}\'".format(cmd)):
|
||||||
|
|
||||||
WOShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l "
|
WOShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l "
|
||||||
"2> /dev/null | {{ cat; echo -e"
|
"2> /dev/null | {{ cat; echo -e"
|
||||||
" \\\""
|
" \\\""
|
||||||
"\\n0 0 * * 0 "
|
"\\n0 0 * * 0 "
|
||||||
"{0}".format(cmd) +
|
"{0}".format(cmd) +
|
||||||
" # {0}".format(comment)+
|
" # {0}".format(comment) +
|
||||||
"\\\"; } | crontab -\"")
|
"\\\"; } | crontab -\"")
|
||||||
Log.debug(self, "Cron set")
|
Log.debug(self, "Cron set")
|
||||||
|
|
||||||
|
def remove_cron(self, cmd):
|
||||||
|
|
||||||
def remove_cron(self,cmd):
|
|
||||||
if WOShellExec.cmd_exec(self, "crontab -l | grep -q \'{0}\'".format(cmd)):
|
if WOShellExec.cmd_exec(self, "crontab -l | grep -q \'{0}\'".format(cmd)):
|
||||||
if not WOShellExec.cmd_exec(self, "/bin/bash -c "
|
if not WOShellExec.cmd_exec(self, "/bin/bash -c "
|
||||||
"\"crontab "
|
"\"crontab "
|
||||||
"-l | sed '/{0}/d'"
|
"-l | sed '/{0}/d'"
|
||||||
"| crontab -\""
|
"| crontab -\""
|
||||||
.format(cmd)):
|
.format(cmd)):
|
||||||
Log.error(self, "Failed to remove crontab entry",False)
|
Log.error(self, "Failed to remove crontab entry", False)
|
||||||
else:
|
else:
|
||||||
Log.debug(self, "Cron not found")
|
Log.debug(self, "Cron not found")
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ class WODownload():
|
|||||||
if not os.path.exists(directory):
|
if not os.path.exists(directory):
|
||||||
os.makedirs(directory)
|
os.makedirs(directory)
|
||||||
Log.info(self, "Downloading {0:20}".format(pkg_name), end=' ')
|
Log.info(self, "Downloading {0:20}".format(pkg_name), end=' ')
|
||||||
req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
|
req = urllib.request.Request(
|
||||||
|
url, headers={'User-Agent': 'Mozilla/5.0'})
|
||||||
with urllib.request.urlopen(req) as response, open(filename, 'wb') as out_file:
|
with urllib.request.urlopen(req) as response, open(filename, 'wb') as out_file:
|
||||||
out_file.write(response.read())
|
out_file.write(response.read())
|
||||||
Log.info(self, "{0}".format("[" + Log.ENDC + "Done"
|
Log.info(self, "{0}".format("[" + Log.ENDC + "Done"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
class WOError(Exception):
|
class WOError(Exception):
|
||||||
"""Generic errors."""
|
"""Generic errors."""
|
||||||
|
|
||||||
def __init__(self, msg):
|
def __init__(self, msg):
|
||||||
Exception.__init__(self)
|
Exception.__init__(self)
|
||||||
self.msg = msg
|
self.msg = msg
|
||||||
|
|||||||
@@ -21,14 +21,14 @@ class WOFileUtils():
|
|||||||
Log.info(self, "Removing {0:65}".format(file), end=' ')
|
Log.info(self, "Removing {0:65}".format(file), end=' ')
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
Log.info(self, "{0}".format("[" + Log.ENDC + "Done" +
|
Log.info(self, "{0}".format("[" + Log.ENDC + "Done" +
|
||||||
Log.OKBLUE + "]"))
|
Log.OKBLUE + "]"))
|
||||||
Log.debug(self, 'file Removed')
|
Log.debug(self, 'file Removed')
|
||||||
if os.path.isdir(file):
|
if os.path.isdir(file):
|
||||||
try:
|
try:
|
||||||
Log.info(self, "Removing {0:65}".format(file), end=' ')
|
Log.info(self, "Removing {0:65}".format(file), end=' ')
|
||||||
shutil.rmtree(file)
|
shutil.rmtree(file)
|
||||||
Log.info(self, "{0}".format("[" + Log.ENDC + "Done" +
|
Log.info(self, "{0}".format("[" + Log.ENDC + "Done" +
|
||||||
Log.OKBLUE + "]"))
|
Log.OKBLUE + "]"))
|
||||||
except shutil.Error as e:
|
except shutil.Error as e:
|
||||||
Log.debug(self, "{err}".format(err=str(e.reason)))
|
Log.debug(self, "{err}".format(err=str(e.reason)))
|
||||||
Log.error(self, 'Unable to Remove file ')
|
Log.error(self, 'Unable to Remove file ')
|
||||||
|
|||||||
@@ -28,10 +28,12 @@ class WOMysql():
|
|||||||
"""Method for MySQL connection"""
|
"""Method for MySQL connection"""
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
"""Makes connection with MySQL server"""
|
# Makes connection with MySQL server
|
||||||
try:
|
try:
|
||||||
if os.path.exists('/etc/mysql/conf.d/my.cnf'):
|
if os.path.exists('/etc/mysql/conf.d/my.cnf'):
|
||||||
connection = pymysql.connect(read_default_file='/etc/mysql/conf.d/my.cnf')
|
connection = \
|
||||||
|
pymysql.connect(read_default_file='/etc/mysql/'
|
||||||
|
'conf.d/my.cnf')
|
||||||
else:
|
else:
|
||||||
connection = pymysql.connect(read_default_file='~/.my.cnf')
|
connection = pymysql.connect(read_default_file='~/.my.cnf')
|
||||||
return connection
|
return connection
|
||||||
@@ -45,9 +47,11 @@ class WOMysql():
|
|||||||
def dbConnection(self, db_name):
|
def dbConnection(self, db_name):
|
||||||
try:
|
try:
|
||||||
if os.path.exists('/etc/mysql/conf.d/my.cnf'):
|
if os.path.exists('/etc/mysql/conf.d/my.cnf'):
|
||||||
connection = pymysql.connect(db=db_name,read_default_file='/etc/mysql/conf.d/my.cnf')
|
connection = pymysql.connect(
|
||||||
|
db=db_name, read_default_file='/etc/mysql/conf.d/my.cnf')
|
||||||
else:
|
else:
|
||||||
connection = pymysql.connect(db=db_name,read_default_file='~/.my.cnf')
|
connection = pymysql.connect(
|
||||||
|
db=db_name, read_default_file='~/.my.cnf')
|
||||||
|
|
||||||
return connection
|
return connection
|
||||||
except DatabaseError as e:
|
except DatabaseError as e:
|
||||||
@@ -58,12 +62,13 @@ class WOMysql():
|
|||||||
except pymysql.err.InternalError as e:
|
except pymysql.err.InternalError as e:
|
||||||
Log.debug(self, str(e))
|
Log.debug(self, str(e))
|
||||||
raise MySQLConnectionError
|
raise MySQLConnectionError
|
||||||
except Exception as e :
|
except Exception as e:
|
||||||
Log.debug(self, "[Error]Setting up database: \'" + str(e) + "\'")
|
Log.debug(self, "[Error]Setting up database: \'" + str(e) + "\'")
|
||||||
raise MySQLConnectionError
|
raise MySQLConnectionError
|
||||||
|
|
||||||
def execute(self, statement, errormsg='', log=True):
|
def execute(self, statement, errormsg='', log=True):
|
||||||
"""Get login details from /etc/mysql/conf.d/my.cnf & Execute MySQL query"""
|
# Get login details from /etc/mysql/conf.d/my.cnf
|
||||||
|
# & Execute MySQL query
|
||||||
connection = WOMysql.connect(self)
|
connection = WOMysql.connect(self)
|
||||||
log and Log.debug(self, "Exceuting MySQL Statement : {0}"
|
log and Log.debug(self, "Exceuting MySQL Statement : {0}"
|
||||||
.format(statement))
|
.format(statement))
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import platform
|
|||||||
import socket
|
import socket
|
||||||
import configparser
|
import configparser
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import psutil
|
import psutil
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
@@ -149,11 +148,13 @@ class WOVariables():
|
|||||||
|
|
||||||
# MySQL repo and packages
|
# MySQL repo and packages
|
||||||
if wo_platform_distro == 'ubuntu':
|
if wo_platform_distro == 'ubuntu':
|
||||||
wo_mysql_repo = ("deb [arch=amd64,ppc64el] http://sfo1.mirrors.digitalocean.com/mariadb/repo/"
|
wo_mysql_repo = ("deb [arch=amd64,ppc64el] "
|
||||||
|
"http://sfo1.mirrors.digitalocean.com/mariadb/repo/"
|
||||||
"10.3/ubuntu {codename} main"
|
"10.3/ubuntu {codename} main"
|
||||||
.format(codename=wo_platform_codename))
|
.format(codename=wo_platform_codename))
|
||||||
elif wo_platform_distro == 'debian':
|
elif wo_platform_distro == 'debian':
|
||||||
wo_mysql_repo = ("deb [arch=amd64,ppc64el] http://sfo1.mirrors.digitalocean.com/mariadb/repo/"
|
wo_mysql_repo = ("deb [arch=amd64,ppc64el] "
|
||||||
|
"http://sfo1.mirrors.digitalocean.com/mariadb/repo/"
|
||||||
"10.3/debian {codename} main"
|
"10.3/debian {codename} main"
|
||||||
.format(codename=wo_platform_codename))
|
.format(codename=wo_platform_codename))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user