Esempio n. 1
0
    def __select_from(self, message, items):
        for l in message:
            uprint(l)
        count = len(message)
        
        while True:
            for i, v in enumerate(items):
                uprint("[{0}] {1}".format(i, v))
            count += len(items)

            result = input()
            count += 1
            
            try:
                result = int(result)
                if result >= 0 and result <= i:
                    result = items[result]
                    break
            except:
                pass

            uprint("Incorrect input!")
            count += 1

        console.cleanLastRows(count)
        return result
Esempio n. 2
0
    def __select_from(self, message, items):
        for l in message:
            uprint(l)
        count = len(message)

        while True:
            for i, v in enumerate(items):
                uprint("[{0}] {1}".format(i, v))
            count += len(items)

            result = input()
            count += 1

            try:
                result = int(result)
                if result >= 0 and result <= i:
                    result = items[result]
                    break
            except:
                pass

            uprint("Incorrect input!")
            count += 1

        console.cleanLastRows(count)
        return result
Esempio n. 3
0
    def _select_org_task(self, unmapped_task, tasklist):
        uprint("\"{0}\" has no exact mapping in your local org-tree.".format(
            unmapped_task.title))
        uprint("Please manually choose the wanted item:")
        count = 2

        items = [[
            i, v,
            difflib.SequenceMatcher(a=unmapped_task.title, b=v.title).ratio()
        ] for i, v in enumerate(tasklist)]
        items.sort(key=lambda v: v[2], reverse=True)
        items_count = len(items)
        items_count_for_showing = 10

        while True:
            for i in range(min(items_count, items_count_for_showing)):
                uprint("[{0}] {1}".format(i, items[i][1].title))
                count += 1

            if items_count > items_count_for_showing:
                uprint("[m] ...")
                count += 1

            uprint("[n] -- create new")
            uprint("[d] -- discard new")
            count += 2

            result = input()
            count += 1

            try:
                if result == 'm':
                    items_count_for_showing = items_count
                    continue
                elif result == 'n':
                    result = 'new'
                    break
                elif result == 'd':
                    result = 'discard'
                    break

                result = int(result)
                if result >= 0 and result <= items_count:
                    result = items[result][0]
                    break
            except:
                pass

            uprint("Incorrect input!")
            count += 1

        console.cleanLastRows(count)
        return result
Esempio n. 4
0
    def __select_org_task(self, unmapped_task, tasklist):        
        uprint("\"{0}\" has not exact mapping in your local org-tree.".format(unmapped_task.title))
        uprint("Please manualy choose necessary item:")
        count = 2

        items = [[i, v, difflib.SequenceMatcher(a=unmapped_task.title, b=v.title).ratio()]
                 for i, v in enumerate(tasklist)]
        items.sort(key=lambda v: v[2], reverse=True)
        items_count = len(items)
        items_count_for_showing = 10
        
        while True:
            for i in range(min(items_count, items_count_for_showing)):
                uprint("[{0}] {1}".format(i, items[i][1].title))
                count += 1 
                
            if items_count > items_count_for_showing:
                uprint("[m] ...")
                count += 1
            
            uprint("[n] -- create new")
            uprint("[d] -- discard new")
            count += 2

            result = input()
            count += 1
            
            try:
                if result == 'm':
                    items_count_for_showing = items_count
                    continue
                elif result == 'n':
                    result = 'new'
                    break
                elif result == 'd':
                    result = 'discard'
                    break

                result = int(result)
                if result >= 0 and result <= items_count:
                    result = items[result][0]
                    break
            except:
                pass

            uprint("Incorrect input!")
            count += 1

        console.cleanLastRows(count)
        return result
Esempio n. 5
0
    def __merge_notes(self, mapping):
        detected_change = self.__extract_from_base(mapping, 'notes')
        if detected_change is not None:
            return detected_change
        
        uprint("Task \"{0}\" has different values for attribute \"notes\"".format(mapping.org.title))
        uprint("Please manualy choose necessary:")
        count = 2

        items = [mapping.org.notes, mapping.remote.notes]
        while True:
            for i, v in enumerate(items):
                uprint("[{0}] Use this block:".format(i))
                count += 1
                
                for line in v:
                    uprint(line)
                    count += 1
                    
                uprint("-------------------------------------")
                count += 1
        
            uprint("[e] Edit in external editor")
            count += 1
            
            result = input()
            count += 1
            
            try:
                if result == 'e':
                    result = None
                    break
                
                result = int(result)
                if result >= 0 and result <= i:
                    result = items[result]
                    break
            except:
                pass

            uprint("Incorrect input!")
            count += 1

        console.cleanLastRows(count)
        if result is not None:
            return result

        # External editor
        temp_fid, temp_name = tempfile.mkstemp()
        try:
            with codecs.open(temp_name, "w", encoding="utf-8") as temp_file:
                for item in items:
                    for line in item:
                        temp_file.write(line)
                        temp_file.write('\n')
                    
            subprocess.call('vim -n {0}'.format(temp_name), shell=True)
            
            with codecs.open(temp_name, "r", encoding="utf-8") as temp_file:
                result = [x.strip() for x in temp_file.readlines()]
            
        except Exception as e:
            uprint(e)
            
        os.close(temp_fid)
        os.remove(temp_name)
        return result
Esempio n. 6
0
    def _merge_notes(self, mapping):
        uprint(
            "Task \"{0}\" has different values for attribute \"notes\"".format(
                mapping.org.title))
        uprint("Please manualy choose necessary:")
        count = 2

        items = [mapping.org.notes, mapping.remote.notes]
        while True:
            for i, v in enumerate(items):
                uprint("[{0}] Use this block:".format(i))
                count += 1

                for line in v:
                    uprint(line)
                    count += 1

                uprint("-------------------------------------")
                count += 1

            uprint("[e] Edit in external editor")
            count += 1

            result = input()
            count += 1

            try:
                if result == 'e':
                    result = None
                    break

                result = int(result)
                if result >= 0 and result <= i:
                    result = items[result]
                    break
            except:
                pass

            uprint("Incorrect input!")
            count += 1

        console.cleanLastRows(count)
        if result is not None:
            return result

        # External editor
        temp_fid, temp_name = tempfile.mkstemp()
        try:
            with codecs.open(temp_name, "w", encoding="utf-8") as temp_file:
                for item in items:
                    for line in item:
                        temp_file.write(line)
                        temp_file.write('\n')

            subprocess.call('vim -n {0}'.format(temp_name), shell=True)

            with codecs.open(temp_name, "r", encoding="utf-8") as temp_file:
                result = [x.strip() for x in temp_file.readlines()]

        except Exception as e:
            uprint(e)

        os.close(temp_fid)
        os.remove(temp_name)
        return result