Example #1
0
    def get_path_from_sobject(my, sobject):

        icon_path = None
        path = None

        search_type = sobject.get_search_type()
        search_code = sobject.get_value("code", no_exception=True)
        if not search_code:
            search_code = sobject.get_id()

        # FIXME: make this faster
        snapshot = Snapshot.get_snapshot(search_type, search_code, context='icon')
        if not snapshot:
            snapshot = Snapshot.get_snapshot(search_type, search_code, context='publish')
        if not snapshot:
            snapshot = Snapshot.get_snapshot(search_type, search_code, process='publish')
        if not snapshot:
            snapshot = Snapshot.get_snapshot(search_type, search_code)


        if snapshot:
            file_type = "web"
            icon_path = snapshot.get_web_path_by_type(file_type)

            file_type = "main"
            path = snapshot.get_web_path_by_type(file_type)

        if icon_path:
            path = icon_path
        elif path:
            path = my.find_icon_link(path)

 
        return path
Example #2
0
    def get_display(self):
        sobject = self.get_current_sobject()

        snapshots = []
        if isinstance(sobject, Layer):
            # for layer renders, we try to get all render sobjects
            renders = Render.get_all_by_sobject(sobject)
            if renders:
                snapshots = Snapshot.get_by_sobjects(renders, is_current=True)
        else:  # for object that has direct snapshots like plates
            snapshot = Snapshot.get_current_by_sobject(sobject)
            if snapshot:
                snapshots.append(snapshot)

        if not snapshots:
            return "<i>- no files -</i>"

        div = DivWdg()

        for snapshot in snapshots:
            file_types = snapshot.get_all_file_types()
            table = Table(css='embed')

            for file_type in file_types:
                table.add_row()

                table.add_cell(self.get_open_wdg(snapshot, file_type))
                dir = snapshot.get_client_lib_dir(file_type=file_type)

                table.add_cell("%s: <i>%s</i>" % (file_type, dir))

            div.add(table)
        return div
Example #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__()))
Example #4
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__()))
Example #5
0
    def get_display(self):
        sobject = self.get_current_sobject()

        snapshots = []
        if isinstance(sobject, Layer):
            # for layer renders, we try to get all render sobjects
            renders = Render.get_all_by_sobject(sobject)
            if renders:
                snapshots = Snapshot.get_by_sobjects(renders, is_current=True)
        else: # for object that has direct snapshots like plates
            snapshot = Snapshot.get_current_by_sobject(sobject)
            if snapshot:
                snapshots.append(snapshot)

        if not snapshots:
            return "<i>- no files -</i>"

        div = DivWdg()

        for snapshot in snapshots:
            file_types = snapshot.get_all_file_types()
            table = Table(css='embed')

            for file_type in file_types:
                table.add_row()
                
                table.add_cell( self.get_open_wdg(snapshot, file_type) )
                dir = snapshot.get_client_lib_dir(file_type=file_type)
                
                
                table.add_cell( "%s: <i>%s</i>" % (file_type, dir) )
         

            div.add(table)
        return div
Example #6
0
    def _test_symlink(self):
        if os.name == 'nt':
            return

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

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


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

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

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

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

        # if not inplace or preallocate mode, keep_file_name should be False
        checkin = FileAppendCheckin(snap.get_code(), [file_path2], file_types=['add'], keep_file_name=False, checkin_type='auto')
        checkin.execute()
        snap = checkin.get_snapshot()
        main_lib_path = snap.get_lib_path_by_type('add')
        self.assertEquals(snap.get_value('is_current'), True)
        self.assertEquals(snap.get_value('is_latest'), True)
        self.assertEquals(main_lib_path.endswith('/sym_test/.versions/symlink_append_sym_test_v001.txt'), True)
        versionless_snap = Snapshot.get_versionless(self.person.get_search_type(), self.person.get_id(), "sym_test", mode='latest', create=False)
        if versionless_snap:
            lib_path = versionless_snap.get_lib_path_by_type('add')
            self.assertEquals(lib_path.endswith('/sym_test/symlink_append_sym_test.txt'), True)
            self.assertEquals(os.path.exists(lib_path), True)
Example #7
0
def get_dirs_with_naming(search_key=None, process_list=None):
    import json
    from pyasm.biz import Snapshot
    from pyasm.biz import Project
    from pyasm.search import SearchType

    dir_naming = Project.get_dir_naming()

    dirs_dict = {
        'versions': [],
        'versionless': [],
    }

    if process_list:
        processes = process_list
    else:
        from pyasm.biz import Pipeline
        sobjects = server.server._get_sobjects(search_key)
        sobject = sobjects[0]
        pipelines = Pipeline.get_by_search_type(sobject.get_base_search_type())
        processes = pipelines[0].get_process_names()

    search_type, search_code = server.split_search_key(search_key)
    search_type = search_type.split('?')[0]

    for process in processes:
        # querying sobjects every time because we need to refresh naming
        sobject = server.query(search_type,
                               filters=[('code', search_code)],
                               return_sobjects=True,
                               single=True)
        dir_naming.set_sobject(sobject)
        file_object = SearchType.create('sthpw/file')
        dir_naming.set_file_object(file_object)
        snapshot = Snapshot.create(sobject,
                                   snapshot_type='file',
                                   context=process,
                                   commit=False)
        dir_naming.set_snapshot(snapshot)
        dirs_dict['versions'].append(dir_naming.get_dir('relative'))

        snapshot_versionless = Snapshot.create(sobject,
                                               snapshot_type='file',
                                               context=process,
                                               process=process,
                                               commit=False,
                                               version=-1)
        dir_naming.set_snapshot(snapshot_versionless)
        dirs_dict['versionless'].append(dir_naming.get_dir('relative'))

    return json.dumps(dirs_dict, separators=(',', ':'))
Example #8
0
    def _handle_ref_node(self, node, widget, upstream=False, recursive=True):

        # get the reference snapshot (should maybe use the loader or
        # at least share the code
        instance = Xml.get_attribute(node,"instance")
        search_type = Xml.get_attribute(node,"search_type")
        search_id = Xml.get_attribute(node,"search_id")
        context = Xml.get_attribute(node,"context")
        version = Xml.get_attribute(node,"version")
        # this is often the Maya file node name or XSI long clip name
        node_name = Xml.get_attribute(node, "node")
        my_name = Xml.get_node_name(node)

        # get the snapshot
        ref_snapshot = Snapshot.get_by_version(search_type, search_id,\
                    context, version)
        #ref_snapshot = Snapshot.get_latest(search_type,search_id, context)
        if ref_snapshot == None:
            widget.add("|---> <font color='red'>Error: No reference found for [%s, %s, %s]</font>" % \
                (search_type, search_id, context) )
            return

        toggle_id = self.generate_unique_id('toggle')
        widget.add(FloatDivWdg(), toggle_id)
        version = ref_snapshot.get_value("version")

        
        try: 
            sobject = ref_snapshot.get_sobject()
        except SObjectNotFoundException, e:
            widget.add('[%s|%s] may have been deleted or is not viewable.' % (ref_snapshot.get_value('search_type'),\
                ref_snapshot.get_value('search_id')))
            return
Example #9
0
    def get_message(my):

        search_type_obj = my.sobject.get_search_type_obj()
        title = search_type_obj.get_title()

        notification_message = my.notification.get_value("message")

        message = "%s %s" % (title, my.sobject.get_name())
        if notification_message:
            message = "%s (%s)" % (message, notification_message)

        update_desc = my.sobject.get_update_description()
        parent_search_type = my.sobject.get_value('search_type')
        grand_parent = None
        if 'prod/submission' in parent_search_type:
            parent = Search.get_by_id(parent_search_type,
                                      my.sobject.get_value('search_id'))
            snapshot = Snapshot.get_latest_by_sobject(parent, 'publish')
            if snapshot:
                file_name = snapshot.get_file_name_by_type('main')
                update_desc = '%s \n %s \n' % (update_desc, file_name)
            grand_parent = parent.get_parent()
            if grand_parent:
                update_desc = '%s %s' % (update_desc, grand_parent.get_code())
        command_desc = my.command.get_description()

        message = '%s\n\nReport from transaction:\n%s\n\n%s' \
            % (message, update_desc, command_desc)
        return message
Example #10
0
 def get_xml_value(my):
     if my.sobject.has_value(my.name):
         return my.sobject.get_xml_value( my.name )
     else:
         from pyasm.biz import Snapshot
         return Snapshot.get_latest_by_sobject(\
                 my.sobject).get_xml_value( my.name )
Example #11
0
 def get_xml_value(my):
     if my.sobject.has_value(my.name):
         return my.sobject.get_xml_value(my.name)
     else:
         from pyasm.biz import Snapshot
         return Snapshot.get_latest_by_sobject(\
                 my.sobject).get_xml_value( my.name )
    def get_path_from_sobject(my, sobject):

        icon_path = None
        path = None

        base_search_type = sobject.get_base_search_type()
        if base_search_type == "sthpw/snapshot":
            #sobject = sobject.get_parent()
            snapshot = sobject

        else:
            search_type = sobject.get_search_type()
            search_code = sobject.get_value("code", no_exception=True)
            if not search_code:
                search_code = sobject.get_id()


            # FIXME: make this faster

            snapshot = Snapshot.get_snapshot(search_type, search_code, process=['icon','publish',''])

        if snapshot:
            file_type = "web"
            icon_path = snapshot.get_web_path_by_type(file_type)

            file_type = "main"
            path = snapshot.get_web_path_by_type(file_type)

        if icon_path:
            path = icon_path
        elif path:
            path = my.find_icon_link(path)

 
        return path
Example #13
0
    def get_loader_xml(my, ticket, project_code, snapshot_code, context="", options=""):
        '''uses the loader to generate an execute xml that can be
        used to load the assets'''
        try:
            my.init(ticket)
            Project.set_project(project_code)

            snapshot = Snapshot.get_by_code(snapshot_code)

            # get the loader implementation
            loader_context = ProdLoaderContext()
            loader_context.set_context(context)

            # pass on any message options for the loader
            if options != "":
                loader_context.set_options(options)

            loader = loader_context.get_loader(snapshot)
            loader.execute()

            execute_xml = loader.get_execute_xml()
            xml = execute_xml.get_xml()

        finally:
            DbContainer.close_all()
        
        return xml
Example #14
0
    def get_message(my):
        
        search_type_obj = my.sobject.get_search_type_obj()
        title = search_type_obj.get_title()
        
        notification_message = my.notification.get_value("message")

        message = "%s %s" % (title, my.sobject.get_name())
        if notification_message:
            message = "%s (%s)" %(message, notification_message)

        update_desc = my.sobject.get_update_description()
        parent_search_type = my.sobject.get_value('search_type')
        grand_parent = None
        if 'prod/submission' in parent_search_type:
            parent = Search.get_by_id(parent_search_type, my.sobject.get_value('search_id') )
            snapshot = Snapshot.get_latest_by_sobject(parent, 'publish')
            if snapshot:
                file_name = snapshot.get_file_name_by_type('main')
                update_desc = '%s \n %s \n' %(update_desc, file_name)
            grand_parent = parent.get_parent()
            if grand_parent:
                update_desc = '%s %s'%(update_desc, grand_parent.get_code())
        command_desc = my.command.get_description()

        message = '%s\n\nReport from transaction:\n%s\n\n%s' \
            % (message, update_desc, command_desc)
        return message
Example #15
0
    def execute(my):
        from pyasm.flash.widget import FlashLayerCheckboxWdg

        web = WebContainer.get_web()
        cam_search_key = web.get_form_value(FlashRenderTableElementWdg.RENDER_CAM)
        # FIXME: why is this called "context"
        context_name = web.get_form_value(FlashRenderTableElementWdg.CONTEXT_NAME)

        # submit all the selected sobjects
        context = "publish"
        for search_key in my.search_keys:
            sobject = Search.get_by_search_key(search_key)

            snapshot = Snapshot.get_latest_by_sobject(sobject, context)
            if not snapshot:
                raise TacticException("No checkins of context '%s' for '%s' exists" % (context, sobject.get_code()))
            render = FlashGenerateExecuteXml(sobject.get_code())
            render.set_snapshot_code(snapshot.get_code())

            # render.execute()

            # store this in the appropriate queue
            dispatch = TacticDispatcher()
            dispatch.set_description("Flash Render: %s" % sobject.get_code())
            dispatch.execute_slave(render)

        my.description = "Submitted: %s" % ", ".join(my.search_keys)
Example #16
0
 def get_xml_value(self):
     if self.sobject.has_value(self.name):
         return self.sobject.get_xml_value( self.name )
     else:
         from pyasm.biz import Snapshot
         return Snapshot.get_latest_by_sobject(\
                 self.sobject).get_xml_value( self.name )
Example #17
0
    def get_path_from_sobject(my, sobject):

        icon_path = None
        path = None

        base_search_type = sobject.get_base_search_type()
        if base_search_type == "sthpw/snapshot":
            #sobject = sobject.get_parent()
            snapshot = sobject

        else:
            search_type = sobject.get_search_type()
            search_code = sobject.get_value("code", no_exception=True)
            if not search_code:
                search_code = sobject.get_id()


            # FIXME: make this faster

            snapshot = Snapshot.get_snapshot(search_type, search_code, process=['icon','publish',''])

        if snapshot:
            file_type = "web"
            icon_path = snapshot.get_web_path_by_type(file_type)

            file_type = "main"
            path = snapshot.get_web_path_by_type(file_type)

        if icon_path:
            path = icon_path
        elif path:
            path = my.find_icon_link(path)

 
        return path
Example #18
0
    def execute(my):
        from pyasm.flash.widget import FlashLayerCheckboxWdg    
        web = WebContainer.get_web()
        cam_search_key = web.get_form_value( FlashRenderTableElementWdg.RENDER_CAM)
        # FIXME: why is this called "context"
        context_name = web.get_form_value( FlashRenderTableElementWdg.CONTEXT_NAME)

        # submit all the selected sobjects
        context = "publish"
        for search_key in my.search_keys:
            sobject = Search.get_by_search_key(search_key)

            snapshot = Snapshot.get_latest_by_sobject(sobject, context)
            if not snapshot:
                raise TacticException("No checkins of context '%s' for '%s' exists" % (context, sobject.get_code() ) )
            render = FlashGenerateExecuteXml(sobject.get_code())
            render.set_snapshot_code(snapshot.get_code())
            
            #render.execute()
           
            # store this in the appropriate queue
            dispatch = TacticDispatcher()
            dispatch.set_description("Flash Render: %s" % sobject.get_code())
            dispatch.execute_slave(render)
            
        my.description = "Submitted: %s" % ", ".join(my.search_keys)
Example #19
0
 def get_xml_value(self):
     if self.sobject.has_value(self.name):
         return self.sobject.get_xml_value(self.name)
     else:
         from pyasm.biz import Snapshot
         return Snapshot.get_latest_by_sobject(\
                 self.sobject).get_xml_value( self.name )
Example #20
0
    def get_files(self):

        paths = []

        # remember this here for now
        self.files = {}
        self.snapshots = {}

        search_key = self.kwargs.get("search_key")
        sobject = SearchKey.get_by_search_key(search_key)
        # if it is deleted, return
        if not sobject:
            return []

        if isinstance(sobject, Snapshot):
            snapshots = [sobject]
        else:
            snapshots = Snapshot.get_by_sobject(sobject, "publish")

        for snapshot in snapshots:
            snapshot_paths = snapshot.get_all_lib_paths()

            files = snapshot.get_all_file_objects()

            for path, file in zip(snapshot_paths, files):

                # if the path is a directory, get all of the files
                if os.path.isdir(path):
                    for root, dirnames, filenames in os.walk(path):

                        for filename in filenames:
                            item_path = "%s/%s" % (root, filename)
                            paths.append(item_path)
                            self.files[item_path] = file
                            self.snapshots[item_path] = snapshot

                        for dirname in dirnames:
                            item_path = "%s/%s/" % (root, dirname)
                            paths.append(item_path)
                            self.files[item_path] = file
                            self.snapshots[item_path] = snapshot
                    """
                    dirlist = os.listdir(path)
                    for item in dirlist:
                        item_path = "%s%s" % (path, item)
                        if os.path.isdir(path):
                            item_path = "%s/" % item_path
                        paths.append(item_path)
                        self.files[path] = file
                    """

                else:
                    paths.append(path)
                    self.files[path] = file
                    base_dir_alias = file.get_value('base_dir_alias')
                    if not self.base_dir and base_dir_alias:
                        self.base_dir = Environment.get_asset_dir(
                            alias=base_dir_alias)

        return paths
Example #21
0
 def add_ref_by_snapshot_code(my, snapshot_code, instance_name=None, parent=None, type='ref', node_name='', tag='main'):
     snapshot = Snapshot.get_by_code(snapshot_code)
     if not snapshot:
         Environment.add_warning("Reference not found", "Found reference to snapshot [%s] which no longer exists in the Tactic database" % snapshot_code)
         return
         
     return my.add_ref_by_snapshot(snapshot, instance_name, parent, type, node_name, tag=tag)
Example #22
0
    def execute(my):
        database = "sthpw" 

        sql = DbContainer.get(database)
        value_array = sql.do_query("select code, cc from (select code, count(code) as cc from file group by code order by cc desc) as X where cc > 1;")
        #value_array = sql.do_query("select code, cc from (select code, count(code) as cc from file group by code order by cc desc) as X;")

        print "found [%s] pairs" % len(value_array)

        for count, value_list in enumerate(value_array):
            if count >= BATCH:
                break

            # get the file object
            file_code = value_list[0]
            search = Search("sthpw/file")
            search.add_filter("code", file_code)
            files = search.get_sobjects()

            #if len(files) == 1:
            #    continue

            for file in files:
                project_code = file.get_value("project_code")
                if not project_code:
                    print "WARNING: file [%s] has no project_code" % file_code
                    continue

                project = Project.get_by_code(project_code)
                initials = project.get_initials()

                id = file.get_id()
                new_file_code = "%s%s" % (id, initials)
                if file_code == new_file_code:
                    continue

                print "-"*20
                print "switching: ", file_code, "to", new_file_code


                snapshot_code = file.get_value("snapshot_code")
                snapshot = Snapshot.get_by_code(snapshot_code)
                assert snapshot

                snapshot_xml = snapshot.get_xml_value("snapshot")
                print snapshot_xml.to_string()
                node = snapshot_xml.get_node("snapshot/file[@file_code='%s']" % file_code)
                Xml.set_attribute(node, "file_code", new_file_code)
                print snapshot_xml.to_string()

                assert node


                # set the file_code
                file.set_value("code", new_file_code)
                file.commit()

                # set the snapshot
                snapshot.set_value("snapshot", snapshot_xml.to_string() )
                snapshot.commit()
Example #23
0
 def get_snapshot(my, node_name, snapshot_type="asset"):
     ''' use this only if the info is not already in the
         session_contents table'''
     snapshot_code = my.get_snapshot_code(node_name, snapshot_type)
     if snapshot_code == "":
         return None
     return Snapshot.get_by_code(snapshot_code)
Example #24
0
    def execute(my):

        search = Search(Submission)
        search.set_show_retired(True)
        submissions = search.get_sobjects()

        for submission in submissions:
            snapshot = Snapshot.get_latest_by_sobject(submission, "publish")
            paths = snapshot.get_all_lib_paths()

            bins = submission.get_bins()
            if not bins:
                 print "Bin for submissin [%s] does not exist" % submission.get_id()
                 continue
            bin = bins[0]
            code = bin.get_code()
            type = bin.get_value("type")
            label = bin.get_value("label")

            for path in paths:
                if not os.path.exists(path):
                    print "WARNING: path '%s' does not exist" % path
                    continue

                dirname = os.path.dirname(path)
                basename = os.path.basename(path)
                
                new_dirname = "%s/%s/%s/%s" % (dirname,type,label,code)
                if not os.path.exists(new_dirname):
                    os.makedirs(new_dirname)

                new_path = "%s/%s" % (new_dirname, basename)

                print new_path
                FileUndo.move(path, new_path)
Example #25
0
    def _test_symlink(my):
        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()

        checkin = FileCheckin(my.person, file_path, context="sym_test", checkin_type='auto')
        checkin.execute()

        snap = Snapshot.get_versionless(my.person.get_search_type(), my.person.get_id(), "sym_test", mode='latest', create=False)
        my.assertEquals(True, isinstance(snap, Snapshot))
        if snap:
            lib_path =snap.get_lib_path_by_type('main')
            my.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)
            my.assertEquals(True, os.path.exists(real_path))
            my.assertEquals(expected_rel_path, rel_path)
            os.chdir(wd)
Example #26
0
 def get_snapshot(my, node_name, snapshot_type="asset"):
     ''' use this only if the info is not already in the
         session_contents table'''
     snapshot_code = my.get_snapshot_code(node_name, snapshot_type)
     if snapshot_code == "":
         return None
     return Snapshot.get_by_code(snapshot_code)
Example #27
0
    def get_display(self):
        sobject = self.get_current_sobject()


        # this is a comp object ... need to find the shot
        if not isinstance(sobject, Shot) :
            shot = sobject.get_parent("prod/shot")
        else:
            shot = sobject

        # now get all of the layers
        layers = shot.get_all_children("prod/layer")
        div = DivWdg()
    
        #div.set_style('width: 100px; overflow": auto')
        table = Table(css='embed')

        table.add_row()
        table.add_cell( shot.get_code() )

        render = Render.get_last(shot)
        if not render:
            table.add_cell("<i>No renders</i>")
        else:
            render = Snapshot.get_current_by_sobject(render)
            table.add_cell( self.get_open_wdg(render) )
            dir = render.get_web_dir()
            table.add_cell( "<i>%s</i>" % dir )


        for layer in layers:
            table.add_row()
            table.add_cell( layer.get_value("name") )

            render = Render.get_last(layer)
            if render:
                render = Snapshot.get_current_by_sobject(render)
            if not render:
                table.add_cell("<i>No renders</i>")
            else:
                table.add_cell( self.get_open_wdg(render) )
                dir = render.get_client_lib_dir()
                table.add_cell( "<i>%s</i>" % dir )


        div.add(table)
        return div
Example #28
0
    def execute(my):
        print "EXECUTING sample command"

        # create the render
        render = SearchType.create("prod/render")
        render.set_parent(my.prev_command.sobject)
        render.set_value("pipeline_code", "turntable")
        render.commit()
        Task.add_initial_tasks(render)

        prev_sobject = my.prev_command.sobject
        prev_process = "model"
        this_sobject = my.prev_command.sobject
        this_process = "turntable"

        # get the deliverable
        snapshot = Snapshot.get_latest_by_sobject(prev_sobject, prev_process)
        if not snapshot:
            return

        # once we have this snapshot, open the file and process
        lib_dir = snapshot.get_lib_dir()
        file_name = snapshot.get_name_by_type("maya")

        file_path = "%s/%s" % (lib_dir, file_name)

        f = open(file_path, 'r')
        lines = f.readlines()
        f.close()

        tmp_dir = Environment.get_tmp_dir()
        new_file_name = "whatever.new"
        new_file_path = "%s/%s" % (tmp_dir, new_file_name)

        f2 = open(new_file_path, 'wb')
        for i, line in enumerate(lines):
            line = "%s - %s" % (i, line)
            f2.write(line)
        f2.close()

        file_paths = [new_file_path]
        file_types = ['maya']

        from pyasm.checkin import FileCheckin
        checkin = FileCheckin.get(this_sobject,
                                  file_paths,
                                  file_types,
                                  context=this_process)
        checkin.execute()

        my.set_event_name("task/approved")
        my.set_process("preprocess")
        my.set_pipeline_code("turntable")
        my.sobjects = [render]

        # ???
        my.sobject = render

        my.set_as_approved()
Example #29
0
    def _test_strict_checkin(my):

        server = Config.get_value("install", "server")
        process = "process"
        person_code = my.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(my.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 versionless
            versionless = Snapshot.get_versionless(my.person.get_search_type(), my.person.get_id(), context, mode='latest', create=False)
            my.assertEquals(None, versionless)

            
            path = snapshot.get_path_by_type("main")

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

            file_objects = snapshot.get_all_file_objects()
            my.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)
            my.assertEquals(test_path, path)
Example #30
0
    def init_cgi(my):
        web = WebContainer.get_web()
        snapshot_code = web.get_form_value("snapshot_code")
        namespace = web.get_form_value("namespace")

        snapshot = Snapshot.get_by_code(snapshot_code)
        session = SessionContents.get(asset_mode=True)

        my.set_info(snapshot, session, namespace)
Example #31
0
    def execute(my):
        print "EXECUTING sample command"

        # create the render
        render = SearchType.create("prod/render")
        render.set_parent(my.prev_command.sobject)
        render.set_value("pipeline_code", "turntable")
        render.commit()
        Task.add_initial_tasks(render)

        prev_sobject = my.prev_command.sobject
        prev_process = "model"
        this_sobject = my.prev_command.sobject
        this_process = "turntable"

        # get the deliverable
        snapshot = Snapshot.get_latest_by_sobject(prev_sobject, prev_process)
        if not snapshot:
            return

        # once we have this snapshot, open the file and process
        lib_dir = snapshot.get_lib_dir()
        file_name = snapshot.get_name_by_type("maya")

        file_path = "%s/%s" % (lib_dir, file_name)

        f = open( file_path, 'r')
        lines = f.readlines()
        f.close()

        tmp_dir = Environment.get_tmp_dir()
        new_file_name = "whatever.new"
        new_file_path = "%s/%s" % (tmp_dir, new_file_name)

        f2 = open( new_file_path, 'wb')
        for i, line in enumerate(lines):
            line = "%s - %s" % ( i,line)
            f2.write(line)
        f2.close()

        file_paths = [new_file_path]
        file_types = ['maya']

        from pyasm.checkin import FileCheckin
        checkin = FileCheckin.get(this_sobject, file_paths, file_types, context=this_process)
        checkin.execute()

        my.set_event_name("task/approved")
        my.set_process("preprocess")
        my.set_pipeline_code("turntable")
        my.sobjects = [render]

        # ???
        my.sobject = render


        my.set_as_approved()
Example #32
0
    def init_cgi(my):
        web = WebContainer.get_web()
        snapshot_code = web.get_form_value("snapshot_code")
        namespace = web.get_form_value("namespace")

        snapshot = Snapshot.get_by_code(snapshot_code)
        session = SessionContents.get(asset_mode=True)

        my.set_info(snapshot, session, namespace)
Example #33
0
    def get_display(self):
        sobject = self.get_current_sobject()

        # this is a comp object ... need to find the shot
        if not isinstance(sobject, Shot):
            shot = sobject.get_parent("prod/shot")
        else:
            shot = sobject

        # now get all of the layers
        layers = shot.get_all_children("prod/layer")
        div = DivWdg()

        #div.set_style('width: 100px; overflow": auto')
        table = Table(css='embed')

        table.add_row()
        table.add_cell(shot.get_code())

        render = Render.get_last(shot)
        if not render:
            table.add_cell("<i>No renders</i>")
        else:
            render = Snapshot.get_current_by_sobject(render)
            table.add_cell(self.get_open_wdg(render))
            dir = render.get_web_dir()
            table.add_cell("<i>%s</i>" % dir)

        for layer in layers:
            table.add_row()
            table.add_cell(layer.get_value("name"))

            render = Render.get_last(layer)
            if render:
                render = Snapshot.get_current_by_sobject(render)
            if not render:
                table.add_cell("<i>No renders</i>")
            else:
                table.add_cell(self.get_open_wdg(render))
                dir = render.get_client_lib_dir()
                table.add_cell("<i>%s</i>" % dir)

        div.add(table)
        return div
Example #34
0
 def get_node_name(my, snapshot_code, namespace):
     xml = my._get_data()
     snapshot = Snapshot.get_by_code(snapshot_code)
     type = snapshot.get_type()
     if type == 'anim_export':
         type = 'anim'
     node = xml.get_node("session/node[@%s_snapshot_code='%s' and @namespace='%s']"\
         % (type, snapshot.get_code(), namespace  ))
     if node is not None:
         return Xml.get_attribute(node, 'name')
     else:
         return ''
Example #35
0
 def execute(my):
     # NONE option is used for clearing the labels
     from pyasm.widget import SelectWdg
     if my.value == SelectWdg.NONE_MODE:
         my.value = ''
     for snap_code in my.snap_codes:
         snap_code = snap_code.split('|')[0]
         snapshot = Snapshot.get_by_code(snap_code)
         
         if snapshot:
             snapshot.set_value(my.attr_name, my.value)
             snapshot.commit()
Example #36
0
 def get_node_name(my, snapshot_code, namespace):
     xml = my._get_data()
     snapshot = Snapshot.get_by_code(snapshot_code)
     type = snapshot.get_type()
     if type == 'anim_export':
         type = 'anim'
     node = xml.get_node("session/node[@%s_snapshot_code='%s' and @namespace='%s']"\
         % (type, snapshot.get_code(), namespace  ))
     if node is not None:
         return Xml.get_attribute(node, 'name')
     else:
         return ''
Example #37
0
    def preprocess(self):
        self.is_locked_dict = {}
        for snapshot in self.sobjects:
            key = self.get_key(snapshot)

            is_locked = self.is_locked_dict.get(key)
            if is_locked == None:
                context = snapshot.get_value("context")
                try:
                    parent = snapshot.get_parent()
                    is_locked = Snapshot.is_locked(parent, context)

                    self.is_locked_dict[key] = is_locked
                except SearchException as e:
                    continue
Example #38
0
    def _append_xml(my, asset, context, inst_mode, uber_xml ):
        '''append xml to the uber_xml'''
        snapshot = Snapshot.get_latest_by_sobject(asset, context)
        loader_context = ProdLoaderContext()
        loader_context.set_context(context)
        loader_context.set_option('instantiation', inst_mode)
        loader = loader_context.get_loader(snapshot)
        loader.execute()

        execute_xml = loader.get_execute_xml()
        xml = execute_xml.get_xml()
        xml = Xml(string=xml)
        nodes =  xml.get_nodes("execute/*")
        for node in nodes:
            uber_xml.append( "    %s" % xml.to_string(node, pretty=False))
    def preprocess(my):
        my.is_locked_dict = {}
        for snapshot in my.sobjects:
            key = my.get_key(snapshot)

            is_locked = my.is_locked_dict.get(key)
            if is_locked == None:
                context = snapshot.get_value("context")
                try:
                    parent = snapshot.get_parent()
                    is_locked = Snapshot.is_locked(parent, context)

                    my.is_locked_dict[key] = is_locked
                except SearchException, e:
                    continue
Example #40
0
    def preprocess(my):
        my.is_locked_dict = {}
        for snapshot in my.sobjects:
            key = my.get_key(snapshot)

            is_locked = my.is_locked_dict.get(key)
            if is_locked == None:
                context = snapshot.get_value("context")
                try:
                    parent = snapshot.get_parent()
                    is_locked = Snapshot.is_locked(parent, context)

                    my.is_locked_dict[key] = is_locked
                except SearchException, e:
                    continue
Example #41
0
    def preprocess(self):
        self.is_locked_dict = {}
        for snapshot in self.sobjects:
            key = self.get_key(snapshot)

            is_locked = self.is_locked_dict.get(key)
            if is_locked == None:
                context = snapshot.get_value("context")
                try:
                    parent = snapshot.get_parent()
                    is_locked = Snapshot.is_locked(parent, context)

                    self.is_locked_dict[key] = is_locked
                except SearchException as e:
                    continue
Example #42
0
    def get_shot_loader_xml(my, ticket, project_code, snapshot_code, shot_code, instance_name, context="", options=""):
        '''uses the loader to generate an execute xml that can be
        used to load the assets'''
        try:
            my.init(ticket)
            Project.set_project(project_code)

            snapshot = Snapshot.get_by_code(snapshot_code)

            # get the shot
            shot = Shot.get_by_code(shot_code)
            if not shot:
                raise ServiceException("No shot [%s] exists" % shot_code)


            # get the loader implementation
            loader_context = ProdLoaderContext()
            loader_context.set_shot(shot)
            loader_context.set_context(context)

            # pass on any message options for the loader
            if options != "":
                loader_context.set_options(options)

            loader = loader_context.get_loader(snapshot)

            # just set the shot if we are loading the shot
            if shot_code == instance_name:
                loader.set_instance(shot)
            else:
                instance = ShotInstance.get_by_shot(shot, instance_name)
                if not instance:
                    raise TacticException('Asset Instance [%s] not found in shot [%s]'%(instance_name, shot.get_code()))
                loader.set_instance(instance)

            # setting all instances in anim to be loaded with the unique flag
            loader.set_unique()

            loader.execute()

            execute_xml = loader.get_execute_xml()
            xml = execute_xml.get_xml()

        finally:
            DbContainer.close_all()
        
        return xml
Example #43
0
    def get_display(self):
        sobject = self.get_current_sobject()

        

        context = self.kwargs.get('context')
        if not context:
            context = "publish"
            
        snapshot = Snapshot.get_latest_by_sobject(sobject, context)
        if not snapshot:
            return "Nothing checked in"
        xml = snapshot.get_xml_value("snapshot")
        print xml.to_string()


        # this is a comp object ... need to find the shot
        shot = sobject.get_parent("prod/shot")

        # now get all of the layers
        layers = shot.get_all_children("prod/layer")




        div = DivWdg()

        table = Table(css='embed')

        # get the renders for each of the references in the snapshot
        #ref_nodes = xml.get_nodes("snapshot/file/ref")
        ref_nodes = xml.get_nodes("snapshot/input_ref")
        unknown_ref_nodes = xml.get_nodes("snapshot/unknown_ref")
        if ref_nodes:
            table.add_row_cell('Ref:')
            
            self.draw_node(ref_nodes, table)
        if unknown_ref_nodes:
            table.add_row_cell('Unknown Ref:')
            for node in unknown_ref_nodes:
                table.add_row()
                table.add_cell(xml.get_attribute(node, 'path'))

        div.add(table)
        return div
Example #44
0
    def _get_file_info(my, sobject):
        ''' return the web url and the file name with flash sobject'''
        snapshot = web_dir = None
        if sobject:
            snapshot = my.snapshot_dict.get(sobject.get_search_key())
            if not snapshot:
                snapshot = Snapshot.get_latest_by_sobject(sobject)
                
            web_dir = sobject.get_remote_web_dir()
       
        if snapshot:
            fla = snapshot.get_name_by_type(".fla")
            fla_file_name = snapshot.get_file_name_by_type(".fla")
            fla_link = "%s/%s" % (web_dir, fla_file_name)
            return fla_link, fla      

        else:
            return None, None
Example #45
0
    def _get_file_info(my, sobject, snapshot=None, file_type='main'):
        ''' return the web url and the file name with media sobject'''
        web_dir = None
        if not sobject:
            return None, None

        if not snapshot:
            key = sobject.get_search_key()
            # the latest snapshot
            snapshot = Snapshot.get_latest_by_sobject(sobject)

        if snapshot:
            fla = snapshot.get_name_by_type(file_type)
            fla_file_name = snapshot.get_file_name_by_type(file_type)
            web_dir = sobject.get_remote_web_dir()
            fla_link = "%s/%s" % (web_dir, fla_file_name)
            return fla_link, fla
        else:
            return None, None
Example #46
0
    def get_display(my):
        top = DivWdg()
        top.add_color("color", "color")
        #top.add_color("background", "background")
        top.add_class("spt_simple_upload_top")
        
        top.add(my.browse)
       

        hidden = HiddenWdg( "%s|path" %  my.get_input_name() )
        hidden.add_class("spt_upload_hidden")
        top.add(hidden)


        # this can be used for some other transaction that picks up this file to checkin
        hidden = HiddenWdg( "%s|ticket" %  my.get_input_name() )
        hidden.add_class("spt_upload_ticket")
        top.add(hidden)

        # if not specified, get the sobject's icon context 
        my.context = my.kwargs.get("context")
        if not my.context:
            current = my.get_current_sobject()
            if current:
                my.context = current.get_icon_context()
            else:
                from pyasm.biz import Snapshot
                my.context = Snapshot.get_default_context()

        top.add_attr("spt_context", my.context)

        top.add( my.get_info_wdg() )


        files_div = DivWdg()
        top.add(files_div)
        files_div.add_class("spt_upload_files")
        files_div.add_style("font-size: 11px")
        files_div.add_style("margin-top: 10px")

        my.add_action()

        return top
Example #47
0
    def execute(my):

        if my.project_code:
            Project.set_project(project_code)

        snapshot = Snapshot.get_by_code(my.snapshot_code)

        # get the loader implementation
        from pyasm.prod.load import ProdLoaderContext
        loader_context = ProdLoaderContext()
        loader_context.set_context(snapshot.get_value("context"))

        # pass on any message options for the loader
        #if options != "":
        #    loader_context.set_options(options)

        loader = loader_context.get_loader(snapshot)
        loader.execute()

        my.execute_xml = loader.get_execute_xml().to_string()
Example #48
0
    def _get_file_info(my, sobject, snapshot=None, file_type='main'):
        ''' return the web url and the file name with media sobject'''
        web_dir = None
        if not sobject:
            return None, None


        if not snapshot:
	    key = sobject.get_search_key()
            # the latest snapshot
            snapshot = Snapshot.get_latest_by_sobject(sobject)
            
        if snapshot:
            fla = snapshot.get_name_by_type(file_type)
            fla_file_name = snapshot.get_file_name_by_type(file_type)
            web_dir = sobject.get_remote_web_dir()
            fla_link = "%s/%s" % (web_dir, fla_file_name)
            return fla_link, fla
        else:
            return None, None
Example #49
0
    def delete(my, log=True):
        '''This is for undo'''
        # TODO: the should probably be clearer!!!!
        if log == False:
            super(Shot, my).delete(log)
            return

        # An asset can only be deleted if only icon snapshots exist
        snapshots = Snapshot.get_by_sobject(my)

        only_icons = True
        for snapshot in snapshots:
            context = snapshot.get_value("context")
            if context != my.get_icon_context():
                only_icons = False

        if not only_icons:
            raise TacticException("Cannot delete because snapshots exist")

        # only delete if not tasks have been assigned
        tasks = Task.get_by_sobject(my)
        has_assigned = False
        for task in tasks:
            assigned = task.get_value("assigned")
            if assigned != "" and assigned != "None":
                has_assigned = True

        if has_assigned:
            raise TacticException(
                "Cannot delete because tasks have been assigned")

        # delete tasks and icons
        for snapshot in snapshots:
            snapshot.delete()
        for task in tasks:
            task.delete()

        my.description = "Deleted '%s', search_type '%s'" % (
            my.get_code(), my.get_search_type)

        super(Shot, my).delete(log)
Example #50
0
    def add_ref_by_snapshot_code(my,
                                 snapshot_code,
                                 instance_name=None,
                                 parent=None,
                                 type='ref',
                                 node_name='',
                                 tag='main'):
        snapshot = Snapshot.get_by_code(snapshot_code)
        if not snapshot:
            Environment.add_warning(
                "Reference not found",
                "Found reference to snapshot [%s] which no longer exists in the Tactic database"
                % snapshot_code)
            return

        return my.add_ref_by_snapshot(snapshot,
                                      instance_name,
                                      parent,
                                      type,
                                      node_name,
                                      tag=tag)
Example #51
0
    def draw_node(self, ref_nodes, table):
        if not ref_nodes:
            return

        for ref_node in ref_nodes:
            snapshot = Snapshot.get_ref_snapshot_by_node(ref_node,
                                                         mode='latest')
            if not snapshot:
                print "Snapshot for ref_node does not exist"
                continue

            render = snapshot.get_parent()
            table.add_row()

            parent = render.get_parent()
            table.add_cell(parent.get_name())

            table.add_cell(self.get_open_wdg(render))

            dir = render.get_client_lib_dir()
            table.add_cell("<i>%s</i>" % dir)
Example #52
0
    def get_display(my):
        top = DivWdg()
        top.add_color("color", "color")
        #top.add_color("background", "background")
        top.add_class("spt_simple_upload_top")

        top.add(my.browse)

        hidden = HiddenWdg("%s|path" % my.get_input_name())
        hidden.add_class("spt_upload_hidden")
        top.add(hidden)

        # this can be used for some other transaction that picks up this file to checkin
        hidden = HiddenWdg("%s|ticket" % my.get_input_name())
        hidden.add_class("spt_upload_ticket")
        top.add(hidden)

        # if not specified, get the sobject's icon context
        my.context = my.kwargs.get("context")
        if not my.context:
            current = my.get_current_sobject()
            if current:
                my.context = current.get_icon_context()
            else:
                from pyasm.biz import Snapshot
                my.context = Snapshot.get_default_context()

        top.add_attr("spt_context", my.context)

        top.add(my.get_info_wdg())

        files_div = DivWdg()
        top.add(files_div)
        files_div.add_class("spt_upload_files")
        files_div.add_style("font-size: 11px")
        files_div.add_style("margin-top: 10px")

        my.add_action()

        return top