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


Python Utils.debug_print方法代码示例

本文整理汇总了Python中utils.Utils.debug_print方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.debug_print方法的具体用法?Python Utils.debug_print怎么用?Python Utils.debug_print使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.Utils的用法示例。


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

示例1: rename_job

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import debug_print [as 别名]
	def rename_job(args):
		"""rename a job in user's crontab"""
		if "quiet" in args:
			Utils.DEBUG = not args.quiet
		count = 0
		old_name = str(args.old_name)
		new_name = str(args.new_name)
		if Utils.check_job_name(new_name) == -1:
			Utils.debug_print("Error: job name cannot be '{}'.".format(name))
			sys.exit(1)
		if Utils.check_job_name(new_name) == -2:
			Utils.debug_print("Error: job name cannot contain a '%' symbol.")
			sys.exit(1)
		cron = TCronTab(user=True)
		for job in cron:
			if job.get_name() == old_name:
				job.set_name(new_name)
				count += 1
		if count:
			cron.activate_triggered_jobs(old_name, "deleted")
			cron.activate_triggered_jobs(new_name, "added")
		cron.write_to_user(user=True)
		if count == 0:
			Utils.debug_print("Error: job '{}' does not exist.".format(old_name))
		elif count == 1:
			Utils.debug_print("1 job has been renamed from '{}' to '{}'."
				.format(old_name, new_name))
		else:
			Utils.debug_print("{} jobs have been renamed from '{}' to '{}'."
				.format(count, old_name, new_name))
开发者ID:linostar,项目名称:SuperCron,代码行数:32,代码来源:supercron.py

示例2: clear_jobs

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import debug_print [as 别名]
	def clear_jobs(args):
		if "quiet" in args:
			Utils.DEBUG = not args.quiet
		if "force" in args and args.force:
			SuperCron._generic_clear_jobs(args, not Utils.DEBUG)
			return
		Utils.debug_print("Note: this will not affect crontab entries not added by SuperCron.")
		confirm_clear = raw_input("Are you sure you want to clear all of your SuperCron jobs? [y/n]: ")
		if confirm_clear == "y":
			SuperCron._generic_clear_jobs(args, args.quiet)
		else:
			Utils.debug_print("Cancelled.")
开发者ID:linostar,项目名称:SuperCron,代码行数:14,代码来源:supercron.py

示例3: _generic_clear_jobs

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import debug_print [as 别名]
	def _generic_clear_jobs(args, quiet):
		Utils.DEBUG = not quiet
		count = 0
		cron = TCronTab(user=True)
		for job in cron:
			if job.is_superjob():
				job.set_name(SuperCron.TOBEDELETED)
				job.set_trigger("")
				count += 1
		cron.remove_all(comment=SuperCron.TOBEDELETED)
		cron.write_to_user(user=True)
		if count == 1:
			Utils.debug_print("1 job has been removed from your crontab.")
		else:
			Utils.debug_print("{} jobs have been removed from your crontab.".format(count))
开发者ID:linostar,项目名称:SuperCron,代码行数:17,代码来源:supercron.py

示例4: delete_job

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import debug_print [as 别名]
	def delete_job(args):
		"""delete the specified job from user's crontab"""
		if "quiet" in args:
			Utils.DEBUG = not args.quiet
		name = str(args.name)
		count = 0
		cron = TCronTab(user=True)
		for job in cron:
			if job.get_name() == name:
				cron.remove(job)
				count += 1
		if count:
			cron.activate_triggered_jobs(name, "deleted")
		cron.write_to_user(user=True)
		if count == 1:
			Utils.debug_print("1 job named '{}' has been deleted.".format(name))
		else:
			Utils.debug_print("{} jobs named '{}' have been deleted.".format(count, name))
开发者ID:linostar,项目名称:SuperCron,代码行数:20,代码来源:supercron.py

示例5: add_job

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import debug_print [as 别名]
	def add_job(args):
		"""add the job to crontab"""
		if "quiet" in args:
			Utils.DEBUG = not args.quiet
		name = str(args.name)
		if Utils.check_job_name(name) == -1:
			Utils.debug_print("Error: job name cannot be '{}'.".format(name))
			sys.exit(1)
		if Utils.check_job_name(name) == -2:
			Utils.debug_print("Error: job name cannot contain a '%' symbol.")
			sys.exit(1)
		command = str(args.command[0])
		repetition = str(args.repetition[0])
		repeat = Repetition.parse_repetition(repetition)
		if not repeat:
			Utils.debug_print("Error: invalid repetition sentence: '{}'."
				.format(repetition))
			sys.exit(1)
		cron = TCronTab(user=True)
		job = cron.new(command=command, comment=name)
		if "reboot" in repeat:
			job.every_reboot()
		else:
			if "min_every" in repeat:
				job.minute.every(repeat['min_every'])
			if "min_on" in repeat:
				job.minute.on(repeat['min_on'])
			if "hour_every" in repeat:
				job.hour.every(repeat['hour_every'])
			if "hour_on" in repeat:
				job.hour.on(repeat['hour_on'])
			if "day_every" in repeat:
				job.day.every(repeat['day_every'])
			if "day_on" in repeat:
				job.day.on(repeat['day_on'])
			if "dow_on" in repeat:
				job.dow.on(*repeat['dow_on'])
			if "dow_during" in repeat:
				job.dow.during(*repeat['dow_during'])
			if "month_every" in repeat:
				job.month.every(repeat['month_every'])
			if "month_during" in repeat:
				job.month.during(*repeat['month_during'])
			if "month_on" in repeat:
				job.month.on(*repeat['month_on'])
		job.enable()
		cron.activate_triggered_jobs(name, "added")
		cron.write_to_user(user=True)
		Utils.debug_print("Job named '{}' has been successfully added.".format(name))
开发者ID:linostar,项目名称:SuperCron,代码行数:51,代码来源:supercron.py

示例6: trigger_job

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import debug_print [as 别名]
	def trigger_job(args):
		remove_trigger = False
		count = 0
		cron = TCronTab(user=True)
		if "quiet" in args:
			Utils.DEBUG = not args.quiet
		name = str(args.name)
		trigger = str(args.trigger[0])
		jobs = cron.find_name(name)
		if trigger.lower().strip() == "none":
			remove_trigger = True
			for job in jobs:
				job.set_trigger("")
				count += 1
		else:
			trigger_list = Utils.parse_trigger(trigger.strip())
			if trigger_list:
				for job in jobs:
					job.set_trigger(trigger_list)
					count += 1
			else:
				print(trigger.strip())
				Utils.debug_print("Error: invalid trigger (expected format is \"NONE\" or \"ACTION if NAME is STATE\").")
				sys.exit(1)
		cron.write_to_user(user=True)
		if remove_trigger:
			if count == 1:
				Utils.debug_print("Trigger was removed from 1 job named '{}'.".format(name))
			else:
				Utils.debug_print("Trigger was removed from {} jobs named '{}'.".format(count, name))
		else:
			if count == 1:
				Utils.debug_print("Trigger '{}' was added to 1 job named '{}'."
					.format(trigger.strip(), name))
			else:
				Utils.debug_print("Trigger '{}' was added to {} jobs named '{}'."
					.format(trigger.strip(), count, name))
开发者ID:linostar,项目名称:SuperCron,代码行数:39,代码来源:supercron.py

示例7: _generic_enable_job

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import debug_print [as 别名]
	def _generic_enable_job(name, enable_it, quiet=None):
		"""enable or disable job(s) by their name"""
		if quiet != None:
			Utils.DEBUG = not quiet
		count = 0
		cron = TCronTab(user=True)
		for job in cron:
			if job.get_name() == name and job.is_enabled() != enable_it:
				job.enable(enable_it)
				count += 1
		if enable_it:
			action = "enabled"
			if count:
				cron.activate_triggered_jobs(name, "enabled")
		else:
			action = "disabled"
			if count:
				cron.activate_triggered_jobs(name, "disabled")
		cron.activate_triggered_jobs(name, "toggled")
		cron.write_to_user(user=True)
		if count == 1:
			Utils.debug_print("1 job named '{}' has been {}.".format(name, action))
		else:
			Utils.debug_print("{} jobs named '{}' have been {}.".format(count, name, action))
开发者ID:linostar,项目名称:SuperCron,代码行数:26,代码来源:supercron.py

示例8: search_job

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import debug_print [as 别名]
	def search_job(args):
		"""That moment when you have to rely on a function to look for a job"""
		try:
			count = 0
			name = str(args.name)
			job_list = []
			cron = TCronTab(user=True)
			if name == "@all":
				for job in cron:
					job_name = job.get_name()
					enabled = "ON" if job.is_enabled() else "OFF"
					job_list.append([job_name, job.repr_trigger(), enabled, str(job.slices), job.command])
			elif name == "@supercron":
				for job in cron:
					if job.is_superjob():
						job_name = job.get_name()
						enabled = "ON" if job.is_enabled() else "OFF"
						job_list.append([job_name, enabled, job.repr_trigger(), str(job.slices), job.command])
			else:
				jobs = cron.find_name(name)
				for job in jobs:
					enabled = "ON" if job.is_enabled() else "OFF"
					job_list.append([name, enabled, job.repr_trigger(), str(job.slices), job.command])
			if job_list:
				col_widths = []
				col_titles = ["Name", "State", "Trigger", "Repetition", "Command"]
				for i in range(0, 5):
					col_widths.append(max(max(len(n[i]) for n in job_list) + 2, len(col_titles[i]) + 2))
				Utils.debug_print("".join(word.ljust(col_widths[i]) for word, i in zip(col_titles, range(0, 5))))
				Utils.debug_print("-" * (sum(col_widths) - 2))
				for job_item in job_list:
					Utils.debug_print("".join(word.ljust(col_widths[i]) for word, i in zip(job_item, range(0, 5))))
					count += 1
			else:
				Utils.debug_print("Zero search results.")
			return count
		except:
			# in case of any error, so the unittests can detect it
			return -1
开发者ID:linostar,项目名称:SuperCron,代码行数:41,代码来源:supercron.py

示例9: debug

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import debug_print [as 别名]
 def debug( self, *args, **kargs ):
     if self.opts['debug'] == True:
         Utils.debug_print( *args, **kargs )
开发者ID:joetainment,项目名称:mmmmtools,代码行数:5,代码来源:ObjectBase.py

示例10: parse_repetition

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import debug_print [as 别名]
	def parse_repetition(repetition):
		"""parse and convert different types of repetition clauses"""
		repeat = {}
		repetition = Repetition.expand_repetition(repetition.lower())
		# check for repetition clauses like: "every reboot"
		matched = re.search(r"(at|every)\s+(boot|reboot)", repetition)
		if matched:
			repeat['reboot'] = True
		# check for repetition clauses like: "once every 21 minutes"
		matched = re.search(r"(once\s+)?every\s+(\d+\s+)?minute(s)?", repetition)
		if matched:
			if not matched.group(2):
				repeat['min_every'] = 1
			elif int(matched.group(2)) > 0 and int(matched.group(2)) < 60:
				repeat['min_every'] = int(matched.group(2))
			else:
				Utils.debug_print("Error: invalid value '{}'. Expected 1-59 for minutes.")
				sys.exit(1)
		# check for repetition clauses like: "once every 3 hours"
		matched = re.search(r"(once\s+)?every\s+(\d+\s+)?hour(s)?", repetition)
		if matched:
			if not matched.group(2):
				repeat['hour_every'] = 1
			elif int(matched.group(2)) > 0 and int(matched.group(2)) < 24:
				repeat['hour_every'] = int(matched.group(2))
			else:
				Utils.debug_print("Error: invalid value '{}'. Expected 1-23 for hours.")
				sys.exit(1)
		# check for repetition clauses like: "once every 11 days"
		matched = re.search(r"(once\s+)?every\s+(\d+\s+)?day(s)?", repetition)
		if matched:
			if not matched.group(2):
				repeat['day_every'] = 1
			elif int(matched.group(2)) > 0 and int(matched.group(2)) < 460:
				repeat['day_every'] = int(matched.group(2))
			else:
				Utils.debug_print("Error: invalid value '{}'. Expected 1-31 for days.")
				sys.exit(1)
		# check for repetition clauses like: "once every 3 months"
		matched = re.search(r"(once\s+)?every\s+(\d+\s+)?month(s)?", repetition)
		if matched:
			if not matched.group(2):
				repeat['month_every'] = 1
			elif int(matched.group(2)) > 0 and int(matched.group(2)) < 13:
				repeat['month_every'] = int(matched.group(2))
			else:
				Utils.debug_print("Error: invalid value '{}'. Expected 1-12 for months.")
				sys.exit(1)
		# check for repetition clause: "everyday"
		matched = re.match(r"\b(everyday|anyday)\b", repetition)
		if matched:
			repeat['day_every'] = 1
		# check for repetition clause: "at midnight"
		matched = re.match(r"(at\s*)?\bmidnight\b", repetition)
		if matched:
			repeat['min_on'] = 0
			repeat['hour_on'] = 0
		# check for repetition clauses like: "10:32 am"
		matched = re.search(r"(on|at\s*)?\b(\d{1,2}):(\d{1,2})\b(\s*(am|pm))?", repetition)
		if matched:
			hour = int(matched.group(2))
			minute = int(matched.group(3))
			if matched.group(4):
				if matched.group(5) == "pm":
					if hour != 12:
						hour += 12
				else:
					if hour == 12:
						hour = 0
			if hour < 24 and minute < 59:
				repeat['min_on'] = minute
				repeat['hour_on'] = hour
			else:
				Utils.debug_print("Error: invalid value for hour and/or minute.")
				sys.exit(1)
		# check for repetition clauses like: "19/05"
		matched = re.search(r"(on\s*)?\b(\d{1,2})[/-](\d{1,2})\b", repetition)
		if matched:
			day = int(matched.group(2))
			month = int(matched.group(3))
			if month > 12 or month < 1:
				Utils.debug_print("Error: invalid value for month (expected value: 1-12).")
				sys.exit(1)
			if month == 2 and (day > 29 or day < 1):
				Utils.debug_print("Error: invalid value for day (expected value: 1-29).")
				sys.exit(1)
			if month in (4, 6, 9, 11) and (day > 30 or day < 1):
				Utils.debug_print("Error: invalid value for day (expected value: 1-30).")
				sys.exit(1)
			if day > 31 or day < 1:
				Utils.debug_print("Error: invalid value for day (expected value: 1-31).")
				sys.exit(1)
			else:
				repeat['day_on'] = day
				repeat['month_on'] = [month]
		# check for repetition clauses like: "on monday"
		m_repetition = repetition.replace(" and ", " on ").replace(",and ", " on ").replace(",", " on ")
		matched = re.finditer(r"(on\s+)(monday|tuesday|wednesday|thursday|friday|saturday|sunday)s?", m_repetition)
		weekdays = []
		for match in matched:
#.........这里部分代码省略.........
开发者ID:linostar,项目名称:SuperCron,代码行数:103,代码来源:repetition_parsing.py

示例11: interactive_mode

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import debug_print [as 别名]
	def interactive_mode():
		try:
			action_list = ("add", "rename", "delete", "enable", "disable", "search", "clear", "trigger")
			Utils.debug_print("SuperCron (interactive mode)")
			Utils.debug_print("")
			action = raw_input("Action [add/rename/delete/enable/disable/trigger/search/clear]: ")
			action = str(action.lower().strip())
			if action not in action_list:
				Utils.debug_print("Error: action '{}' not recognized.".format(action))
				sys.exit(1)
			args = Namespace()
			if action == "clear":
				Utils.debug_print("")
				SuperCron.clear_jobs(args)
				return
			if action == "rename":
				args.old_name = raw_input("Job old name: ")
				args.new_name = raw_input("Job new name: ")
				Utils.debug_print("")
				SuperCron.rename_job(args)
				return
			if action == "trigger":
				trigger_parts = []
				args.name = raw_input("Enter name of triggered job: ")
				trigger_parts.append(raw_input("Action on the triggered job [on/off/toggle]: "))
				trigger_parts.append(raw_input("Name of the triggering job: "))
				trigger_parts.append(raw_input("Condition on the triggering job [enabled/disabled/toggled/added/deleted]: "))
				args.trigger = ["{t[0]} if {t[1]} is {t[2]}".format(t=trigger_parts)]
				Utils.debug_print("")
				SuperCron.trigger_job(args)
				return
			args.name = raw_input("Job name: ")
			if action == "add":
				args.command = [raw_input("Command to be executed: ")]
				args.repetition = [raw_input("Repetition sentence: ")]
				Utils.debug_print("")
				SuperCron.add_job(args)
			elif action == "delete":
				Utils.debug_print("")
				SuperCron.delete_job(args)
			elif action == "enable":
				Utils.debug_print("")
				SuperCron.enable_job(args)
			elif action == "disable":
				Utils.debug_print("")
				SuperCron.disable_job(args)
			elif action == "search":
				Utils.debug_print("")
				SuperCron.search_job(args)
		except KeyboardInterrupt:
			Utils.debug_print("\nCancelled.")
开发者ID:linostar,项目名称:SuperCron,代码行数:53,代码来源:supercron.py


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