def send_mail(to_addr, subject, message): log = get_logger(__name__) log.debug('Sending mail to %s - %s' % (to_addr, subject)) config = get_config() from_addr = config['admin']['smtp_from'] subject_prefix = config['admin']['smtp_subject_prefix'] host = config['admin']['smtp_host'] port = config['admin']['smtp_port'] user = config['admin']['smtp_user'] password = config['admin']['smtp_password'] tls = config['admin']['smtp_tls'] key = config['admin']['smtp_keyfile'] cert = config['admin']['smtp_certfile'] try: smtp = smtplib.SMTP(host, port) if tls: smtp.starttls(keyfile, certfile) if user: smtp.login(user, password) msg = "From: %s\r\n" % from_addr msg = msg + "To: %s\r\n" % to_addr msg = msg + "Subject: %s%s\r\n" % (subject_prefix, subject) msg = msg + message smtp.sendmail(from_addr, to_addr, msg) except socket.error, e: log.error("unable to send email - %s %s" % (e.args[0], e.args[1]))
def nose_main(args, test_config): """ This function provides an alternative to main() that is more friendly for nose tests as it doesn't catch any exceptions. Required Arguments: args The args to pass to lay_cement test_config A test config to pass to lay_cement Usage: .. code-block:: python from iustools.core.appmain import nose_main from iustools.core.config import get_nose_config args = [__file__, 'nosetests', '--quiet'] (res_dict, output_text) = nose_main(args, get_nose_config()) """ lay_cement(config=test_config, banner=BANNER, args=args) log = get_logger(__name__) log.debug("Cement Framework Initialized!") if not len(args) > 1: args.append('default') (res, output_txt) = run_command(args[1]) return (res, output_txt)
def main(): try: ensure_api_compat(__name__, REQUIRED_CEMENT_API) lay_cement(config=default_config, banner=BANNER) log = get_logger(__name__) log.debug("Cement Framework Initialized!") if not len(sys.argv) > 1: sys.argv.append('default') config = get_config() # create the lock file if os.path.exists(config['lockfile']): raise SatCLIRuntimeError, \ "lock file exists, is satcli already running?" else: f = open(config['lockfile'], 'w+') f.write(get_timestamp()) f.close() run_command(sys.argv[1]) except CementArgumentError, e: print("CementArgumentError > %s" % e) sys.exit(e.code)
def nose_main(args, test_config): """ This function provides an alternative to main() that is more friendly for nose tests as it doesn't catch any exceptions. """ lay_cement(config=test_config, banner=BANNER, args=args) log = get_logger(__name__) log.debug("Cement Framework Initialized!") if not len(args) > 1: args.append('default') (res, output_txt) = run_command(args[1]) return (res, output_txt)
def main(args=None): try: lay_cement(config=default_config, banner=BANNER, args=args) log = get_logger(__name__) log.debug("Cement Framework Initialized!") if not len(sys.argv) > 1: sys.argv.append('default') run_command(sys.argv[1]) except CementArgumentError, e: # Display the apps exception names instead for the Cement exceptions. print("CementTestArgumentError > %s" % e) sys.exit(e.code)
def main(args=None): try: if not args: args = sys.argv lay_cement(config=default_config, banner=BANNER, args=args, version=VERSION) log = get_logger(__name__) log.debug("Cement Framework Initialized!") if not len(args) > 1: args.append('default') run_command(args[1]) except MFConfigError, e: print("MFConfigError > %s" % e) sys.exit(e.code)
def main(): ensure_abi_compat(__name__, REQUIRED_CEMENT_ABI) # Warning: You shouldn't modify below this point unless you know what # you're doing. lay_cement(default_config, version_banner=BANNER) log = get_logger(__name__) log.debug("Cement Framework Initialized!") # react to the passed command. command should be the first arg always try: if not len(sys.argv) > 1: raise CementArgumentError, "A command is required. See --help?" run_command(sys.argv[1]) except CementArgumentError, e: print("CementArgumentError > %s" % e)
"""Cement methods and classes to handle cli option/arg parsing.""" import os import sys import re import optparse from cement.core.configuration import namespaces from cement.core.log import get_logger log = get_logger(__name__) def init_parser(banner=None): """ Create an OptionParser object and returns its parser member. Keyword arguments: banner Optional version banner to display for --version Returns: OptionParser object. """ fmt = optparse.IndentedHelpFormatter( indent_increment=4, max_help_position=32, width=77, short_first=1 ) parser = optparse.OptionParser(formatter=fmt, version=banner) return parser
"""Methods and classes to handle Cement plugin support.""" import os import re from configobj import ConfigObj from cement.core.configuration import namespaces from cement.core.exc import CementConfigError, CementRuntimeError from cement.core.log import get_logger, setup_logging_for_plugin_provider from cement.core.hook import run_hooks from cement.core.configuration import set_config_opts_per_file, t_f_pass from cement.core.namespace import CementNamespace, get_config log = get_logger(__name__) def get_enabled_plugins(): """ Open plugin config files from plugin_config_dir and determine if they are enabled. If so, append them to 'enabled_plugins' in the root config. Uses the namespaces['root'].config dictionary. """ config = get_config() if config.has_key('enabled_plugins'): enabled_plugins = config['enabled_plugins'] else: enabled_plugins = [] # determine enabled plugins