Esempio n. 1
0
def userInfo( url='', apiUser='', newUser=False ) :
    'Retrieves the User ID to use for the window'
    
    user, userID, userList='', '', []
    
    isGUI = False
    try :
        #Validate Against DCC Environment
        if F.get_app() is not None :
            isGUI = True
    except :
        pass

    if isGUI :
        user=popup( title='Enter NIM Login', msg='Please enter your NIM username:'******'input', defaultInput=apiUser )
    else :
        user=raw_input('Please enter your NIM username: '******'q': 'getUserID', 'u': user}, debug=False, nimURL=url )
            print("userID: %s" % userID)
        else :
            userID=Api.get( sqlCmd={ 'q': 'getUserID', 'u': user}, debug=False )
            print("userID: %s" % userID)

        if type(userID)==type(list()) and len(userID)==1 :
            try :
                userID=userID[0]['ID']
                P.info( 'User set to "%s" (ID #%s)' % (user, userID) )
                if newUser == False:
                    #  Update Preferences :
                    Prefs.update( attr='NIM_User', value=user )
                    if isGUI :
                        popup( title='NIM User Set', msg='The NIM user has been set to %s.' % user)
                    else :
                        print('The NIM user has been set to %s.' % user)
                return (user, userID)
            except :
                return False
        else :
            P.error( 'Failed to find NIM user.' )
            if isGUI :
                response = popup( title='User Not Found', msg='The username entered is not a valid NIM user.\n\n Would you like to enter a new username?', type='okCancel')
            else :
                response=raw_input('The username entered is not a valid NIM user. Would you like to enter a new username? (Y/N)')
                if response == 'Y' or response == 'y' :
                    response = 'OK'

            if(response=='OK'):
                userInfo( url=url, newUser=newUser )
            else :
                return False
Esempio n. 2
0
    def ingest_prefs(self):
        'Sets NIM dictionary from preferences'
        self.app = F.get_app()
        self.prefs = Prefs.read()

        if not self.prefs:
            return False

        P.info('Preferences being read...')

        #  Set User Information :
        user = self.prefs['NIM_User']
        userID = Api.get(sqlCmd={'q': 'getUserID', 'u': user}, debug=False)
        if userID:
            if type(userID) == type(list()) and len(userID) == 1:
                userID = userID[0]['ID']
            try:
                self.nim['user'] = {'name': user, 'ID': str(userID)}
            except:
                self.nim['user'] = {'name': '', 'ID': ''}
                P.warning('Unable to set User information in NIM!')

            #  Get Show/Shot Prefs :
            try:
                self.set_name(elem='job', name=self.prefs[self.app + '_Job'])
                self.set_name(elem='asset',
                              name=self.prefs[self.app + '_Asset'])
                self.set_tab(_type=self.prefs[self.app + '_Tab'])
                self.set_name(elem='show', name=self.prefs[self.app + '_Show'])
                self.set_name(elem='shot', name=self.prefs[self.app + '_Shot'])
                self.set_name(elem='filter',
                              name=self.prefs[self.app + '_Filter'])
                self.set_name(elem='task', name=self.prefs[self.app + '_Task'])
                self.set_name(elem='base',
                              name=self.prefs[self.app + '_Basename'])
                self.set_name(elem='ver',
                              name=self.prefs[self.app + '_Version'])
            except:
                P.error(
                    'Sorry, unable to get NIM preferences, cannot run NIM GUI')
                P.error('    %s' % traceback.print_exc())
                win.popup(
                    title='NIM Error',
                    msg=
                    'Sorry, unable to get NIM preferences, cannot run NIM GUI')
                return False
            return self
        else:
            return False
Esempio n. 3
0
def _inputURL():
    'Gets the NIM API URL from the user, via a popup'
    global nim_URL, version

    isGUI = False
    try:
        #Validate Against DCC Environment
        if F.get_app() is not None:
            isGUI = True
    except:
        pass

    #  Prompt user to input URL :
    msg = 'Please input the NIM API URL :'
    if isGUI:
        url = Win.popup(title=winTitle + ' - Get URL',
                        msg=msg,
                        type='input',
                        defaultInput=nim_URL)
    else:
        url = raw_input(msg)
    #P.info( 'NIM URL Set to: %s' % url )
    if url:
        # Check for '/nimAPI.php?' at end of URL

        if url.endswith('nimAPI.php'):
            url = url + "?"
        '''
        if not url.endswith('/nimAPI.php?'):
            if not url.endswith('/'):
                url = url+"/nimAPI.php?"
            else :
                url = url+"nimAPI.php?"
        '''

        return url

    else:
        return False
Esempio n. 4
0
def mk_default(recreatePrefs=False, notify_success=True):
    'Makes default preferences'

    global apps
    global nim_api
    global nim_user, nim_userID
    global nim_URL

    isGUI = False
    try:
        #Validate Against DCC Environment
        if F.get_app() is not None:
            isGUI = True
    except:
        pass

    nimHome = mk_home()
    prefsFile = get_path()
    apps = F.get_apps()
    #nim_user=F.get_user()
    url, userID = 1, ''

    #  Create home dir, if necessary :
    mk_home()

    #  Check to see if preferences need to be re-created :
    if os.path.exists(prefsFile):
        #  If preferences have missing attributes, add those attributes to prefs file:
        prefs_check = check()
        if prefs_check:
            #  Open NIM prefs file for appending :
            _prefFile = open(prefsFile, 'a')
            _prefFile.write('\n')
            #  Write NIM preferences :
            nim_prefs = _nimPrefs()
            missing_at_least_one_nim_pref = False
            for key in prefs_check:
                if key in nim_prefs:
                    missing_at_least_one_nim_pref = True
                    _prefFile.write(key + '=' + nim_prefs[key] + '\n')
            if missing_at_least_one_nim_pref:
                _prefFile.write('\n')
            #  Write Application Preferences :
            for app in apps:
                app_prefs = _appPrefs(app)
                for key in prefs_check:
                    if key in app_prefs:
                        _prefFile.write(key + '=' + app_prefs[key] + '\n')
                _prefFile.write('\n')
            #  Close file :
            _prefFile.close()
        else:
            #  Ask to recreate existing preferences :
            if recreatePrefs:
                if isGUI:
                    recreate=Win.popup( title=winTitle+' - Prefs Exist', \
                        msg='Preferences already exist.\nWould you like to re-create your preferences?', \
                        type='okCancel' )
                else:
                    recreate = raw_input(
                        "Preferences already exist. Would you like to re-create your preferences? (Y\N) "
                    )
                    if recreate == 'Y' or recreate == 'y':
                        recreate = 'OK'

                if recreate == 'OK':
                    P.info('Deleting previous preferences file...')
                    try:
                        os.remove(prefsFile)
                    except Exception, e:
                        P.error('Unable to delete preferences')
                        P.error('    %s' % traceback.print_exc())
                        return False
                else:
                    return prefsFile
            else:
                return prefsFile
Esempio n. 5
0
import nim_print as P
import nim_win as Win
'''
isGUI = True
try :
    #Validate Against Terminal
    if sys.stdin.isatty():
        isGUI = False
except :
    pass
'''

isGUI = False
try:
    #Validate Against DCC Environment
    if F.get_app() is not None:
        isGUI = True
except:
    pass

#print "isGUI: %s" % isGUI

#  Variables :
prefs_dirName = '.nim'
prefs_fileName = 'prefs.nim'
version = 'v4.0.61'
winTitle = 'NIM_' + version
nim_URL = 'http://hostname/nimAPI.php'
nim_useSLL = 'False'
nim_scripts = os.path.abspath(
    os.path.join(os.path.dirname(__file__), os.pardir))
Esempio n. 6
0
    def __init__(self):
        'Initializes the NIM attributes'
        super(NIM, self).__init__()
        self.nim = {}

        #  Store preferences :
        self.prefs = Prefs.read()

        #  Store the different GUI elements to be populated :
        self.elements = [
            'job', 'asset', 'show', 'shot', 'filter', 'task', 'base', 'ver'
        ]
        self.print_elements = [
            'job', 'asset', 'show', 'shot', 'filter', 'task', 'basename',
            'version'
        ]
        self.comboBoxes = ['job', 'asset', 'show', 'shot', 'filter', 'task']
        self.listViews = ['base', 'ver']

        #  Instantiate dictionary of settings :
        for elem in self.elements:
            self.clear(elem)

        #  Make image attributes :
        for elem in ['asset', 'shot']:
            self.nim[elem]['img_pix'] = ''
            self.nim[elem]['img_label'] = ''

        #  Set file attributes :
        self.nim['file'] = {
            'path': '',
            'filename': '',
            'dir': '',
            'basename': '',
            'compPath': '',
            'version': ''
        }
        self.set_filePath()

        #  Extra NIM attributes :
        for elem in ['comment', 'fileExt', 'tag']:
            self.nim[elem] = {'name': '', 'input': None}
        self.nim['server'] = {
            'name': '',
            'path': '',
            'input': '',
            'ID': '',
            'Dict': ''
        }
        self.nim['fileExt']['fileType'] = ''
        self.nim['app'] = F.get_app()
        self.nim['class'] = None
        self.nim['mode'] = None
        self.nim['pub'] = False

        #  Attempt to set User information :
        self.nim['user'] = {'name': '', 'ID': ''}
        if self.prefs:
            if 'NIM_User' in self.prefs.keys():
                self.nim['user']['name'] = self.prefs['NIM_User']
                if self.nim['user']['name']:
                    self.nim['user']['ID'] = Api.get_userID(
                        user=self.nim['user']['name'])

        #  App Specific :
        if self.nim['app'] == 'C4D':
            #  Group ID's :
            self.grpIDs = {
                'main': 101,
                'top': 102,
                'jobAsset': 103,
                'tab': 104,
                'job': 105,
                'asset': 106,
                'showShot': 107,
                'taskBase': 108,
                'ver': 109,
                'btn': 110
            }
            #  Input ID's :
            self.inputIDs = {
                'job': 200,
                'server': 201,
                'asset': 202,
                'show': 203,
                'shot': 204,
                'filter': 205,
                'task': 206,
                'base': 207,
                'tag': 208,
                'comment': 209,
                'ver': 210,
                'verFilepath': 211,
                'verUser': 212,
                'verDate': 213,
                'verComment': 214,
                'checkbox': 215
            }
            #  Text ID's :
            self.textIDs = {
                'job': 300,
                'server': 301,
                'asset': 302,
                'show': 303,
                'shot': 304,
                'filter': 305,
                'task': 306,
                'base': 307,
                'tag': 308,
                'comment': 309,
                'ver': 310,
                'verFilepath': 311,
                'verUser': 312,
                'verDate': 313,
                'verComment': 314
            }
            #  Lowest Menu IDs :
            self.start_menuIDs = {
                'job': 1000,
                'asset': 2000,
                'show': 3000,
                'shot': 4000,
                'filter': 5000,
                'task': 6000,
                'base': 7000,
                'ver': 8000
            }
            #  Menu ID's :
            self.menuIDs = {
                'job': {},
                'asset': {},
                'show': {},
                'shot': {},
                'filter': {},
                'task': {},
                'base': {},
                'ver': {}
            }
            #  Button ID :
            self.btnID = 10070
            self.cancelBtnID = 10071

        return
Esempio n. 7
0
def popup( title='', msg='', type='ok', defaultInput='', pyside=False, _list=[], selNum=0, winPrnt=None ) :
    'Attempts to build a simple dialog window in either native application calls, or PySide'
    app=F.get_app()
    userInput=''
    
    #  Create PySide window :
    if pyside :
        try :
            if type=='comboBox' :
                userInput, ok=QtGui.QInputDialog.getItem( winPrnt, title, msg, _list, 0, False )
                if not ok :
                    userInput=None
        except :
            P.error( 'Sorry, problem loading the dialog.' )
    
    # Cinesync Window :        
    elif app == 'Cinesync':
        try:
            if type == 'input' or type == 'okCancel':
                userInput, ok = QtGui.QInputDialog.getText(winPrnt, title, msg, QtGui.QLineEdit.Normal, defaultInput)
                if not ok:
                    userInput = None

        except Exception as err:
            P.error('Error with dialog: %s' % str(err))
    
    #  Maya Window :
    elif app=='Maya' :
        import maya.cmds as mc
        if type=='ok' :
            userInput=mc.confirmDialog( title=title, message=msg, button=['OK'], \
                defaultButton='OK' )
        elif type=='okCancel' :
            userInput=mc.confirmDialog( title=title, message=msg, button=['OK', 'Cancel'], \
                defaultButton='OK', cancelButton='Cancel', dismissString='Cancel' )
        elif type=='input' :
            userInput=mc.promptDialog( title=title, message=msg, text=defaultInput, \
                button=['OK', 'Cancel'], defaultButton='OK', cancelButton='Cancel', dismissString='Cancel' )
            if userInput=='OK' :
                userInput=str(mc.promptDialog( query=True, text=True ))
            else :
                userInput=''
    
    #  Nuke Window :
    elif app=='Nuke' :
        import nuke
        if type=='ok' :
            userInput=nuke.message( msg )
        elif type=='okCancel' :
            userInput=nuke.ask( msg )
            if userInput :
                userInput='OK'
            else :
                userInput='Cancel'
        elif type=='input' :
            userInput=nuke.getInput( msg, defaultInput )
    
    #  Hiero Window :
    elif app=='Hiero' :
        import hiero.ui
        from hiero.core import log
        if type=='ok' :
            dialog=QtGui.QMessageBox.information( hiero.ui.mainWindow(), title, msg, \
                QtGui.QMessageBox.Ok)
            if dialog==QtGui.QMessageBox.Ok :
                userInput='OK'
        elif type=='okCancel' :
            dialog=QtGui.QMessageBox.question( hiero.ui.mainWindow(), title, msg, \
                QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Ok )
            if dialog==QtGui.QMessageBox.Ok :
                userInput='OK'
            elif dialog==QtGui.QMessageBox.Cancel :
                userInput='Cancel'
        elif type=='input' :
            dialog=QtGui.QInputDialog.getText( QtGui.QInputDialog(), title, msg, \
                QtGui.QLineEdit.Normal )
            if dialog[1] :
                userInput=dialog[0]
            else :
                userInput=None
    
    #  C4D Window :
    elif app=='C4D' :
        import c4d
        from c4d import gui
        if type=='ok' :
            userInput=gui.MessageDialog( msg )
        elif type=='okCancel' :
            userInput=gui.QuestionDialog( text=msg )
            if userInput : userInput='OK'
        elif type=='input' :
            userInput=gui.InputDialog( msg )
    
    #  3dsMax :
    elif app=='3dsMax' :
        import MaxPlus
        #maxWin=MaxPlus.Win32_GetMAXHWnd()

        if type=='ok' :
            dialog=QtGui.QMessageBox.information( None, title, msg, \
                QtGui.QMessageBox.Ok)
            if dialog==QtGui.QMessageBox.Ok :
                userInput='OK'
        elif type=='okCancel' :
            dialog=QtGui.QMessageBox.question( None, title, msg, \
                QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Ok )
            if dialog==QtGui.QMessageBox.Ok :
                userInput='OK'
            elif dialog==QtGui.QMessageBox.Cancel :
                userInput='Cancel'
        elif type=='input' :
            dialog=QtGui.QInputDialog.getText( QtGui.QInputDialog(), title, msg, \
                QtGui.QLineEdit.Normal )
            if dialog[1] :
                userInput=dialog[0]
            else :
                userInput=None

    #  Houdini :
    elif app=='Houdini' :
        import hou
        if type=='ok' :
            dialog=QtGui.QMessageBox.information( None, title, msg, \
                QtGui.QMessageBox.Ok)
            if dialog==QtGui.QMessageBox.Ok :
                userInput='OK'
        elif type=='okCancel' :
            dialog=QtGui.QMessageBox.question( None, title, msg, \
                QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Ok )
            if dialog==QtGui.QMessageBox.Ok :
                userInput='OK'
            elif dialog==QtGui.QMessageBox.Cancel :
                userInput='Cancel'
        elif type=='input' :
            inputFont = QtGui2.QFont()
            inputFont.setFamily("Ariel")
            inputFont.setPointSize(20)
            inputDialog = QtGui.QInputDialog(None)
            inputDialog.setStyleSheet( "* {background-color: #333333; color: white;}" );
            inputDialog.setInputMode(QtGui.QInputDialog.TextInput)
            inputDialog.setWindowTitle(title)
            inputDialog.setLabelText(msg)
            inputDialog.setFont(inputFont)
            ok = inputDialog.exec_()
            if(ok):
                userInput = inputDialog.textValue()
            else :
                userInput = None

    #  Flame :
    elif app=='Flame' :
        if type=='ok' :
            dialog=QtGui.QMessageBox.information( None, title, msg, \
                QtGui.QMessageBox.Ok)
            if dialog==QtGui.QMessageBox.Ok :
                userInput='OK'
        elif type=='okCancel' :
            dialog=QtGui.QMessageBox.question( None, title, msg, \
                QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Ok )
            if dialog==QtGui.QMessageBox.Ok :
                userInput='OK'
            elif dialog==QtGui.QMessageBox.Cancel :
                userInput='Cancel'
        elif type=='input' :
            dialog=QtGui.QInputDialog.getText( QtGui.QInputDialog(), title, msg, \
                QtGui.QLineEdit.Normal )
            if dialog[1] :
                userInput=dialog[0]
            else :
                userInput=None

    #P.info('Returning PopUP INFO: %s' % userInput)
    return userInput
Esempio n. 8
0
def setApiKey( url='' ) :
    'Sets the NIM user API Key'
    #print('setApiKey::')
    nim_apiKey = ''
    
    connect_info = Api.get_connect_info()
    api_url = connect_info['nim_apiURL']
    api_user = connect_info['nim_apiUser']

    app=F.get_app()

    isGUI = False
    try :
        #Validate Against DCC Environment
        if F.get_app() is not None :
            isGUI = True
    except :
        pass

    if isGUI :
        if app == 'C4D' :
            api_key=popup( title='Enter NIM API Key', msg='Enter the NIM API Key for your user:'******'input', defaultInput='' )
        else :
            api_key=popup( title='Enter NIM API Key', msg='Failed to validate user.\n\n \
                            NIM Security is set to require the use of API Keys.\n \
                            Please obtain a valid NIM API KEY from your NIM Administrator.\n\n \
                            Enter the NIM API Key for your user:'******'input', defaultInput='' )
    else :
        print('Failed to validate user.\n \
                NIM Security is set to require the use of API Keys.\n \
                Please obtain a valid NIM API KEY from your NIM Administrator.')
        api_key=raw_input('Enter the NIM API Key for your user: '******'Cancel' :
        return False
    else :
        #  Get user ID :
        if api_url :
            testAPI = Api.testAPI(nimURL=api_url, nim_apiUser=api_user, nim_apiKey=api_key)
            if type(testAPI[0])==type(dict()) :
                if testAPI[0]['error'] != '':
                    P.error( testAPI[0]['error'] )
                    if isGUI :
                        response = popup( title='NIM API Invalid', msg='The NIM API Key entered is invalid.\n\nRe-enter API Key?', type='okCancel')
                    else :
                        print('The NIM API Key entered is invalid.')
                        response=raw_input('Re-enter API Key? (Y/N): ')
                        if response == 'Y' or response == 'y' :
                            response = 'OK'

                    if(response=='OK'):
                        setApiKey( url=url )
                    else :
                        return False
                else :
                    #  Update NIM Key File :
                    print "Key Valid: %s" % testAPI[0]['keyValid']
                    if testAPI[0]['keyValid'] == 'true' :
                        try :
                            keyFile = os.path.normpath( os.path.join( Prefs.get_home(), 'nim.key' ) )
                            print keyFile
                            ''' #Python 2.7
                            with open(keyFile, 'r+') as f:
                                f.seek(0)
                                f.write(api_key)
                                f.truncate()
                            '''
                            # Using Python2.6 for compatibiity
                            keyFO = open(keyFile, "w")
                            keyFO.seek(0)
                            keyFO.write(api_key)
                            keyFO.truncate()
                            keyFO.close()
                            if isGUI :
                                popup( title='NIM API Key Set', msg='The NIM API Key has been set.\n\nPlease retry your last command.')
                            else :
                                print('The NIM API Key has been set.\nPlease retry your last command.')
                            return True
                        except :
                            P.error('Failed writing NIM Key file.')
                            P.error( '    %s' % traceback.print_exc() )
                            if isGUI :
                                popup(title='Error', msg='Failed writing NIM Key File.')
                            else :
                                print('Failed writing NIM Key File.')
                            return False
                    else :
                        P.error( 'Failed to validate NIM API.' )
                        if isGUI :
                            response = popup( title='NIM API Invalid', msg='The NIM API Key entered is invalid.\n\nRe-enter API Key?', type='okCancel')
                        else :
                            print('The NIM API Key entered is invalid.')
                            response=raw_input('Re-enter API Key? (Y/N): ')
                            if response == 'Y' or response == 'y' :
                                response = 'OK'

                        if(response=='OK'):
                            setApiKey( url=url )
                        else :
                            return False
            else :
                P.error( 'Failed to validate NIM API.' )
                if isGUI :
                    response = popup( title='NIM API Invalid', msg='The NIM API Key entered is invalid.\n\nRe-enter API Key?', type='okCancel')
                else :
                    print('The NIM API Key entered is invalid.')
                    response=raw_input('Re-enter API Key? (Y/N): ')
                    if response == 'Y' or response == 'y' :
                        response = 'OK'

                if(response=='OK'):
                    setApiKey( url=url )
                else :
                    return False
        else :
            return None