本文整理汇总了Python中gourmet.gdebug.TimeAction类的典型用法代码示例。如果您正苦于以下问题:Python TimeAction类的具体用法?Python TimeAction怎么用?Python TimeAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TimeAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compile_regexps
def compile_regexps (self):
"""Compile our regular expressions for the rezkonv format.
"""
testtimer = TimeAction('mealmaster_importer.compile_regexps',10)
debug("start compile_regexps",5)
plaintext_importer.TextImporter.compile_regexps(self)
self.start_matcher = re.compile(rzc_start_pattern)
self.end_matcher = re.compile("^[=M-][=M-][=M-][=M-][=M-]\s*$")
self.group_matcher = re.compile("^\s*([=M-][=M-][=M-][=M-][=M-]+)-*\s*([^-]+)\s*-*",re.IGNORECASE)
self.ing_cont_matcher = re.compile("^\s*[-;]")
self.ing_opt_matcher = re.compile("(.+?)\s*\(?\s*optional\)?\s*$",re.IGNORECASE)
# or or the German, oder
self.ing_or_matcher = re.compile("^[-= ]*[Oo][dD]?[eE]?[Rr][-= ]*$",re.IGNORECASE)
self.variation_matcher = re.compile("^\s*(VARIATION|HINT|NOTES?|VERÄNDERUNG|VARIANTEN|TIPANMERKUNGEN)(:.*)?",re.IGNORECASE)
# a crude ingredient matcher -- we look for two numbers, intermingled with spaces
# followed by a space or more, followed by a two digit unit (or spaces)
self.ing_num_matcher = re.compile(
"^\s*%(top)s%(num)s+\s+[A-Za-z ][A-Za-z ]? .*"%{'top':convert.DIVIDEND_REGEXP,
'num':convert.NUMBER_REGEXP},
re.IGNORECASE)
self.amt_field_matcher = convert.NUMBER_MATCHER
# we build a regexp to match anything that looks like
# this: ^\s*ATTRIBUTE: Some entry of some kind...$
attrmatch="^\s*("
self.mmf = rzc
for k in self.mmf.recattrs.keys():
attrmatch += "%s|"%re.escape(k)
attrmatch="%s):\s*(.*)\s*$"%attrmatch[0:-1]
self.attr_matcher = re.compile(attrmatch)
testtimer.end()
示例2: add_ref
def add_ref(self, id):
timeaction = TimeAction("importer.add_ref", 10)
if not self.id_converter.has_key(id):
self.id_converter[id] = self.rd.new_id()
self.ing["refid"] = self.id_converter[id]
self.ing["unit"] = "recipe"
timeaction.end()
示例3: __init__
def __init__(
self,
rd=None, # OBSOLETE
total=0,
prog=None, # OBSOLETE
do_markup=True,
conv=None,
rating_converter=None,
name="importer",
):
"""rd is our recipeData instance.
Total is used to keep track of progress.
do_markup should be True if instructions and modifications
come to us unmarked up (i.e. if we need to escape < and &,
etc. -- this might be False if importing e.g. XML).
"""
timeaction = TimeAction("importer.__init__", 10)
if not conv:
self.conv = convert.get_converter()
self.id_converter = {} # a dictionary for tracking named IDs
self.total = total
if prog or rd:
import traceback
traceback.print_stack()
if prog:
print "WARNING: ", self, "handed obsolete parameter prog=", prog
if rd:
print "WARNING: ", self, "handed obsolete parameter rd=", rd
self.do_markup = do_markup
self.count = 0
self.rd = get_recipe_manager()
self.rd_orig_ing_hooks = self.rd.add_ing_hooks
self.added_recs = []
self.added_ings = []
# self.rd_orig_hooks = self.rd.add_hooks
self.rd.add_ing_hooks = []
# self.rd.add_hooks = []
self.position = 0
self.group = None
# allow threaded calls to pause
self.suspended = False
# allow threaded calls to be terminated (this
# has to be implemented in subclasses).
self.terminated = False
# Our rating converter -- if we've been handed a class, we
# assume our caller will handle doing the
# conversion. Otherwise we do it ourselves.
if rating_converter:
self.rating_converter = rating_converter
self.do_conversion = False
else:
self.rating_converter = RatingConverter()
self.do_conversion = True
self.km = keymanager.get_keymanager()
timeaction.end()
SuspendableThread.__init__(self, name=name)
示例4: add_unit
def add_unit (self, unit):
testtimer = TimeAction('mealmaster_importer.add_unit',10)
unit = unit.strip()
if self.mmf.unit_conv.has_key(unit):
unit = self.mmf.unit_conv[unit]
importer.Importer.add_unit(self,unit)
testtimer.end()
示例5: add_ref
def add_ref (self, id):
timeaction = TimeAction('importer.add_ref',10)
if not self.id_converter.has_key(id):
self.id_converter[id]=self.rd.new_id()
self.ing['refid']=self.id_converter[id]
self.ing['unit']='recipe'
timeaction.end()
示例6: compile_regexps
def compile_regexps (self):
testtimer = TimeAction('mealmaster_importer.compile_regexps',10)
debug("start compile_regexps",5)
plaintext_importer.TextImporter.compile_regexps(self)
self.start_matcher = re.compile(mm_start_pattern)
self.end_matcher = re.compile("^[M-][M-][M-][M-][M-]\s*$")
self.group_matcher = re.compile("^\s*([M-][M-][M-][M-][M-])-*\s*([^-]+)\s*-*",re.IGNORECASE)
self.ing_cont_matcher = re.compile("^\s*[-;]")
self.ing_opt_matcher = re.compile("(.+?)\s*\(?\s*optional\)?\s*$",re.IGNORECASE)
self.ing_or_matcher = re.compile("^[- ]*[Oo][Rr][- ]*$",re.IGNORECASE)
self.variation_matcher = re.compile("^\s*(VARIATION|HINT|NOTES?)(:.*)?",re.IGNORECASE)
# a crude ingredient matcher -- we look for two numbers,
# intermingled with spaces followed by a space or more,
# followed by a two digit unit (or spaces)
self.ing_num_matcher = re.compile(
"^\s*%s+\s+[a-z ]{1,2}\s+.*\w+.*"%convert.NUMBER_REGEXP,
re.IGNORECASE)
self.amt_field_matcher = re.compile("^(\s*%s\s*)$"%convert.NUMBER_REGEXP)
# we build a regexp to match anything that looks like
# this: ^\s*ATTRIBUTE: Some entry of some kind...$
self.mmf = mmf
attrmatch="^\s*("
for k in self.mmf.recattrs.keys():
attrmatch += "%s|"%re.escape(k)
attrmatch="%s):\s*(.*)\s*$"%attrmatch[0:-1]
self.attr_matcher = re.compile(attrmatch)
testtimer.end()
示例7: add_amt
def add_amt (self, amount):
timeaction = TimeAction('importer.add_amt',10)
"""We should NEVER get non-numeric amounts.
Amounts must contain [/.0-9 ] e.g. 1.2 or 1 1/5
or 1/3 etc."""
#gt.gtk_update()
self.ing['amount'],self.ing['rangeamount']=parse_range(amount)
timeaction.end()
示例8: add_item
def add_item (self, item):
testtimer = TimeAction('mealmaster_importer.add_item',10)
self.ing['item']=item.strip()
# fixing bug 1061363, potatoes; cut and mashed should become just potatoes
# for keying purposes
key_base = self.ing['item'].split(";")[0]
self.ing['ingkey']=self.km.get_key_fast(key_base)
testtimer.end()
示例9: field_width
def field_width (tuple):
testtimer = TimeAction('mealmaster_importer.field_width',10)
debug("start field_width",10)
if tuple[1]:
testtimer.end()
return tuple[1]-tuple[0]
else:
testtimer.end()
return None
示例10: get_fields
def get_fields (string, tuples):
testtimer = TimeAction('mealmaster_importer.get_fields',10)
debug("start get_fields",10)
lst = []
for t in tuples:
if t:
lst.append(string[t[0]:t[1]])
else:
lst.append("")
testtimer.end()
return lst
示例11: start_ing
def start_ing (self, **kwargs):
timeaction = TimeAction('importer.start_ing',10)
#gt.gtk_update()
self.ing=kwargs
#if self.ing.has_key('id'):
# self.ing['recipe_id']=self.ing['id']
# del self.ing['id']
# print 'WARNING: setting ingredients ID is deprecated. Assuming you mean to set recipe_id'
#elif self.rec.has_key('id'):
# self.ing['recipe_id']=self.rec['id']
#debug('ing ID %s, recipe ID %s'%(self.ing['recipe_id'],self.rec['id']),0)
timeaction.end()
示例12: check_for_sleep
def check_for_sleep (self):
timeaction = TimeAction('importer.check_for_sleep',10)
#gt.gtk_update()
if self.terminated:
raise Terminated("Importer Terminated!")
while self.suspended:
#gt.gtk_update()
if self.terminated:
raise Terminated("Importer Terminated!")
else:
time.sleep(1)
timeaction.end()
示例13: __init__
def __init__(self):
# hooks run after adding, modifying or deleting a recipe.
# Each hook is handed the recipe, except for delete_hooks,
# which is handed the ID (since the recipe has been deleted)
self.add_hooks = []
self.modify_hooks = []
self.delete_hooks = []
self.add_ing_hooks = []
timer = TimeAction("initialize_connection + setup_tables", 2)
self.initialize_connection()
self.setup_tables()
timer.end()
示例14: field_match
def field_match (strings, tup, matcher):
testtimer = TimeAction('mealmaster_importer.field_match',10)
debug("start field_match",10)
if type(matcher)==type(""):
matcher=re.compile(matcher)
for f in [s[tup[0]:tup[1]] for s in strings]:
#f=s[tup[0]:tup[1]]
if f and not matcher.match(f):
testtimer.end()
return False
testtimer.end()
return True
示例15: handle_group
def handle_group (self, groupm):
"""Start a new ingredient group."""
testtimer = TimeAction('mealmaster_importer.handle_group',10)
debug("start handle_group",10)
# the only group of the match will contain
# the name of the group. We'll put it into
# a more sane title case (MealMaster defaults
# to all caps
name = groupm.groups()[1].title()
self.group=name
if re.match('^[^A-Za-z]*$',self.group): self.group=None
testtimer.end()