def get_cut_info(self, flg_get_latest_if_no_approved=False):
        """
        Return the cut information for a shot.
        ex: {'sg_handle_end': 1266, 'sg_handle_start': 997, 'sg_cut_end': 1258, 'sg_cut_start': 1005}
        """
        # attempt to get the approved cut data, if possible
        fields = ["sg_handle_start", "sg_handle_end", "sg_cut_start","sg_cut_end"]
        cut_data = self.shotgun_field(fields)
        shotgun_shot_id = self.shotgun_field('id')

        # if this doesn't exist have to query the cut data base for it.
        api = shotgun_session().api()

        if flg_get_latest_if_no_approved and not cut_data["sg_handle_start"]:
            print 'approved cut data not found, getting in from latest cut.'
            cut_data = api.find_one(
                                     'Cut_sg_shots_Connection',
                                     [['shot','is',{'type':'Shot','id':shotgun_shot_id}]],
                                     fields,
                                     [{'field_name':'id','direction':'desc'}]
                                    )

        # must check if cut_data not None
        if cut_data == None:
            pass
        elif cut_data["sg_handle_start"]==None:
            cut_data = None
        else:
            # filter the result, shotgun usually return with id and type, along with the query fields
            field_values = [ cut_data[f] for f in fields ]
            cut_data = dict(zip (  fields, field_values ))

        return cut_data
    def list_shots(self, ShotClass=None):
        '''
        List the scene in shotgun scene order
        '''
        if not ShotClass: ShotClass = Shot

        if self._cache_shot_list==None:
            all_shot_data           = shotgun_session().list_shots(self.name, fields=[   'id',
                                                                                'code',
                                                                                'sg_cut_order',
                                                                                'sg_handle_start',
                                                                                'sg_handle_end',
                                                                                'sg_cut_start',
                                                                                'sg_cut_end',
                                                                                'sg_status_list'])
            self._cache_shot_list   = [   ShotClass(
                                              shot              = data["code"],
                                              scene             = self,
                                              project           = self.project,
                                              shotgun_fields    = data,
                                              ) for data in all_shot_data ]

            # if the order is none, set it to 10000 + the int( name )
            for shot in self._cache_shot_list:
                if shot.shotgun_field("sg_cut_order") == None:
                    shot._shotgun_fields["sg_cut_order"] = self.generate_shot_order(shot.name)

            self._cache_shot_list.sort( lambda x,y: cmp(x.shotgun_field("sg_cut_order"), y.shotgun_field("sg_cut_order"))  )


        return self._cache_shot_list
    def _get_render_data_shotgun(self, search_spec=None, result_spec=None):
        if result_spec==None:
            result_spec =  ['department','sg_tank_address', 'sg_status_1', 'created_at', 'user','sg_rv_preview_link',
                            'sg_comments','sg_status_1']

        if search_spec==None:
            search_spec = [     ['sg_tank_address','contains','Scene(%s)'%self.name],
                                ['sg_tank_address','contains','ShotRender'],
                                ["sg_status_list","is_not", "omt"]]

        all_render = shotgun_session().api().find("Version",
                                    search_spec,
                                    result_spec,
                                    order = [{'field_name':'created_at','direction':'desc'}]
                                   )

        all_render_aux = [ {"aux": projectAwareness.determine_aux_data_from_tank_address_fast(r["sg_tank_address"]), "sg_data":r}
                          for r in all_render if r["sg_tank_address"]!=None]

        return self._organize_render_data(all_render_aux)
    def shotgun_field(self, fields):
        """
        Return the shotgun fields related to the shot.
        ex:
        shot.shotgun_field(['code','type','id','sg_handle_start'])
        {'sg_handle_start': 997, 'code': '21a_010', 'type': 'Shot', 'id': 3849}
        """
        # first check if data is already all cache
        field_name_list = [fields] if type(fields) == str else fields

        field_value_list = [ self._shotgun_fields[field_name] for field_name in field_name_list if self._shotgun_fields.has_key(field_name) ]

        if len(field_value_list) != len(field_name_list):
            result = shotgun_session().get_shot(self.scene.name, self.name, fields=field_name_list)

            # now cache the read values
            for k in result.keys():
                self._shotgun_fields[k] = result[k]

            return result[fields] if type(fields)==str else result
        else:
            return field_value_list[0] if len(field_value_list)==1 else dict(zip( field_name_list, field_value_list))
    def list_shots(self):
        '''
        List the scene in shotgun scene order
        '''
        if self._cache_shot_list==None:
            if self.name in ASSET_RENDER_TYPES:
                if self.name=="Character":
                    char_list = shotgun_session().list_character()
                    char_var_list = shotgun_session().list_character_var()
                    asset_list = char_list + char_var_list
                else:
                    asset_list = {
                                    'Prop':shotgun_session().list_prop,
                                    'Stage':shotgun_session().list_stage,
                                    'Environment':shotgun_session().list_environment,
                                    'Skydome':shotgun_session().list_skydome,
                                  }[self.name]()


                asset_list.sort(lambda x, y: cmp(x['code'], y['code']))
                self._cache_shot_list = []

                i=0
                for asset_data in asset_list:
                    asset_data["sg_cut_order"] = i
                    asset_data["sg_handle_start"] = 0
                    asset_data["sg_handle_end"] = 0
                    asset_data["sg_cut_start"] = 0
                    asset_data["sg_cut_end"] = 0

                    i+=1
                    self._cache_shot_list.append( Shot(
                                                        shot              = asset_data["code"],
                                                        scene             = self,
                                                        project           = self.project,
                                                        shotgun_fields    = asset_data,
                                                       ))



            else:
                ContextSession.Scene.list_shots(self, Shot)

        return self._cache_shot_list
    def list_scenes(self, SceneClass=None):
        '''
        List the scene in shotgun scene order
        '''
        if not SceneClass: SceneClass = Scene

        if self._cache_scene_list == None:
            all_scene_data = shotgun_session().list_scenes(fields=['id','code','sg_sort_order'])

            self._cache_scene_list = [  SceneClass(
                                               scene            = data["code"],
                                               project          = self,
                                               shotgun_fields   = data )
                                                    for data in all_scene_data ]

            # if the order is none, set it to 10000 + the int( name )
            for scene in self._cache_scene_list:
                if scene.shotgun_field("sg_sort_order") == None:
                    scene_name_int = int( re.search("([0-9]+)", scene.name).groups()[0] )
                    scene._shotgun_fields["sg_sort_order"] = 1000000 + scene_name_int

            self._cache_scene_list.sort( lambda x,y: cmp(x.shotgun_field("sg_sort_order"), y.shotgun_field("sg_sort_order"))  )

        return self._cache_scene_list
 def list_all_shotgun_fields(self):
     """
     Return all the possible fields of a Shotgun Shot
     """
     return shotgun_session().api().schema_field_read("Scene").keys()
def main(argv):
    # preference migration, this is to be remove after a while,
    # with new release, the preferences are stored per user per machine
    # migrate old preference
    old_pref_file = "/tmp/dailies_tool.conf"
    pref_file = "/tmp/review_tool.%s.conf" % os.environ.get("USER","general")
    if not os.path.isfile(pref_file) and os.path.isfile(old_pref_file):
        shutil.copyfile(old_pref_file, pref_file)

    app = QtGui.QApplication(sys.argv)
    splash = DrSplash(title="Review Tool",
                      version="Ver "+ os.environ.get("REVIEW_TOOL_VER", ""),
                      icon_path = reviewTool.gui.resource.getImage("applications-multimedia.png")
                      )

    splash.log("loading Tank...")
    import tank

    from reviewTool import TANK_VFS_DISABLE

    if not(TANK_VFS_DISABLE):
        splash.log("initialize Tank virtual file system...")
        tank.local.Tm()


    splash.log("initializing shotgun...")
    from drTank.util import shotgun_session
    shotgun_session()

    splash.log("initializing gui...")
    from reviewTool.gui.ContextWidget   import ContextWidget
    cw = ContextWidget(None)

    cw.show()
    splash.finish(cw)

    cw.splitter_2.setSizes([480,320])

    QtGui.QApplication.processEvents()

    cw.logger.info("Review tool startup success.")

    if len(argv)>1 and argv[1].startswith('playlist='):

        id_list = argv[1].replace('playlist=', '').split(',')

        for pid in id_list:
            QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
            try:
                cw.populate_mix_master_from_shotgun( playlist_id=int(pid) )
            except:
                print "failed to load playlist with id", pid

            QtGui.QApplication.restoreOverrideCursor()

    elif len(argv)>1 and argv[1].startswith('cliplist='):

        id_list = argv[1].replace('cliplist=','').split(',')
        id_list = [ int(id) for id in id_list ]

        QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
        try:
            cw.populate_mix_master_from_shotgun( clip_id_list=id_list )
        except:
            traceback.print_exc()
            print "failed to load clips with ids", id_list

        QtGui.QApplication.restoreOverrideCursor()

    import platform
    if platform.system()=="Linux":
        rvexe = os.environ.get("RV_EXE")
        os.environ["RV_EXE"] = "%s -init /drd/software/ext/rv/lin64/config/drd_init " % rvexe

        #os.environ["RV_EXE"] = "/drd/software/ext/rv/lin64/rv-Linux-x86-64-3.10.10/bin/rv"
        # /drd/software/ext/rv/lin64/config/drd_init_3.8.6_anim.mu"


    '''-----------
      test block
    -----------'''
    sys.exit(app.exec_())