import json
import socket
import pwd
-import pipes
-import codecs
-import ipaddress
+import sys
+import glob
# Third party modules
import six
from .app import PpApplication
-__version__ = '0.1.0'
+__version__ = '0.2.1'
LOG = logging.getLogger(__name__)
self.out_dir = None
self.environments = []
self.env_name = None
+ self.env_dir = None
super(CheckPuppetEnvApp, self).__init__(
appname=appname, verbose=verbose, version=version, base_dir=base_dir,
# -------------------------------------------------------------------------
def perform_arg_parser(self):
+ puppet_root_env_dir = self.puppet_root_env_dir
+ retval = 5
+
if self.args.env_dir:
- self.puppet_root_env_dir = self.args.env_dir
+ puppet_root_env_dir = self.args.env_dir
+ retval = 0
+
+ if not os.path.exists(puppet_root_env_dir):
+ msg = (
+ self.appname + ': ' +
+ "Puppet environment directory {!r} does not exists.".format(puppet_root_env_dir))
+ sys.stderr.write(msg + '\n\n')
+ self.exit(retval)
+
+ if not os.path.isdir(puppet_root_env_dir):
+ msg = (
+ self.appname + ': ' +
+ "Path for Puppet environment directory {!r} is not a directory.".format(
+ puppet_root_env_dir))
+ sys.stderr.write(msg + '\n\n')
+ self.exit(retval)
+
+ self.puppet_root_env_dir = puppet_root_env_dir
+ self._init_puppet_environments()
self.env_name = self.args.env
+ self.env_dir = os.path.join(self.puppet_root_env_dir, self.env_name)
+
+ if not os.path.exists(self.env_dir):
+ msg = (
+ self.appname + ': ' +
+ "Invalid Puppet environment {e!r} - directory {d!r} does not exists.".format(
+ e=self.env_name, d=self.env_dir))
+ sys.stderr.write(msg + '\n\n')
+ msg = "Valid environments are:\n"
+ for env in self.environments:
+ msg += " * {}\n".format(env)
+ sys.stderr.write(msg + '\n')
+ self.arg_parser.print_usage(sys.stdout)
+ self.exit(0)
+
+ if not os.path.isdir(puppet_root_env_dir):
+ msg = (
+ self.appname + ': ' +
+ "Invalid Puppet environment {e!r} - path {d!r} is not a directory.".format(
+ e=self.env_name, d=self.env_dir))
+ sys.stderr.write(msg + '\n\n')
+ msg = "Valid environments are:\n"
+ for env in self.environments:
+ msg += " * {}\n".format(env)
+ sys.stderr.write(msg + '\n')
+ self.exit(retval)
+
+ out_dir = self.out_dir
+ retval = 6
if self.args.out_dir:
- self.out_dir = self.args.out_dir
+ out_dir = self.args.out_dir
+ retval = 0
+
+ if not os.path.exists(out_dir):
+ msg = (
+ self.appname + ': ' +
+ "Output directory {!r} does not exists.".format(out_dir))
+ sys.stderr.write(msg + '\n\n')
+ self.exit(retval)
+
+ if not os.path.isdir(out_dir):
+ msg = (
+ self.appname + ': ' +
+ "Path for Output directory {!r} is not a directory.".format(
+ out_dir))
+ sys.stderr.write(msg + '\n\n')
+ self.exit(retval)
+
+ self.out_dir = out_dir
+
+ # -------------------------------------------------------------------------
+ def _init_puppet_environments(self):
+
+ pattern = os.path.join(self.puppet_root_env_dir, '*')
+ dirs = glob.glob(pattern)
+
+ self.environments = []
+ for path in dirs:
+ if os.path.isdir(path):
+ env = os.path.basename(path)
+ self.environments.append(env)
+
+ self.environments.sort(key=str.lower)
# -------------------------------------------------------------------------
def post_init(self):