Example #1
0
    def do_p_edit(self, line):
        """Edit a project.
        p_edit <project name>"""
        session = db.getSession()
        project = dbutils.getOrCreateProject(line, createIfNeeded=False)

        if not project:
            raise YokadiException("Project does not exist.")

        # Create project line
        projectLine = parseutils.createLine(project.name, "", project.getKeywordDict())

        # Edit
        line = tui.editLine(projectLine)

        # Update project
        projectName, garbage, keywordDict = parseutils.parseLine(line)
        if garbage:
            raise BadUsageException("Cannot parse line, got garbage (%s)" % garbage)
        if not dbutils.createMissingKeywords(list(keywordDict.keys())):
            return
        try:
            project.name = projectName
            project.setKeywordDict(keywordDict)
            session.merge(project)
            session.commit()
        except IntegrityError:
            session.rollback()
            raise YokadiException("A project named %s already exists. Please find another name" % projectName)
Example #2
0
    def do_p_edit(self, line):
        """Edit a project.
        p_edit <project name>"""
        project = dbutils.getOrCreateProject(line, createIfNeeded=False)

        if not project:
            raise YokadiException("Project does not exist.")

        # Create project line
        projectLine = parseutils.createLine(project.name, "",
                                            project.getKeywordDict())

        # Edit
        line = tui.editLine(projectLine)

        # Update project
        projectName, garbage, keywordDict = parseutils.parseLine(line)
        if garbage:
            raise BadUsageException("Cannot parse line, got garbage (%s)" %
                                    garbage)
        if not dbutils.createMissingKeywords(keywordDict.keys()):
            return
        try:
            project.name = projectName
        except DuplicateEntryError:
            raise YokadiException(
                "A project named %s already exists. Please find another name" %
                projectName)
        project.setKeywordDict(keywordDict)
Example #3
0
 def testCreateLine(self):
     for dummy, parsedStruct in gTaskLineToParsedStructList:
         # We do not check the result of createLine() against the
         # original task line because there are many ways to write the same
         # taskLine.
         taskLine = parseutils.createLine(*parsedStruct)
         result = parseutils.parseLine(taskLine)
         self.assertEqual(result, parsedStruct)
Example #4
0
 def testCreateLine(self):
     for dummy, parsedStruct in gTaskLineToParsedStructList:
         # We do not check the result of createLine() against the
         # original task line because there are many ways to write the same
         # taskLine.
         taskLine = parseutils.createLine(*parsedStruct)
         result = parseutils.parseLine(taskLine)
         self.assertEqual(result, parsedStruct)
Example #5
0
    def _t_edit(self, line):
        """Code shared by t_edit and bug_edit."""
        def editComplete(text, state):
            """ Specific completer for the edit prompt.
            This subfunction should stay here because it needs to access to cmd members"""
            if state == 0:
                origline = readline.get_line_buffer()
                line = origline.lstrip()
                stripped = len(origline) - len(line)
                begidx = readline.get_begidx() - stripped
                endidx = readline.get_endidx() - stripped
                if begidx > 0:
                    self.completion_matches = projectAndKeywordCompleter(
                        "", text, line, begidx, endidx, shift=1)
                else:
                    self.completion_matches = []
            try:
                return self.completion_matches[state]
            except IndexError:
                return None

        task = self.getTaskFromId(line)

        if self.cryptoMgr.isEncrypted(task.title):
            self.cryptoMgr.force_decrypt = True  # Decryption must be turned on to edit
        title = self.cryptoMgr.decrypt(task.title)

        # Create task line
        taskLine = parseutils.createLine("", title, task.getKeywordDict())

        oldCompleter = readline.get_completer(
        )  # Backup previous completer to restore it in the end
        readline.set_completer(editComplete)  # Switch to specific completer

        while True:
            # Edit
            print "(Press Ctrl+C to cancel)"
            try:
                line = tui.editLine(taskLine)
                if not line.strip():
                    tui.warning("Missing title")
                    continue
            except KeyboardInterrupt:
                print
                print "Cancelled"
                task = None
                break
            foo, title, keywordDict = parseutils.parseLine(task.project.name +
                                                           " " + line)
            if self.cryptoMgr.isEncrypted(task.title):
                title = self.cryptoMgr.encrypt(title)
            if dbutils.updateTask(task, task.project.name, title, keywordDict):
                break

        readline.set_completer(oldCompleter)  # Restore standard completer
        return task
Example #6
0
    def _t_edit(self, line):
        """Code shared by t_edit and bug_edit."""
        def editComplete(text, state):
            """ Specific completer for the edit prompt.
            This subfunction should stay here because it needs to access to cmd members"""
            if state == 0:
                origline = readline.get_line_buffer()
                line = origline.lstrip()
                stripped = len(origline) - len(line)
                begidx = readline.get_begidx() - stripped
                endidx = readline.get_endidx() - stripped
                if begidx > 0:
                    self.completion_matches = projectAndKeywordCompleter("", text, line, begidx, endidx, shift=1)
                else:
                    self.completion_matches = []
            try:
                return self.completion_matches[state]
            except IndexError:
                return None

        task = self.getTaskFromId(line)

        if self.cryptoMgr.isEncrypted(task.title):
            self.cryptoMgr.force_decrypt = True  # Decryption must be turned on to edit
        title = self.cryptoMgr.decrypt(task.title)

        # Create task line
        taskLine = parseutils.createLine("", title, task.getKeywordDict())

        oldCompleter = readline.get_completer()  # Backup previous completer to restore it in the end
        readline.set_completer(editComplete)  # Switch to specific completer

        while True:
            # Edit
            print("(Press Ctrl+C to cancel)")
            try:
                line = tui.editLine(taskLine)
                if not line.strip():
                    tui.warning("Missing title")
                    continue
            except KeyboardInterrupt:
                print()
                print("Cancelled")
                task = None
                break
            foo, title, keywordDict = parseutils.parseLine(task.project.name + " " + line)
            if self.cryptoMgr.isEncrypted(task.title):
                title = self.cryptoMgr.encrypt(title)
            if dbutils.updateTask(task, task.project.name, title, keywordDict):
                break

        readline.set_completer(oldCompleter)  # Restore standard completer
        self.session.merge(task)
        return task
Example #7
0
 def formatLine(entry):
     status = entry.status[0].upper()
     line = parseutils.createLine(None, entry.title, entry.keywords)
     return "%d %s %s" % (entry.id, status, line)
Example #8
0
    def _t_edit(self, line, keywordEditor=None):
        """Code shared by t_edit and bug_edit.
        if keywordEditor is not None it will be called after editing the task.
        Returns the modified task if OK, None if cancelled"""
        def editComplete(text, state):
            """ Specific completer for the edit prompt.
            This subfunction should stay here because it needs to access to cmd members"""
            if state == 0:
                origline = readline.get_line_buffer()
                line = origline.lstrip()
                stripped = len(origline) - len(line)
                begidx = readline.get_begidx() - stripped
                endidx = readline.get_endidx() - stripped
                if begidx > 0:
                    self.completion_matches = projectAndKeywordCompleter(
                        "", text, line, begidx, endidx, shift=1)
                else:
                    self.completion_matches = []
            try:
                return self.completion_matches[state]
            except IndexError:
                return None

        task = self.getTaskFromId(line)

        if self.cryptoMgr.isEncrypted(task.title):
            self.cryptoMgr.force_decrypt = True  # Decryption must be turned on to edit
        title = self.cryptoMgr.decrypt(task.title)

        # Create task line
        keywordDict = task.getKeywordDict()
        userKeywordDict, keywordDict = dbutils.splitKeywordDict(keywordDict)
        taskLine = parseutils.createLine("", title, userKeywordDict)

        oldCompleter = readline.get_completer(
        )  # Backup previous completer to restore it in the end
        readline.set_completer(editComplete)  # Switch to specific completer

        # Edit
        try:
            while True:
                print("(Press Ctrl+C to cancel)")
                try:
                    line = tui.editLine(taskLine)
                    if not line.strip():
                        tui.warning("Missing title")
                        continue
                except KeyboardInterrupt:
                    print()
                    print("Cancelled")
                    return None
                _, title, userKeywordDict = parseutils.parseLine(
                    task.project.name + " " + line)
                if self.cryptoMgr.isEncrypted(task.title):
                    title = self.cryptoMgr.encrypt(title)

                if dbutils.createMissingKeywords(userKeywordDict.keys()):
                    # We were able to create missing keywords if there were any,
                    # we can now exit the edit loop
                    break
        finally:
            readline.set_completer(oldCompleter)

        keywordDict.update(userKeywordDict)
        if keywordEditor:
            keywordEditor(keywordDict)

        task.title = title
        task.setKeywordDict(keywordDict)
        return task
Example #9
0
    def _t_edit(self, line, keywordEditor=None):
        """Code shared by t_edit and bug_edit.
        if keywordEditor is not None it will be called after editing the task.
        Returns the modified task if OK, None if cancelled"""
        def editComplete(text, state):
            """ Specific completer for the edit prompt.
            This subfunction should stay here because it needs to access to cmd members"""
            if state == 0:
                origline = readline.get_line_buffer()
                line = origline.lstrip()
                stripped = len(origline) - len(line)
                begidx = readline.get_begidx() - stripped
                endidx = readline.get_endidx() - stripped
                if begidx > 0:
                    self.completion_matches = projectAndKeywordCompleter("", text, line, begidx, endidx, shift=1)
                else:
                    self.completion_matches = []
            try:
                return self.completion_matches[state]
            except IndexError:
                return None

        task = self.getTaskFromId(line)

        # Create task line
        keywordDict = task.getKeywordDict()
        userKeywordDict, keywordDict = dbutils.splitKeywordDict(keywordDict)
        taskLine = parseutils.createLine("", task.title, userKeywordDict)

        oldCompleter = readline.get_completer()  # Backup previous completer to restore it in the end
        readline.set_completer(editComplete)  # Switch to specific completer

        # Edit
        try:
            while True:
                print("(Press Ctrl+C to cancel)")
                try:
                    line = tui.editLine(taskLine)
                    if not line.strip():
                        tui.warning("Missing title")
                        continue
                except KeyboardInterrupt:
                    print()
                    print("Cancelled")
                    return None
                _, title, userKeywordDict = parseutils.parseLine(task.project.name + " " + line)

                if dbutils.createMissingKeywords(userKeywordDict.keys()):
                    # We were able to create missing keywords if there were any,
                    # we can now exit the edit loop
                    break
        finally:
            readline.set_completer(oldCompleter)

        keywordDict.update(userKeywordDict)
        if keywordEditor:
            keywordEditor(keywordDict)

        task.title = title
        task.setKeywordDict(keywordDict)
        return task
Example #10
0
 def formatLine(entry):
     status = entry.status[0].upper()
     line = parseutils.createLine(None, entry.title, entry.keywords)
     return "%d %s %s" % (entry.id, status, line)