Exemplo n.º 1
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')
Exemplo n.º 2
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')
Exemplo n.º 3
0
    def copy_sobject(my,
                     sobject,
                     dst_search_type,
                     context=None,
                     checkin_mode='inplace'):

        new_sobject = SearchType.create(dst_search_type)
        search_type = SearchType.get(dst_search_type)
        columns = SearchType.get_columns(dst_search_type)

        data = sobject.get_data()
        for name, value in data.items():
            if name in ['id', 'code', 'pipeline_code']:
                continue

            if name not in columns:
                continue

            if not value:
                continue
            new_sobject.set_value(name, value)

        new_sobject.commit()

        # get all of the current snapshots and file paths associated
        if not context:
            snapshots = Snapshot.get_all_current_by_sobject(sobject)
        else:
            snapshots = [Snapshot.get_current_by_sobject(sobject, context)]

        if not snapshots:
            return

        msgs = []
        for snapshot in snapshots:
            #file_paths = snapshot.get_all_lib_paths()
            file_paths_dict = snapshot.get_all_paths_dict()
            file_types = file_paths_dict.keys()
            if not file_types:
                continue

            # make sure the paths match the file_types
            file_paths = [file_paths_dict.get(x)[0] for x in file_types]

            mode = checkin_mode

            # checkin the files (inplace)
            try:
                context = snapshot.get_value('context')
                checkin = FileCheckin(new_sobject,
                                      context=context,
                                      file_paths=file_paths,
                                      file_types=file_types,
                                      mode=mode)
                checkin.execute()

                #print "done: ", context, new_sobject.get_related_sobjects("sthpw/snapshot")
            except CheckinException, e:
                msgs.append('Post-process Check-in Error for %s: %s ' %
                            (context, e.__str__()))
Exemplo n.º 4
0
    def _check_in_swf(my, snapshot, sobject, render, pat, final_pat,
                      render_dir, filenames):
        final_path = icon_path = ''
        for name in filenames:
            if pat.match(name):
                final_name = pat.sub(final_pat, name)
                shutil.move(render_dir + "/" + name, render_dir \
                    + "/" + final_name)
                src_path = "%s/%s" % (render_dir, final_name)
                if final_name.endswith('.png'):
                    icon_creator = IconCreator(src_path)
                    icon_creator.create_icons()
                    icon_path = icon_creator.get_icon_path()
                elif final_name.endswith('.swf'):
                    final_path = src_path
        types = ["main"]
        paths = [final_path]

        if icon_path:
            paths.append(icon_path)
            types.append('icon')
        checkin = FileCheckin(render,
                              paths,
                              types,
                              context="render",
                              column="images")
        checkin.execute()
Exemplo n.º 5
0
    def copy_sobject(my, sobject, dst_search_type, context=None, checkin_mode='inplace'):

        new_sobject = SearchType.create(dst_search_type)
        search_type = SearchType.get(dst_search_type)
        columns = SearchType.get_columns(dst_search_type)

        data = sobject.get_data()
        for name, value in data.items():
            if name in ['id','pipeline_code']:
                continue

            if name not in columns:
                continue

            if not value:
                continue

            if name == "code":
                value = Common.get_next_sobject_code(sobject, 'code')
                if not value:
                    continue
            new_sobject.set_value(name, value)
        if SearchType.column_exists(dst_search_type, "project_code"):
            project_code = Project.get_project_code()
            new_sobject.set_value("project_code", project_code)
        new_sobject.commit()



        # get all of the current snapshots and file paths associated
        if not context:
            snapshots = Snapshot.get_all_current_by_sobject(sobject)
        else:
            snapshots = [Snapshot.get_current_by_sobject(sobject, context)]

        if not snapshots:
            return

        msgs = []
        for snapshot in snapshots:
            #file_paths = snapshot.get_all_lib_paths()
            file_paths_dict = snapshot.get_all_paths_dict()
            file_types = file_paths_dict.keys()
            if not file_types:
                continue

            # make sure the paths match the file_types
            file_paths = [file_paths_dict.get(x)[0] for x in file_types]

            mode = checkin_mode

            # checkin the files (inplace)
            try:
                context = snapshot.get_value('context')
                checkin = FileCheckin(new_sobject, context=context, file_paths=file_paths, file_types=file_types, mode=mode)
                checkin.execute()

                #print "done: ", context, new_sobject.get_related_sobjects("sthpw/snapshot")
            except CheckinException, e:
                msgs.append('Post-process Check-in Error for %s: %s ' %(context, e.__str__()))
Exemplo n.º 6
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')
Exemplo n.º 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)
Exemplo n.º 8
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)
Exemplo n.º 9
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)
Exemplo n.º 10
0
    def execute(my):   
        import urllib
        from pyasm.checkin import FileCheckin
        from pyasm.search import Search
        pic_dict = {}
        pics = []
        order_dict = {}
        for ocode in my.orders:
            order = my.server.eval("@SOBJECT(twog/order['code','%s'])" % ocode)[0]
            ord_s = Search('twog/order')
            ord_s.add_filter('code',ocode)
            order = ord_s.get_sobject()
            if order:
                order_dict[ocode] = order
                poster = order.get_value('imdb_poster_url')
                if poster not in pics:
                    pics.append(poster)
                    pic_dict[poster] = [ocode]
                else:
                    pic_dict[poster].append(ocode)
        pic_places = {}
        number = 0
        for pic in pics:
            extension_s = pic.split('.')
            extension = extension_s[len(extension_s) - 1]
            place = '/var/www/html/imdb_images/associator%s.%s' % (number, extension) 
            f = open(place,'wb')
            f.write(urllib.urlopen(pic).read())
            f.close()
            pic_places[pic] = place
            number = number + 1

        for pic in pics:
            server_path = pic_places[pic]
            linked_orders = pic_dict[pic]
            for ocode in linked_orders: 
                sobject = order_dict[ocode]
                if sobject:
                    file_types = ['main']
                    context = "icon"
                    checkin = FileCheckin(
                        sobject,
                        file_paths=server_path,
                        file_types=file_types,
                        context=context,
                        mode="copy"
                    )
                    checkin.execute()

        
            

        return ''
Exemplo n.º 11
0
    def _test_data_flow(my):

        # create a dummy sobject
        sobject = SearchType.create("unittest/city")
        sobject.commit()

        # check in a file to the city
        file_path = "./ttteeesssttt.txt"
        file = open(file_path, 'w')
        file.write("test test test")
        file.close()

        file_paths = [file_path]
        file_types = ['main']
        context = "publish"
        from pyasm.checkin import FileCheckin
        checkin = FileCheckin(
                    sobject,
                    file_paths=file_paths,
                    file_types=file_types,
                    context="fla",
                    mode="move"
            )
        checkin.execute()


        # create a pipeline
        pipeline_xml = '''
        <pipeline>
          <process type="auto" name="a"/>
          <process type="auto" name="b"/>
          <process type="approval" name="c"/>
          <connect from="a" to="b"/>
          <connect from="b" to="c"/>
        </pipeline>
        '''
        pipeline, processes = my.get_pipeline(pipeline_xml)

        sobject.set_value("pipeline_code", pipeline.get_code())
        sobject.commit()


        process = processes.get("a")
        process.set_json_value("workflow", {
            'output': {
                'sobject': 'sobject',
                'process': 'fla',
                'version': 'latest',
            }
            'checkin': ['fla'],
        } )
Exemplo n.º 12
0
    def _parse_form(my):
 
        # get the downloaded files and sort them
        web = WebContainer.get_web()
        
        my.upload_values.sort()

        filenames = []
        ticket = web.get_cookie("login_ticket")
        # create a new entry for every file
        for upload_value in my.upload_values:
            tmp_dir = Environment.get_tmp_dir()
            basename = os.path.basename(upload_value)
            file_path = "%s/upload/%s/%s" % (tmp_dir, ticket, basename)

            filenames.append(basename)

            creator = IconCreator(file_path)
            creator.create_icons()

            my.file_paths = [file_path]
            file_types = ["main"]

            web_path = creator.get_web_path()
            if web_path != None:
                my.file_paths.append(web_path)
                file_types.append("web")

            icon_path = creator.get_icon_path()
            if icon_path != None:
                my.file_paths.append(icon_path)
                file_types.append("icon")

            sobject = None
            if my.search_key:
                sobject = Search.get_by_search_key(my.search_key)
            else:    
                sobject = SObjectFactory.create(my.search_type)
                sobject.commit()

            checkin = FileCheckin( sobject, my.file_paths, file_types,\
                column=my.column )
             
            checkin.set_description(web.get_form_value(SObjectUploadCmd.PUBLISH_COMMENT))
            checkin.execute()
            my.repo_file_list.append(checkin.file_dict)
            

        
        my.description = "Added files: %s" % filenames
Exemplo n.º 13
0
    def postprocess(my):

        if my.sobject.is_general_asset():
            return
        # check to see if there are any snapshots
        # context is specified here to ignore any icon snapshots
        snapshot = Snapshot.get_latest_by_sobject(my.sobject,
                                                  context='publish')

        if snapshot:
            return

        column = "snapshot"
        new_file_paths = []
        file_paths = []
        # copy the default file to /tmp
        template_code = my.get_default_code()
        template = my.get_template_obj()
        if template:
            template_code = template.get_value('code')
            tmpl_snapshot = Snapshot.get_latest_by_sobject(template)

            file_paths = tmpl_snapshot.get_all_lib_paths()
        else:
            file_types = ['.fla', '.png', '_icon.png', '.swf']
            # TODO: this is a web depedency we don't need
            from pyasm.web import WebContainer
            web = WebContainer.get_web()
            for type in file_types:
                file_paths.append('%s/template/%s%s' % (web.get_context_dir(), \
                    template_code, type))

        for file_path in file_paths:
            # rename and copy each file to /tmp
            base_name = os.path.basename(file_path)
            base_name = File.remove_file_code(base_name)
            base_name = base_name.replace(template_code, \
                my.get_naming().get_current_code(my.sobject) )

            # do a straight copy : No undo
            tmp_dir = Environment.get_tmp_dir()
            new_file_path = "%s/download/%s" % (tmp_dir, base_name)
            shutil.copyfile(file_path, new_file_path)
            new_file_paths.append(new_file_path)

        file_types = [".fla", ".png", "icon", ".swf"]
        checkin = FileCheckin( my.sobject, new_file_paths, file_types, \
            snapshot_type="flash", column=column  )
        checkin.execute()
Exemplo n.º 14
0
    def postprocess(my):

        if my.sobject.is_general_asset():
            return
        # check to see if there are any snapshots
        # context is specified here to ignore any icon snapshots
        snapshot = Snapshot.get_latest_by_sobject(my.sobject, context='publish')

        if snapshot:
            return

        column = "snapshot"
        new_file_paths = []
        file_paths = []
        # copy the default file to /tmp
        template_code = my.get_default_code()
        template = my.get_template_obj()
        if template:
            template_code = template.get_value('code')
            tmpl_snapshot = Snapshot.get_latest_by_sobject(template)
                    
            file_paths = tmpl_snapshot.get_all_lib_paths()
        else:
            file_types = ['.fla','.png','_icon.png','.swf']    
            # TODO: this is a web depedency we don't need
            from pyasm.web import WebContainer
            web = WebContainer.get_web()
            for type in file_types:
                file_paths.append('%s/template/%s%s' % (web.get_context_dir(), \
                    template_code, type))
                
        for file_path in file_paths:
            # rename and copy each file to /tmp
            base_name = os.path.basename(file_path)
            base_name = File.remove_file_code(base_name)
            base_name = base_name.replace(template_code, \
                my.get_naming().get_current_code(my.sobject) )
            
            # do a straight copy : No undo
            tmp_dir = Environment.get_tmp_dir()
            new_file_path = "%s/download/%s" % (tmp_dir,base_name)
            shutil.copyfile(file_path, new_file_path)
            new_file_paths.append(new_file_path)


        file_types = [".fla", ".png", "icon",".swf"]
        checkin = FileCheckin( my.sobject, new_file_paths, file_types, \
            snapshot_type="flash", column=column  )
        checkin.execute()
Exemplo n.º 15
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()
Exemplo n.º 16
0
    def _parse_form(my):

        # get the downloaded files and sort them
        web = WebContainer.get_web()

        my.upload_values.sort()

        filenames = []
        ticket = web.get_cookie("login_ticket")
        # create a new entry for every file
        for upload_value in my.upload_values:
            tmp_dir = Environment.get_tmp_dir()
            basename = os.path.basename(upload_value)
            file_path = "%s/upload/%s/%s" % (tmp_dir, ticket, basename)

            filenames.append(basename)

            creator = IconCreator(file_path)
            creator.create_icons()

            my.file_paths = [file_path]
            file_types = ["main"]

            web_path = creator.get_web_path()
            if web_path != None:
                my.file_paths.append(web_path)
                file_types.append("web")

            icon_path = creator.get_icon_path()
            if icon_path != None:
                my.file_paths.append(icon_path)
                file_types.append("icon")

            sobject = None
            if my.search_key:
                sobject = Search.get_by_search_key(my.search_key)
            else:
                sobject = SObjectFactory.create(my.search_type)
                sobject.commit()

            checkin = FileCheckin(sobject, my.file_paths, file_types, column=my.column)

            checkin.set_description(web.get_form_value(SObjectUploadCmd.PUBLISH_COMMENT))
            checkin.execute()
            my.repo_file_list.append(checkin.file_dict)

        my.description = "Added files: %s" % filenames
Exemplo n.º 17
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))
Exemplo n.º 18
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) )
Exemplo n.º 19
0
 def _check_in_swf(my, snapshot, sobject, render, pat, final_pat, render_dir, filenames):
     final_path = icon_path = ''
     for name in filenames:
         if pat.match(name):
             final_name = pat.sub(final_pat, name)
             shutil.move(render_dir + "/" + name, render_dir \
                 + "/" + final_name)
             src_path = "%s/%s" % (render_dir, final_name) 
             if final_name.endswith('.png'):
                 icon_creator = IconCreator(src_path)
                 icon_creator.create_icons()
                 icon_path = icon_creator.get_icon_path()
             elif final_name.endswith('.swf'):
                 final_path = src_path
     types = ["main"]
     paths = [final_path]
     
     if icon_path:
         paths.append(icon_path)
         types.append('icon')
     checkin = FileCheckin(render, paths, types, context="render", column="images")
     checkin.execute()
Exemplo n.º 20
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)
Exemplo n.º 21
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)
Exemplo n.º 22
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')
Exemplo n.º 23
0
    def setup(self):

        # create a dummy sobject
        sobject = SearchType.create("unittest/city")
        sobject.commit()

        # check in a file to the city
        file_path = "./test.txt"
        file = open(file_path, 'w')
        file.write("test test test")
        file.close()

        file_paths = [file_path]
        file_types = ['main']
        context = "publish"
        from pyasm.checkin import FileCheckin
        checkin = FileCheckin(sobject,
                              file_paths=file_paths,
                              file_types=file_types,
                              context="test",
                              mode="move")
        checkin.execute()

        return sobject
Exemplo n.º 24
0
    def _test_notification(self):
        
        sobject = SearchType.create("sthpw/notification")
        sobject.set_value('subject', 'TACTIC Unittest 001: a new item has been added.')
        sobject.set_value("event",'insert|unittest/country')
        sobject.commit()

        sobject = SearchType.create("sthpw/notification")
        sobject.set_value('subject', 'TACTIC Unittest 002: an item has been updated.')
        sobject.set_value("event",'update|unittest/country')
        sobject.commit()

        sobject = SearchType.create("sthpw/notification")
        sobject.set_value('subject', 'TACTIC Unittest 003: New notes added.')
        sobject.set_value("event",'insert|sthpw/note')
        sobject.commit()      

        sobject = SearchType.create("sthpw/notification")
        sobject.set_value('subject', 'TACTIC Unittest 004: New task assigned.')
        sobject.set_value("event",'change|sthpw/task|status')
        sobject.commit()

        sobject = SearchType.create("sthpw/notification")
        sobject.set_value('subject', 'TACTIC Unittest 005: task status has been changed.')
        sobject.set_value("event",'change|sthpw/task|assigned')
        sobject.commit()

        sobject = SearchType.create("sthpw/notification")
        sobject.set_value('subject', 'TACTIC Unittest 006: Files are checked in.')
        sobject.set_value("event",'checkin|unittest/country')
        sobject.commit()

        # Item added
        self.clear_notification()
        sobject1 = SearchType.create("unittest/country")
        sobject1.set_value('code', 'test_update_trigger')
        sobject1.commit()

        # Updated item
        sobject1.set_value('code','success') 
        sobject1.commit()  

        # Note added
        Note.create(self.person, "test note2", context='default2')

        # Task assigned
        sobject = Task.create(self.person,'hi','hellotest',assigned="test assigned")

        # Task status changed
        tasks = Task.get_by_sobject(self.person)
        tasks[0].set_value('process','success')
        tasks[0].commit()

        # Files are checked in
        file_path = "./notification_test_check.txt"
        for i in range(0,4):
            file = open(file_path, 'w')
            file.write("whatever")
            file.close()
        checkin = FileCheckin(sobject1, file_path, "main", context='test', checkin_type='auto')
        checkin.execute()
        Trigger.call_all_triggers()

        if os.path.exists(file_path):
            os.remove(file_path)
Exemplo n.º 25
0
    def convert_images(self):

        render_dir = self.render_context.get_render_dir()

        # copy for now
        file_root = "maya_render"
        padding = 4
	type = "png"

        # check the expected images
        single = True
        if single == True:
            render_path = "%s/%s.iff" % (render_dir,file_root)
            final_path = "%s/%s.%s" % (render_dir,file_root,type)
            cmd = "imgcvt -f iff -t %s %s %s" % \
                (type, render_path, final_path)
            print cmd
            os.system(cmd)



            # create a render log entry
            file = open("%s/session.xml" % render_dir, "r")
            session_xml = file.read()
            file.close()

            # attach the sobject and snapshot to the render
            snapshot = self.render_context.get_snapshot()
            sobject = self.render_context.get_sobject()

            frame_range = self.render_context.get_frame_range()

            render = Render.create(sobject, snapshot, session_xml, frame_range.get_key(), version=1)

            # checkin the render
            icon_creator = IconCreator(final_path)
            icon_creator.create_icons()

            web = icon_creator.get_web_path()
            icon = icon_creator.get_icon_path()
            paths = [final_path,web,icon]
            types = ["main","web","icon"]

            self.description = "Rendered image"

            # check in the sobject
            checkin = FileCheckin(sobject, paths, types, \
                context="icon", column="images")
            checkin.execute()

            # check in the render
            checkin = FileCheckin(render, paths, types, \
                context="render", column="images")
            checkin.execute()




        else:
            render_path = "%s/%s.iff.####" % (render_dir,file_root)
            final_path = "%s/%s.####.%s" % (render_dir,file_root,type)

            frame_range = self.render_context.get_frame_range()
            render_paths = FileGroup.expand_paths(render_path,frame_range.get_key())
            final_paths = FileGroup.expand_paths(final_path,frame_range.get_key())


            for i in range(0, len(render_paths)):

                # convert the image
                cmd = "imgcvt -f iff -t %s %s %s" % \
                    (type, render_paths[i], final_paths[i])
                print cmd
                os.system(cmd)
Exemplo n.º 26
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())
Exemplo n.º 27
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") )
Exemplo n.º 28
0
        if my._is_flash(search_type_obj):
            snapshot_type = "flash"
        else:
            snapshot_type = "file"

        checkin = FileCheckin( sobject, my.file_paths, file_types,
            column=my.column, snapshot_type=snapshot_type )
        # handle the description
        web = WebContainer.get_web()

        comment = web.get_form_value(my.PUBLISH_COMMENT)
        my.add_description('[%s] %s ' %(sobject.get_code(), comment))
        checkin.set_description(comment)
        
        
        checkin.execute()
        checkin_info = []
        for key, value in checkin.file_dict.items():
            if not my.get_response_list(): 
                checkin_info.append("'%s=%s'" %(key, value))
            else:
                for type in my.get_response_list():
                    if type in key:
                        checkin_info.append("'%s=%s'" %(key, value))
                        break
                    
        my.repo_file_list.append(','.join(checkin_info))
        

    def get_response_list(my):
        ''' define a list of file extensions that we want to display in 
Exemplo n.º 29
0
    def execute(self):

        project_code = self.kwargs.get('project_code')
        project_title = self.kwargs.get('project_title')
        project_type = self.kwargs.get('project_type')
        project_description = self.kwargs.get("description")
        if not project_type:
            project_type = "simple"

        is_template = self.kwargs.get('is_template')
        project_theme = self.kwargs.get('project_theme')

        use_default_side_bar = self.kwargs.get('use_default_side_bar')
        if use_default_side_bar in [False, 'false']:
            use_default_side_bar = False
        else:
            use_default_side_bar = True

        assert project_code
        assert project_type
        if project_type:
            # check to see if it exists
            search = Search("sthpw/project_type")
            search.add_filter("code", project_type)
            project_type_sobj = search.get_sobject()
            if not project_type_sobj:

                # just create a default one in this case if it is named
                # after the project code
                if not is_template and project_type == project_code:
                    project_type = 'default'

                # create a new project type
                search = Search("sthpw/project_type")
                search.add_filter("code", project_type)
                project_type_sobj = search.get_sobject()
                if not project_type_sobj:
                    project_type_sobj = SearchType.create("sthpw/project_type")
                    project_type_sobj.set_value("code", project_type)
                    project_type_sobj.set_value("type", "simple")

                    project_type_sobj.commit()

        # set the current project to Admin
        Project.set_project("admin")

        # create a new project sobject
        project = SearchType.create("sthpw/project")
        project.set_value("code", project_code)
        project.set_value("title", project_title)
        project.set_value("type", project_type)
        if project_description:
            project.set_value("description", project_description)
        # set the update of the database to current (this is obsolete)
        #project.set_value("last_db_update", "now()")
        project.set_value("last_version_update", "2.5.0.v01")

        if is_template in ['true', True, 'True']:
            project.set_value("is_template", True)
        else:
            project.set_value("is_template", False)

        if project_type != "default":
            category = Common.get_display_title(project_type)
            project.set_value("category", category)

        project.commit()

        # if there is an image, check it in
        upload_path = self.kwargs.get("project_image_path")
        if upload_path:
            if not os.path.exists(upload_path):
                raise TacticException(
                    "Cannot find upload image for project [%s]" % upload_path)
            file_type = 'main'

            file_paths = [upload_path]
            file_types = [file_type]

            source_paths = [upload_path]
            from pyasm.biz import IconCreator
            if os.path.isfile(upload_path):
                icon_creator = IconCreator(upload_path)
                icon_creator.execute()

                web_path = icon_creator.get_web_path()
                icon_path = icon_creator.get_icon_path()
                if web_path:
                    file_paths = [upload_path, web_path, icon_path]
                    file_types = [file_type, 'web', 'icon']

            from pyasm.checkin import FileCheckin
            checkin = FileCheckin(project,
                                  context='icon',
                                  file_paths=file_paths,
                                  file_types=file_types)
            checkin.execute()

        # find project's base_type
        base_type = project.get_base_type()

        if not base_type and project_type == 'unittest':
            base_type = 'unittest'
        elif not base_type:
            base_type = 'simple'

        # get the database for this project
        db_resource = project.get_project_db_resource()

        database = db_resource.get_database_impl()
        #database = DatabaseImpl.get()
        database_type = database.get_database_type()
        if database_type == 'Oracle':
            raise TacticException(
                "Creation of project is not supported. Please create manually")

        # creating project database
        print "Creating database '%s' ..." % project_code
        try:
            # create the datbase
            database.create_database(db_resource)
        except Exception as e:
            print str(e)
            print "WARNING: Error creating database [%s]" % project_code

        # import the appropriate schema with config first
        database.import_schema(db_resource, base_type)

        self.create_schema(project_code)

        # before we upgrade, we have to commit the transaction
        # This is because upgrade actually run as separate processes
        # so if not commit has been made, the tables from importing the
        # schema will not have existed yet
        DbContainer.commit_thread_sql()

        self.upgrade()

        # import the appropriate data
        database.import_default_data(db_resource, base_type)

        # import default links
        if use_default_side_bar:
            self.import_default_side_bar()

        # create specified stypes
        self.create_search_types()

        # create theme
        if project_theme:
            self.create_theme(project_theme)

        # set as main project
        is_main_project = self.kwargs.get("is_main_project")
        if is_main_project in [True, 'true', 'on']:
            Config.set_value("install", "default_project", project_code)
            Config.save_config()
            Config.reload_config()

        # initiate the DbContainer
        DbContainer.get('sthpw')

        self.info['result'] = "Finished creating project [%s]." % project_code

        print "Done."
Exemplo n.º 30
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()
Exemplo n.º 31
0
    def convert_images(my):

        render_dir = my.render_context.get_render_dir()

        # copy for now
        file_root = "maya_render"
        padding = 4
        type = "png"

        # check the expected images
        single = True
        if single == True:
            render_path = "%s/%s.iff" % (render_dir, file_root)
            final_path = "%s/%s.%s" % (render_dir, file_root, type)
            cmd = "imgcvt -f iff -t %s %s %s" % \
                (type, render_path, final_path)
            print cmd
            os.system(cmd)

            # create a render log entry
            file = open("%s/session.xml" % render_dir, "r")
            session_xml = file.read()
            file.close()

            # attach the sobject and snapshot to the render
            snapshot = my.render_context.get_snapshot()
            sobject = my.render_context.get_sobject()

            frame_range = my.render_context.get_frame_range()

            render = Render.create(sobject,
                                   snapshot,
                                   session_xml,
                                   frame_range.get_key(),
                                   version=1)

            # checkin the render
            icon_creator = IconCreator(final_path)
            icon_creator.create_icons()

            web = icon_creator.get_web_path()
            icon = icon_creator.get_icon_path()
            paths = [final_path, web, icon]
            types = ["main", "web", "icon"]

            my.description = "Rendered image"

            # check in the sobject
            checkin = FileCheckin(sobject, paths, types, \
                context="icon", column="images")
            checkin.execute()

            # check in the render
            checkin = FileCheckin(render, paths, types, \
                context="render", column="images")
            checkin.execute()

        else:
            render_path = "%s/%s.iff.####" % (render_dir, file_root)
            final_path = "%s/%s.####.%s" % (render_dir, file_root, type)

            frame_range = my.render_context.get_frame_range()
            render_paths = FileGroup.expand_paths(render_path,
                                                  frame_range.get_key())
            final_paths = FileGroup.expand_paths(final_path,
                                                 frame_range.get_key())

            for i in range(0, len(render_paths)):

                # convert the image
                cmd = "imgcvt -f iff -t %s %s %s" % \
                    (type, render_paths[i], final_paths[i])
                print cmd
                os.system(cmd)
Exemplo n.º 32
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)
Exemplo n.º 33
0
        # checkin all of the files into the sobjects
        if my._is_flash(search_type_obj):
            snapshot_type = "flash"
        else:
            snapshot_type = "file"

        checkin = FileCheckin(sobject, my.file_paths, file_types, column=my.column, snapshot_type=snapshot_type)
        # handle the description
        web = WebContainer.get_web()

        comment = web.get_form_value(my.PUBLISH_COMMENT)
        my.add_description("[%s] %s " % (sobject.get_code(), comment))
        checkin.set_description(comment)

        checkin.execute()
        checkin_info = []
        for key, value in checkin.file_dict.items():
            if not my.get_response_list():
                checkin_info.append("'%s=%s'" % (key, value))
            else:
                for type in my.get_response_list():
                    if type in key:
                        checkin_info.append("'%s=%s'" % (key, value))
                        break

        my.repo_file_list.append(",".join(checkin_info))

    def get_response_list(my):
        """ define a list of file extensions that we want to display in 
            commmand's response. By default, it will allow any files"""
Exemplo n.º 34
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)
Exemplo n.º 35
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()
Exemplo n.º 36
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()
Exemplo n.º 37
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)
Exemplo n.º 38
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()
Exemplo n.º 39
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)
Exemplo n.º 40
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())
Exemplo n.º 41
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)
Exemplo n.º 42
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"))
Exemplo n.º 43
0
    def execute(self):

        project_code = self.kwargs.get('project_code')
        project_title = self.kwargs.get('project_title')
        project_type = self.kwargs.get('project_type')
        project_description = self.kwargs.get("description")
        if not project_type:
            project_type = "simple"

        is_template = self.kwargs.get('is_template')
        project_theme = self.kwargs.get('project_theme')

        use_default_side_bar = self.kwargs.get('use_default_side_bar')
        if use_default_side_bar in [False, 'false']:
            use_default_side_bar = False
        else:
            use_default_side_bar = True


        assert project_code
        assert project_type
        if project_type:
            # check to see if it exists
            search = Search("sthpw/project_type")
            search.add_filter("code", project_type)
            project_type_sobj = search.get_sobject()
            if not project_type_sobj:

                # just create a default one in this case if it is named
                # after the project code
                if not is_template and project_type == project_code:
                    project_type = 'default'
                    
                # create a new project type
                search = Search("sthpw/project_type")
                search.add_filter("code", project_type)
                project_type_sobj = search.get_sobject()
                if not project_type_sobj:
                    project_type_sobj = SearchType.create("sthpw/project_type")
                    project_type_sobj.set_value("code", project_type)
                    project_type_sobj.set_value("type", "simple")

                    project_type_sobj.commit()

        # set the current project to Admin
        Project.set_project("admin")


        # create a new project sobject
        project = SearchType.create("sthpw/project")
        project.set_value("code", project_code)
        project.set_value("title", project_title)
        project.set_value("type", project_type)
        if project_description:
            project.set_value("description", project_description)
        # set the update of the database to current (this is obsolete)
        #project.set_value("last_db_update", "now()")
        project.set_value("last_version_update", "2.5.0.v01")

        if is_template in ['true', True, 'True']:
            project.set_value("is_template", True)
        else:
            project.set_value("is_template", False)


        if project_type != "default":
            category = Common.get_display_title(project_type)
            project.set_value("category", category)


        project.commit()
       
 

        # if there is an image, check it in
        upload_path = self.kwargs.get("project_image_path")
        if upload_path:
            if not os.path.exists(upload_path):
                raise TacticException("Cannot find upload image for project [%s]" % upload_path)
            file_type = 'main'

            file_paths = [upload_path]
            file_types = [file_type]

            source_paths = [upload_path]
            from pyasm.biz import IconCreator
            if os.path.isfile(upload_path):
                icon_creator = IconCreator(upload_path)
                icon_creator.execute()

                web_path = icon_creator.get_web_path()
                icon_path = icon_creator.get_icon_path()
                if web_path:
                    file_paths = [upload_path, web_path, icon_path]
                    file_types = [file_type, 'web', 'icon']

            from pyasm.checkin import FileCheckin
            checkin = FileCheckin(project, context='icon', file_paths=file_paths, file_types=file_types)
            checkin.execute()

        # find project's base_type
        base_type = project.get_base_type()

        if not base_type and project_type =='unittest':
            base_type = 'unittest'
        elif not base_type:
            base_type = 'simple'


        # get the database for this project
        db_resource = project.get_project_db_resource()

        database = db_resource.get_database_impl()
        #database = DatabaseImpl.get()
        database_type = database.get_database_type()
        if database_type == 'Oracle':
            raise TacticException("Creation of project is not supported. Please create manually")




        # creating project database
        print "Creating database '%s' ..." % project_code
        try:
            # create the datbase
            database.create_database(db_resource)
        except Exception as e:
            print str(e)
            print "WARNING: Error creating database [%s]" % project_code





        # import the appropriate schema with config first
        database.import_schema(db_resource, base_type)

        self.create_schema(project_code)

        # before we upgrade, we have to commit the transaction
        # This is because upgrade actually run as separate processes
        # so if not commit has been made, the tables from importing the
        # schema will not have existed yet
        DbContainer.commit_thread_sql()


        self.upgrade()

        # import the appropriate data
        database.import_default_data(db_resource, base_type)


        # import default links
        if use_default_side_bar:
            self.import_default_side_bar()


        # create specified stypes
        self.create_search_types()


        # create theme
        if project_theme:
            self.create_theme(project_theme)



        # set as main project
        is_main_project = self.kwargs.get("is_main_project")
        if is_main_project in [True,'true','on']:
            Config.set_value("install", "default_project", project_code)
            Config.save_config()
            Config.reload_config()

        # initiate the DbContainer
        DbContainer.get('sthpw')


        self.info['result'] = "Finished creating project [%s]."%project_code

        print "Done."
Exemplo n.º 44
0
    def _test_notification(my):

        sobject = SearchType.create("sthpw/notification")
        sobject.set_value('subject',
                          'TACTIC Unittest 001: a new item has been added.')
        sobject.set_value("event", 'insert|unittest/country')
        sobject.commit()

        sobject = SearchType.create("sthpw/notification")
        sobject.set_value('subject',
                          'TACTIC Unittest 002: an item has been updated.')
        sobject.set_value("event", 'update|unittest/country')
        sobject.commit()

        sobject = SearchType.create("sthpw/notification")
        sobject.set_value('subject', 'TACTIC Unittest 003: New notes added.')
        sobject.set_value("event", 'insert|sthpw/note')
        sobject.commit()

        sobject = SearchType.create("sthpw/notification")
        sobject.set_value('subject', 'TACTIC Unittest 004: New task assigned.')
        sobject.set_value("event", 'change|sthpw/task|status')
        sobject.commit()

        sobject = SearchType.create("sthpw/notification")
        sobject.set_value(
            'subject', 'TACTIC Unittest 005: task status has been changed.')
        sobject.set_value("event", 'change|sthpw/task|assigned')
        sobject.commit()

        sobject = SearchType.create("sthpw/notification")
        sobject.set_value('subject',
                          'TACTIC Unittest 006: Files are checked in.')
        sobject.set_value("event", 'checkin|unittest/country')
        sobject.commit()

        # Item added
        my.clear_notification()
        sobject1 = SearchType.create("unittest/country")
        sobject1.set_value('code', 'test_update_trigger')
        sobject1.commit()

        # Updated item
        sobject1.set_value('code', 'success')
        sobject1.commit()

        # Note added
        Note.create(my.person, "test note2", context='default2')

        # Task assigned
        sobject = Task.create(my.person,
                              'hi',
                              'hellotest',
                              assigned="test assigned")

        # Task status changed
        tasks = Task.get_by_sobject(my.person)
        tasks[0].set_value('process', 'success')
        tasks[0].commit()

        # Files are checked in
        file_path = "./notification_test_check.txt"
        for i in range(0, 4):
            file = open(file_path, 'w')
            file.write("whatever")
            file.close()
        checkin = FileCheckin(sobject1,
                              file_path,
                              "main",
                              context='test',
                              checkin_type='auto')
        checkin.execute()
        Trigger.call_all_triggers()

        if os.path.exists(file_path):
            os.remove(file_path)
Exemplo n.º 45
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()
Exemplo n.º 46
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)
Exemplo n.º 47
0
    def execute(my):

        project_code = my.kwargs.get("project_code")
        project_title = my.kwargs.get("project_title")
        project_type = my.kwargs.get("project_type")
        if not project_type:
            project_type = "simple"

        is_template = my.kwargs.get("is_template")
        project_theme = my.kwargs.get("project_theme")

        use_default_side_bar = my.kwargs.get("use_default_side_bar")
        if use_default_side_bar in [False, "false"]:
            use_default_side_bar = False
        else:
            use_default_side_bar = True

        assert project_code
        assert project_type
        if project_type:
            # check to see if it exists
            search = Search("sthpw/project_type")
            search.add_filter("code", project_type)
            project_type_sobj = search.get_sobject()
            if not project_type_sobj:

                # just create a default one in this case if it is named
                # after the project code
                if not is_template and project_type == project_code:
                    project_type = "default"

                # create a new project type
                search = Search("sthpw/project_type")
                search.add_filter("code", project_type)
                project_type_sobj = search.get_sobject()
                if not project_type_sobj:
                    project_type_sobj = SearchType.create("sthpw/project_type")
                    project_type_sobj.set_value("code", project_type)
                    project_type_sobj.set_value("type", "simple")
                    project_type_sobj.commit()

        # set the current project to Admin
        Project.set_project("admin")

        # create a new project sobject
        project = SearchType.create("sthpw/project")
        project.set_value("code", project_code)
        project.set_value("title", project_title)
        project.set_value("type", project_type)
        # set the update of the database to current (this is obsolete)
        # project.set_value("last_db_update", "now()")
        project.set_value("last_version_update", "2.5.0.v01")

        if is_template in ["true", True, "True"]:
            project.set_value("is_template", True)
        else:
            project.set_value("is_template", False)

        if project_type != "default":
            category = Common.get_display_title(project_type)
            project.set_value("category", category)

        project.commit()

        # if there is an image, check it in
        upload_path = my.kwargs.get("project_image_path")
        if upload_path:
            if not os.path.exists(upload_path):
                raise TacticException("Cannot find upload image for project [%s]" % upload_path)
            file_type = "main"

            file_paths = [upload_path]
            file_types = [file_type]

            source_paths = [upload_path]
            from pyasm.biz import IconCreator

            if os.path.isfile(upload_path):
                icon_creator = IconCreator(upload_path)
                icon_creator.execute()

                web_path = icon_creator.get_web_path()
                icon_path = icon_creator.get_icon_path()
                if web_path:
                    file_paths = [upload_path, web_path, icon_path]
                    file_types = [file_type, "web", "icon"]

            from pyasm.checkin import FileCheckin

            checkin = FileCheckin(project, context="icon", file_paths=file_paths, file_types=file_types)
            checkin.execute()

        # find project's base_type
        base_type = project.get_base_type()

        if not base_type and project_type == "unittest":
            base_type = "unittest"
        elif not base_type:
            base_type = "simple"

        # get the database for this project
        db_resource = project.get_project_db_resource()

        database = db_resource.get_database_impl()
        # database = DatabaseImpl.get()
        database_type = database.get_database_type()
        if database_type == "Oracle":
            raise TacticException("Creation of project is not supported. Please create manually")

        # creating project database
        print "Creating database '%s' ..." % project_code
        try:
            # create the datbase
            database.create_database(db_resource)
        except Exception, e:
            print str(e)
            print "WARNING: Error creating database [%s]" % project_code
Exemplo n.º 48
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)
Exemplo n.º 49
0
    def execute(my):

        project_code = my.kwargs.get('project_code')
        project_title = my.kwargs.get('project_title')
        project_type = my.kwargs.get('project_type')
        if not project_type:
            project_type = "simple"

        is_template = my.kwargs.get('is_template')
        project_theme = my.kwargs.get('project_theme')

        use_default_side_bar = my.kwargs.get('use_default_side_bar')
        if use_default_side_bar in [False, 'false']:
            use_default_side_bar = False
        else:
            use_default_side_bar = True

        assert project_code
        assert project_type
        if project_type:
            # check to see if it exists
            search = Search("sthpw/project_type")
            search.add_filter("code", project_type)
            project_type_sobj = search.get_sobject()
            if not project_type_sobj:

                # just create a default one in this case if it is named
                # after the project code
                if not is_template and project_type == project_code:
                    project_type = 'default'

                # create a new project type
                search = Search("sthpw/project_type")
                search.add_filter("code", project_type)
                project_type_sobj = search.get_sobject()
                if not project_type_sobj:
                    project_type_sobj = SearchType.create("sthpw/project_type")
                    project_type_sobj.set_value("code", project_type)
                    project_type_sobj.set_value("type", "simple")
                    project_type_sobj.commit()

        # set the current project to Admin
        Project.set_project("admin")

        # create a new project sobject
        project = SearchType.create("sthpw/project")
        project.set_value("code", project_code)
        project.set_value("title", project_title)
        project.set_value("type", project_type)
        # set the update of the database to current (this is obsolete)
        #project.set_value("last_db_update", "now()")
        project.set_value("last_version_update", "2.5.0.v01")

        if is_template in ['true', True, 'True']:
            project.set_value("is_template", True)
        else:
            project.set_value("is_template", False)

        if project_type != "default":
            category = Common.get_display_title(project_type)
            project.set_value("category", category)

        project.commit()

        # if there is an image, check it in
        upload_path = my.kwargs.get("project_image_path")
        if upload_path:
            if not os.path.exists(upload_path):
                raise TacticException(
                    "Cannot find upload image for project [%s]" % upload_path)
            file_type = 'main'

            file_paths = [upload_path]
            file_types = [file_type]

            source_paths = [upload_path]
            from pyasm.biz import IconCreator
            if os.path.isfile(upload_path):
                icon_creator = IconCreator(upload_path)
                icon_creator.execute()

                web_path = icon_creator.get_web_path()
                icon_path = icon_creator.get_icon_path()
                if web_path:
                    file_paths = [upload_path, web_path, icon_path]
                    file_types = [file_type, 'web', 'icon']

            from pyasm.checkin import FileCheckin
            checkin = FileCheckin(project,
                                  context='icon',
                                  file_paths=file_paths,
                                  file_types=file_types)
            checkin.execute()

        # find project's base_type
        base_type = project.get_base_type()

        if not base_type and project_type == 'unittest':
            base_type = 'unittest'
        elif not base_type:
            base_type = 'simple'

        # get the database for this project
        db_resource = project.get_project_db_resource()

        database = db_resource.get_database_impl()
        #database = DatabaseImpl.get()
        database_type = database.get_database_type()
        if database_type == 'Oracle':
            raise TacticException(
                "Creation of project is not supported. Please create manually")

        # creating project database
        print "Creating database '%s' ..." % project_code
        try:
            # create the datbase
            database.create_database(db_resource)
        except Exception, e:
            print str(e)
            print "WARNING: Error creating database [%s]" % project_code
Exemplo n.º 50
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()