Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Completed venv installation for pattoo web #147

Merged
merged 10 commits into from
Sep 1, 2020
1 change: 0 additions & 1 deletion bin/pattoo_webd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# Standard libraries
import sys
import os

# Try to create a working PYTHONPATH
_BIN_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
_ROOT_DIRECTORY = os.path.abspath(os.path.join(_BIN_DIRECTORY, os.pardir))
Expand Down
123 changes: 0 additions & 123 deletions setup/_check_config.py

This file was deleted.

46 changes: 46 additions & 0 deletions setup/_pattoo_web/configure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Configure pattoo web."""
import os
from pattoo_shared.installation import configure, shared
from pattoo_shared import files


def install(pattoo_home):
"""Start configuration process.

Args:
None

Returns:
None

"""
# Initialize key variables
if os.environ.get('PATTOO_CONFIGDIR') is None:
os.environ['PATTOO_CONFIGDIR'] = '{0}etc{0}pattoo'.format(os.sep)
config_dir = os.environ.get('PATTOO_CONFIGDIR')

pattoo_webd_dict = {
'pattoo_webd': {
'ip_listen_address': '0.0.0.0',
'ip_bind_port': 20200,
},
'pattoo_web_api': {
'ip_address': '::1',
'ip_bind_port': 20202
},
}

# Attempt to create configuration directory
files.mkdir(config_dir)

# Create the pattoo user and group
configure.create_user('pattoo', pattoo_home, ' /bin/false', True)

# Attempt to change the ownership of the config and pattoo-home directories
shared.chown(config_dir)
shared.chown(pattoo_home)

# Configure pattoo web
configure.configure_component('pattoo_webd', config_dir, pattoo_webd_dict)

# Done
95 changes: 95 additions & 0 deletions setup/_pattoo_web/shared.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
"""Shared functions and methods utilized by the pattoo installation."""
# Standard imports
import sys
import subprocess
import traceback


def run_script(cli_string, die=True, verbose=True):
"""Run the cli_string UNIX CLI command and record output.

Args:
cli_string: String of command to run
die: Exit with error if True

Returns:
(returncode, stdoutdata, stderrdata):
Execution code, STDOUT output and STDERR output.

"""
# Initialize key variables
messages = []
stdoutdata = ''.encode()
stderrdata = ''.encode()
returncode = 1

# Enable verbose mode if True
if verbose is True:
print('Running Command: "{}"'.format(cli_string))

# Run update_targets script
do_command_list = list(cli_string.split(' '))

# Create the subprocess object
try:
process = subprocess.Popen(
do_command_list,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdoutdata, stderrdata = process.communicate()
returncode = process.returncode
except:
(exc_type, exc_value, exc_traceback) = sys.exc_info()
messages.append('''\
Bug: Exception Type:{}, Exception Instance: {}, Stack Trace Object: {}]\
'''.format(exc_type, exc_value, exc_traceback))
messages.append(traceback.format_exc())

# Crash if the return code is not 0
if bool(returncode) is True:
# Print the Return Code header
messages.append(
'Return code:{}'.format(returncode)
)

# Print the STDOUT
for line in stdoutdata.decode().split('\n'):
messages.append(
'STDOUT: {}'.format(line)
)

# Print the STDERR
for line in stderrdata.decode().split('\n'):
messages.append(
'STDERR: {}'.format(line)
)

# Log message
if verbose is True:
print('messages: {}'.format(messages))
if bool(messages) is True:
for log_message in messages:
if verbose is True:
print(log_message)

if bool(die) is True:
# All done
sys.exit(2)

# Return
return (returncode, stdoutdata, stderrdata)


def log(message):
"""Log messages and exit abnormally.

Args:
message: Message to print

Returns:
None

"""
# exit
print('\nPATTOO Error: {}'.format(message))
sys.exit(3)
Loading