当前位置: 首页>>代码示例>>Python>>正文


Python util.die函数代码示例

本文整理汇总了Python中util.die函数的典型用法代码示例。如果您正苦于以下问题:Python die函数的具体用法?Python die怎么用?Python die使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了die函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main():

    parser = argparse.ArgumentParser()

    # parameter for the AFL.
    parser.add_argument(
            'AFL',
            help='Application File Locator value (coded in hexadecimal).'
            )

    # doctest flag.
    parser.add_argument(
            '-t',
            '--test',
            help='run the doctests and exit.',
            action='store_true'
            )

    args = parser.parse_args()

    test = args.test
    afl = args.AFL

    if test:
        doctest.testmod()
        return

    valid_in = validate(afl)

    if not valid_in:
        util.die("A valid AFL value should be a multiple of 4 Bytes.")

    print human(afl)

    return
开发者ID:jopela,项目名称:HairyEMV,代码行数:35,代码来源:afl.py

示例2: fetch_roster

 def fetch_roster(self):
     try:
         xmpp.ClientXMPP.get_roster(self)
         logging.info("Roster: %s" % self.roster)
         return self.roster
     except Exception, exc:
         util.die("Couldn't fetch roster: %s" % exc)
开发者ID:AlokKothari,项目名称:Locker,代码行数:7,代码来源:client.py

示例3: check_required

    def check_required(self, path):
        ok = 1
        for name_reqd, val_reqd in self.reqd:
            if not self.__data.has_key(name_reqd):
                print "Missing configuration parameter: %s" % name_reqd
                if name_reqd == 'DENY_THRESHOLD_INVALID':
                    print "\nNote: The configuration parameter DENY_THRESHOLD has been renamed"
                    print "      DENY_THRESHOLD_INVALID.  Please update your DenyHosts configuration"
                    print "      file to reflect this change."

                    if self.__data.has_key('DENY_THRESHOLD'):
                        print "\n*** Using deprecated DENY_THRESHOLD value for DENY_THRESHOLD_INVALID ***"
                        self.__data['DENY_THRESHOLD_INVALID'] = self.__data['DENY_THRESHOLD']
                    else:
                        ok = 0                        
                elif name_reqd == 'DENY_THRESHOLD_RESTRICTED':
                    print "\nNote: DENY_THRESHOLD_RESTRICTED has not been defined. Setting this"
                    print "value to DENY_THRESHOLD_ROOT"
                    self.__data['DENY_THRESHOLD_RESTRICTED'] = self.__data['DENY_THRESHOLD_ROOT']
                else:
                    ok = 0
            #elif val_reqd and not self.__data[name_reqd]:
            elif val_reqd and not self.__data[name_reqd] and not name_reqd in self.to_int:
                print "Missing configuration value for: %s" % name_reqd
                ok = 0

        if not ok:
            die("You must correct these problems found in: %s" % path)
开发者ID:MikeRixWolfe,项目名称:denyhosts,代码行数:28,代码来源:prefs.py

示例4: __init__

    def __init__(self, logfile, prefs, lock_file,
                 ignore_offset=0, first_time=0,
                 noemail=0, daemon=0):
        self.__denied_hosts = {}
        self.__prefs = prefs
        self.__lock_file = lock_file
        self.__first_time = first_time
        self.__noemail = noemail
        self.__report = Report(prefs.get("HOSTNAME_LOOKUP"), is_true(prefs['SYSLOG_REPORT']))
        self.__daemon = daemon
        self.__sync_server = prefs.get('SYNC_SERVER')
        self.__sync_upload = is_true(prefs.get("SYNC_UPLOAD"))
        self.__sync_download = is_true(prefs.get("SYNC_DOWNLOAD"))


        r = Restricted(prefs)
        self.__restricted = r.get_restricted()
        info("restricted: %s", self.__restricted)
        self.init_regex()

        try:
            self.file_tracker = FileTracker(self.__prefs.get('WORK_DIR'),
                                            logfile)
        except Exception, e:
            self.__lock_file.remove()
            die("Can't read: %s" % logfile, e)
开发者ID:GerHobbelt,项目名称:denyhosts,代码行数:26,代码来源:deny_hosts.py

示例5: main

def main():

    parser = argparse.ArgumentParser()

    parser.add_argument("decline", help="value of the decline xIAC (e.g:FC0011AB00)")

    parser.add_argument("online", help="value of the online xIAC (e.g:FC0011AB00)")

    parser.add_argument("default", help="value of the decline xIAC (e.g:FC0011AB00)")

    parser.add_argument("-t", "--test", help="run the doctests", default=False, action="store_true")

    args = parser.parse_args()

    if args.test:
        import doctest

        doctest.testmod()
        return

    # xIAC
    decline = util.rm(args.decline)
    online = util.rm(args.online)
    default = util.rm(args.default)

    valid_in = validate(decline, online, default)

    if not valid_in:
        util.die("xIAC must all have the same length and be HEX values.")

    print human(decline, online, default)
    return
开发者ID:jopela,项目名称:HairyEMV,代码行数:32,代码来源:xIAC.py

示例6: main

def main():

    parser = argparse.ArgumentParser()

    # parameter for the AIP.
    parser.add_argument(
            'AIP',
            help='Application Interchange Profile (coded in hexadecimal).'
            )

    # doctest flag.
    parser.add_argument(
            '-t',
            '--test',
            help='run the doctests and exit.',
            action='store_true'
            )

    args = parser.parse_args()

    if args.test:
        doctest.testmod()
        return

    valid_in = validate(args.AIP)

    if not valid_in:
        util.die("a valid AIP has a lenght of 2 Bytes and is code in HEX")

    print human(args.AIP)

    return
开发者ID:jopela,项目名称:HairyEMV,代码行数:32,代码来源:aip.py

示例7: handle_change

	def handle_change(self, thread_name, check_id, check_name, lock_uid, status, check_result):
		if status == 'offline':
			updown = 'down'
		elif status == 'online':
			updown = 'up'

		safe_print("[%s] ... confirmed, target is %s state now", (thread_name, status))
		update_result = Check.objects.raw("UPDATE checks SET status = %s, confirmations = 0, `lock` = '', last_checked = NOW() WHERE id = %s AND `lock` = %s", (status, check_id, lock_uid))

		if update_result.rowcount == 1:
			# we still had the lock at the point where status was toggled
			# then, send the alert
			alert_result = database.query("SELECT contacts.id, contacts.type, contacts.data FROM contacts, alerts WHERE contacts.id = alerts.contact_id AND alerts.check_id = %s AND alerts.type IN ('both', %s)", (check_id, updown))

			for alert_row in alert_result.fetchall():
				safe_print("[%s] ... alerting contact %d", (thread_name, alert_row['id']))
				alert_func = getattr(alerts, alert_row['type'], None)

				if not alert_func:
					util.die("Invalid alert handler [%s]!" % (alert_row['type']))

				# build context
				context = {}
				context['check_id'] = check_id
				context['check_name'] = check_name
				context['contact_id'] = alert_row['id']
				context['title'] = "Check %s: %s" % (status, check_name)
				context['status'] = status
				context['updown'] = updown
				context['message'] = check_result['message']

				alert_func(util.decode(alert_row['data']), context)

			# also add an event
			database.query("INSERT INTO check_events (check_id, type) VALUES (%s, %s)", (check_id, updown))
开发者ID:ZUNbado,项目名称:pymonitor,代码行数:35,代码来源:monitor.py

示例8: main

def main():

    parser = argparse.ArgumentParser()

    # parameter for the TLV.
    parser.add_argument(
            'TLV',
            help='TLV string (coded in hexadecimal).'
            )

    # doctest flag.
    parser.add_argument(
            '-t',
            '--test',
            help='run the doctests and exit.',
            action='store_true'
            )

    args = parser.parse_args()

    if args.test:
        doctest.testmod()
        return
    
    if not validate(args.TLV):
        util.die("A valid TLV value must be encoded in HEX and be an integer"\
                "multiple of Bytes greater then 0")


    print human(args.TLV)

    return
开发者ID:jopela,项目名称:HairyEMV,代码行数:32,代码来源:tlv.py

示例9: sms_twilio

def sms_twilio(data, context):
	'''
	Sends an SMS message via Twilio to the given number.
	The message is "[title] message"
	config must include the strings twilio_accountsid, twilio_authtoken, and twilio_number

	data['number']: phone number to send SMS message to.
	data['twilio_accountsid'], data['twilio_authtoken'], data['twilio_number']: optional Twilio configuration
	context['title']: used in creating SMS message
	context['message']: used in creating SMS message
	'''
	from config import config
	from twilio.rest import TwilioRestClient

	if 'number' not in data:
		util.die('alert_sms_twilio: missing number')

	config_target = config

	if 'twilio_accountsid' in data and 'twilio_authtoken' in data and 'twilio_number' in data:
		config_target = data

	sms_message = "[%s] %s" % (context['title'], context['message'])
	client = TwilioRestClient(config_target['twilio_accountsid'], config_target['twilio_authtoken'])

	message = client.messages.create(body = sms_message, to = data['number'], from_ = config_target['twilio_number'])
开发者ID:hantrick,项目名称:pybearmon,代码行数:26,代码来源:alerts.py

示例10: main

def main():
    global projectshort

    # No emails for a repository in the process of being imported
    git_dir = git.rev_parse(git_dir=True, _quiet=True)
    if os.path.exists(os.path.join(git_dir, 'pending')):
        return

    projectshort = get_module_name()

    def get_config(hook, skip=False):
        hook_val = None
        try:
            hook_val = git.config(hook, _quiet=True)
        except CalledProcessError:
            pass

        if not hook_val and not skip:
            die("%s is not set" % hook)

        return hook_val

    global debug
    if (len(sys.argv) > 1):
        debug = True
        print "Debug Mode on"
    else:
        debug = False

    recipients = get_config("hooks.mailinglist", debug)
    smtp_host = get_config("hooks.smtp-host", debug)
    smtp_port = get_config("hooks.smtp-port", True)
    smtp_sender = get_config("hooks.smtp-sender", debug)
    smtp_sender_user = get_config("hooks.smtp-sender-username", True)
    smtp_sender_pass = get_config("hooks.smtp-sender-password", True)

    changes = []

    if len(sys.argv) > 1:
        # For testing purposes, allow passing in a ref update on the command line
        if len(sys.argv) != 4:
            die("Usage: generate-commit-mail OLDREV NEWREV REFNAME")
        changes.append(make_change(recipients, smtp_host, smtp_port, smtp_sender, smtp_sender_user, smtp_sender_pass,
                                   sys.argv[1], sys.argv[2], sys.argv[3]))
    else:
        for line in sys.stdin:
            items = line.strip().split()
            if len(items) != 3:
                die("Input line has unexpected number of items")
            changes.append(make_change(recipients, smtp_host, smtp_port, smtp_sender, smtp_sender_user, smtp_sender_pass,
                                       items[0], items[1], items[2]))

    for change in changes:
        all_changes[change.refname] = change

    for change in changes:
        change.prepare()
        change.send_emails()
        processed_changes[change.refname] = change
开发者ID:tmorgner,项目名称:email-hook,代码行数:59,代码来源:post-receive-email.py

示例11: start

def start():
    logging.info("Starting")
    secrets = lockerfs.loadJsonFile("secrets.json")
    app.client = client.Client(app.info, jid=secrets["jid"], password=secrets["password"])
    if app.client.connect():
        app.client.process(threaded=True)
        app.started = True
    else:
        util.die("XMPP connection failed")
开发者ID:maxogden,项目名称:Locker,代码行数:9,代码来源:webservice.py

示例12: environ_sub

 def environ_sub(self, value):
     while True:
         environ_match = ENVIRON_REGEX.search(value)
         if not environ_match: return value
         name = environ_match.group("environ")
         env = os.environ.get(name)
         if not env:
             die("Could not find environment variable: %s" % name)
         value = ENVIRON_REGEX.sub(env, value)
开发者ID:MikeRixWolfe,项目名称:denyhosts,代码行数:9,代码来源:prefs.py

示例13: get_config

    def get_config(hook, skip=False):
        hook_val = None
        try:
            hook_val = git.config(hook, _quiet=True)
        except CalledProcessError:
            pass

        if not hook_val and not skip:
            die("%s is not set" % hook)

        return hook_val
开发者ID:tmorgner,项目名称:email-hook,代码行数:11,代码来源:post-receive-email.py

示例14: ch_def

def ch_def():
    """ Returns the default channel with which communication with
    the card will occur. """
        
    try:
        reader_def = reader_name_def()
        t = terminal_select(reader_def)
        card = t.connect(PROTO_DEF)
        ch = card.getBasicChannel()
        return ch
    except:
        util.die("could not get a connection to the card with the default terminal.")
开发者ID:Sesha1986,项目名称:EMVZombie,代码行数:12,代码来源:terminal.py

示例15: remove

 def remove(self, die_=True):
     try:
         if self.fd: os.close(self.fd)
     except:
         pass
     
     self.fd = None
     try:
         os.unlink(self.lockpath)
     except Exception, e:
         if die_:
             die("Error deleting DenyHosts lock file: %s" % self.lockpath, e)
开发者ID:MikeRixWolfe,项目名称:denyhosts,代码行数:12,代码来源:lockfile.py


注:本文中的util.die函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。