Example #1
0
def eventLoop():
    """Main event loop"""
    delta = timedelta(hours=float(getConfigKey("ALARM_DELAY")))
    suspend = timedelta(hours=float(getConfigKey("ALARM_SUSPEND")))
    cmdDelayTemplate = getConfigKey("ALARM_DELAY_CMD")
    cmdDueTemplate = getConfigKey("ALARM_DUE_CMD")
    session = db.getSession()
    # For the two following dict, task id is key, and value is (duedate, triggerdate)
    triggeredDelayTasks = {}
    triggeredDueTasks = {}
    activeTaskFilter = [
        Task.status != "done", Task.projectId == Project.id,
        Project.active == True
    ]
    while event[0]:
        now = datetime.today().replace(microsecond=0)
        delayTasks = session.query(Task).filter(Task.dueDate < now + delta,
                                                Task.dueDate > now,
                                                *activeTaskFilter)
        dueTasks = session.query(Task).filter(Task.dueDate < now,
                                              *activeTaskFilter)
        processTasks(delayTasks, triggeredDelayTasks, cmdDelayTemplate,
                     suspend)
        processTasks(dueTasks, triggeredDueTasks, cmdDueTemplate, suspend)
        time.sleep(DELAY)
Example #2
0
def eventLoop():
    """Main event loop"""
    delta = timedelta(hours=float(getConfigKey("ALARM_DELAY")))
    suspend = timedelta(hours=float(getConfigKey("ALARM_SUSPEND")))
    cmdDelayTemplate = getConfigKey("ALARM_DELAY_CMD")
    cmdDueTemplate = getConfigKey("ALARM_DUE_CMD")
    session = db.getSession()
    # For the two following dict, task id is key, and value is (duedate, triggerdate)
    triggeredDelayTasks = {}
    triggeredDueTasks = {}
    activeTaskFilter = [Task.status != "done",
                        Task.projectId == Project.id,
                        Project.active == True]  # noqa

    def process(now):
        delayTasks = session.query(Task).filter(Task.dueDate < now + delta,
                                                Task.dueDate > now,
                                                *activeTaskFilter)
        dueTasks = session.query(Task).filter(Task.dueDate < now,
                                              *activeTaskFilter)
        processTasks(delayTasks, triggeredDelayTasks, cmdDelayTemplate, suspend)
        processTasks(dueTasks, triggeredDueTasks, cmdDueTemplate, suspend)

    nextProcessTime = datetime.today().replace(microsecond=0)
    while event[0]:
        now = datetime.today().replace(microsecond=0)
        if now > nextProcessTime:
            process(now)
            nextProcessTime = now + timedelta(seconds=PROCESS_INTERVAL)
        time.sleep(EVENTLOOP_INTERVAL)
Example #3
0
 def __init__(self):
     try:
         self.aliases = eval(db.getConfigKey("ALIASES", environ=False))
     except NoResultFound:
         self.aliases = {}
     except Exception:
         tui.error("Aliases syntax error. Ignored")
         self.aliases = {}
Example #4
0
 def parser_t_purge(self):
     parser = YokadiOptionParser()
     parser.usage = "t_purge [options]"
     parser.description = "Remove old done tasks from all projects."
     parser.add_argument("-f", "--force", dest="force", default=False, action="store_true",
                       help="Skip confirmation prompt")
     delay = int(db.getConfigKey("PURGE_DELAY", environ=False))
     parser.add_argument("-d", "--delay", dest="delay", default=delay,
                       type=int, help="Delay (in days) after which done tasks are destroyed. Default is %d." % delay)
     return parser
Example #5
0
 def __init__(self):
     # Cache encryption passphrase
     self.passphrase = None
     # Force decryption (and ask passphrase) instead of decrypting only when passphrase was
     # previously provided
     self.force_decrypt = False
     try:
         self.crypto_check = db.getConfigKey("CRYPTO_CHECK", environ=False)
     except NoResultFound:
         # Ok, set it to None. It will be setup after user defined passphrase
         self.crypto_check = None
Example #6
0
 def __init__(self):
     # Cache encryption passphrase
     self.passphrase = None
     # Force decryption (and ask passphrase) instead of decrypting only when passphrase was
     # previously provided
     self.force_decrypt = False
     try:
         self.crypto_check = db.getConfigKey("CRYPTO_CHECK", environ=False)
     except NoResultFound:
         # Ok, set it to None. It will be setup after user defined passphrase
         self.crypto_check = None
Example #7
0
def eventLoop():
    """Main event loop"""
    delta = timedelta(hours=float(getConfigKey("ALARM_DELAY")))
    suspend = timedelta(hours=float(getConfigKey("ALARM_SUSPEND")))
    cmdDelayTemplate = getConfigKey("ALARM_DELAY_CMD")
    cmdDueTemplate = getConfigKey("ALARM_DUE_CMD")
    # For the two following dict, task id is key, and value is (duedate, triggerdate)
    triggeredDelayTasks = {}
    triggeredDueTasks = {}
    activeTaskFilter = [Task.q.status != "done",
                      Task.q.projectID == Project.q.id,
                      Project.q.active == True]
    while event[0]:
        now = datetime.today().replace(microsecond=0)
        delayTasks = Task.select(AND(Task.q.dueDate < now + delta,
                                   Task.q.dueDate > now,
                                   *activeTaskFilter))
        dueTasks = Task.select(AND(Task.q.dueDate < now,
                                 *activeTaskFilter))
        processTasks(delayTasks, triggeredDelayTasks, cmdDelayTemplate, suspend)
        processTasks(dueTasks, triggeredDueTasks, cmdDueTemplate, suspend)
        time.sleep(DELAY)
Example #8
0
 def askPassphrase(self):
     """Ask user for passphrase if needed"""
     cache = bool(int(db.getConfigKey("PASSPHRASE_CACHE", environ=False)))
     if self.passphrase and cache:
         return
     self.passphrase = tui.editLine("", prompt="passphrase> ", echo=False)
     self.passphrase = adjustString(self.passphrase, KEY_LENGTH)
     if not self.isPassphraseValid() and cache:
         self.passphrase = None
         self.force_decrypt = False  # As passphrase is invalid, don't force decrypt for next time
         raise YokadiException("Passphrase differ from previous one."
                     "If you really want to change passphrase, "
                     "you should blank the  CRYPTO_CHECK parameter "
                     "with c_set CRYPTO_CHECK '' "
                     "Note that you won't be able to retrieve previous tasks you "
                     "encrypted with your lost passphrase")
     else:
         # Now that passphrase is valid, we will always decrypt encrypted data
         self.force_decrypt = True
Example #9
0
 def askPassphrase(self):
     """Ask user for passphrase if needed"""
     cache = bool(int(db.getConfigKey("PASSPHRASE_CACHE", environ=False)))
     if self.passphrase and cache:
         return
     self.passphrase = tui.editLine("", prompt="passphrase> ", echo=False)
     self.passphrase = adjustString(self.passphrase, KEY_LENGTH)
     if not self.isPassphraseValid() and cache:
         self.passphrase = None
         self.force_decrypt = False  # As passphrase is invalid, don't force decrypt for next time
         raise YokadiException(
             "Passphrase differ from previous one."
             "If you really want to change passphrase, "
             "you should blank the  CRYPTO_CHECK parameter "
             "with c_set CRYPTO_CHECK '' "
             "Note that you won't be able to retrieve previous tasks you "
             "encrypted with your lost passphrase")
     else:
         # Now that passphrase is valid, we will always decrypt encrypted data
         self.force_decrypt = True
Example #10
0
 def parser_t_purge(self):
     parser = YokadiOptionParser()
     parser.usage = "t_purge [options]"
     parser.description = "Remove old done tasks from all projects."
     parser.add_argument("-f",
                         "--force",
                         dest="force",
                         default=False,
                         action="store_true",
                         help="Skip confirmation prompt")
     delay = int(db.getConfigKey("PURGE_DELAY", environ=False))
     parser.add_argument(
         "-d",
         "--delay",
         dest="delay",
         default=delay,
         type=int,
         help=
         "Delay (in days) after which done tasks are destroyed. Default is %d."
         % delay)
     return parser