• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python util.die函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: start

def start(secrets):
    logging.info("Starting")
    app.client = client.Client(app.info, jid=secrets["jid"], password=secrets["password"])
    address = (secrets["host"], secrets["port"]) if (secrets.has_key("host") and secrets.has_key("port")) else ()
    logging.info("XMPP connecting with address " + str(address))
    if app.client.connect(address):
        app.client.process(threaded=True)
        app.started = True
    else:
        # XXX We shouldn't die here, we should still serve existing data and try again.  
        # We could also prompt for credentials again
        util.die("XMPP connection failed")
开发者ID:AlokKothari,项目名称:Locker,代码行数:12,代码来源:webservice.py


示例17: create

    def create(self):
        try:
            self.fd = os.open(self.lockpath,
                              os.O_CREAT |  # create file
                              os.O_TRUNC |  # truncate it, if it exists
                              os.O_WRONLY | # write-only
                              os.O_EXCL,    # exclusive access
                              0644)         # file mode

        except Exception, e:
            pid = self.get_pid()
            die("DenyHosts could not obtain lock (pid: %s)" % pid, e)
开发者ID:GerHobbelt,项目名称:denyhosts,代码行数:12,代码来源:lockfile.py


示例18: http_status

def http_status(data):
	# keys: status, url (also http_helper params)
	if 'status' not in data or 'url' not in data:
		util.die('checks.http_status: missing status')

	result = http_helper(data)

	if result['status'] == 'fail':
		return result
	elif str(result['code']) == data['status']:
		return {'status': 'success'}
	else:
		return {'status': 'fail', 'message': "target [%s] returned unexpected status [%s], expected [%s]" % (data['url'], str(result['code']), data['status'])}
开发者ID:ekiminatorn,项目名称:pybearmon,代码行数:13,代码来源:checks.py


示例19: http_contains

def http_contains(data):
	# keys: substring, url (also http_helper params)
	if 'substring' not in data or 'url' not in data:
		util.die('checks.http_contains: missing substring')

	result = http_helper(data)

	if result['status'] == 'fail':
		return result
	elif data['substring'] in result['content']:
		return {'status': 'success'}
	else:
		return {'status': 'fail', 'message': "target [%s] does not contain string [%s]" % (data['url'], data['substring'])}
开发者ID:ekiminatorn,项目名称:pybearmon,代码行数:13,代码来源:checks.py


示例20: ping

def ping(data):
	# keys: target
	if 'target' not in data:
		util.die('checks.ping: missing target')

	import subprocess

	target = data['target']
	result = subprocess.Popen(['ping', target, '-c', '3', '-w', '3'], stdout=subprocess.PIPE).stdout.read()

	if '100% packet loss' in result:
		return {'status': 'fail', 'message': "No response from %s" % (target,)}
	else:
		return {'status': 'success'}
开发者ID:ekiminatorn,项目名称:pybearmon,代码行数:14,代码来源:checks.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.distance函数代码示例发布时间:2022-05-27
下一篇:
Python util.decode_html函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap