예제 #1
0
 def Report(self, subcount_created=0, subcount_updated=0):
     str_tips = []
     self.counts.created.completed.subcount = subcount_created
     self.counts.updated.completed.subcount = subcount_updated
     str_tips += self.ReportSingle('were newly created',
                                   self.counts.created,
                                   self.info.str_value('created'))
     str_tips += self.ReportSingle('already exist and were updated',
                                   self.counts.updated,
                                   self.info.str_value('updated'))
     str_tips += self.ReportSingle('already exist but were unchanged',
                                   self.counts.skipped,
                                   process_subcounts=False)
     if self.counts.error:
         str_tips.append("%d Error(s) occurred " % self.counts.error.val)
     if self.status == EvernoteAPIStatus.ExceededLocalLimit:
         str_tips.append(
             "Action was prematurely terminated because locally-defined limit of %d was exceeded."
             % self.counts.max_allowed)
     report_title = "   > %s Complete" % self.info.Action
     if self.counts.total is 0:
         report_title += self.info.FormatLine(": No {r} were processed")
     show_report(report_title,
                 self.ReportHeader,
                 str_tips,
                 blank_line_before=False,
                 do_print=self.__do_print)
     log_blank('counters')
     log(self.counts.fullSummary(self.name + ': End'), 'counters')
예제 #2
0
파일: db.py 프로젝트: holycrepe/anknotes
 def scalar(self, sql='1', *a, **kw):
     log_text = 'Call to DB.ankdb_scalar():'
     if not isinstance(self, ank_DB):
         log_text += '\n   - Self:       ' + pf(self)
     if a:
         log_text += '\n   - Args:       ' + pf(a)
     if kw:
         log_text += '\n   - KWArgs:     ' + pf(kw)
     last_query='<None>'
     if hasattr(self, 'ankdb_lastquery'):
         last_query = self.ankdb_lastquery
         if is_str(last_query):
             last_query = last_query[:50]
         else:
             last_query = pf(last_query)
         log_text += '\n   - Last Query: ' + last_query
     log(log_text + '\n', 'sql\\ankdb_scalar')
     try:
         res = self.execute(sql, a, kw)
     except TypeError as e:
         log(" > ERROR with ankdb_scalar while executing query: %s\n >  LAST QUERY: %s" % (str(e), last_query), 'sql\\ankdb_scalar', crosspost='sql\\ankdb_scalar-error')
         raise
     if not isinstance(res, sqlite.Cursor):
         log(' > Cursor: %s' % pf(res), 'sql\\ankdb_scalar')
     try:
         res = res.fetchone()
     except TypeError as e:
         log(" > ERROR with ankdb_scalar while fetching result: %s\n >  LAST QUERY: %s" % (str(e), last_query), 'sql\\ankdb_scalar', crosspost='sql\\ankdb_scalar-error')
         raise
     log_blank('sql\\ankdb_scalar')
     if res:
         return res[0]
     return None
예제 #3
0
 def __init__(self, max=None, interval=100, info=None, infoStr=None, automated=None, begin=True,
              label=None, display_initial_info=None, max_allowed=None, do_print=False, **kw):
     """
     :type info : ActionInfo
     """
     args = DictCaseInsensitive(kw, locals(), delete='kw infoStr info max self')
     simple_label = False
     self.counts = EvernoteCounter()
     self.__interval = interval
     self.__reported_progress = False
     if not isinstance(max, int):
         if hasattr(max, '__len__'):
             max = len(max)
         else:
             max = None
     self.counts.max = -1
     if max is not None:
         self.counts.max = max
         args.max = self.counts.max
     if is_str(info):
         # noinspection PyTypeChecker
         info = ActionInfo(info, **args)
     elif infoStr and not info:
         info = ActionInfo(infoStr, **args)
     elif label and not info:
         simple_label = True
         if display_initial_info is None:
             display_initial_info = False
         info = ActionInfo(label, **args)
     elif label:
         info.Label = label
     if self.counts.max > 0 and info and (info.Max is None or info.Max < 1):
         info.Max = max
     self.counts.max_allowed = self.counts.max if max_allowed is None else max_allowed
     self.__did_break = True
     self.__do_print = do_print
     self.__info = info
     self.__action_initialized = False
     self.__action_attempted = self.hasActionInfo and (display_initial_info is not False)
     if self.__action_attempted:
         if self.info is None:
             log("Unexpected; Timer '%s' has no ActionInfo instance" % label, do_print=True)
         else:
             self.__action_initialized = self.info.displayInitialInfo(**args) is EvernoteAPIStatus.Initialized
     if begin:
         self.reset(False)
     log_blank(filename='counters')
     log(self.counts.fullSummary(self.name + ': Start'), 'counters')
예제 #4
0
 def Report(self, subcount_created=0, subcount_updated=0):
     str_tips = []
     self.counts.created.completed.subcount = subcount_created
     self.counts.updated.completed.subcount = subcount_updated
     str_tips += self.ReportSingle('were newly created', self.counts.created, self.info.str_value('created'))
     str_tips += self.ReportSingle('already exist and were updated', self.counts.updated, self.info.str_value('updated'))
     str_tips += self.ReportSingle('already exist but were unchanged', self.counts.skipped, process_subcounts=False)
     if self.counts.error:
         str_tips.append("%d Error(s) occurred " % self.counts.error.val)
     if self.status == EvernoteAPIStatus.ExceededLocalLimit:
         str_tips.append("Action was prematurely terminated because locally-defined limit of %d was exceeded." %
                         self.counts.max_allowed)
     report_title = "   > %s Complete" % self.info.Action
     if self.counts.total is 0:
         report_title += self.info.FormatLine(": No {r} were processed")
     show_report(report_title, self.ReportHeader, str_tips, blank_line_before=False, do_print=self.__do_print)
     log_blank('counters')
     log(self.counts.fullSummary(self.name + ': End'), 'counters')
예제 #5
0
 def __init__(self,
              max=None,
              interval=100,
              info=None,
              infoStr=None,
              automated=None,
              begin=True,
              label=None,
              display_initial_info=None,
              max_allowed=None,
              do_print=False,
              **kw):
     """
     :type info : ActionInfo
     """
     args = DictCaseInsensitive(kw,
                                locals(),
                                delete='kw infoStr info max self')
     simple_label = False
     self.counts = EvernoteCounter()
     self.__interval = interval
     self.__reported_progress = False
     if not isinstance(max, int):
         if hasattr(max, '__len__'):
             max = len(max)
         else:
             max = None
     self.counts.max = -1
     if max is not None:
         self.counts.max = max
         args.max = self.counts.max
     if is_str(info):
         # noinspection PyTypeChecker
         info = ActionInfo(info, **args)
     elif infoStr and not info:
         info = ActionInfo(infoStr, **args)
     elif label and not info:
         simple_label = True
         if display_initial_info is None:
             display_initial_info = False
         info = ActionInfo(label, **args)
     elif label:
         info.Label = label
     if self.counts.max > 0 and info and (info.Max is None or info.Max < 1):
         info.Max = max
     self.counts.max_allowed = self.counts.max if max_allowed is None else max_allowed
     self.__did_break = True
     self.__do_print = do_print
     self.__info = info
     self.__action_initialized = False
     self.__action_attempted = self.hasActionInfo and (display_initial_info
                                                       is not False)
     if self.__action_attempted:
         if self.info is None:
             log("Unexpected; Timer '%s' has no ActionInfo instance" %
                 label,
                 do_print=True)
         else:
             self.__action_initialized = self.info.displayInitialInfo(
                 **args) is EvernoteAPIStatus.Initialized
     if begin:
         self.reset(False)
     log_blank(filename='counters')
     log(self.counts.fullSummary(self.name + ': Start'), 'counters')