예제 #1
0
    def return_ordered_from_db(self, name):

        self.db_cursor.execute(
            "SELECT value FROM sequence_values " +
            " WHERE notebook=? AND name=?", (self.notebookname, name))
        fetched = self.db_cursor.fetchall()
        values = [deconvert(x[0]) for x in fetched]

        if self.get_type_db(name) == "<class 'datetime.date'>":

            values = [is_date(x) for x in values]

        if values:

            if name not in self.temp_sequences:

                self.temp_sequences['###type###'][name] = self.get_type_db(
                    name)
                self.temp_sequences[name] = OrderedList(values)

                return self.temp_sequences[name]
            if not self.temp_sequences[name]:
                self.temp_sequences[name] = OrderedList()
            return self.temp_sequences[name]

        return OrderedList()
예제 #2
0
    def reset_indexes(self, indexes=None, project=None, db_only=False):

        if not project:
            project = self.current
        if not db_only and not self.db_only:
            if not indexes:
                self.projects[project]['indexes'] = OrderedList()
            elif isinstance(indexes, list):
                self.projects[project]['indexes'] = OrderedList(
                    sorted(indexes, key=lambda x_temp: Index(x_temp)))
        if self.using_database:
            self.delete_all_indexes_DB(project=project)
            for temp_index in sorted(indexes,
                                     key=lambda x_temp: Index(x_temp)):
                self.add_index_DB(project=project, index=temp_index)
예제 #3
0
    def get_project(self, project=None):

        if not project:
            project = self.current

        if self.using_database:

            temp_keys = self.get_keys_DB(project=project)
            temp_indexes = sorted(self.get_indexes_DB(project=project),
                                  key=lambda x_temp: Index(x_temp))
            temp_dates = sorted(self.get_dates_DB(project=project))
            temp_simple = self.get_simple_DB(project=project)

            lastup, uptohere, mainterm, series_enter, opened = temp_simple[
                0], temp_simple[1], temp_simple[2], temp_simple[
                    3], temp_simple[4]

            temp_dict = {}
            temp_dict['defaultkeys'] = temp_keys
            temp_dict['position'] = (lastup, uptohere)
            temp_dict['going'] = (mainterm, series_enter)
            temp_dict['date'] = temp_dates
            temp_dict['indexes'] = OrderedList(temp_indexes)
            temp_dict['status'] = {
                'started': temp_dates[0],
                'open': opened,
                'lastmodified': temp_dates
            }
            return temp_dict

        if project in self.projects:
            return self.projects[project]
예제 #4
0
class TimeLine:
    def __init__(self):

        self.dates = OrderedList()
        self.index_to_dates = {}
        self.dates_to_index = {}
        self.index_to_event = {}

    def add_event(self, date, event, index):

        newdate = TimeLineDateTime(date)
        if newdate.exists:
            self.dates.add(newdate)
        self.index_to_dates[index] = date
        self.dates_to_index[date] = index
        self.index_to_event[index] = event
예제 #5
0
    def clear_indexes(self, project=None, db_only=False):

        if not project:
            project = self.current
        if not db_only and not self.db_only:
            self.projects[project]['indexes'] = OrderedList()

        if self.using_database:

            self.delete_all_indexes_DB(project=project)
예제 #6
0
    def load_project_into_DB(self, project=None, all_projects=None):

        try:
            defaultkeys = all_projects[project]['defaultkeys']
        except:
            print(project, ':', 'defaultkeys FAILED')
            defaultkeys = []
        try:
            indexes = all_projects[project]['indexes']
        except:
            print(project, ':', 'index FAILED')
            indexes = OrderedList()
        try:

            lastup = all_projects[project]['position'][0]
        except:
            print(project, ':', 'lastup FAILED')
            lastup = Index(2)

        try:
            uptohere = uptohere = all_projects[project]['position'][1]
        except:
            print(project, ':', 'uptohere FAILED')
            uptohere = Index(2)
        try:
            mainterm = mainterm = all_projects[project]['going'][0]
        except:
            print(project, ':', 'mainterm FAILED')
            mainterm = 'quit'

        try:

            series_enter = series_enter = all_projects[project]['going'][1]
        except:
            print(project, ':', 'series enter FAILED')
            series_enter = ''
        try:
            date = all_projects[project]['date']
        except:
            date = [str(str(datetime.datetime.now()))]

        self.initiate_project(project_name=project,
                              defaultkeys=defaultkeys,
                              lastup=lastup,
                              indexes=indexes,
                              uptohere=uptohere,
                              mainterm=mainterm,
                              series_enter=series_enter,
                              date=date,
                              opened=False)
예제 #7
0
    def set_indexes(self, project=None, indexes=None, db_only=False):

        if indexes is None:
            indexes = OrderedList()

        if not project:
            project = self.current

        if indexes and not db_only:

            self.projects[project]['indexes'] = indexes

        if self.using_database:
            self.clear_indexes(project=project, db_only=True)
            for index_temp in indexes.list:
                self.add_index_DB(project=project, index=index_temp)
예제 #8
0
    def initiate_project(self,
                         project_name=None,
                         defaultkeys=None,
                         indexes=None,
                         lastup=None,
                         uptohere=None,
                         mainterm=None,
                         series_enter=None,
                         date=None,
                         opened=True):
        if indexes is None:
            indexes = OrderedList()

        if project_name not in self.projects:
            self.projects[project_name] = {}
            self.projects[project_name]['defaultkeys'] = defaultkeys
            self.projects[project_name]['position'] = (lastup, uptohere)
            self.projects[project_name]['going'] = (mainterm, series_enter)
            self.projects[project_name]['date'] = [str(date)]
            self.projects[project_name]['indexes'] = indexes
            self.projects[project_name]['status'] = {
                'started': str(date),
                'open': opened,
                'lastmodified': []
            }
        self.set_current_project(project_name)
        if self.using_database:
            if opened:
                opened = 'TRUE'
            else:
                opened = 'FALSE'
            self.add_new_project_DB(project=project_name)
            self.add_simple_DB(project=project_name,
                               lastup=lastup,
                               uptohere=uptohere,
                               mainterm=mainterm,
                               series_enter=series_enter,
                               opened=opened)
            for key in defaultkeys:
                self.add_key_DB(project=project_name, key=key)
            self.add_date_DB(project=project_name, date=str(date))
            self.set_indexes(project=project_name, indexes=indexes)
예제 #9
0
    def query(self, term1='', term2='', term3='', action=None):
        sv = None
        dbv = None

        if action == 'get':

            if term1 == '#TYPE#' and not term2:

                if self.using_shelf:
                    sv = list(self.sequence_dictionary[term1].keys())

                    if not sv:

                        sv = []
                    print(sv)

                if self.using_database:
                    dbv = self.get_all_types_db()
                return self.return_value(
                    sv, dbv,
                    str(term1) + '/' + str(term2) + str(term3) + '/' + action)

            elif term1 == '#TYPE#':

                if self.using_shelf:
                    if term2 in self.sequence_dictionary[term1]:
                        sv = self.sequence_dictionary[term1][term2]
                    else:
                        sv = ''
                if self.using_database:
                    dbv = self.get_type_db(term2)
                    if dbv in type_table:
                        dbv = type_table[dbv]
                return self.return_value(
                    sv, dbv,
                    str(term1) + '/' + str(term2) + str(term3) + '/' + action)

            elif term1 and not term2:

                if self.using_shelf:
                    if term1 in self.sequence_dictionary:
                        sv = self.sequence_dictionary[term1]
                    else:
                        sv = OrderedList()
                if self.using_database:
                    dbv = self.return_ordered_from_db(term1)

                return self.return_value(
                    sv, dbv,
                    str(term1) + '/' + str(term2) + str(term3) + '/' + action)

            elif not term1:

                if self.using_shelf:
                    sv = list(self.sequence_dictionary.keys())
                    if not sv:
                        sv = []

                if self.using_database:
                    dbv = self.get_all_names_db()
                return self.return_value(
                    sv, dbv,
                    str(term1) + '/' + str(term2) + str(term3) + '/' + action)

        if action == 'in':

            if term1 == '#TYPE#':

                if self.using_shelf:

                    sv = term2 in self.sequence_dictionary[term1]

                if self.using_database:

                    dbv = self.contains_type_db(term2)
                return self.return_value(
                    sv, dbv,
                    str(term1) + '/' + str(term2) + str(term3) + '/' + action)

            elif not term2:

                if self.using_shelf:

                    sv = term1 in self.sequence_dictionary

                if self.using_database:

                    dbv = self.contains_name_db(term1)
                return self.return_value(
                    sv, dbv,
                    str(term1) + '/' + str(term2) + str(term3) + '/' + action)

            elif term1 and term2:

                if self.using_shelf:
                    if term1 in self.sequence_dictionary:
                        sv = term2 in self.sequence_dictionary[term1].list
                if self.using_database:
                    dbv = term2 in self.return_ordered_from_db(term1).list
                return self.return_value(
                    sv, dbv,
                    str(term1) + '/' + str(term2) + str(term3) + '/' + action)

        if action == 'set':

            if term1 == '#TYPE#' and term2 and term3:

                if self.using_shelf:

                    self.sequence_dictionary[term1][term2] = term3

                if self.using_database:

                    if term3 in [float, str, datetime.date, Index]:
                        term = str(term3)

                    self.add_sequence_name_db(term2)
                    self.add_type_db(term2, term3)

            elif term1 and term2 and not term3:

                if self.using_shelf:

                    if term1 not in self.sequence_dictionary:

                        self.sequence_dictionary[term1] = OrderedList()
                        self.sequence_dictionary[term1].add(term2)
                    else:
                        try:
                            self.sequence_dictionary[term1].add(term2)
                        except:
                            print('SEQUENCE ERROR')
                if self.using_database:

                    self.add_value_db(term1, term2)

        if action == 'delete':

            if term1 == '#TYPE#' and term2:

                if self.using_shelf:

                    if term2 in self.sequence_dictionary[term1]:

                        del self.sequence_dictionary[term1][term2]

                if self.using_database:
                    self.delete_type_db(term2)
                    self.delete_sequence_name_db(term2)

            elif term1 and term2:

                if self.using_shelf:

                    if term1 in self.sequence_dictionary:

                        self.sequence_dictionary[term1].delete(term2)

                if self.using_database:

                    self.delete_value_db(term1, term2)

            elif not term2:

                if self.using_shelf:

                    del self.sequence_dictionary[term1]

                if self.using_database:

                    self.delete_all_values_db(term1)

        if action == 'initiate':

            if term1 and not term2 and not term2:

                if self.using_shelf:

                    self.sequence_dictionary[term1] = OrderedList()
예제 #10
0
def toggle_ordered_list(editor):
    fixed_type = preferences.PREFS.get("fixed_ol_type")
    OrderedList(editor, preferences, fixed_type if fixed_type else "")
예제 #11
0
def toggleOrderedList(self):
    if preferences.PREFS.get("fixed_ol_type"):
        OrderedList(self, self.parentWindow, True)
    else:
        OrderedList(self, self.parentWindow)
예제 #12
0
from orderedlist import Node, OrderedList

test = Node(10)

print test

l = OrderedList()

l.add(10)
l.add(20)
l.add(12)
l.add(5)
l.add(1)
l.add(44)

print l
예제 #13
0
 def setUp(self):
     self.mylist = OrderedList()
예제 #14
0
class OrderedListTest(unittest.TestCase):
    def setUp(self):
        self.mylist = OrderedList()

    def tearDown(self):
        self.mylist = None

    def test_size(self):
        self.mylist.add(31)
        self.mylist.add(77)
        self.mylist.add(17)
        self.mylist.add(93)
        self.mylist.add(26)
        self.mylist.add(54)
        self.assertEqual(self.mylist.size(), 6)

    def test_search(self):
        self.mylist.add(31)
        self.mylist.add(77)
        self.mylist.add(17)
        self.mylist.add(93)
        self.mylist.add(26)
        self.mylist.add(54)
        self.assertEqual(self.mylist.search(93), True)

    def test_find_list_item(self):
        self.mylist.add(31)
        self.mylist.add(77)
        self.mylist.add(17)
        self.mylist.add(93)
        self.mylist.add(26)
        self.mylist.add(54)
        self.assertEqual(self.mylist.find_list_item(),
                         [17, 26, 31, 54, 77, 93])
예제 #15
0
def transform(complexobject,start=True,indexstrings=True):

     """ copies dictionary, and applies tranformations
     """

     def dummy (y):
          return y
     if start:
          complexobject = copy.deepcopy(complexobject)
          start = False
          
          

     if isinstance(complexobject,dict):
          for x in list(complexobject.keys()):
              complexobject[x]=transform(complexobject[x],start=start)
          return complexobject
     elif isinstance(complexobject,list):
          newlist = []
          for x in complexobject:
               newlist += [transform(x,start=start)]
          return newlist
     elif isinstance(complexobject,set):
          newset = set()
          for x in complexobject:
               newset.add(transform(x,start=start))
          return newset
     elif isinstance(complexobject,tuple):
          newlist = []
          for x in complexobject:
               newlist += [transform(x,start=start)]
          return tuple(newlist)

               
     else:

               if type(complexobject) == type(Index(0)):
                    return '<'+str(complexobject)+'>'
               elif isinstance(complexobject,str) and len(complexobject)>4\
                    and complexobject[0:2] == '<<'\
                    and complexobject[-2:] == '>>':
                    return OrderedList(eval(complexobject[2:-2]),indexstrings=indexstrings)
                   
               elif isinstance(complexobject,str) and len(complexobject)>2\
                    and complexobject[0] == '<' \
                    and complexobject[-1] == '>':
                    return Index(complexobject[1:-1])
               elif isinstance(complexobject,str) and len(complexobject)>6\
                    and complexobject[0:3] == '###'\
                    and complexobject[-3:] == '###'\
                    and complexobject[3:-3] in ['float','str','date']:
                   return {'float':type(1.2),
                           'str':type('st'),
                           'date':type(datetime.datetime.now())}[complexobject[3:-3]]
               elif type(complexobject) == type(datetime.datetime.now()):
                    return str(complexobject)
               elif isinstance(complexobject,str) and COLON in complexobject and DASH in complexobject and PERIOD in complexobject and \
                    complexobject.replace(DASH,EMPTYCHAR).replace(PERIOD,EMPTYCHAR).replace(COLON,EMPTYCHAR).replace(BLANK,EMPTYCHAR).isnumeric():
                    return is_date(complexobject,returndate=True)
##               elif isinstance(complexobject,str) and complexobject.startswith('datetime.datetime'):
##                        return eval(complexobject)
               elif type(complexobject) == type(ordlist_example):
                    return '<<['+str(complexobject)+']>>'
               elif isinstance(complexobject,str) and complexobject in ['b#True','b#False']:
                   if complexobject == 'b#True':
                       return True
                   return False
               elif isinstance(complexobject,bool):
                   if complexobject:
                       return 'b#True'
                   return 'b#False'
               else:
                    return complexobject
예제 #16
0
### Takes a dictionary, makes a copy of it, and applies
### transformations to INDEXES and DATES, yielding strings 

import copy
from indexclass import Index
import datetime
from globalconstants import DASH, COLON, PERIOD, BLANK, PLUS, EMPTYCHAR
from orderedlist import OrderedList

ordlist_example = OrderedList(['1'],indexstrings=True)


def is_date(entry,returndate=False):


    """Utility to test if a string constitutes a date, returning either
    a boolean value or a converted date """

    date_constraints = {0:(-800000000000,+80000000000),
                        1:(1,12),
                        2:(1,31),
                        3:(0,23),
                        4:(0,59),
                        5:(0,59),
                        6:(0,1000000)}

    if not isinstance(entry,(tuple,list)):

        if entry.count(DASH)>1 and entry.count(COLON)>1 and entry.count(PERIOD)==1:
             entry = entry.replace(DASH,BLANK).replace(COLON,BLANK).replace(PERIOD,BLANK).split(BLANK)
             entry = [int(a.strip()) for a in entry]
예제 #17
0
    def __init__(self):

        self.dates = OrderedList()
        self.index_to_dates = {}
        self.dates_to_index = {}
        self.index_to_event = {}
"""


from stack import Stack
from queue import Queue
from deque import Deque
from node import Node
from unorderdlist import UnorderedList
from orderedlist import OrderedList
from binarytree import BinaryTree

stack = Stack()
queue = Queue()
deque = Deque()
lst = UnorderedList()
olst = OrderedList()

#===============
# Testing a Stack
#===============


def populate(stack, string):
    """Add the string to the stack"""
    for i in string:
        stack.push(i)


def reverse(stack):
    """With LIFO the last character to be added
        to the stack will be the first to be read"""