Exemplo n.º 1
0
def savePrefs():

    global DAVOS_PREFS

    if DAVOS_PREFS:
        p = pathResolve(r"%USERPROFILE%\davos_prefs.json")
        jsonWrite(p, DAVOS_PREFS)
Exemplo n.º 2
0
def loadPrefs():

    global DAVOS_PREFS

    try:
        p = pathResolve(r"%USERPROFILE%\davos_prefs.json")
        DAVOS_PREFS = jsonRead(p)
    except EnvironmentError:
        DAVOS_PREFS = {}

    return DAVOS_PREFS
Exemplo n.º 3
0
def iterNodeAttrFiles(**kwargs):

    bResolved = kwargs.pop("resolved", True)

    for sNodeAttr in iterAttrsUsedAsFilename(**kwargs):

        try:
            p = mc.getAttr(sNodeAttr)
        except Exception as e:
            sErr = unicode(e)
            print ("{}: {}".format(sNodeAttr, sErr) if sNodeAttr not in sErr else sErr).strip()
            continue

        if p:
            yield pathResolve(p) if bResolved else p, sNodeAttr
Exemplo n.º 4
0
def iterNodeAttrFiles(**kwargs):

    bResolved = kwargs.pop("resolved", True)

    for sNodeAttr in iterAttrsUsedAsFilename(**kwargs):

        try:
            p = mc.getAttr(sNodeAttr)
        except Exception as e:
            sErr = unicode(e)
            print("{}: {}".format(sNodeAttr, sErr)
                  if sNodeAttr not in sErr else sErr).strip()
            continue

        if p:
            yield pathResolve(p) if bResolved else p, sNodeAttr
Exemplo n.º 5
0
def report(foundList, errorList, sDbPath=""):

    def _u(v):
        return unicode_(v) if isinstance(v, basestring) else v

    numNodes = len(foundList)
    foundList = sorted((e for e in foundList if e), key=lambda e:e.dbMtime)
    table = []
    for rcEntry in foundList:
        try:
            dbnode = rcEntry._dbnode
            sOnlineTime = strftime(long(dbnode.synced_online) / 1000) if dbnode.synced_online else ""

            texts = map(_u, (rcEntry.dbPath(),
                             rcEntry.author,
                             rcEntry.origin,
                             strftime(toTimestamp(rcEntry.dbMtime)),
                             cmpStr(rcEntry.dbMtime, rcEntry.fsMtime),
                             strftime(toTimestamp(rcEntry.fsMtime)),
                             repr(rcEntry.fileSize),
                             cmpStr(rcEntry.fileSize, rcEntry.sourceSize),
                             repr(rcEntry.sourceSize),
                             sOnlineTime,
                             ))
        except Exception as e:
            print toStr(e), ":", rcEntry.absPath()
            continue

        table.append(texts)

    headers = ["file", "author", "site", "published", "", "modified",
               "current size", "", "source size", "synced online"]
    print tabulate(table, headers, tablefmt="simple")
    print len(foundList), "bad on", numNodes, "files - scan errors:", len(errorList)

    sFileName = sDbPath.strip("/").replace("/", "_") + "_report.html"
    sHtmlPath = pathResolve("%USERPROFILE%/Documents/{}".format(sFileName))

    sCharset = '<head>\n<meta charset="UTF-8">\n</head>\n'
    with codecs.open(sHtmlPath, "w", "utf_8") as fo:
        fo.writelines(sCharset + tabulate(table, headers, tablefmt="html"))

    for rcEntry, e in errorList:
        print rcEntry.dbPath(), type(e), e.message, toDisplayText(rcEntry.dbMtime)
Exemplo n.º 6
0
def importFile(sFilePath, **kwargs):

    if not isinstance(sFilePath, basestring):
        raise TypeError, 'Wrong type passed to file path argument: {0}'.format(type(sFilePath))

    if ("%" in sFilePath) or ("$" in sFilePath):
        sResolvedPath = pathResolve(sFilePath)
    else:
        sResolvedPath = sFilePath

    if not osp.isfile(sResolvedPath):
        raise ValueError, 'Import failed. No such file found : "{0}"'.format(sResolvedPath)

    kwargs.pop("defaultNamespace", kwargs.pop("dns", None))
    bReference = kwargs.pop("reference", kwargs.pop("r", False))
    bViewFit = kwargs.pop('viewFit', False)
    bOutNewNodes = kwargs.pop('returnNewNodes', kwargs.pop('rnn', True))
    bPreserveRefs = kwargs.pop('preserveReferences', kwargs.pop('pr', True))
    bNewScene = kwargs.pop('newScene', kwargs.pop('nsc', False))

    if bReference:
        bUseNamespaces = True
        bNewScene = False
    else:
        bUseNamespaces = kwargs.pop('useNamespaces', kwargs.pop('uns', False))

#    sNamespace = ""
    if bUseNamespaces:
        sNamespace = kwargs.pop("namespace", kwargs.pop("ns" , ""))
        if not sNamespace:
            sNamespace = osp.basename(sResolvedPath).rsplit(".", 1)[0]

    ##Three states kwarg:
    ##if newScene == True , importing NewScene is forced
    ##if newScene == False, importing in the CurrentScene
    ##if newScene == "NoEntry", so choose between NewScene and CurrentScene

    if bNewScene == "NoEntry":

        sConfirm = pm.confirmDialog(title="Import File",
                                    message='Import file into ... ?',
                                    button=["New Scene", "Current Scene", "Cancel"],
                                    defaultButton="New Scene",
                                    cancelButton="Cancel",
                                    dismissString="Cancel",
                                    )

        if sConfirm == "Cancel":
            logMsg("Cancelled !" , warning=True)
            return

        bNewScene = True if sConfirm == "New Scene" else False

    if bNewScene:
        if newScene(**kwargs):
            return

    if bReference:
        oNewNodeList = pm.createReference(sFilePath,
                                          namespace=sNamespace,
                                          returnNewNodes=bOutNewNodes,
                                          **kwargs)
    else:
        if bUseNamespaces:
            kwargs["namespace"] = sNamespace

        oNewNodeList = pm.importFile(sResolvedPath,
                                     returnNewNodes=bOutNewNodes,
                                     preserveReferences=bPreserveRefs,
                                     **kwargs)

    oNewNodeList = listForNone(oNewNodeList)

    if oNewNodeList and bViewFit:
        pm.viewFit(all=True)

    return oNewNodeList
Exemplo n.º 7
0
def importFile(sFilePath, **kwargs):

    if not isinstance(sFilePath, basestring):
        raise TypeError, 'Wrong type passed to file path argument: {0}'.format(
            type(sFilePath))

    if ("%" in sFilePath) or ("$" in sFilePath):
        sResolvedPath = pathResolve(sFilePath)
    else:
        sResolvedPath = sFilePath

    if not osp.isfile(sResolvedPath):
        raise ValueError, 'Import failed. No such file found : "{0}"'.format(
            sResolvedPath)

    kwargs.pop("defaultNamespace", kwargs.pop("dns", None))
    bReference = kwargs.pop("reference", kwargs.pop("r", False))
    bViewFit = kwargs.pop('viewFit', False)
    bOutNewNodes = kwargs.pop('returnNewNodes', kwargs.pop('rnn', True))
    bPreserveRefs = kwargs.pop('preserveReferences', kwargs.pop('pr', True))
    bNewScene = kwargs.pop('newScene', kwargs.pop('nsc', False))

    if bReference:
        bUseNamespaces = True
        bNewScene = False
    else:
        bUseNamespaces = kwargs.pop('useNamespaces', kwargs.pop('uns', False))


#    sNamespace = ""
    if bUseNamespaces:
        sNamespace = kwargs.pop("namespace", kwargs.pop("ns", ""))
        if not sNamespace:
            sNamespace = osp.basename(sResolvedPath).rsplit(".", 1)[0]

    ##Three states kwarg:
    ##if newScene == True , importing NewScene is forced
    ##if newScene == False, importing in the CurrentScene
    ##if newScene == "NoEntry", so choose between NewScene and CurrentScene

    if bNewScene == "NoEntry":

        sConfirm = pm.confirmDialog(
            title="Import File",
            message='Import file into ... ?',
            button=["New Scene", "Current Scene", "Cancel"],
            defaultButton="New Scene",
            cancelButton="Cancel",
            dismissString="Cancel",
        )

        if sConfirm == "Cancel":
            logMsg("Cancelled !", warning=True)
            return

        bNewScene = True if sConfirm == "New Scene" else False

    if bNewScene:
        if newScene(**kwargs):
            return

    if bReference:
        oNewNodeList = pm.createReference(sFilePath,
                                          namespace=sNamespace,
                                          returnNewNodes=bOutNewNodes,
                                          **kwargs)
    else:
        if bUseNamespaces:
            kwargs["namespace"] = sNamespace

        oNewNodeList = pm.importFile(sResolvedPath,
                                     returnNewNodes=bOutNewNodes,
                                     preserveReferences=bPreserveRefs,
                                     **kwargs)

    oNewNodeList = listForNone(oNewNodeList)

    if oNewNodeList and bViewFit:
        pm.viewFit(all=True)

    return oNewNodeList
Exemplo n.º 8
0
    def getPath(self, sSpace, sSection, pathVar="", tokens=None, default="NoEntry", **kwargs):

        bResVars = kwargs.get("resVars", True)
        bResEnvs = kwargs.get("resEnvs", True)

        sRcPath = ""
        if sSpace:
            sRcPath = self.getVar(sSection, sSpace + "_path", default=default,
                                  resVars=bResVars)
            if not sRcPath:
                return sRcPath

        if pathVar:
            try:
                sRcPath = pathJoin(sRcPath, self.getVar(sSection, pathVar))
            except AttributeError:
                if default != "NoEntry":
                    return default
                raise

        if bResEnvs:
            sRcPath = pathResolve(sRcPath)

        sFieldSet = set()
        if bResVars:
            # resolve vars from config
            sFieldSet = set(findFmtFields(sRcPath))
            if sFieldSet:

                confTokens = self.getVar(sSection, pathVar + "_tokens", default={})
                sConfFieldSet = set(confTokens.iterkeys())

                for sField in sFieldSet:

                    if sField in confTokens:
                        continue

                    value = self.getVar(sSection, sField, "")
                    if value:
                        sConfFieldSet.add(sField)
                    else:
                        value = '{' + sField + '}'

                    confTokens[sField] = value

                if confTokens:
                    sRcPath = sRcPath.format(**confTokens)

                sFieldSet -= sConfFieldSet

        # resolve remaining vars from input tokens
        if tokens:
            if not isinstance(tokens, dict):
                raise TypeError("argument 'tokens' must be of type <dict>. Got {}"
                                .format(type(tokens)))

            sFieldSet = sFieldSet - set(tokens.iterkeys())
            if sFieldSet:
                msg = ("Cannot resolve path: '{}'. \n\tMissing tokens: {}"
                        .format(sRcPath, list(sFieldSet)))
                raise RuntimeError(msg)

            sRcPath = sRcPath.format(**tokens)

        return pathNorm(sRcPath, keepEndSlash=True)