Example #1
0
    def _test_symlink(self):
        if os.name == 'nt':
            return

        # create a new test.txt file
        file_path = "./symlink.txt"
        file = open(file_path, 'w')
        file.write("symlink test")
        file.close()

        file_path2 = "./symlink_append.txt"
        file = open(file_path2, 'w')
        file.write("append test")
        file.close()


        checkin = FileCheckin(self.person, file_path, context="sym_test", checkin_type='auto')
        checkin.execute()
        snap = checkin.get_snapshot()
        versionless_snap = Snapshot.get_versionless(self.person.get_search_type(), self.person.get_id(), "sym_test", mode='latest', create=False)
        self.assertEquals(True, isinstance(versionless_snap, Snapshot))

        main_lib_path = snap.get_lib_path_by_type('main')
        self.assertEquals(main_lib_path.endswith('/sym_test/.versions/symlink_sym_test_v001.txt'), True)
        if versionless_snap:
            lib_path =versionless_snap.get_lib_path_by_type('main')
            self.assertEquals(True, os.path.exists(lib_path)) 
            rel_path = os.readlink(lib_path)
            lib_dir = os.path.dirname(lib_path)

            # this is essentially handle_link() in FileUndo class
            wd = os.getcwd()
            os.chdir(lib_dir)
            real_path = os.path.join(lib_dir, os.path.abspath(rel_path))
            # lib_path points to real_path

            expected_rel_path  = Common.relative_path(lib_path, real_path)
            self.assertEquals(True, os.path.exists(real_path))
            self.assertEquals(expected_rel_path, rel_path)
            os.chdir(wd)

        # if not inplace or preallocate mode, keep_file_name should be False
        checkin = FileAppendCheckin(snap.get_code(), [file_path2], file_types=['add'], keep_file_name=False, checkin_type='auto')
        checkin.execute()
        snap = checkin.get_snapshot()
        main_lib_path = snap.get_lib_path_by_type('add')
        self.assertEquals(snap.get_value('is_current'), True)
        self.assertEquals(snap.get_value('is_latest'), True)
        self.assertEquals(main_lib_path.endswith('/sym_test/.versions/symlink_append_sym_test_v001.txt'), True)
        versionless_snap = Snapshot.get_versionless(self.person.get_search_type(), self.person.get_id(), "sym_test", mode='latest', create=False)
        if versionless_snap:
            lib_path = versionless_snap.get_lib_path_by_type('add')
            self.assertEquals(lib_path.endswith('/sym_test/symlink_append_sym_test.txt'), True)
            self.assertEquals(os.path.exists(lib_path), True)
Example #2
0
    def create_snapshot(my):
        # set up a real person and snapshot (as opposed to virtual)
        code = 'phil'
       
        my.person = SearchType.create( 'unittest/person' )
        my.person.set_value("code",code)
        my.person.set_value("name_first", "Philip")
        my.person.commit()


        # create a new test.txt file
        file_path = "./naming_test.txt"
        for i in range(0,4):
            file = open(file_path, 'w')
            file.write("whatever")
            file.close()
        checkin = FileCheckin(my.person, file_path, "main", context='naming_test')
        checkin.execute()
        my.snapshot = checkin.get_snapshot()

        # create another test_base.txt file
        file_path = "./naming_base_test.txt"
        for i in range(0,4):
            file = open(file_path, 'w')
            file.write("whatever")
            file.close()
        checkin = FileCheckin(my.person, file_path, "main", context='naming_base_test')
        checkin.execute()
        my.base_snapshot = checkin.get_snapshot()

        dir_path = "./naming_test_folder"
        dir_path2 = "./.tactic_test" # test . folder
        dir_path3 = "./naming_test_folder3"
        dir_path4 = "./naming_test_folder4"
        for path in [dir_path, dir_path2, dir_path3, dir_path4]:
            if not os.path.exists(path):
                os.makedirs(path)

        checkin = FileCheckin(my.person, dir_path, "main", context='naming_base_test', checkin_type='auto')
        checkin.execute()
        my.auto_snapshot = checkin.get_snapshot()
        checkin = FileCheckin(my.person, dir_path2, "main", context='naming_folder_test', snapshot_type='directory', checkin_type='auto')
        checkin.execute()
        my.auto_snapshot2 = checkin.get_snapshot()

        # test a blank checkin_type
        checkin = FileCheckin(my.person, dir_path3, "main", context='naming_base_test', snapshot_type='directory', checkin_type='')
        checkin.execute()
        my.auto_snapshot3 = checkin.get_snapshot()
Example #3
0
    def _test_checkin_type(my):
        my.assertEquals(my.auto_snapshot.get_version(), 2)
        dir_name = my.auto_snapshot.get_file_name_by_type('main')
        my.assertEquals(dir_name, 'naming_test_folder_naming_base_test_v002')

        dir_name = my.auto_snapshot2.get_file_name_by_type('main')

        my.assertEquals(1, my.auto_snapshot2.get_version())
        my.assertEquals(dir_name, '.tactic_test_naming_folder_test_v001')

        dir_name = my.auto_snapshot3.get_file_name_by_type('main')
        # this takes the auto generated name
        my.assertEquals(dir_name, 'naming_test_folder3_naming_base_test_v003')

        # this one would take into account of the new naming entry introduced in _test_get_naming
        # test a blank checkin_type
        dir_path4 = "./naming_test_folder4"
        checkin = FileCheckin(my.person,
                              dir_path4,
                              "main",
                              context='naming_base_test',
                              snapshot_type='directory',
                              checkin_type='')
        checkin.execute()
        my.auto_snapshot4 = checkin.get_snapshot()
        dir_name = my.auto_snapshot4.get_file_name_by_type('main')
        lib_dir = my.auto_snapshot4.get_dir('relative')
        my.assertEquals(dir_name, 'generic_phil_v004')
        my.assertEquals(lib_dir, 'unittest/cut/generic/phil')
Example #4
0
    def _test_copycheckin(self):

        # create a new copy_test.txt file
        file_path = "./copy_test.txt"
        file = open(file_path, 'w')
        file.write("copy contents")
        file.close()

        file_paths = [file_path]
        file_types = ['main']
        context = "publish"
        from pyasm.checkin import FileCheckin
        checkin = FileCheckin(
                    self.person,
                    file_paths=file_paths,
                    file_types=file_types,
                    context=context,
                    mode="copy"
            )
        checkin.execute()
        self.assertEquals(True, os.path.exists(file_path) )

        snap = checkin.get_snapshot()
        file_obj = snap.get_file_by_type('main')
        file_name = file_obj.get_file_name()
        self.assertEquals(file_name, 'copy_test_publish_v002.txt')
Example #5
0
    def _test_checkin_type(my):
        my.assertEquals(my.auto_snapshot.get_version(), 2)
        dir_name = my.auto_snapshot.get_file_name_by_type('main')
        my.assertEquals(dir_name , 'naming_test_folder_naming_base_test_v002')
        
        dir_name = my.auto_snapshot2.get_file_name_by_type('main')

        my.assertEquals(1, my.auto_snapshot2.get_version())
        my.assertEquals(dir_name , '.tactic_test_naming_folder_test_v001')

        dir_name = my.auto_snapshot3.get_file_name_by_type('main')
        # this takes the auto generated name
        my.assertEquals(dir_name , 'naming_test_folder3_naming_base_test_v003')


        # this one would take into account of the new naming entry introduced in _test_get_naming
        # test a blank checkin_type
        dir_path4 = "./naming_test_folder4"
        checkin = FileCheckin(my.person, dir_path4, "main", context='naming_base_test', snapshot_type='directory', checkin_type='')
        checkin.execute()
        my.auto_snapshot4 = checkin.get_snapshot()
        dir_name = my.auto_snapshot4.get_file_name_by_type('main')
        lib_dir = my.auto_snapshot4.get_dir('relative')
        my.assertEquals(dir_name , 'generic_phil_v004')
        my.assertEquals(lib_dir , 'unittest/cut/generic/phil')
Example #6
0
    def _test_base_dir_alias(my):

        Config.set_value(
            "checkin", "asset_base_dir", {
                'default': '/tmp/tactic/default',
                'alias': '/tmp/tactic/alias',
                'alias2': '/tmp/tactic/alias2',
            })
        asset_dict = Environment.get_asset_dirs()
        default_dir = asset_dict.get("default")
        my.assertEquals("/tmp/tactic/default", default_dir)

        aliases = asset_dict.keys()
        # "plugins" is assumed in some branch
        if 'plugins' in aliases:
            my.assertEquals(4, len(aliases))
        else:
            my.assertEquals(3, len(aliases))
        my.assertNotEquals(None, "alias" in aliases)

        # create a naming
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "alias")
        naming.set_value("dir_naming", "alias")
        naming.set_value("file_naming", "text.txt")
        naming.set_value("base_dir_alias", "alias")
        naming.commit()

        # create 2nd naming where
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "alias2")
        naming.set_value("dir_naming", "alias2")
        naming.set_value("base_dir_alias", "alias2")
        naming.set_value("file_naming", "text.txt")
        naming.set_value("checkin_type", "auto")
        naming.commit()

        my.clear_naming()

        # create a new test.txt file
        for context in ['alias', 'alias2']:
            file_path = "./test.txt"
            file = open(file_path, 'w')
            file.write("whatever")
            file.close()

            checkin = FileCheckin(my.person, file_path, context=context)
            checkin.execute()
            snapshot = checkin.get_snapshot()

            lib_dir = snapshot.get_lib_dir()
            expected = "/tmp/tactic/%s/%s" % (context, context)
            my.assertEquals(expected, lib_dir)

            path = "%s/text.txt" % (lib_dir)
            exists = os.path.exists(path)
            my.assertEquals(True, exists)
Example #7
0
    def _test_base_dir_alias(my):

        Config.set_value("checkin", "asset_base_dir", {
            'default': '/tmp/tactic/default',
            'alias': '/tmp/tactic/alias',
            'alias2': '/tmp/tactic/alias2',
        });
        asset_dict = Environment.get_asset_dirs()
        default_dir = asset_dict.get("default")
        my.assertEquals( "/tmp/tactic/default", default_dir)

        aliases = asset_dict.keys()
        # "plugins" is assumed in some branch 
        if 'plugins' in aliases:
            my.assertEquals( 4, len(aliases))
        else:
            my.assertEquals( 3, len(aliases))
        my.assertNotEquals( None, "alias" in aliases )

        # create a naming
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "alias")
        naming.set_value("dir_naming", "alias")
        naming.set_value("file_naming", "text.txt")
        naming.set_value("base_dir_alias", "alias")
        naming.commit()

        # create 2nd naming where 
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "alias2")
        naming.set_value("dir_naming", "alias2")
        naming.set_value("base_dir_alias", "alias2")
        naming.set_value("file_naming", "text.txt")
        naming.set_value("checkin_type", "auto")
        naming.commit()

        my.clear_naming()

        # create a new test.txt file
        for context in ['alias', 'alias2']:
            file_path = "./test.txt"
            file = open(file_path, 'w')
            file.write("whatever")
            file.close()

            checkin = FileCheckin(my.person, file_path, context=context)
            checkin.execute()
            snapshot = checkin.get_snapshot()

            lib_dir = snapshot.get_lib_dir()
            expected = "/tmp/tactic/%s/%s" % (context, context)
            my.assertEquals(expected, lib_dir)

            path = "%s/text.txt" % (lib_dir)
            exists = os.path.exists(path)
            my.assertEquals(True, exists)
Example #8
0
    def _test_checkin(self):

        # create a new test.txt file
        file_path = "./test.txt"
        file = open(file_path, 'w')
        file.write("whatever")
        file.close()

        checkin = FileCheckin(self.person, file_path, "test")
        checkin.execute()

        # check that the file exists
        snapshot = checkin.get_snapshot()
        xml = snapshot.get_xml_value("snapshot")
        file_code = xml.get_value("snapshot/file/@file_code")
        file_name = xml.get_value("snapshot/file/@name")

        self.assertNotEqual(None, file)

        lib_path = "%s/%s" % (snapshot.get_lib_dir(), file_name)
        self.assertEquals(True, os.path.exists(lib_path))
Example #9
0
    def _test_checkin(self):

        # create a new test.txt file
        file_path = "./test.txt"
        file = open(file_path, 'w')
        file.write("whatever")
        file.close()

        checkin = FileCheckin(self.person, file_path, "test")
        checkin.execute()

        # check that the file exists
        snapshot = checkin.get_snapshot()
        xml = snapshot.get_xml_value("snapshot")
        file_code = xml.get_value("snapshot/file/@file_code")
        file_name = xml.get_value("snapshot/file/@name")

        self.assertNotEqual(None, file)

        lib_path = "%s/%s" % (snapshot.get_lib_dir(),file_name)
        self.assertEquals(True, os.path.exists(lib_path) )
Example #10
0
    def _test_file_owner(self):
        # FIXME: this test has hard coded st_uids that only work on very
        # specific conditions
        return

        if os.name == 'nt':
            return
        # create a new test.txt file
        file_path = "./test2.txt"
        file = open(file_path, 'w')
        file.write("whatever")
        file.close()
        # owned by root
        os.system('echo south123paw | sudo -S chown root.root \"%s\"' %
                  file_path)

        stat = os.stat(file_path)
        self.assertEquals(stat.st_uid, 0)

        checkin = FileCheckin(self.person, file_path, "test")
        checkin.execute()

        # check that the file exists
        snapshot = checkin.get_snapshot()
        xml = snapshot.get_xml_value("snapshot")
        file_code = xml.get_value("snapshot/file/@file_code")
        file_name = xml.get_value("snapshot/file/@name")

        self.assertNotEqual(None, file)

        lib_path = "%s/%s" % (snapshot.get_lib_dir(), file_name)
        self.assertEquals(True, os.path.exists(lib_path))
        stat = os.stat(lib_path)
        if Config.get_value("checkin", "sudo_no_password") == 'true':
            self.assertEquals(stat.st_uid, 48)
        else:
            # if not set, it will remain owned by root
            self.assertEquals(stat.st_uid, 0)
Example #11
0
    def _test_file_owner(self):
        # FIXME: this test has hard coded st_uids that only work on very
        # specific conditions
        return

        if os.name == 'nt':
            return
        # create a new test.txt file
        file_path = "./test2.txt"
        file = open(file_path, 'w')
        file.write("whatever")
        file.close()
        # owned by root
        os.system('echo south123paw | sudo -S chown root.root \"%s\"'%file_path)

        stat = os.stat(file_path)
        self.assertEquals(stat.st_uid, 0)

        checkin = FileCheckin(self.person, file_path, "test")
        checkin.execute()

        # check that the file exists
        snapshot = checkin.get_snapshot()
        xml = snapshot.get_xml_value("snapshot")
        file_code = xml.get_value("snapshot/file/@file_code")
        file_name = xml.get_value("snapshot/file/@name")

        self.assertNotEqual(None, file)

        lib_path = "%s/%s" % (snapshot.get_lib_dir(),file_name)
        self.assertEquals(True, os.path.exists(lib_path) )
        stat = os.stat(lib_path)
        if Config.get_value("checkin", "sudo_no_password") == 'true': 
            self.assertEquals(stat.st_uid, 48)
        else:
            # if not set, it will remain owned by root
            self.assertEquals(stat.st_uid, 0)
Example #12
0
    def _test_copycheckin(self):

        # create a new copy_test.txt file
        file_path = "./copy_test.txt"
        file = open(file_path, 'w')
        file.write("copy contents")
        file.close()

        file_paths = [file_path]
        file_types = ['main']
        context = "publish"
        from pyasm.checkin import FileCheckin
        checkin = FileCheckin(self.person,
                              file_paths=file_paths,
                              file_types=file_types,
                              context=context,
                              mode="copy")
        checkin.execute()
        self.assertEquals(True, os.path.exists(file_path))

        snap = checkin.get_snapshot()
        file_obj = snap.get_file_by_type('main')
        file_name = file_obj.get_file_name()
        self.assertEquals(file_name, 'copy_test_publish_v002.txt')
Example #13
0
    def _test_strict_checkin(self):

        server = Config.get_value("install", "server")
        #process = "process"
        person_code = self.person.get_code()

        filename = "filename.jpg"

        process = "strict"

        subcontexts = [
            '', '', # do 2 checkins
            'hi', 'hi',
            'medium',
            'low',
        ]

        for i, subcontext in enumerate(subcontexts):

            if subcontext:
                context = "%s/%s" % (process, subcontext)
            else:
                context = process

            # create a new test.txt file
            file_path = "./%s" % filename
            file = open(file_path, 'w')
            file.write("test")
            file.close()


            #import time
            #start = time.time()

            checkin = FileCheckin(self.person, file_path, context=context, checkin_type='strict')
            checkin.execute()
            snapshot = checkin.get_snapshot()
            #print "time: ", time.time() - start
            #print "---"

            # make sure there is no latest versionless except for process/low
            versionless = Snapshot.get_versionless(self.person.get_search_type(), self.person.get_id(), context, mode='latest', create=False)

            versionless_current = Snapshot.get_versionless(self.person.get_search_type(), self.person.get_id(), context, mode='current', create=False)

            if context == 'strict/low':
                self.assertNotEquals(None, versionless)
                file_objects = versionless.get_all_file_objects()
                self.assertEquals(1, len(file_objects))

                file_object = file_objects[0]
                relative_dir = file_object.get_value("relative_dir")
                file_name = file_object.get_value("file_name")
                self.assertEquals(file_name ,'filename_latest.jpg')
            else:
                self.assertEquals(None, versionless)

            # make sure there is no current versionless except for process/hi
            if context == 'strict/hi':
                self.assertNotEquals(None, versionless_current)
                file_objects = versionless_current.get_all_file_objects()
                self.assertEquals(1, len(file_objects))

                file_object = file_objects[0]
                relative_dir = file_object.get_value("relative_dir")
                file_name = file_object.get_value("file_name")
                self.assertEquals(file_name, 'filename_current.jpg')
                
            else:
                self.assertEquals(None, versionless_current)

            
            path = snapshot.get_path_by_type("main")

            asset_dir = Config.get_value("checkin", "asset_base_dir", sub_key="default")

            file_objects = snapshot.get_all_file_objects()
            self.assertEquals(1, len(file_objects))

            file_object = file_objects[0]
            relative_dir = file_object.get_value("relative_dir")
            file_name = file_object.get_value("file_name")

            test_path = "%s/%s/%s" % (asset_dir, relative_dir, file_name)
            self.assertEquals(test_path, path)
Example #14
0
    def _test_inplace_checkin(self):

        # create a new test.txt file
        tmp_dir = Environment.get_tmp_dir()
        dir = "%s/temp" % tmp_dir
        if not os.path.exists(dir):
            os.makedirs(dir)
        file_path = "%s/test_inplace.txt" % dir

        if os.path.exists(file_path):
            os.unlink(file_path)

        file = open(file_path, 'w')
        file.write("whatever")
        file.close()

        # inplace checkin: tell tactic that this is the correct path
        mode = "inplace"
        base_dir = tmp_dir
        context = "inplace"
        checkin = FileCheckin(self.person,
                              file_path,
                              context=context,
                              mode=mode)
        checkin.execute()
        snapshot = checkin.get_snapshot()

        file_code = snapshot.get_file_code_by_type("main")
        file_object = File.get_by_code(file_code)

        relative_dir = file_object.get_value("relative_dir")
        # The relative dir is empty if the file is outside the repository
        self.assertEquals("", relative_dir)

        lib_dir = snapshot.get_lib_dir(file_type="main")
        file_name = snapshot.get_file_name_by_type("main")
        lib_path = "%s/%s" % (lib_dir, file_name)
        self.assertEquals(True, os.path.exists(lib_path))
        self.assertEquals(file_path, lib_path)

        # check in a file alredy in the repository
        asset_dir = Config.get_value("checkin",
                                     "asset_base_dir",
                                     sub_key="default")
        file_path2 = "%s/unittest/text.txt" % asset_dir

        file = open(file_path2, 'w')
        file.write("whatever")
        file.close()

        checkin = FileCheckin(self.person,
                              file_path2,
                              context=context,
                              mode=mode)
        checkin.execute()
        snapshot = checkin.get_snapshot()

        file_code = snapshot.get_file_code_by_type("main")
        file_object = File.get_by_code(file_code)

        # check that the relative dir is as expected
        relative_dir = file_object.get_value("relative_dir")
        self.assertEquals(relative_dir, "unittest")

        # check that the path returned correctly
        lib_path = snapshot.get_path_by_type("main")
        self.assertEquals(file_path2, lib_path)

        if os.path.exists(file_path):
            os.unlink(file_path)
        if os.path.exists(file_path2):
            os.unlink(file_path2)
Example #15
0
    def _test_inplace_checkin(self):

        # create a new test.txt file
        tmp_dir = Environment.get_tmp_dir()
        dir = "%s/temp" % tmp_dir
        if not os.path.exists(dir):
            os.makedirs(dir)
        file_path = "%s/test_inplace.txt" % dir

        if os.path.exists(file_path):
            os.unlink(file_path)

        file = open(file_path, 'w')
        file.write("whatever")
        file.close() 


        # inplace checkin: tell tactic that this is the correct path
        mode = "inplace"
        base_dir = tmp_dir
        context = "inplace"
        checkin = FileCheckin(self.person, file_path, context=context, mode=mode)
        checkin.execute()
        snapshot = checkin.get_snapshot()

        file_code = snapshot.get_file_code_by_type("main")
        file_object = File.get_by_code(file_code)

        relative_dir = file_object.get_value("relative_dir")
        # The relative dir is empty if the file is outside the repository
        self.assertEquals("", relative_dir)

        lib_dir = snapshot.get_lib_dir(file_type="main")
        file_name = snapshot.get_file_name_by_type("main")
        lib_path = "%s/%s" % (lib_dir, file_name)
        self.assertEquals( True, os.path.exists(lib_path) )
        self.assertEquals( file_path, lib_path)




        # check in a file alredy in the repository
        asset_dir = Config.get_value("checkin", "asset_base_dir", sub_key="default")
        file_path2 = "%s/unittest/text.txt" % asset_dir

        file = open(file_path2, 'w')
        file.write("whatever")
        file.close() 

        checkin = FileCheckin(self.person, file_path2, context=context, mode=mode)
        checkin.execute()
        snapshot = checkin.get_snapshot()

        file_code = snapshot.get_file_code_by_type("main")
        file_object = File.get_by_code(file_code)

        # check that the relative dir is as expected
        relative_dir = file_object.get_value("relative_dir")
        self.assertEquals( relative_dir, "unittest" )

        # check that the path returned correctly
        lib_path = snapshot.get_path_by_type("main")
        self.assertEquals( file_path2, lib_path )

        if os.path.exists(file_path):
            os.unlink(file_path)
        if os.path.exists(file_path2):
            os.unlink(file_path2)
Example #16
0
    def _test_level(my):

        # add a country
        sobject = SearchType.create("unittest/country")
        sobject.set_value("code", "canada")
        sobject.commit()


        # add a city
        sobject = SearchType.create("unittest/city")
        sobject.set_value("code", "toronto")
        sobject.set_value("country_code", "canada")
        sobject.commit()

        my.person.set_value("city_code", "toronto")
        my.person.commit()
        

        level_type = "unittest/city"
        level_code = "toronto"
        level = Search.get_by_code(level_type, level_code)
        level_id = level.get_id()


        # create a new test.txt file
        my.file_path = "./biz_test.txt"
        for i in range(0,4):
            file = open(my.file_path, 'w')
            file.write("whatever")
            file.close()
       
        # creating version 5
        checkin = FileCheckin(my.person, my.file_path, "main", context=my.context)
        checkin.execute()
        
        my.file_path = "./biz_fulltest.txt"
        file = open(my.file_path, 'w')
        file.write("whatever")
        file.close()
        # for checkin using test/subtest
        checkin = FileCheckin(my.person, my.file_path, "main", context=my.full_context)
        checkin.execute()


        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, my.context, version=-1, use_cache=True, level_type=level_type, level_id=level_id)
        # make sure we get the top level one
        my.assertEquals( 5, snapshot.get_value("version") )
        my.assertEquals( "", snapshot.get_value("level_type") )
        # integer None is now converted to 0
        my.assertEquals( 0, snapshot.get_value("level_id") )


        # checkin the file to the level
        my.file_path = "./biz_test_level.txt"
        for i in range(0,4):
            file = open(my.file_path, 'w')
            file.write("whatever")
            file.close()
        checkin = FileCheckin(my.person, my.file_path, "main", context=my.context, level_type=level_type, level_id=level_id)
        checkin.execute()

        snapshot = checkin.get_snapshot()
        version = snapshot.get_version()
        my.assertEquals(1, version)
        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, my.context, version='-1', use_cache=True, level_type=level_type, level_id=level_id)

        my.assertEquals( level_type, snapshot.get_value("level_type") )
        my.assertEquals( level_id, snapshot.get_value("level_id") )
        my.assertEquals( 1, snapshot.get_value("version") )
        my.assertEquals( True, snapshot.get_value("is_latest") )
        my.assertEquals( True, snapshot.get_value("is_current") )


        # get latest version and revision of the person and make sure 
        # it has its own is_latest
        top_snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, context=my.context, version=-1, revision=-1, use_cache=False)
        version = top_snapshot.get_version()
        my.assertEquals(5, version)
        revision = top_snapshot.get_value('revision')
        my.assertEquals(0, revision)
        my.assertEquals( True, top_snapshot.get_value("is_latest") )
        my.assertEquals( True, top_snapshot.get_value("is_current") )
Example #17
0
    def _test_snapshot(my):


        # create a new test.txt file
        for i in range(0,4):

            # create a new test.txt file
            my.file_path = "./biz_test.txt"
            for i in range(0,4):
                file = open(my.file_path, 'w')
                file.write("whatever")
                file.close()

            checkin = FileCheckin(my.person, my.file_path, "main", context=my.context)
            checkin.execute()

            # get snapshot from database
            snapshot = checkin.get_snapshot()
            code = snapshot.get_value("code")
            s = Search("sthpw/snapshot")
            s.add_filter("code", code)
            snapshot = s.get_sobject()


        # get version -1
        snapshot = Snapshot.get_by_version(my.search_type, my.search_id, context=my.context, version=-1, use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)

        # latest version
        snapshot = Snapshot.get_latest(my.search_type, my.search_id, context=my.context, use_cache=False)
        version = snapshot.get_version()

        my.assertEquals('biz_test_test_v004.txt', snapshot.get_all_file_names()[0])
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(0, revision)

        for i in range(0,2):
            file = open(my.file_path, 'w')
            file.write("whatever")
            file.close()

            # check in 2 current revisions
            checkin = FileCheckin(my.person, my.file_path, "main", context=my.context, is_revision=True, is_current=True)
            checkin.execute()
            snapshot = checkin.get_snapshot()

            # get snapshot from database
            #snapshot = checkin.get_snapshot()
            code = snapshot.get_value("code")
            s = Search("sthpw/snapshot")
            s.add_filter("code", code)
            snapshot = s.get_sobject()


        # get current version and revision latest
        snapshot = Snapshot.get_by_version(my.search_type, my.search_code, context=my.context, version=0, revision=-1, use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(2, revision)
            
        # get revision
        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, context=my.context, version=-1, revision=-1, use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(2, revision)
        is_latest = snapshot.get_value('is_latest')
        my.assertEquals(True, is_latest)
        
        # v4r1 should not be latest
        snapshot = Snapshot.get_by_version(my.search_type, my.search_id, context=my.context, version=4, revision=1, use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(1, revision)
        is_latest = snapshot.get_value('is_latest')
        my.assertEquals(False, is_latest)

        # is_latest is v4r2, so can't find v4r0 any more
        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, context=my.context, version=-1, revision=None, use_cache=False)
        
        my.assertEquals(None, snapshot)

        # use max to find v4r0
        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, context=my.context, version='max', revision=None, use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(0, revision)
    
        # add 2 non current revisions
        for i in range(0,2):
            file = open(my.file_path, 'w')
            file.write("whatever")
            file.close()

            # check in 2 revisions
            checkin = FileCheckin(my.person, my.file_path, "main", context=my.context, is_revision=True, is_current=False)
            checkin.execute()


        # get latest version and revision
        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, context=my.context, version=-1, revision=-1, use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(4, revision)
        is_latest = snapshot.get_value('is_latest')
        my.assertEquals(True, is_latest)


        # get current version and latest revision (but current v4r2 takes precedence)
        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, context=my.context, version=0, revision=-1, use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(2, revision)
        is_latest = snapshot.get_value('is_latest')
        my.assertEquals(False, is_latest)


        # get current version and 0 revision (but current v4r2 is the real current, returns None)
        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, context=my.context, version=0, revision=None, use_cache=False)
        my.assertEquals(None, snapshot)

        
        # is_latest is v4r4, so can't find v4r0 any more
        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, context=my.context, version=-1, revision=None, use_cache=False)
        my.assertEquals(None, snapshot)
        
        
        # use max to find v4r0
        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, context=my.context, version='max', revision=None, use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(0, revision)

        
        # create a new test.txt file
        my.file_path = "./biz_test_version.txt"
        file = open(my.file_path, 'w')
        file.write("whatever")
        file.close()

        # check in another revision v4r5 
        checkin = FileCheckin(my.person, my.file_path, "main", context=my.context, is_revision=True, is_current=False)
        checkin.execute()
        my.assertEquals(4, checkin.snapshot.get_version())
        my.assertEquals(5, checkin.snapshot.get_value('revision'))
                
        # create a new test_version.txt file
        my.file_path = "./biz_test_version.txt"
        file = open(my.file_path, 'w')
        file.write("whatever")
        file.close()
        # check in new revision v101 with a new context
        checkin = FileCheckin(my.person, my.file_path, "main", context='rev_test', is_revision=True, is_current=False)
        checkin.execute()
        my.assertEquals(1, checkin.snapshot.get_version())
        my.assertEquals(1, checkin.snapshot.get_value('revision'))

        # create a new test_version.txt file
        my.file_path = "./biz_test_version.txt"
        file = open(my.file_path, 'w')
        file.write("whatever")
        file.close()

        checkin = FileCheckin(my.person, my.file_path, "main", context='rev_test', is_revision=False, is_current=False)
        checkin.execute()
        # this should increment to v2r1
        my.assertEquals(2, checkin.snapshot.get_version())
Example #18
0
    def _test_checkin_type(my):
        my.assertEquals(my.auto_snapshot.get_version(), 2)
        dir_name = my.auto_snapshot.get_file_name_by_type('main')
        my.assertEquals(dir_name , 'naming_test_folder_naming_base_test_v002')
        
        dir_name = my.auto_snapshot2.get_file_name_by_type('main')

        my.assertEquals(1, my.auto_snapshot2.get_version())
        my.assertEquals(dir_name , '.tactic_test_naming_folder_test_v001')

        dir_name = my.auto_snapshot3.get_file_name_by_type('main')
        # this takes the auto generated name
        my.assertEquals(dir_name , 'naming_test_folder3_naming_base_test_v003')


        # this one would take into account of the new naming entry introduced in _test_get_naming
        # test a blank checkin_type
        dir_path4 = "./naming_test_folder4"
        checkin = FileCheckin(my.person, dir_path4, "main", context='naming_base_test', snapshot_type='directory', checkin_type='', mode='copy')
        checkin.execute()
        my.auto_snapshot4 = checkin.get_snapshot()
        dir_name = my.auto_snapshot4.get_file_name_by_type('main')
        lib_dir = my.auto_snapshot4.get_dir('relative')
        my.assertEquals(dir_name , 'generic_phil_v004')
        my.assertEquals(lib_dir , 'unittest/cut/generic/phil')
        snapshot_xml = my.auto_snapshot4.get_xml_value('snapshot')
        checkin_type = snapshot_xml.get_nodes_attr('/snapshot','checkin_type')
        # un-specified checkin_type with a matching naming will default to "strict"
        my.assertEquals('strict', checkin_type[0])

        # this should pick the auto checkin_type naming convention with the _OO at the end of context
        checkin = FileCheckin(my.person, dir_path4, "main", context='naming_base_test_OO', snapshot_type='directory', checkin_type='', mode='copy')
        checkin.execute()
        my.auto_snapshot4 = checkin.get_snapshot()
        dir_name = my.auto_snapshot4.get_file_name_by_type('main')
        lib_dir = my.auto_snapshot4.get_dir('relative')
        my.assertEquals(dir_name , 'generic_phil_v001')
        my.assertEquals(lib_dir , 'unittest/cut/generic/phil')
        snapshot_xml = my.auto_snapshot4.get_xml_value('snapshot')
        checkin_type = snapshot_xml.get_nodes_attr('/snapshot','checkin_type')
        # un-specified checkin_type with a matching naming will default to "strict"
        my.assertEquals('auto', checkin_type[0])


        dir_path4 = "./naming_test_folder4"
        checkin = FileCheckin(my.person, dir_path4, "main", context='naming_base_test', snapshot_type='directory', checkin_type='auto')
        checkin.execute()
        my.auto_snapshot5 = checkin.get_snapshot()
        snapshot_xml = my.auto_snapshot5.get_xml_value('snapshot')
        checkin_type = snapshot_xml.get_nodes_attr('/snapshot','checkin_type')
        
        dir_name = my.auto_snapshot5.get_file_name_by_type('main')
        lib_dir = my.auto_snapshot5.get_dir('relative')
        my.assertEquals(dir_name , 'generic_phil_v005')
        my.assertEquals(lib_dir , 'unittest/cut/generic/phil')
        my.assertEquals('auto', checkin_type[0])

        versionless = Snapshot.get_versionless(my.auto_snapshot5.get_value('search_type'), my.auto_snapshot5.get_value('search_id'), 'naming_base_test', mode='latest', create=False)

        dir_name = versionless.get_file_name_by_type('main')
        lib_dir = versionless.get_dir('relative')
        my.assertEquals(dir_name , 'generic_phil')
        my.assertEquals(lib_dir , 'unittest/cut/generic/phil')
        path = versionless.get_lib_path_by_type()
Example #19
0
    def _test_auto_checkin(self):
        server = Config.get_value("install", "server")
        process = "process"
        person_code = self.person.get_code()

        filename = "filename.jpg"

        process = "process"

        subdirs = [
            '', '', # do 2 checkins
            'subdir',
            'subdir/subsubdir'
        ]

        for i, subdir in enumerate(subdirs):

            if subdir:
                context = "%s/%s/%s" % (process, subdir, filename)
            else:
                context = "%s/%s" % (process, filename)

            # create a new test.txt file
            file_path = "./%s" % filename
            file = open(file_path, 'w')
            file.write("test")
            file.close()


            #import time
            #start = time.time()

            checkin = FileCheckin(self.person, file_path, context=context, checkin_type='auto')
            checkin.execute()

            #print "time: ", time.time() - start
            #print "---"


            # check the returned snapshot
            snapshot = checkin.get_snapshot()
            self.assertEquals(context, snapshot.get_value("context") )
            if i != 1: # the second checkin is version 2
                version = 1
                self.assertEquals(1, snapshot.get_value("version") )
            else:
                version = 2
            self.assertEquals(version, snapshot.get_value("version") )

            # check the file object data
            file_objects = snapshot.get_all_file_objects()
            self.assertEquals(1, len(file_objects))
            file_object = file_objects[0]
            repo_filename = file_object.get_value("file_name")

            if server:
                expected = "filename_process_%s_v%0.3d.jpg" % (server, version)
            else:
                expected = "filename_process_v%0.3d.jpg" % (version)
            self.assertEquals(expected, repo_filename)

            relative_dir = file_object.get_value("relative_dir")
            if subdir:
                expected = "unittest/person/%s/process/.versions/%s" % (person_code, subdir)
            else:
                expected = "unittest/person/%s/process/.versions" % person_code
            self.assertEquals(expected, relative_dir)

            asset_dir = Config.get_value("checkin", "asset_base_dir", sub_key="default")
            path = "%s/%s/%s" % (asset_dir, relative_dir, repo_filename)


            # make sure the path from the snapshot is correct
            snapshot_path = snapshot.get_path_by_type("main")
            self.assertEquals(path, snapshot_path)


            exists = os.path.exists(path)
            self.assertEquals(True, exists)


            # check that a versionless has been created
            versionless = Snapshot.get_versionless(self.person.get_search_type(), self.person.get_id(), context, mode='latest', create=False)

            self.assertNotEquals( None, versionless)

            self.assertEquals(-1, versionless.get_value("version") )

            versionless_path = versionless.get_path_by_type("main", "lib")
            versionless_dir = os.path.dirname(versionless_path)

            # test that it is a link
            lexists = os.path.lexists(versionless_path)
            self.assertEquals(True, lexists)

            # check the real path links to the versioned path
            real_path = os.path.realpath(versionless_path)
            self.assertEquals(real_path, path)

            # check that it actually points to a valid path
            exists = os.path.exists(versionless_path)
            self.assertEquals(True, exists)
Example #20
0
    def _test_strict_checkin(self):

        server = Config.get_value("install", "server")
        #process = "process"
        person_code = self.person.get_code()

        filename = "filename.jpg"

        process = "strict"

        subcontexts = [
            '',
            '',  # do 2 checkins
            'hi',
            'hi',
            'medium',
            'low',
        ]

        for i, subcontext in enumerate(subcontexts):

            if subcontext:
                context = "%s/%s" % (process, subcontext)
            else:
                context = process

            # create a new test.txt file
            file_path = "./%s" % filename
            file = open(file_path, 'w')
            file.write("test")
            file.close()

            #import time
            #start = time.time()

            checkin = FileCheckin(self.person,
                                  file_path,
                                  context=context,
                                  checkin_type='strict')
            checkin.execute()
            snapshot = checkin.get_snapshot()
            #print "time: ", time.time() - start
            #print "---"

            # make sure there is no latest versionless except for process/low
            versionless = Snapshot.get_versionless(
                self.person.get_search_type(),
                self.person.get_id(),
                context,
                mode='latest',
                create=False)

            versionless_current = Snapshot.get_versionless(
                self.person.get_search_type(),
                self.person.get_id(),
                context,
                mode='current',
                create=False)

            if context == 'strict/low':
                self.assertNotEquals(None, versionless)
                file_objects = versionless.get_all_file_objects()
                self.assertEquals(1, len(file_objects))

                file_object = file_objects[0]
                relative_dir = file_object.get_value("relative_dir")
                file_name = file_object.get_value("file_name")
                self.assertEquals(file_name, 'filename_latest.jpg')
            else:
                self.assertEquals(None, versionless)

            # make sure there is no current versionless except for process/hi
            if context == 'strict/hi':
                self.assertNotEquals(None, versionless_current)
                file_objects = versionless_current.get_all_file_objects()
                self.assertEquals(1, len(file_objects))

                file_object = file_objects[0]
                relative_dir = file_object.get_value("relative_dir")
                file_name = file_object.get_value("file_name")
                self.assertEquals(file_name, 'filename_current.jpg')

            else:
                self.assertEquals(None, versionless_current)

            path = snapshot.get_path_by_type("main")

            asset_dir = Config.get_value("checkin",
                                         "asset_base_dir",
                                         sub_key="default")

            file_objects = snapshot.get_all_file_objects()
            self.assertEquals(1, len(file_objects))

            file_object = file_objects[0]
            relative_dir = file_object.get_value("relative_dir")
            file_name = file_object.get_value("file_name")

            test_path = "%s/%s/%s" % (asset_dir, relative_dir, file_name)
            self.assertEquals(test_path, path)
Example #21
0
    def _test_symlink(self):
        if os.name == 'nt':
            return

        # create a new test.txt file
        file_path = "./symlink.txt"
        file = open(file_path, 'w')
        file.write("symlink test")
        file.close()

        file_path2 = "./symlink_append.txt"
        file = open(file_path2, 'w')
        file.write("append test")
        file.close()

        checkin = FileCheckin(self.person,
                              file_path,
                              context="sym_test",
                              checkin_type='auto')
        checkin.execute()
        snap = checkin.get_snapshot()
        versionless_snap = Snapshot.get_versionless(
            self.person.get_search_type(),
            self.person.get_id(),
            "sym_test",
            mode='latest',
            create=False)
        self.assertEquals(True, isinstance(versionless_snap, Snapshot))

        main_lib_path = snap.get_lib_path_by_type('main')
        self.assertEquals(
            main_lib_path.endswith(
                '/sym_test/.versions/symlink_sym_test_v001.txt'), True)
        if versionless_snap:
            lib_path = versionless_snap.get_lib_path_by_type('main')
            self.assertEquals(True, os.path.exists(lib_path))
            rel_path = os.readlink(lib_path)
            lib_dir = os.path.dirname(lib_path)

            # this is essentially handle_link() in FileUndo class
            wd = os.getcwd()
            os.chdir(lib_dir)
            real_path = os.path.join(lib_dir, os.path.abspath(rel_path))
            # lib_path points to real_path

            expected_rel_path = Common.relative_path(lib_path, real_path)
            self.assertEquals(True, os.path.exists(real_path))
            self.assertEquals(expected_rel_path, rel_path)
            os.chdir(wd)

        # if not inplace or preallocate mode, keep_file_name should be False
        checkin = FileAppendCheckin(snap.get_code(), [file_path2],
                                    file_types=['add'],
                                    keep_file_name=False,
                                    checkin_type='auto')
        checkin.execute()
        snap = checkin.get_snapshot()
        main_lib_path = snap.get_lib_path_by_type('add')
        self.assertEquals(snap.get_value('is_current'), True)
        self.assertEquals(snap.get_value('is_latest'), True)
        self.assertEquals(
            main_lib_path.endswith(
                '/sym_test/.versions/symlink_append_sym_test_v001.txt'), True)
        versionless_snap = Snapshot.get_versionless(
            self.person.get_search_type(),
            self.person.get_id(),
            "sym_test",
            mode='latest',
            create=False)
        if versionless_snap:
            lib_path = versionless_snap.get_lib_path_by_type('add')
            self.assertEquals(
                lib_path.endswith('/sym_test/symlink_append_sym_test.txt'),
                True)
            self.assertEquals(os.path.exists(lib_path), True)
Example #22
0
    def _test_auto_checkin(self):
        server = Config.get_value("install", "server")
        process = "process"
        person_code = self.person.get_code()

        filename = "filename.jpg"

        process = "process"

        subdirs = [
            '',
            '',  # do 2 checkins
            'subdir',
            'subdir/subsubdir'
        ]

        for i, subdir in enumerate(subdirs):

            if subdir:
                context = "%s/%s/%s" % (process, subdir, filename)
            else:
                context = "%s/%s" % (process, filename)

            # create a new test.txt file
            file_path = "./%s" % filename
            file = open(file_path, 'w')
            file.write("test")
            file.close()

            #import time
            #start = time.time()

            checkin = FileCheckin(self.person,
                                  file_path,
                                  context=context,
                                  checkin_type='auto')
            checkin.execute()

            #print "time: ", time.time() - start
            #print "---"

            # check the returned snapshot
            snapshot = checkin.get_snapshot()
            self.assertEquals(context, snapshot.get_value("context"))
            if i != 1:  # the second checkin is version 2
                version = 1
                self.assertEquals(1, snapshot.get_value("version"))
            else:
                version = 2
            self.assertEquals(version, snapshot.get_value("version"))

            # check the file object data
            file_objects = snapshot.get_all_file_objects()
            self.assertEquals(1, len(file_objects))
            file_object = file_objects[0]
            repo_filename = file_object.get_value("file_name")

            if server:
                expected = "filename_process_%s_v%0.3d.jpg" % (server, version)
            else:
                expected = "filename_process_v%0.3d.jpg" % (version)
            self.assertEquals(expected, repo_filename)

            relative_dir = file_object.get_value("relative_dir")
            if subdir:
                expected = "unittest/person/%s/process/.versions/%s" % (
                    person_code, subdir)
            else:
                expected = "unittest/person/%s/process/.versions" % person_code
            self.assertEquals(expected, relative_dir)

            asset_dir = Config.get_value("checkin",
                                         "asset_base_dir",
                                         sub_key="default")
            path = "%s/%s/%s" % (asset_dir, relative_dir, repo_filename)

            # make sure the path from the snapshot is correct
            snapshot_path = snapshot.get_path_by_type("main")
            self.assertEquals(path, snapshot_path)

            exists = os.path.exists(path)
            self.assertEquals(True, exists)

            # check that a versionless has been created
            versionless = Snapshot.get_versionless(
                self.person.get_search_type(),
                self.person.get_id(),
                context,
                mode='latest',
                create=False)

            self.assertNotEquals(None, versionless)

            self.assertEquals(-1, versionless.get_value("version"))

            versionless_path = versionless.get_path_by_type("main", "lib")
            versionless_dir = os.path.dirname(versionless_path)

            # test that it is a link
            lexists = os.path.lexists(versionless_path)
            self.assertEquals(True, lexists)

            # check the real path links to the versioned path
            real_path = os.path.realpath(versionless_path)
            self.assertEquals(real_path, path)

            # check that it actually points to a valid path
            exists = os.path.exists(versionless_path)
            self.assertEquals(True, exists)
Example #23
0
    def _test_with_naming(self):

        server = Config.get_value("install", "server")
        process = "process"
        person_code = self.person.get_code()

        filename = "filename.jpg"

        process = "naming"

        subdirs = ['']

        # create a naming
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "naming/*")
        naming.set_value("file_naming", "TEST{basefile}_v{version}.{ext}")
        naming.commit()

        # create 2nd naming where 
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "naming/empty_dir_test")
        naming.set_value("file_naming", "TEST{basefile}_v{version}.{ext}")
        naming.set_value("dir_naming", "{@GET(.description)}")
        naming.commit()

        # create 3rd latest_versionless naming where 
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "strict/low")
        naming.set_value("file_naming", "{basefile}_latest.{ext}")
        naming.set_value("dir_naming", "{@GET(.description)}")
        naming.set_value("latest_versionless", "1")
        naming.commit()

        # create 4th current_versionless naming where 
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "strict/hi")
        naming.set_value("file_naming", "{basefile}_current.{ext}")
        naming.set_value("dir_naming", "{@GET(.description)}")
        naming.set_value("current_versionless", "1")
        naming.commit()

        self.clear_naming()


        for i, subdir in enumerate(subdirs):

            if subdir:
                context = "%s/%s/%s" % (process, subdir, filename)
            else:
                context = "%s/%s" % (process, filename)

            # create a new test.txt file
            file_path = "./%s" % filename
            file = open(file_path, 'w')
            file.write("test")
            file.close()

           
 


            #checkin = FileCheckin(self.person, file_path, context=context, checkin_type='auto')
            #checkin = FileCheckin(self.person, file_path, context=context, checkin_type='strict')
            checkin = FileCheckin(self.person, file_path, context=context)
            checkin.execute()

            # ensure that the check-in type is strict
            checkin_type = checkin.get_checkin_type()
            self.assertEquals("strict", checkin_type)

            snapshot = checkin.get_snapshot()

            checked_context = snapshot.get_value("context")


            path = snapshot.get_path_by_type("main")
            basename = os.path.basename(path)
            expected = "TESTfilename_v001.jpg"
            self.assertEquals(expected, basename)


        # create a new test.txt file
        file_path = "./%s" % filename
        file = open(file_path, 'w')
        file.write("test2")
        file.close()
        checkin = FileCheckin(self.person, file_path, context='naming/empty_dir_test')
        checkin.execute()
Example #24
0
    def _test_with_naming(self):

        server = Config.get_value("install", "server")
        process = "process"
        person_code = self.person.get_code()

        filename = "filename.jpg"

        process = "naming"

        subdirs = ['']

        # create a naming
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "naming/*")
        naming.set_value("file_naming", "TEST{basefile}_v{version}.{ext}")
        naming.commit()

        # create 2nd naming where
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "naming/empty_dir_test")
        naming.set_value("file_naming", "TEST{basefile}_v{version}.{ext}")
        naming.set_value("dir_naming", "{@GET(.description)}")
        naming.commit()

        # create 3rd latest_versionless naming where
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "strict/low")
        naming.set_value("file_naming", "{basefile}_latest.{ext}")
        naming.set_value("dir_naming", "{@GET(.description)}")
        naming.set_value("latest_versionless", "1")
        naming.commit()

        # create 4th current_versionless naming where
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "strict/hi")
        naming.set_value("file_naming", "{basefile}_current.{ext}")
        naming.set_value("dir_naming", "{@GET(.description)}")
        naming.set_value("current_versionless", "1")
        naming.commit()

        self.clear_naming()

        for i, subdir in enumerate(subdirs):

            if subdir:
                context = "%s/%s/%s" % (process, subdir, filename)
            else:
                context = "%s/%s" % (process, filename)

            # create a new test.txt file
            file_path = "./%s" % filename
            file = open(file_path, 'w')
            file.write("test")
            file.close()

            #checkin = FileCheckin(self.person, file_path, context=context, checkin_type='auto')
            #checkin = FileCheckin(self.person, file_path, context=context, checkin_type='strict')
            checkin = FileCheckin(self.person, file_path, context=context)
            checkin.execute()

            # ensure that the check-in type is strict
            checkin_type = checkin.get_checkin_type()
            self.assertEquals("strict", checkin_type)

            snapshot = checkin.get_snapshot()

            checked_context = snapshot.get_value("context")

            path = snapshot.get_path_by_type("main")
            basename = os.path.basename(path)
            expected = "TESTfilename_v001.jpg"
            self.assertEquals(expected, basename)

        # create a new test.txt file
        file_path = "./%s" % filename
        file = open(file_path, 'w')
        file.write("test2")
        file.close()
        checkin = FileCheckin(self.person,
                              file_path,
                              context='naming/empty_dir_test')
        checkin.execute()
Example #25
0
    def postprocess(my):
        sobject = my.sobject
        texture_snapshot = Snapshot.get_latest_by_sobject(sobject)
        web = WebContainer.get_web()

        source_search_key = web.get_form_value("predefined_source")
        if source_search_key and texture_snapshot:
            source = Search.get_by_search_key(source_search_key)
            source_snapshot = Snapshot.get_latest_by_sobject(source)
            
            xml = texture_snapshot.get_xml_value("snapshot")
            builder = SnapshotBuilder(xml)
            builder.add_ref_by_snapshot(source_snapshot)
            texture_snapshot.set_value("snapshot", builder.to_string() )
            texture_snapshot.commit()

            return




        # if no files have been uploaded, don't do anything
        field_storage = web.get_form_value("add_source")
        if field_storage == "":
            return

        # process and get the uploaded files
        upload = FileUpload()
        upload.set_field_storage(field_storage)
        upload.execute()
        files = upload.get_files()
        if not files:
            return

        file_types = upload.get_file_types()
        
        asset_code = sobject.get_value("asset_code")

        # checkin this as a new source
        import os
        source_code = os.path.basename(files[0])
        source_description = "Referred to %s" % my.sobject.get_code()
        source_category = "default"
        source = TextureSource.create(asset_code, source_code, \
            source_category, source_description)

        # add the file as a snapshot to this source
        checkin = FileCheckin(source, files, file_types )
        checkin.execute()

        source_snapshot = Snapshot.get_latest_by_sobject(source)
        xml = source_snapshot.get_xml_value("snapshot")
        builder = SnapshotBuilder(xml)
        builder.add_fref_by_snapshot(texture_snapshot)
        source_snapshot.set_value("snapshot", builder.to_string() )
        source_snapshot.commit()


        # Modify the snapshot in the original texture to reference this
        # source.  This assumes that the other uploaded snapshot has
        # already been dealt with.
        source_snapshot = checkin.get_snapshot()

        # FIXME: what if no texture was uploaded???
        xml = texture_snapshot.get_xml_value("snapshot")
        builder = SnapshotBuilder(xml)
        builder.add_ref_by_snapshot(source_snapshot)
        texture_snapshot.set_value("snapshot", builder.to_string() )
        texture_snapshot.commit()
Example #26
0
    def _test_file_naming_manual_version(my):
       
        my.clear_naming()

        naming = SearchType.create('config/naming')
        naming.set_value('search_type','unittest/person')
        naming.set_value('context', 'naming_test')
        naming.set_value('dir_naming', '{project.code}/cut/{sobject.code}')
        naming.set_value('file_naming', '{sobject.code}_v{snapshot.version}.{ext}')
        naming.commit()

        from pyasm.common import Environment
        base_dir = Environment.get_asset_dir()
        
        preallocated = my.snapshot.get_preallocated_path(file_type='maya', file_name='what_v005.ma',ext='ma')
        my.assertEquals('%s/unittest/cut/phil/phil_v001.ma'%base_dir, preallocated)

        # now turn on manual_version
        naming.set_value('manual_version', True)
        naming.commit()

        my.clear_naming()
        preallocated = my.snapshot.get_preallocated_path(file_type='maya', file_name='what_v005.ma',ext='ma')
        my.assertEquals('%s/unittest/cut/phil/phil_v005.ma'%base_dir, preallocated)
        
        # Uppercase V and more digits
        preallocated = my.snapshot.get_preallocated_path(file_type='maya', file_name='what_V0010.ma',ext='ma')
        my.assertEquals('%s/unittest/cut/phil/phil_v010.ma'%base_dir, preallocated)
        #my.snapshot.commit()

        # zero or negative version is ignored
        # create a new manual version test.txt file
        file_path = "./naming_v0000_test.txt"
        for i in range(0,4):
            file = open(file_path, 'w')
            file.write("whatever")
            file.close()
        checkin = FileCheckin(my.person, file_path, "main", context='naming_test')
        checkin.execute()
        my.snapshot = checkin.get_snapshot()
        my.assertEquals(11, my.snapshot.get_version())

        # zero or negative version is ignored
        # create a new manual version test.txt file
        file_path = "./naming_v-23_test.txt"
        for i in range(0,4):
            file = open(file_path, 'w')
            file.write("whatever")
            file.close()
        checkin = FileCheckin(my.person, file_path, "main", context='naming_test')
        checkin.execute()
        my.snapshot = checkin.get_snapshot()
        my.assertEquals(12, my.snapshot.get_version())
        file_path = "./naming_v025_test.txt"
        for i in range(0,4):
            file = open(file_path, 'w')
            file.write("whatever")
            file.close()
        checkin = FileCheckin(my.person, file_path, "main", context='naming_test')
        checkin.execute()
        my.snapshot = checkin.get_snapshot()
        my.assertEquals(25, my.snapshot.get_version())


        naming.delete()

        my.clear_naming()
Example #27
0
    def _test_snapshot(my):

        # create a new test.txt file
        for i in range(0, 4):

            # create a new test.txt file
            my.file_path = "./biz_test.txt"
            for i in range(0, 4):
                file = open(my.file_path, 'w')
                file.write("whatever")
                file.close()

            checkin = FileCheckin(my.person,
                                  my.file_path,
                                  "main",
                                  context=my.context)
            checkin.execute()

            # get snapshot from database
            snapshot = checkin.get_snapshot()
            code = snapshot.get_value("code")
            s = Search("sthpw/snapshot")
            s.add_filter("code", code)
            snapshot = s.get_sobject()

        # get version -1
        snapshot = Snapshot.get_by_version(my.search_type,
                                           my.search_id,
                                           context=my.context,
                                           version=-1,
                                           use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)

        # latest version
        snapshot = Snapshot.get_latest(my.search_type,
                                       my.search_id,
                                       context=my.context,
                                       use_cache=False)
        version = snapshot.get_version()

        my.assertEquals('biz_test_test_v004.txt',
                        snapshot.get_all_file_names()[0])
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(0, revision)

        for i in range(0, 2):
            file = open(my.file_path, 'w')
            file.write("whatever")
            file.close()
            # check in 2 current revisions
            checkin = FileCheckin(my.person,
                                  my.file_path,
                                  "main",
                                  context=my.context,
                                  is_revision=True,
                                  is_current=True)
            checkin.execute()
            snapshot = checkin.get_snapshot()

            # get snapshot from database
            #snapshot = checkin.get_snapshot()
            code = snapshot.get_value("code")
            s = Search("sthpw/snapshot")
            s.add_filter("code", code)
            snapshot = s.get_sobject()

        # get current version and revision latest
        snapshot = Snapshot.get_by_version(my.search_type,
                                           my.search_code,
                                           context=my.context,
                                           version=0,
                                           revision=-1,
                                           use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(2, revision)

        # get revision
        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         context=my.context,
                                         version=-1,
                                         revision=-1,
                                         use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(2, revision)
        is_latest = snapshot.get_value('is_latest')
        my.assertEquals(True, is_latest)

        # v4r1 should not be latest
        snapshot = Snapshot.get_by_version(my.search_type,
                                           my.search_id,
                                           context=my.context,
                                           version=4,
                                           revision=1,
                                           use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(1, revision)
        is_latest = snapshot.get_value('is_latest')
        my.assertEquals(False, is_latest)

        # is_latest is v4r2, so can't find v4r0 any more
        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         context=my.context,
                                         version=-1,
                                         revision=None,
                                         use_cache=False)

        my.assertEquals(None, snapshot)

        # use max to find v4r0
        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         context=my.context,
                                         version='max',
                                         revision=None,
                                         use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(0, revision)

        # add 2 non current revisions
        for i in range(0, 2):
            file = open(my.file_path, 'w')
            file.write("whatever")
            file.close()

            # check in 2 revisions
            checkin = FileCheckin(my.person,
                                  my.file_path,
                                  "main",
                                  context=my.context,
                                  is_revision=True,
                                  is_current=False)
            checkin.execute()

        # get latest version and revision
        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         context=my.context,
                                         version=-1,
                                         revision=-1,
                                         use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(4, revision)
        is_latest = snapshot.get_value('is_latest')
        my.assertEquals(True, is_latest)

        # get current version and latest revision (but current v4r2 takes precedence)
        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         context=my.context,
                                         version=0,
                                         revision=-1,
                                         use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(2, revision)
        is_latest = snapshot.get_value('is_latest')
        my.assertEquals(False, is_latest)

        # get current version and 0 revision (but current v4r2 is the real current, returns None)
        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         context=my.context,
                                         version=0,
                                         revision=None,
                                         use_cache=False)
        my.assertEquals(None, snapshot)

        # is_latest is v4r4, so can't find v4r0 any more
        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         context=my.context,
                                         version=-1,
                                         revision=None,
                                         use_cache=False)
        my.assertEquals(None, snapshot)

        # use max to find v4r0
        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         context=my.context,
                                         version='max',
                                         revision=None,
                                         use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(0, revision)

        # create a new test.txt file
        my.file_path = "./biz_test_version.txt"
        file = open(my.file_path, 'w')
        file.write("whatever")
        file.close()

        # check in another revision v4r5
        checkin = FileCheckin(my.person,
                              my.file_path,
                              "main",
                              context=my.context,
                              is_revision=True,
                              is_current=False)
        checkin.execute()
        my.assertEquals(4, checkin.snapshot.get_version())
        my.assertEquals(5, checkin.snapshot.get_value('revision'))

        # create a new test_version.txt file
        my.file_path = "./biz_test_version.txt"
        file = open(my.file_path, 'w')
        file.write("whatever")
        file.close()
        # check in new revision v101 with a new context
        checkin = FileCheckin(my.person,
                              my.file_path,
                              "main",
                              context='rev_test',
                              is_revision=True,
                              is_current=False)
        checkin.execute()
        my.assertEquals(1, checkin.snapshot.get_version())
        my.assertEquals(1, checkin.snapshot.get_value('revision'))

        # create a new test_version.txt file
        my.file_path = "./biz_test_version.txt"
        file = open(my.file_path, 'w')
        file.write("whatever")
        file.close()

        checkin = FileCheckin(my.person,
                              my.file_path,
                              "main",
                              context='rev_test',
                              is_revision=False,
                              is_current=False)
        checkin.execute()
        # this should increment to v2r1
        my.assertEquals(2, checkin.snapshot.get_version())
Example #28
0
    def postprocess(self):
        sobject = self.sobject
        texture_snapshot = Snapshot.get_latest_by_sobject(sobject)
        web = WebContainer.get_web()

        source_search_key = web.get_form_value("predefined_source")
        if source_search_key and texture_snapshot:
            source = Search.get_by_search_key(source_search_key)
            source_snapshot = Snapshot.get_latest_by_sobject(source)

            xml = texture_snapshot.get_xml_value("snapshot")
            builder = SnapshotBuilder(xml)
            builder.add_ref_by_snapshot(source_snapshot)
            texture_snapshot.set_value("snapshot", builder.to_string())
            texture_snapshot.commit()

            return

        # if no files have been uploaded, don't do anything
        field_storage = web.get_form_value("add_source")
        if field_storage == "":
            return

        # process and get the uploaded files
        upload = FileUpload()
        upload.set_field_storage(field_storage)
        upload.execute()
        files = upload.get_files()
        if not files:
            return

        file_types = upload.get_file_types()

        asset_code = sobject.get_value("asset_code")

        # checkin this as a new source
        import os
        source_code = os.path.basename(files[0])
        source_description = "Referred to %s" % self.sobject.get_code()
        source_category = "default"
        source = TextureSource.create(asset_code, source_code, \
            source_category, source_description)

        # add the file as a snapshot to this source
        checkin = FileCheckin(source, files, file_types)
        checkin.execute()

        source_snapshot = Snapshot.get_latest_by_sobject(source)
        xml = source_snapshot.get_xml_value("snapshot")
        builder = SnapshotBuilder(xml)
        builder.add_fref_by_snapshot(texture_snapshot)
        source_snapshot.set_value("snapshot", builder.to_string())
        source_snapshot.commit()

        # Modify the snapshot in the original texture to reference this
        # source.  This assumes that the other uploaded snapshot has
        # already been dealt with.
        source_snapshot = checkin.get_snapshot()

        # FIXME: what if no texture was uploaded???
        xml = texture_snapshot.get_xml_value("snapshot")
        builder = SnapshotBuilder(xml)
        builder.add_ref_by_snapshot(source_snapshot)
        texture_snapshot.set_value("snapshot", builder.to_string())
        texture_snapshot.commit()
Example #29
0
    def _test_level(my):

        # add a country
        sobject = SearchType.create("unittest/country")
        sobject.set_value("code", "canada")
        sobject.commit()

        # add a city
        sobject = SearchType.create("unittest/city")
        sobject.set_value("code", "toronto")
        sobject.set_value("country_code", "canada")
        sobject.commit()

        my.person.set_value("city_code", "toronto")
        my.person.commit()

        level_type = "unittest/city"
        level_code = "toronto"
        level = Search.get_by_code(level_type, level_code)
        level_id = level.get_id()

        # create a new test.txt file
        my.file_path = "./biz_test.txt"
        for i in range(0, 4):
            file = open(my.file_path, 'w')
            file.write("whatever")
            file.close()

        # creating version 5
        checkin = FileCheckin(my.person,
                              my.file_path,
                              "main",
                              context=my.context)
        checkin.execute()

        my.file_path = "./biz_fulltest.txt"
        file = open(my.file_path, 'w')
        file.write("whatever")
        file.close()
        # for checkin using test/subtest
        checkin = FileCheckin(my.person,
                              my.file_path,
                              "main",
                              context=my.full_context)
        checkin.execute()

        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         my.context,
                                         version=-1,
                                         use_cache=True,
                                         level_type=level_type,
                                         level_id=level_id)
        # make sure we get the top level one
        my.assertEquals(5, snapshot.get_value("version"))
        my.assertEquals("", snapshot.get_value("level_type"))
        # integer None is now converted to 0
        my.assertEquals(0, snapshot.get_value("level_id"))

        # checkin the file to the level
        my.file_path = "./biz_test_level.txt"
        for i in range(0, 4):
            file = open(my.file_path, 'w')
            file.write("whatever")
            file.close()
        checkin = FileCheckin(my.person,
                              my.file_path,
                              "main",
                              context=my.context,
                              level_type=level_type,
                              level_id=level_id)
        checkin.execute()

        snapshot = checkin.get_snapshot()
        version = snapshot.get_version()
        my.assertEquals(1, version)
        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         my.context,
                                         version='-1',
                                         use_cache=True,
                                         level_type=level_type,
                                         level_id=level_id)

        my.assertEquals(level_type, snapshot.get_value("level_type"))
        my.assertEquals(level_id, snapshot.get_value("level_id"))
        my.assertEquals(1, snapshot.get_value("version"))
        my.assertEquals(True, snapshot.get_value("is_latest"))
        my.assertEquals(True, snapshot.get_value("is_current"))

        # get latest version and revision of the person and make sure
        # it has its own is_latest
        top_snapshot = Snapshot.get_snapshot(my.search_type,
                                             my.search_id,
                                             context=my.context,
                                             version=-1,
                                             revision=-1,
                                             use_cache=False)
        version = top_snapshot.get_version()
        my.assertEquals(5, version)
        revision = top_snapshot.get_value('revision')
        my.assertEquals(0, revision)
        my.assertEquals(True, top_snapshot.get_value("is_latest"))
        my.assertEquals(True, top_snapshot.get_value("is_current"))