Ejemplo n.º 1
0
    def query_depend_fp(self, db, showobj, file_selected):
        from dsk.base.db_helper.db_helper_funct import ShotgunQuery as SQ

        result = None
        if db is None or showobj is None:
            return result

        for x in self.downstream_published_files:

            if x['name'] == file_selected:
                entity_publish_id = x['id']
                result = SQ.published_file_query_one(showobj.id,
                                                     entity_publish_id,
                                                     conn=db.get_conn())
                if len(result) == 1:
                    return result[0]
                return None

        for x in self.upstream_published_files:

            if x['name'] == file_selected:
                entity_publish_id = x['id']
                result = SQ.published_file_query_one(showobj.id,
                                                     entity_publish_id,
                                                     conn=db.get_conn())
                if len(result) == 1:
                    return result[0]
                return None

        return result
Ejemplo n.º 2
0
def test_get_devshow():
    a = ShotgunQuery.show_id_by_name(conn, 'dev_show')
    assert 'id' in a
    shotlist = ShotgunQuery.shot_list_with_id(a['id'], conn)
    assert len(shotlist) > 0

    assetList = ShotgunQuery.asset_list_with_id(a['id'], conn)
    assert len(assetList) > 0
Ejemplo n.º 3
0
    def update_media_version_shot_info(self,
                                       showobj,
                                       shotobj,
                                       version_type=None,
                                       force=True):
        """Version stuff for asset

            :param showobj: ShowInfoDb object
            :param shotobj: ShotInfoDb object
            :param version_type: default None, a list of version type
                   example: ['deadlineNukeRender', 'publishedNukeRender']
            :param force: bool force the query

        """

        if force == False and shotobj.is_version_set():
            return shotobj.get_media_version()

        #steplist = map(lambda x: x ,filter(lambda x: x.active == True,steplist))
        res = list()
        if showobj.id != -1 and shotobj.id != -1:
            res = SQ.query_shot_media_versions(showobj.id,
                                               shotobj.id,
                                               VersionInfoDb.VF,
                                               version_type=version_type,
                                               conn=self.get_conn())

        versions = shotobj.set_media_version(res)
        return versions
Ejemplo n.º 4
0
    def load_asset_if_not(self, db, asset_names):
        """Load none asset loaded into show
            :param:
                   asset_names (list/str): a valid code name for asset
        """
        from dsk.base.db_helper.db_helper_funct import ShotgunQuery as SQ
        if isinstance(asset_names, basestring):
            asset_names = [asset_names]

        assets = self.get_assets()
        in_all_ready = assets.childNames()

        to_query = list()
        all_ready_there = list()
        for s in asset_names:
            if s not in in_all_ready:
                to_query.append(s)
            else:
                ch = assets.getChildByName(s)
                if ch is None:
                    log.error("cannot retrieve asset: %s", s)
                else:
                    all_ready_there.append(ch)

        asset_list = list()
        if len(to_query) > 0:
            asset_list = SQ.assets_with_id(self.id, to_query, db.get_conn())
            self.init_with_assets(asset_list)
        return asset_list + all_ready_there
Ejemplo n.º 5
0
    def update_media_version_asset_info(self,
                                        showobj,
                                        assetobj,
                                        version_type=None,
                                        force=False):
        """Version stuff for asset

            :param showobj: ShowInfoDb object
            :param assetobj: AssetInfoDb object
            :param version_type: default None, a list of version type
                   example: ['deadlineNukeRender', 'publishedNukeRender']
            :param force: bool force the query
        """
        if force == False and assetobj.is_version_set():
            return assetobj.get_media_version()

        res = list()
        if showobj.id != -1 and assetobj.id != -1:
            res = SQ.query_asset_media_versions(showobj.id,
                                                assetobj.id,
                                                VersionInfoDb.VF,
                                                version_type=version_type,
                                                conn=self.get_conn())
        versions = assetobj.set_media_version(res)
        return versions
Ejemplo n.º 6
0
def test_file_type_filter():
    ft = SQ.filter_fpt_by_name('maya_model_file', conn=conn)

    for f in ft:
        print("--------->", f.getName(), pformat(f))
    dbc = DbCache()
    print(pformat(dbc.get_file_type_names()))
Ejemplo n.º 7
0
 def cache_file_type(self):
     """Build a dico to map short_name filetype to name
     """
     ft = SQ.fpt_by_name(conn=self.get_conn())
     fpt = self['FPT']
     for f in ft:
         fpt.addChild(f)
     fpt.cache()
Ejemplo n.º 8
0
 def get_lasted_version_for_show(self, showobj, limit=10):
     """Return a list a limit number of the last version for a show
         No cache for now
     """
     res = SQ.get_lasted_version_for_show(showobj.id,
                                          VersionInfoDb.VF,
                                          limit=limit,
                                          conn=self.get_conn())
     return res
Ejemplo n.º 9
0
    def set_show(self, show_name, seq_name=""):
        """Set show: load all the assets and/or shots"""

        if show_name in self.get_show_names():
            showobj = self['Shows'][show_name]
            if showobj.get_sequences().nbOfChildren(
            ) == 0 and self._asset_only == False:
                showobj.init_with_shots(
                    sorted(SQ.shot_list_with_id(showobj.id, self.get_conn()),
                           ShotInfoDb.compare))
            if seq_name != None:
                showobj.set_current_sequence(seq_name)
            else:
                showobj.set_current_sequence("")
            if showobj.get_assets().nbOfChildren(
            ) == 0 and self._shot_only == False:
                showobj.init_with_assets(
                    sorted(SQ.asset_list_with_id(showobj.id, self.get_conn()),
                           AssetInfoDb.compare))
            self._currentshow = show_name
            return True
        return False
Ejemplo n.º 10
0
def test_db_cache_shot_devshow():
    dbc = DbCache(shot_only=False, asset_only=False)
    dbc.init_with_current_shows()

    dbc.set_show("dev_show")

    showobj = dbc.get_current_show_obj()
    assert showobj
    assert len(showobj.get_assetlist_names()) != 0

    # sequence
    ids = list()

    seqs = showobj.get_sequences()
    pformat(dbc.get_file_type_names())
    VER_TYPE = None  #['deadlineNukeRender', 'deadlineMayaRender']
    #fts = SQ.filter_fpt_by_name(VER_TYPE,conn=dbc.get_conn())
    for seq in seqs.getChildren():
        #print(seq.getName(),seq.get_shot_names())
        for shotobj in seq.getChildren():

            #print("shotname",shotobj.getName(),"show id", showobj.id, "shot id", shotobj.id)
            #ids.append(shotobj)
            res = dbc.update_media_version_shot_info(showobj,
                                                     shotobj,
                                                     VER_TYPE,
                                                     force=True)
            print("nb of shot version", len(res))
            ver_type = [x.getName() for x in res]
            ver_type = filter(lambda x: x != "No_Type", ver_type)

            #if ver_type:
            if 0:
                print(ver_type)
                res2 = ShotgunQuery.query_shot_media_latest(
                    showobj.id, shotobj.id, VersionInfoDb.VF, ver_type)

    # asset
    #print "xxxx"
    assets = showobj.get_assets()
    #print "xxxx",assets
    for assetobj in assets.getChildren():
        #print assetobj
        #print "assetname",assetobj.getName(),"show id", showobj.id, "asset id", assetobj.id
        ids.append(assetobj)
        res = dbc.update_media_version_asset_info(showobj, assetobj, VER_TYPE)
        print "nb of asset version", len(res)
        ver_type = [x.getName() for x in res]
        ver_type = filter(lambda x: x != "No_Type", ver_type)
        print ver_type
        """
Ejemplo n.º 11
0
 def _do_users(self):
     """ query and cache step info
     """
     SW.start()
     conn = self.get_conn()
     if self.verbose:
         log.warning("login to shotgun, to get user")
     step = SQ.user_info_with_id(conn=conn)
     parent = self['Users']
     for s in step:
         parent.addChild(s, withRename=False)
     SW.stop()
     if self.verbose:
         log.info("user_query in {}".format(SW.elapsed()))
Ejemplo n.º 12
0
    def init_with_current_shows(self, with_shotgun=True):
        """Initialisation of shows

            :param with_shotgun: default True, will load all the show in shotgun
                   (minus an exception list)  if False load the show define in envi_info instead
            :note: only show header are read... id, sgtk_name, no other data

        """
        s = self['Shows']
        if with_shotgun == True:
            conn = self.get_conn()
            cpl = SQ.get_current_projects(conn=conn)
            for cp in cpl:
                s.addChild(cp)
        else:
            conn = self.get_conn()
            from dskenv.api.dsk_studio import DskStudio
            envi_info = DskStudio()
            envi_info.reset(os.environ.get(dskenv_constants.DSK_ENV_PATH_KEY))
            envi_info.load_data()
            sgtks_names = envi_info.get_projects()
            cpl = SQ.get_current_projects(conn=conn, sgtk_names=sgtks_names)
            for cp in cpl:
                s.addChild(cp)
Ejemplo n.º 13
0
 def get_current_confpipe(self, db=None):
     """Set to the first found"""
     if self._current_configpipe == "":
         ass = self.get_configpipe()
         if ass.nbOfChildren() > 0:
             cas = ass.getChildren()[0]
             self._current_configpipe = cas.getName()
         elif db:
             from dsk.base.db_helper.db_helper_funct import ShotgunQuery
             res = ShotgunQuery.pipeline_config_with_id(self.id,
                                                        conn=db.get_conn())
             self.init_with_pipeline_config(res)
             ass = self.get_configpipe()
             if ass.nbOfChildren() > 0:
                 cas = ass.getChildren()[0]
                 self._current_configpipe = cas.getName()
     return self._current_configpipe
Ejemplo n.º 14
0
    def get_usertask_list(self, db, userlogin):
        from dsk.base.db_helper.db_helper_funct import ShotgunQuery as SQ
        user = db.get_user_dict(userlogin)
        res = list()
        if user:
            ch = self['TaskAssign'].getChildren()
            if len(ch) == 0:
                task_list = SQ.tasks_by_name(self.id, conn=db.get_conn())
                self.init_with_Task(task_list)
            ch = self['TaskAssign'].getChildren()

            idu = int(user['id'])

            for x in ch:
                if idu in x.assigned_ids():
                    res.append("%s" % x.id)

        return list(set(res))
Ejemplo n.º 15
0
    def assetid_filepub_query(self, showobj, assetid, file_type_list):
        """
            :param showobj:
            :param assetid:
            :param file_type_list: (list) pft Short name interface
            :return list: list of PfInfoDb
         """

        file_type_list_id = [
            self.get_ftid_from_short_name(x) for x in file_type_list
        ]
        file_type_list_id = filter(lambda x: x != '', file_type_list_id)
        pft_list = SQ.entity_asset_query_versions(
            showobj.id,
            assetid,
            file_type_list_id=file_type_list_id,
            conn=self.get_conn())

        return pft_list
Ejemplo n.º 16
0
    def load_shot(self, show_name, shot_names):
        """Load a list of shots into db under showname

            :param show_name: (str), valid sgtk name
            :param shot_names: (list or str): a valid code name for shot

        """

        showobj = None
        if show_name in self.get_show_names():
            showobj = self['Shows'][show_name]
        if showobj == None:
            return []
        if isinstance(shot_names, basestring):
            shot_names = [shot_names]
        shot_list = SQ.shots_with_id(showobj.id, shot_names, self.get_conn())
        showobj.init_with_shots(shot_list)
        self._currentshow = show_name
        return shot_list
Ejemplo n.º 17
0
    def load_asset(self, show_name, asset_names):
        """Load a single asset into db under showname

            :param show_name: (str), valid sgtk name
            :param asset_names: (list/str): a valid code name for asset
        """

        showobj = None
        if show_name in self.get_show_names():
            showobj = self['Shows'][show_name]

        if showobj == None:
            return list()
        if isinstance(asset_names, basestring):
            asset_names = [asset_names]

        asset_list = SQ.assets_with_id(showobj.id, asset_names,
                                       self.get_conn())
        showobj.init_with_assets(asset_list)
        self._currentshow = show_name
        return asset_list
Ejemplo n.º 18
0
    def _do_steps(self):
        """Query and cache step info
        """

        conn = self.get_conn()
        if conn == None:
            return
        SW.start()
        if self.verbose:
            log.warning("login to shotgun, to get default step settings")
        steps = SQ.step_list_with_id(conn)
        parent = self['Steps']
        steps_name = dict()
        for s in steps:
            if not s.getName() in steps_name:
                steps_name[s.getName()] = s
        for s in steps_name:
            parent.addChild(steps_name[s], withRename=False)
        SW.stop()
        if self.verbose:
            log.info("step_query in {}".format(SW.elapsed()))
Ejemplo n.º 19
0
    def shotid_filepubobj_query(self, showobj, shotobj, file_type_object_list):
        """
            :param showobj:
            :param shotobj:
            :param file_type_list: (list) pft Short name interface
            :return list: list of PfInfoDb

         """
        file_type_list_id = [x.id for x in file_type_object_list]
        file_type_list_id = filter(lambda x: x != '', file_type_list_id)
        pf_list = SQ.entity_shot_query_versions(
            showobj.id,
            shotobj.id,
            file_type_list_id=file_type_list_id,
            conn=self.get_conn())
        res = list()
        for ftol in file_type_object_list:
            res.append(
                [x for x in pf_list if x.published_file_type["id"] == ftol.id])
        return res

        return pf_list
Ejemplo n.º 20
0
    def get_departments(self):
        """ query and cache department info
        """
        if len(self._dept_shot) + len(self._dept_asset) > 0:
            return self._dept_shot + self._dept_asset

        #if not self._use_coffer:
        conn = self.get_conn()
        log.warning("login to shotgun, to get default department settings")
        dept = SQ.dept_list_with_id(conn)

        for i in dept:
            #print i.getName(),i.__dict__
            if i.is_shot():
                self._dept_shot.append(i)
            elif i.is_asset():
                self._dept_asset.append(i)
            else:
                pass  # we ignore production (prod) for now
                #log.warning('unknown department type %r' % i.dept_type)
        self._dept_shot = sorted(self._dept_shot, DeptInfoDb.compare)
        self._dept_asset = sorted(self._dept_asset, DeptInfoDb.compare)
        return self._dept_shot + self._dept_asset
Ejemplo n.º 21
0
def test_all_show():
    a = ShotgunQuery.get_current_projects(conn)
    print([(x.getName(), x.id) for x in a])
    assert len(a) > 0
Ejemplo n.º 22
0
 def download_icon(self, image_url, dest):
     SW.start()
     SQ.download_icon(image_url, dest, self.get_conn())
     SW.stop()
     if self.verbose:
         log.info("download icon in {}".format(SW.elapsed()))
Ejemplo n.º 23
0
def test_get_setting():
    a = ShotgunQuery.show_id_by_name(conn, 'dev_show')
    assert 'id' in a
    settinglist = ShotgunQuery.query_settings(a['id'], conn)
    for s in settinglist:
        print(s)
Ejemplo n.º 24
0
def test_db_asset_for_build_shot():
    dbc = DbCache(shot_only=False, asset_only=True)

    showobj = dbc.get_showobj('dev_show')
    assert showobj != None
    M_SHADER_SF = 'maya_shader_src_file'
    M_RIG_SF = 'maya_rig_src_file'
    file_type_list = [M_SHADER_SF, M_RIG_SF]  #,'maya_model_file']
    #file_type_list = ['maya_rig_src_file'] #,'maya_model_file']
    #pft_list = dbc.asset_maya_build_query(showobj, assetobj, file_type_list)

    fts = SQ.filter_fpt_by_name(file_type_list, conn=dbc.get_conn())

    shd_src_pub_type = None
    rig_src_pub_type = None

    for f in fts:
        if f.getName() == M_RIG_SF:
            rig_src_pub_type = f
        elif f.getName() == M_SHADER_SF:
            shd_src_pub_type = f

    assert shd_src_pub_type != None
    assert rig_src_pub_type != None

    shot_list = dbc.load_shot('dev_show', ['007_0200', '051_0200'])
    assert len(shot_list) > 0
    for shotobj in shot_list:
        print("SHOT", shotobj.code, shotobj.assets)
        assets_id = shotobj.get_asset_ids()
        assets_name = shotobj.get_asset_names()
        for as_id, as_name in zip(assets_id, assets_name):
            print("asset name:", as_name)
            ass = AssetInfoDb()
            ass.setName(as_name)
            ass.setdata(as_id)
            SW = StopWatch()
            SW.start()
            #pf_list = dbc.assetid_filepub_query(showobj, as_id, file_type_list)
            pf_list = dbc.assetid_filepubobj_query(
                showobj, ass, [rig_src_pub_type, shd_src_pub_type])
            rig_srcs = pf_list[0]
            shd_srcs = pf_list[1]
            SW.stop()
            print("assetid_filepub_query in %f" % SW.elapsed())
            """ much slower
            SW.start()
            a = dbc.assetid_filepub_query(showobj, as_id, [file_type_list[0]])
            SW.stop()
            print("assetid_filepub_query1 in %f" % SW.elapsed())
            SW.start()
            b = dbc.assetid_filepub_query(showobj, as_id, [file_type_list[1]])
            SW.stop()
            print("assetid_filepub_query2 in %f" % SW.elapsed())
            """
            rig_mod_ids = []
            rig_rig_ids = []
            printinfo = True
            for pf in rig_srcs:

                if printinfo: print("VERSION RIG", pf.version_number)

                x = pf.get_upstream_model()
                if x != None:
                    if printinfo:
                        print("\tRIG model version",
                              pf.get_upstream_model_version(), x['id'])
                    rig_mod_ids.append(x['id'])

                x = pf.get_downstream_rig()
                if x:
                    if printinfo:
                        print("\tRIG rig version",
                              pf.get_downstream_rig_version(), x['id'])
                    rig_rig_ids.append(x['id'])

            shd_mod_ids = []
            shd_cfx_ids = []
            shd_shd_ids = []

            for pf in shd_srcs:

                if printinfo: print("VERSION SHADER", pf.version_number)

                x = pf.get_upstream_model()
                if x != None:
                    if printinfo:
                        print("\tshader model version",
                              pf.get_upstream_model_version(), x['id'])
                    shd_mod_ids.append(x['id'])
                x = pf.get_upstream_cfx()
                if x != None:
                    if printinfo:
                        print("\tshader cfx version",
                              pf.get_upstream_cfx_version(), x['id'])
                    shd_cfx_ids.append(x['id'])
                x = pf.get_downstream_shader()
                if x != None:
                    if printinfo:
                        print("\tshader shader version",
                              pf.get_downstream_shader_version(), x['id'])
                    shd_shd_ids.append(x['id'])

            #print "shader model", shd_mod_ids
            #print "shader cfx", shd_cfx_ids
            #print "shader shader",shd_shd_ids

            #entity_publish_id = rig_mod_ids + rig_rig_ids + shd_mod_ids + shd_cfx_ids + shd_shd_ids
            # check cfx model version
            """
            entity_publish_id = shd_cfx_ids
            if len(entity_publish_id) > 0:
                print("Q" * 100, entity_publish_id)
                res = ShotgunQuery.published_file_query(showobj.id, entity_publish_id , conn = dbc.get_conn())
                print ("return res",res)
                for pf in res:
                    x =  pf.get_upstream_model()
                    if x:
                        print(x)
                        print("\t\t\tfound model on cfx at version" % pf.get_upstream_model_version())
                #print(pf.getName(),r.get_file_local_path())
            """
            """