Execute specified arguments and send notification email

    Parameters
    ----------
    args : list
        A execution command/arguments list
    opts : object
        A option instance
167082
def call_and_notificate(args, opts):
    
    # store starttime
    stctime = time.clock()
    stttime = time.time()
    stdtime = datetime.datetime.now()
    # call subprocess
    exit_code, output = call(args)
    # calculate delta
    cdelta = time.clock() - stctime
    tdelta = time.time() - stttime
    endtime = datetime.datetime.now()
    if exit_code == 0:
        status = u"Success"
    else:
        status = u"Fail (%d)" % exit_code
    # create email body
    body = EMAIL_BODY % {
        'prog': get_command_str(args),
        'status': status,
        'stdtime': stdtime,
        'endtime': endtime,
        'tdelta': tdelta,
        'cdelta': cdelta,
        'output': output,
        'cwd': os.getcwd(),
    }
    # create email subject
    subject = opts.subject % {
        'prog': get_command_str(args),
        'status': status.lower(),
    }
    # create email message
    msg = create_message(opts.from_addr,
                         opts.to_addr,
                         subject,
                         body,
                         opts.encoding)
    # obtain password from keyring
    password = keyring.get_password('notify', opts.username)
    # send email
    send_email(msg, opts.host, opts.port, opts.username, password)
406413
def issueCommand(self, command, *args):
        
        result = Deferred()
        self._dq.append(result)
        self.sendLine(b" ".join([command] + list(args)))
        return result
732086
def input(self, opt):
        

        for key in self.command['input']:
            if (key == opt) or (self.command['input'][key]['name'] == opt):
                return self._send_command(['input', key, 'command'])
        return False
1319509
def list_command(opts)
      usage = "Agent exposes the following commands:\n"
      COMMANDS.reject { |k, _| k == :list || k.to_s =~ /test/ }.each do |c|
        c.each { |k, v| usage += " - #{k.to_s}: #{v}\n" }
      end
      CommandIO.instance.reply(opts[:conn], usage)
    end
1041232
def execute(self, arg_list):
        
        arg_map = self.parser.parse_args(arg_list).__dict__
        command = arg_map.pop(self._COMMAND_FLAG)
        return command(**arg_map)
234107
def notify(options = {})
      @@options = options
      @@options[:entity_class] = self
      @@options[:callbacks] = []
      [:create, :update, :destroy].each {|_method| @@options[:callbacks] << @@options[:actions].delete(_method)}
      @@options[:callbacks].compact!
      open_sender_class
      open_receiver_class
      open_notified_class
      @@notified_flag = true
    end
906219
def run(self, *args, **kwargs):
        
        self.log.debug('Starting EBSAuditor')
        data = self.update_data()

        notices = defaultdict(list)
        for account, issues in data.items():
            for issue in issues:
                for recipient in account.contacts:
                    notices[NotificationContact(type=recipient['type'], value=recipient['value'])].append(issue)

        self.notify(notices)
217925
def send_email_notification(self, notification_id=None, include_traceback=False, verbosity=1):
        
        # Load email notification settings if available
        if notification_id is not None:
            try:
                email_settings = settings.EMAIL_NOTIFICATIONS.get(notification_id, {})
            except AttributeError:
                email_settings = {}
        else:
            email_settings = {}

        # Exit if no traceback found and not in 'notify always' mode
        if not include_traceback and not email_settings.get('notification_level', 0):
            print(self.style.ERROR("Exiting, not in 'notify always' mode."))
            return

        # Set email fields.
        subject = email_settings.get('subject', "Django extensions email notification.")

        command_name = self.__module__.split('.')[-1]

        body = email_settings.get(
            'body',
            "Reporting execution of command: '%s'" % command_name
        )

        # Include traceback
        if include_traceback and not email_settings.get('no_traceback', False):
            try:
                exc_type, exc_value, exc_traceback = sys.exc_info()
                trb = ''.join(traceback.format_tb(exc_traceback))
                body += "\n\nTraceback:\n\n%s\n" % trb
            finally:
                del exc_traceback

        # Set from address
        from_email = email_settings.get('from_email', settings.DEFAULT_FROM_EMAIL)

        # Calculate recipients
        recipients = list(email_settings.get('recipients', []))

        if not email_settings.get('no_admins', False):
            recipients.extend(settings.ADMINS)

        if not recipients:
            if verbosity > 0:
                print(self.style.ERROR("No email recipients available."))
            return

        # Send email...
        send_mail(subject, body, from_email, recipients,
                  fail_silently=email_settings.get('fail_silently', True))
1169486
def send_notification(self, method, args, kwargs):
        """"""
        msg = dumps([1, method, args, kwargs])
        self.send(msg)
1278164
def exec(self, args):
        

        logger.debug("update %s", args.update)
        self.update(args.update)
845805
def send_msg(self, address, args=[]):
        
        if not address.startswith('/'):
            address = '/{}'.format(address)
    
        msg = osc_message_builder.OscMessageBuilder(address=address)
    
        for arg in args:
            msg.add_arg(arg)
        self.conn.send(msg.build())
        return
1351238
def cmd(send, _, args):
    
    send("%s! %s" % (args['name'].upper(), random.choice(squirrels)))
59305
def send_command(self, obj, command, *arguments):
        
        self._perform_command('{}/{}'.format(self.session_url, obj.ref), command, OperReturnType.no_output, *arguments)
811453
def execute(self):
        
        #Initialize the option parser
        parser = LaxOptionParser(
            usage="%prog subcommand [options] [args]",
            option_list=BaseCommand.option_list #This will define what is allowed input to the parser (ie --settings=)
        )

        #Parse the options
        options, args = parser.parse_args(self.argv)
        #Handle --settings and --pythonpath properly
        options = handle_default_options(options)

        try:
            #Get the name of the subcommand
            subcommand = self.argv[1]
        except IndexError:
            #If the subcommand name cannot be found, set it to help
            subcommand = 'help'

        #If the subcommand is help, print the usage of the parser, and available command names
        if subcommand == 'help':
            if len(args) <= 2:
                parser.print_help()
                sys.stdout.write(self.help_text + '\n')
        else:
            #Otherwise, run the given command
            self.fetch_command(subcommand).run_from_argv(self.argv)
580457
def process(self, argument_list):
        
        arg_index = 0
        for a in argument_list:
            opt_and_val = a.split("=", 1)
            opt_name = opt_and_val[0]
            try:
                # option
                argument = self.options[opt_name]
            except KeyError:
                # argument
                try:
                    argument = self.arguments[arg_index]
                except IndexError:
                    logger.error("option/argument %r not specified", a)
                    raise NoSuchOptionOrArgument("No such option or argument: %r" % opt_name)
            logger.info("argument found: %s", argument)

            safe_arg_name = normalize_arg_name(argument.name)  # so we can access names-with-dashes

            logger.info("argument is available under name %r", safe_arg_name)

            if isinstance(argument, Argument):
                arg_index += 1
                value = (a, )
            else:
                try:
                    value = (opt_and_val[1], )
                except IndexError:
                    value = tuple()

            arg_val = argument.action(*value)

            logger.info("argument %r has value %r", safe_arg_name, arg_val)
            self.given_arguments[safe_arg_name] = arg_val
        return self.given_arguments
542687
def send_email(sender, msg, driver):
    
    driver.users().messages().send(
        userId=sender,
        body=msg
    ).execute()
1320282
def __send_command(self, command, args=[]):
        ''''''
        self.ws.send(json.dumps({"op": command, "args": args}))