Ejemplo n.º 1
0
    def __init__(self, shot_only=False, asset_only=False, verbose=False):
        """Create an instance, (simple fast nothing important

            :param shot_only: if True will not load asset
            :param asset_only: if True will not load shot
            :param verbose: display query timing information to database

        """

        if shot_only == True:
            log.info("*" * 20 + " running query for shot only " + "*" * 20)
        if asset_only == True:
            log.info("*" * 20 + " running query for asset only " + "*" * 20)
        super(DbCache, self).__init__()

        self._shot_only = shot_only
        self._asset_only = asset_only
        self.verbose = verbose
        self.reset()

        self._asset_type = list()
        self._group_perm = list()

        self._cache_group = dict(
        )  # to build temporary cache for pipeline config
Ejemplo n.º 2
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.º 3
0
    def simple_clone(self, release_top_location, branch=""):
        """Clone an accessible remote git address to a top location

            :param release_top_location: (str existing branch)  a place to install
            :param branch: (str)  an optional existing branch
            :return ResultRepoInstall: success errors log atag
        """

        if not os.path.isdir(release_top_location):
            log.error("release area needs to exist, %s doen't" %
                      release_top_location)
            return False

        x = GitUtils(release_top_location)

        try:
            #The repo gets clone in this function
            x.clone_repo(self.src_repo, "", branch)
        except Exception as e:
            log.error(str(e))
            return ResultRepoInstall(False, [str(e)], ['failed simple_clone'],
                                     None)

        return ResultRepoInstall(True, ["no error"], ['done simple_clone'],
                                 None)
Ejemplo n.º 4
0
 def get_current_confpipe(self, showobj):
     SW.start()
     res = showobj.get_current_confpipe(self)
     SW.stop()
     if self.verbose:
         log.info("get_current_confpipe in {}".format(SW.elapsed()))
     return res
Ejemplo n.º 5
0
    def addChild(self,ch,withRename = False):
        # be sure that that it's valid child
        import traceback
        if isinstance(ch,Tdata):
            if ch in self.getChildren():
                return
            chname = self.findUniqueChildName(ch.getName())
            if withRename == True:
                # be sure that the child name is unique
                ch.setName(chname)
                self.__Children.append(ch)
            else:
                if chname != ch.getName():
                    # an object of the same name
                    # exist an need to be replace
                    childN = self.childNames()
                    try:
                        index = childN.index(ch.getName())
                        self.__Children.pop(index)
                        self.__Children.insert(index,ch)

                    except:
                        traceback.print_exc()
                        self.error("addChild","big Trouble in addChild")
                        sys.exit(1)
                else:
                    self.__Children.append(ch)

            ch.setParent(self)
        else:
            MsgUtils.warning("addChild","Can't add %s to my children List" % ch)
Ejemplo n.º 6
0
    def inspect_shot_depend(self, showobj, shotobj):
        """Load the needed filepublish

            :param showobj: a ShowInfoDb object
            :param shotobj: a ShotInfoDb object

        """
        SW.start()
        # this needs to isolated
        typeList = getShotMapping(showobj.getName())

        allready = shotobj.get_publishedType()
        allready = [x.getName() for x in allready]

        typeListMissing = OrderedDict()
        for i in typeList:
            if not typeList[i].short_name in allready:
                typeListMissing[i] = typeList[i].short_name
        if len(typeListMissing) > 0:

            file_type_obj_list = self._get_ft(typeListMissing)
            pf_list = self.shotid_filepubobj_query(showobj, shotobj,
                                                   file_type_obj_list)

            for k, pf in zip(typeListMissing.keys(), pf_list):
                shotobj.set_plublished_type(typeListMissing[k], pf)

        SW.stop()
        if self.verbose:
            log.info("shotid_filepub_query in {}".format(SW.elapsed()))
Ejemplo n.º 7
0
    def start_engine(engine_name="tk-shell"):
        """Start the given engine in the given context. If no context is provided, start
        the engine in the project context

        :param engine_name:  Name of the engine to start
        :returns:            The running engine
        """
        import tank

        current_engine = tank.platform.current_engine()
        if current_engine:
            return current_engine

        pc_path = os.environ.get("TANK_CURRENT_PC")
        #---------------------------------------------------------------------------
        try:
            tk = tank.sgtk_from_path(pc_path)
            ctx = tk.context_from_path(tk.project_path)
            current_engine = tank.platform.start_engine(engine_name, tk, ctx)
            return current_engine

        except Exception as e:
            log.error("Failed to start Engine - %s" % str(e))
            traceback.print_exc()
        return None
Ejemplo n.º 8
0
 def updateEnable(self, msg):
     if msg.widgetFrom() != self:
         log.error("updateEnable,should be not getting this update")
         return
     if msg.succeed():
         for item in msg.getOptions():
             item.updateEnable()
Ejemplo n.º 9
0
    def inspect_shot_asset_depend(self, showobj, assetobj):
        """Load the needed filepublish

            :param showobj: a ShowInfoDb object
            :param assetobj: a AssetInfoDb object

        """
        typeList = getAssetMapping(showobj.getName())

        assets_name = assetobj.get_asset_names()
        asset_obj_list = showobj.load_asset_if_not(self, assets_name)

        SW.start()
        for assobj in asset_obj_list:
            allready = assobj.get_publishedType()
            allready = [x.getName() for x in allready]
            typeListMissing = OrderedDict()
            for i in typeList:
                if not typeList[i].short_name in allready:
                    typeListMissing[i] = typeList[i].short_name
            if len(typeListMissing) == 0:
                continue
            file_type_obj_list = self._get_ft(typeListMissing)

            pf_list = self.assetid_filepubobj_query(showobj, assobj,
                                                    file_type_obj_list)

            for k, pf in zip(typeListMissing.keys(), pf_list):
                # update data list
                assobj.set_plublished_type(typeListMissing[k], pf)
        SW.stop()
        if self.verbose:
            log.info("assetid_filepub_query in {}".format(SW.elapsed()))
Ejemplo n.º 10
0
 def create_path(fullPath):
     try:
         os.mkdir(fullPath, 0o775)
         return True
     except:
         MsgUtils.msg("Cannot create %r" % fullPath)
         return False
Ejemplo n.º 11
0
    def get_iconfile(self, db, location, base_res=64):
        """Return  iconfile. if iconfile == "", use thumbnailurl
            - download thumbnailurl
            - convert and resize image to png of the needed res

                :param location: a directory to download the image
                :param conn: a shotgun connection
                :param base_res: resolution in x, keep aspect

        """
        if self.iconfile != "" and os.path.isfile(self.iconfile):
            return self.iconfile

        if self.thumbnailurl != "":
            dest = os.path.join(location, self.getName() + ".jpg")
            # destpng = os.path.join(location, self.getName()+".png")
            destjpg = dest
            if not os.path.isfile(destjpg):
                try:
                    db.download_icon(self.thumbnailurl, dest)
                except Exception as e:
                    log.error(str(e))
                    return ""
            self.iconfile = destjpg

        return self.iconfile
Ejemplo n.º 12
0
def H_addSubOptionMenu(widgetApp, amenu, aname, dd):
    alreadyThere = [
        x for x in [x for x in amenu.actions() if str(x.text()) == aname]
    ]
    if len(alreadyThere) == 0:
        if dd == None or len(dd) == 0:
            amenu.addAction(aname)
        else:

            subMenu = QtT.QtWidgets.QMenu(aname, amenu)
            subMenu.setObjectName(aname)
            amenu.addMenu(subMenu)

            for a in dd:

                if len(dd[a]) == 4:
                    la = dd[a][BK.K_TOOL_LABEL]
                    subMenu2 = QtT.QtWidgets.QMenu(la, widgetApp)
                    subMenu2.setObjectName(a)
                    subMenu.addMenu(subMenu2)
                    for b in dd[a][BK.K_TOOL_EXTRA]:
                        act = subMenu2.addAction(b)
                        act.setObjectName(b)
                elif len(dd[a]) == 3:
                    la = dd[a][BK.K_TOOL_LABEL]
                    act = subMenu.addAction(la)
                    act.setObjectName(a)
                    if dd[a][BK.K_TOOL_CHECKABLE]:
                        act.setCheckable(True)
                        act.setChecked(dd[a][BK.K_TOOL_DEFAULT])
                else:
                    log.error(
                        "in H_addSubOptionMenuwrong submenu description %s" %
                        dd[a])
Ejemplo n.º 13
0
    def inspect_asset_depend(self, showobj, assobj):
        typeList = getAssetMapping(showobj.getName())
        SW.start()

        allready = assobj.get_publishedType()
        allready = [x.getName() for x in allready]
        typeListMissing = OrderedDict()
        for i in typeList:
            if not typeList[i].short_name in allready:
                typeListMissing[i] = typeList[i].short_name
        if len(typeListMissing) == 0:
            SW.stop()
            if self.verbose:
                log.info("assetid_filepub_query in {}".format(SW.elapsed()))
            return
        file_type_obj_list = self._get_ft(typeListMissing)

        pf_list = self.assetid_filepubobj_query(showobj, assobj,
                                                file_type_obj_list)

        for k, pf in zip(typeListMissing.keys(), pf_list):
            # update data list
            assobj.set_plublished_type(typeListMissing[k], pf)
        SW.stop()
        if self.verbose:
            log.info("assetid_filepub_query in {}".format(SW.elapsed()))
Ejemplo n.º 14
0
    def OpenFile(self, afile, mode="r"):
        try:
            fFile = open(afile, mode)
        except:
            MsgUtils.error("Can't open %s" % afile)
            fFile = None

        return fFile
Ejemplo n.º 15
0
 def end_log(self):
     if self._logger != None:
         self._logger.info("ENDLOG LOG AT: %s" % time.ctime())
         self._logger.end_log()
     self._logger = None
     self._logF = ""
     MsgUtils.msg("doLog is off, print statement after this should be in the console")
     self._prefs['globalPreference']['DoLog'] = False
Ejemplo n.º 16
0
 def checkAdminPath():
     for path in DefaultPath.__ADMIN_CREATED__:
         if not DiskUtils.is_dir_exist(path):
             MsgUtils.warning("%r needed, creating" % path)
             if DiskUtils.create_path(path) == False:
                 MsgUtils.error("can't create %r" % path)
                 sys.exit(1)
     return True
Ejemplo n.º 17
0
    def treeTextUpdate(self, msg):
        if msg.widgetFrom() != self:
            log.error("treeTextUpdate,should be not getting this update")
            return

        i = msg.getItem()
        if i:
            self.disconnectLocalSignal()  # to avoid bouncing
            i.setText(msg.getWhich(), msg.getProposedName())
            self.connectLocalSignal()
Ejemplo n.º 18
0
 def buildDict(myTask, theDict):
     if JsonHelper.isContainerClass(myTask):
         dd = dict()
         myTask.getVariableMember(
             dd)  # ask the class for what it need to save
         for ch in myTask.getChildrenForXml():
             JsonHelper.buildDict(ch, dd)
         theDict[myTask.getName()] = dd
     else:
         MsgUtils.error("canno't builddict on this object")
Ejemplo n.º 19
0
def H_loadLayout(widgetApp, editor, aDefautPathMgr, nameLayout):

    if nameLayout == "":
        log.info("not layout file specified")
        widgetApp.resize(500, 500)
        widgetApp.move(100, 100)
        return
    afile = editor.layout_file(nameLayout)

    if not DiskUtils.is_file_exist(afile):
        afile = aDefautPathMgr.getDefaultLayoutFile()
        if not DiskUtils.is_file_exist(afile):
            log.debug("cannot find the layout file %s" % afile)
            widgetApp.resize(500, 500)
            widgetApp.move(100, 100)
            return

    settings = QtT.QtCore.QSettings(afile, QtT.QtCore.QSettings.IniFormat,
                                    None)
    if DO_PYQT4:
        widgetApp.resize(settings.value('MainWindow/size').toSize())
        widgetApp.move(settings.value('MainWindow/pos').toPoint())
        widgets = list(
            map(str,
                settings.value('MainWindow/widgets').toStringList()))
        for w in widgets:
            className = str(settings.value('%s/className' % w).toString())
            widgetApp.toolInstanciate(className, w)
        widgetApp.restoreState(
            settings.value('MainWindow/state').toByteArray())
        for w in widgets:
            if w in widgetApp._docksWidget:
                widgetApp._docksWidget[w].getCustomWidget().resize(
                    settings.value('%s/size' % w).toSize())
                isFloating = settings.value('%s/floating' % w).toBool()
                if isFloating:
                    widgetApp._docksWidget[w].getCustomWidget().move(
                        settings.value('%s/pos' % w).toPoint())
    else:
        widgetApp.resize(settings.value('MainWindow/size'))
        widgetApp.move(settings.value('MainWindow/pos'))
        widgets = settings.value('MainWindow/widgets')
        if widgets != None:
            for w in widgets:
                className = str(settings.value('%s/className' % w))
                widgetApp.toolInstanciate(className, w)
            widgetApp.restoreState(settings.value('MainWindow/state'))
            for w in widgets:
                if w in widgetApp._docksWidget:
                    widgetApp._docksWidget[w].getCustomWidget().resize(
                        settings.value('%s/size' % w))
                    isFloating = settings.value('%s/floating' % w)
                    if isFloating:
                        widgetApp._docksWidget[w].getCustomWidget().move(
                            settings.value('%s/pos' % w))
Ejemplo n.º 20
0
    def to_python(self, stream, acontext):
        super(GenMelTask, self).to_python(stream, acontext)

        # command
        command = GenMelTask._LockupMelAttr['command'].get(self, 'command')
        if command == None:
            log.error("'command' is required for a mel task")
            return

        # output
        output = GenMelTask._LockupMelAttr['output'].get(self, 'output')

        # source
        source = GenMelTask._LockupMelAttr['source'].get(self, 'source')

        module = "maya.mel"
        tab = acontext['tab']

        GenTask.do_python_module(stream, acontext, tab, module)

        if source != None:
            stream.write(("%smaya.mel.eval('" % tab) +
                         ('source "%s"' % source) + "')\n")

        res = do_clean_command(command)
        final = ""
        if res.success:
            if output == None:
                final = ("%smaya.mel.eval('" %
                         tab) + res.newCommand + "'" + res.addOn + ")"
            else:
                final = (
                    "%s%s = maya.mel.eval('" %
                    (tab, output)) + res.newCommand + "'" + res.addOn + ")"
        else:
            if output == None:
                final = ("%smaya.mel.eval('" % tab) + command + "')"
            else:
                final = ("%s%s = maya.mel.eval('" %
                         (tab, output)) + command + "')"

        evalEcho = GenMelTask._LockupMelAttr['evalEcho'].get(self, 'evalEcho')
        if evalEcho == True:
            p = re.compile("\(.*\)", re.DOTALL)
            m = p.search(final)
            if m:
                stream.write("%sprint%s\n" % (tab, m.group()))
            stream.write(final + "\n")
            if output != None:
                stream.write("%sprint 'return value " % tab + "%s' % " +
                             output + "\n")
        else:
            stream.write(final + "\n")
        return True
Ejemplo n.º 21
0
 def update_with(self, atask, lockup=None, attribList=None):
     super(GenPyTask, self).update_with(atask, GenPyTask._LockupPyAttr,
                                        GenPyTask._attr_PyTask)
     if hasattr(atask, 'resolveArgValues'):
         self.resolveArgValues = atask.resolveArgValues
         if hasattr(atask, 'resolveKwArgValues'):
             self.resolveKwArgValues = atask.resolveKwArgValues
             if atask.resolveArgValues == False or atask.resolveKwArgValues == False:
                 log.warning(
                     "resolve argument set to false is not supported for now"
                 )
Ejemplo n.º 22
0
    def to_python(self,stream,acontext):
        super(GenPyImportTask, self).to_python(stream,acontext)
        # command
        command = GenPyImportTask._LockupImportAttr['command'].get(self,'command')
        if command == None:
            log.error("'import contents' is required for an import task")
            return False

        scommand = command.split("\n")
        for c in scommand:
            stream.write("%s%s\n" % (acontext['tab'],c))
        return True
Ejemplo n.º 23
0
    def instanciate(self, d):
        if (JsonHelper._CLASSKEY not in d or JsonHelper._MODULEKEY not in d):
            # this is a basic dict
            return d

        # create an instance
        aclass = d[JsonHelper._CLASSKEY]
        amodule = d[JsonHelper._MODULEKEY]

        if (amodule != '__builtin__'):
            cmd = "import %s" % amodule
            try:
                exec(cmd)
            except:
                traceback.print_exc()
                MsgUtils.warning("cannot import %r" % amodule)
                MsgUtils.msg("Creating a generic class container")
                amodule = "tdata"
                aclass = "container"

        cmd = "%s.%s()" % (amodule, aclass)
        newInstance = None
        try:
            newInstance = eval(cmd)
        except:
            traceback.print_exc()
            MsgUtils.error("COMMAND %r" % cmd)
            MsgUtils.msg("class definition %r not found in %r" %
                         (aclass, amodule))
            assert newInstance != None

        # name value and typevalue
        if JsonHelper._NAMEKEY in d:
            newInstance.setName(d[JsonHelper._NAMEKEY])

        if JsonHelper._VALTYPEKEY in d:
            newInstance.setTypeValue(d[JsonHelper._VALTYPEKEY])

        if JsonHelper._VALKEY in d:
            newInstance.setValue(d[JsonHelper._VALKEY])
        if JsonHelper._PROPKEY in d:
            newInstance.setVariableMember(d[JsonHelper._PROPKEY])

        if JsonHelper._CHKEY in d:
            assert type(d[JsonHelper._CHKEY]) == dict
            for k, vn in list(d[JsonHelper._CHKEY].items()):
                chInstance = self.instanciate(vn)
                if JsonHelper.isContainerClass(chInstance):
                    chInstance.setName(str(k))
                    newInstance.addChild(chInstance, False)
                else:
                    MsgUtils.error("trouble reading %r" % type(chInstance))
        return newInstance
Ejemplo n.º 24
0
    def getChildByName(self, key):
        """ from a name find a node in the task node ... the result is cache for futher query
        """
        if key in self.__Cache:
            return self.__Cache[key]

        for cn in self.getChildren():
            if cn.getName() == key:
                self.__Cache[key] = cn
                return cn
        log.debug("getChildByName: node %r not found" % key)
        return None
Ejemplo n.º 25
0
 def findChildRec(self, parent, aPathAsList):
     if len(aPathAsList) == 0:
         return parent
     for i in range(self.childCount(parent)):
         item = self.childAt(parent, i)
         if not item:
             log.error("in base_tw: findChildRec")
             return None
         if item.text(0) == aPathAsList[0]:
             if len(aPathAsList) <= 1:
                 return item
             return self.findChildRec(item,aPathAsList[1:])
     return None
Ejemplo n.º 26
0
    def loadRaw(self, elmt, pTask, maxLevel):
        # foreign xml
        creationList = []
        nb = "n%d:"
        index = 0

        while elmt != None:

            if elmt.nodeType == elmt.ELEMENT_NODE:
                if maxLevel == 0:
                    return []
                if maxLevel != -1:
                    maxLevel -= 1

                if elmt.nodeName != "#text":
                    atask = tdata.container()
                    atask.setName(nb % index + elmt.nodeName)

                    pTask.addChild(atask)

                    index += 1
                    adict = {}
                    if self.getXmlAttr(elmt, adict):
                        atask.__dict__.update(adict)
                    result = self.getKidsRaw(elmt, atask, maxLevel)
                    for r in result:
                        if r[0] == "TexType":
                            atask.setValue(r[1])
                        else:
                            MsgUtils.error("not done  %r %r t=%s v=%s n=%s" %
                                           (pTask.getName(), atask.getName(),
                                            r[0], r[1], r[2]))
            elif elmt.nodeType == elmt.TEXT_NODE:
                edata = self.getTextValue(elmt).strip()
                if edata != "":
                    creationList.append(["TextType", edata, elmt.nodeName])
            elif elmt.nodeType == elmt.COMMENT_NODE:
                edata = self.getTextValue(elmt).strip()
                if edata != "":
                    creationList.append(["CommentType", edata, elmt.nodeName])

            elif elmt.nodeType == elmt.CDATA_SECTION_NODE:
                data = self.getcData(elmt)
                if data != "" and len(data.strip()) > 0:
                    creationList.append(["CdType", data, elmt.nodeName])
            else:
                MsgUtils.warning("NOT YETXX %r %r" %
                                 (elmt.nodeName, elmt.nodeType))

            elmt = elmt.nextSibling
        return creationList
Ejemplo n.º 27
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.º 28
0
 def run(self, with_log, run_dry):
     log_info = ['mxinfocreatedir']
     if with_log:
         log_info.append("ensure_folder_exists {}".format(self.parm1))
     try:
         if run_dry == False:
             FileSystemUtils.ensure_folder_exists(self.parm1, self.mode)
         success = True
         errors = []
     except Exception as e:
         log.error(str(e))
         success = False
         errors = [str(e)]
     return ResultFileProc(success, errors, log_info, None)
Ejemplo n.º 29
0
 def run(self, with_log, run_dry):
     log_info = ['mxinfocopy']
     if with_log:
         log_info.append("Copy File {} {}".format(self.parm1,self.parm2))
     try:
         if run_dry == False:
             FileSystemUtils.copy_file(self.parm1, self.parm2, self.mode)
         success = True
         errors = []
     except Exception as e:
         log.error(str(e))
         success = False
         errors = [str(e)]
     return ResultFileProc(success, errors, log_info, None)
Ejemplo n.º 30
0
    def _init_root_path(self):
        if self._userInfo == None:
            return False
        toCheck = [self._userInfo.local_area,
                   self._userInfo.log_dir]
        checkLayout = False
        for d in toCheck:
            if not DiskUtils.is_dir_exist(d):
                checkLayout = True
                MsgUtils.warning("%r is needed, create..." % d)
                if DiskUtils.create_path_rec(d) == False:
                    MsgUtils.error("can't create %r" % d)
                else:
                    MsgUtils.info("%r created" % d)

                #only on creation,copy if exist the defaultLayoutFile from
                # from the module
        if checkLayout:
            import shutil
            fromlayout = os.path.join(self._resource.resource_path,
                                      initDefault.DEFAULT_LAYOUT_ROOT)
            tolayout = os.path.join(self._userInfo.local_area,
                                    initDefault.DEFAULT_LAYOUT_ROOT)
            fromlayout += ".lyt"
            tolayout += ".lyt"
            if os.path.exists(fromlayout) and not os.path.exists(tolayout):
                shutil.copyfile(fromlayout, tolayout)
                MsgUtils.info("found a defaut layout file %s" % fromlayout)
        self.valid_to_save = self.is_persistant()