Ejemplo n.º 1
0
    def version_history(self, root_id):
        
        # extract root from 
        r = Root.objects(id=root_id)[0]
        
        print "FIRST = " + str(r.id)

        history = []
        prev = r.previous

        while (prev != None and prev != ""):
            history.append(prev)
            root = Root.objects(id=prev)[0]
            prev = root.previous

        return history
Ejemplo n.º 2
0
    def save_root(self, root):
        r = Root()

        # rewirite primary fields
        r.author     = root.author
        r.date       = root.date
        r.repository = root.repository
        r.version    = root.version

        r.previous   = str(root.id)
        
        # copy sections for that root document
        for sec in root.sections:
            r.sections.append(self.save_section(LatestSection.objects(object_id = sec)[0], "old"))

        r.save()
Ejemplo n.º 3
0
    def to_database(self, source_file):
        # create root document
        r = Root()
        
        # load odml file using python-odml module
        odml_root = load(source_file)

        # rewrite root fields
        r.author     = odml_root.author
        r.date       = odml_root.date
        r.repository = odml_root.repository
        r.version    = odml_root.version

        r.previous   = None

        # add sections to 'section' ccollection
        for section in odml_root.sections:
            s = self._save_section(section, None)
            r.sections.append(s)

        # save new object in database
        r.save()
Ejemplo n.º 4
0
    def switch_to_last(self, root_id):

        print "\n --------------------- VERSION MANAGER ----------------------- \n"
        v = Version() 

        # take root object
        root = Root.objects(id=root_id)[0]

        # take it ancestor (as object)
        previous_root = Root.objects(id=root.previous)[0]

        # list for sections storage
        current_sections = []
        old_sections = []

        temp_collection = root.sections

        # add sections to temporary lists, recursively!
        while (len(temp_collection) != 0):
            next_collection = []
            
            for sec in temp_collection:
                current_sections.append(LatestSection.objects(object_id=sec)[0])

                for s in (LatestSection.objects(object_id=sec)[0]).subsections:
                    next_collection.append(s)

            temp_collection = next_collection

        # the same operation for ancestor

        temp_collection = previous_root.sections

        while (len(temp_collection) != 0):
            next_collection = []
            
            for sec in temp_collection:
                old_sections.append(OldSection.objects(object_id=sec)[0])

                for s in (OldSection.objects(object_id=sec)[0]).subsections:
                    next_collection.append(s)

            temp_collection = next_collection


        # old code, delete
        # for sec in previous_root.sections:
        #     old_sections.append(OldSection.objects(object_id=sec)[0])

        # move sections from old to temp

        old_counter = 0
        for s in old_sections: 
            if (TempSection.objects(object_id = s.object_id)).count() == 0:
                print "[ " + s.name + " -> TEMP]"
                v.save_section(s, "temp")
                # s.delete()
                # print "latest del"
                old_counter += 1

        # move sections from latest to old

        current_counter = 0
        for s in current_sections:
            if (OldSection.objects(object_id = s.object_id)).count() == 0:
                print "[ " + s.name + " -> OLD]"
                v.save_section(s, "old")
                # s.delete()
                # print "old del"
                current_counter += 1

        # move sections from temp to latest
        for x in range(0,7):
            print "----------------------"

        temp_counter = 0
        for sec in TempSection.objects():
            print str(sec.id) + " : " + str(sec.name) + " : " + str(sec.object_id)
            for subsec in sec.subsections:
                print "sub:  " + subsec
            print " "
            temp_counter += 1

        print "~~~ \n"
        print "old_counter == " + str(old_counter)
        print "current_counter == " + str(current_counter)
        print "temp_counter == " + str(temp_counter)
        print "current_sections == " + str(len(old_sections))
        print "old_sections == " + str(len(current_sections))

        for s in TempSection.objects():
            # print "s.name == " + str(s.name)
            if (LatestSection.objects(object_id = s.object_id)).count() == 0:
                print "[ " + s.name + " -> LATEST]"
                v.save_section(s, "latest")
                # s.delete()
                # print "temp del"
        
        v.clear_trash()