reformat code

This commit is contained in:
VirtuBox
2019-04-25 01:25:13 +02:00
parent 049b467a00
commit b2f07de184
10 changed files with 49 additions and 39 deletions

View File

@@ -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()

View File

@@ -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

View File

@@ -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.")

View File

@@ -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...")
@@ -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")

View File

@@ -5,6 +5,7 @@ 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)):
@@ -18,8 +19,6 @@ class WOCron():
"\\\"; } | 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 "

View File

@@ -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"

View File

@@ -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

View 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:
@@ -63,7 +67,8 @@ class WOMysql():
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))

View File

@@ -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))