reformat code
This commit is contained in:
@@ -86,7 +86,8 @@ def main():
|
||||
|
||||
# if not root...kick out
|
||||
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)
|
||||
|
||||
# Setup the application
|
||||
@@ -130,5 +131,6 @@ def get_test_app(**kw):
|
||||
app = WOApp(**kw)
|
||||
return app
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Stack Plugin for WordOps"""
|
||||
|
||||
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.core.variables import WOVariables
|
||||
from wo.core.aptget import WOAptGet
|
||||
@@ -20,7 +20,6 @@ from wo.core.variables import WOVariables
|
||||
import random
|
||||
import string
|
||||
import configparser
|
||||
import time
|
||||
import shutil
|
||||
import os
|
||||
import pwd
|
||||
|
||||
@@ -100,8 +100,8 @@ class WOStackMigrateController(CementBaseController):
|
||||
Log.error(
|
||||
self, "Remote MySQL server in use, skipping local install")
|
||||
|
||||
if WOShellExec.cmd_exec(self, "mysqladmin ping") and (not
|
||||
WOAptGet.is_installed(self, 'mariadb-server')):
|
||||
if (WOShellExec.cmd_exec(self, "mysqladmin ping") and
|
||||
(not WOAptGet.is_installed(self, 'mariadb-server'))):
|
||||
|
||||
Log.info(self, "If your database size is big, "
|
||||
"migration may take some time.")
|
||||
|
||||
@@ -36,7 +36,8 @@ class WOAptGet():
|
||||
for single_error in error_list:
|
||||
if "NO_PUBKEY" in single_error:
|
||||
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',
|
||||
shell=True,
|
||||
@@ -47,7 +48,8 @@ class WOAptGet():
|
||||
if proc.returncode == 0:
|
||||
return True
|
||||
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 "
|
||||
"`tail /var/log/wo/wordops.log` and please try again...")
|
||||
|
||||
@@ -60,7 +62,7 @@ class WOAptGet():
|
||||
"""
|
||||
try:
|
||||
check_update = subprocess.Popen(['apt-get upgrade -s | grep '
|
||||
'\"^Inst\" | wc -l'],
|
||||
'\"^Inst\" | wc -l'],
|
||||
stdout=subprocess.PIPE,
|
||||
shell=True).communicate()[0]
|
||||
if check_update == b'0\n':
|
||||
@@ -190,13 +192,13 @@ class WOAptGet():
|
||||
apt_cache = apt.cache.Cache()
|
||||
apt_cache.open()
|
||||
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()
|
||||
return True
|
||||
# apt_cache.close()
|
||||
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`
|
||||
"""
|
||||
@@ -221,11 +223,11 @@ class WOAptGet():
|
||||
if proc.returncode == 0:
|
||||
return True
|
||||
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:
|
||||
WORepo.remove(self, repo_url=repo_url)
|
||||
return False
|
||||
except Exception as e:
|
||||
Log.error(self, "Error while downloading packages, "
|
||||
"apt-get exited with error")
|
||||
|
||||
|
||||
@@ -5,28 +5,27 @@ from wo.core.logging import Log
|
||||
Set CRON on LINUX system.
|
||||
"""
|
||||
|
||||
|
||||
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)):
|
||||
|
||||
WOShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l "
|
||||
"2> /dev/null | {{ cat; echo -e"
|
||||
" \\\""
|
||||
"\\n0 0 * * 0 "
|
||||
"{0}".format(cmd) +
|
||||
" # {0}".format(comment)+
|
||||
"\\\"; } | crontab -\"")
|
||||
"2> /dev/null | {{ cat; echo -e"
|
||||
" \\\""
|
||||
"\\n0 0 * * 0 "
|
||||
"{0}".format(cmd) +
|
||||
" # {0}".format(comment) +
|
||||
"\\\"; } | crontab -\"")
|
||||
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 not WOShellExec.cmd_exec(self, "/bin/bash -c "
|
||||
"\"crontab "
|
||||
"-l | sed '/{0}/d'"
|
||||
"| crontab -\""
|
||||
.format(cmd)):
|
||||
Log.error(self, "Failed to remove crontab entry",False)
|
||||
"\"crontab "
|
||||
"-l | sed '/{0}/d'"
|
||||
"| crontab -\""
|
||||
.format(cmd)):
|
||||
Log.error(self, "Failed to remove crontab entry", False)
|
||||
else:
|
||||
Log.debug(self, "Cron not found")
|
||||
|
||||
@@ -22,7 +22,8 @@ class WODownload():
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory)
|
||||
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:
|
||||
out_file.write(response.read())
|
||||
Log.info(self, "{0}".format("[" + Log.ENDC + "Done"
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
class WOError(Exception):
|
||||
"""Generic errors."""
|
||||
|
||||
def __init__(self, msg):
|
||||
Exception.__init__(self)
|
||||
self.msg = msg
|
||||
|
||||
@@ -21,14 +21,14 @@ class WOFileUtils():
|
||||
Log.info(self, "Removing {0:65}".format(file), end=' ')
|
||||
os.remove(file)
|
||||
Log.info(self, "{0}".format("[" + Log.ENDC + "Done" +
|
||||
Log.OKBLUE + "]"))
|
||||
Log.OKBLUE + "]"))
|
||||
Log.debug(self, 'file Removed')
|
||||
if os.path.isdir(file):
|
||||
try:
|
||||
Log.info(self, "Removing {0:65}".format(file), end=' ')
|
||||
shutil.rmtree(file)
|
||||
Log.info(self, "{0}".format("[" + Log.ENDC + "Done" +
|
||||
Log.OKBLUE + "]"))
|
||||
Log.OKBLUE + "]"))
|
||||
except shutil.Error as e:
|
||||
Log.debug(self, "{err}".format(err=str(e.reason)))
|
||||
Log.error(self, 'Unable to Remove file ')
|
||||
|
||||
@@ -28,10 +28,12 @@ class WOMysql():
|
||||
"""Method for MySQL connection"""
|
||||
|
||||
def connect(self):
|
||||
"""Makes connection with MySQL server"""
|
||||
# Makes connection with MySQL server
|
||||
try:
|
||||
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:
|
||||
connection = pymysql.connect(read_default_file='~/.my.cnf')
|
||||
return connection
|
||||
@@ -45,9 +47,11 @@ class WOMysql():
|
||||
def dbConnection(self, db_name):
|
||||
try:
|
||||
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:
|
||||
connection = pymysql.connect(db=db_name,read_default_file='~/.my.cnf')
|
||||
connection = pymysql.connect(
|
||||
db=db_name, read_default_file='~/.my.cnf')
|
||||
|
||||
return connection
|
||||
except DatabaseError as e:
|
||||
@@ -58,12 +62,13 @@ class WOMysql():
|
||||
except pymysql.err.InternalError as e:
|
||||
Log.debug(self, str(e))
|
||||
raise MySQLConnectionError
|
||||
except Exception as e :
|
||||
except Exception as e:
|
||||
Log.debug(self, "[Error]Setting up database: \'" + str(e) + "\'")
|
||||
raise MySQLConnectionError
|
||||
|
||||
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)
|
||||
log and Log.debug(self, "Exceuting MySQL Statement : {0}"
|
||||
.format(statement))
|
||||
|
||||
@@ -3,7 +3,6 @@ import platform
|
||||
import socket
|
||||
import configparser
|
||||
import os
|
||||
import sys
|
||||
import psutil
|
||||
import datetime
|
||||
|
||||
@@ -149,11 +148,13 @@ class WOVariables():
|
||||
|
||||
# MySQL repo and packages
|
||||
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"
|
||||
.format(codename=wo_platform_codename))
|
||||
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"
|
||||
.format(codename=wo_platform_codename))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user