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

View File

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

View File

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

View File

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

View File

@@ -5,6 +5,7 @@ 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):
if not WOShellExec.cmd_exec(self, "crontab -l | grep -q \'{0}\'".format(cmd)):
@@ -18,8 +19,6 @@ class WOCron():
"\\\"; } | crontab -\"")
Log.debug(self, "Cron set")
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 "

View File

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

View File

@@ -3,6 +3,7 @@
class WOError(Exception):
"""Generic errors."""
def __init__(self, msg):
Exception.__init__(self)
self.msg = msg

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

View File

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