def on_done(self, shelfToolName): ### Update config with new tool name configAll = subPorts.getConfig() configAll['shelftool'] = shelfToolName # print(configAll) plugin_path = '%s/SubTunnel' % (sublime.packages_path()) config = '%s/config.json' % plugin_path f = open(config, 'w') f.write(json.dumps(configAll)) f.close() ### Send the code port = subPorts.getPort() h = Tunnel(self.window,port) code = h.codeAsText python = "hou.shelves.tools()['%s'].setData('%s')" % (shelfToolName,code) hscriptCmd = r'''python -c \"%s\"''' % python cmd = r'''%s "%s"''' % (h.hcommand,hscriptCmd) print ("CMD shelf:", cmd) p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) cmd_stdout, cmd_stderr = p.communicate()
def getNodeType(self): ''' get the selected node type ''' # Note a special treatment of backticks (bash specifics) # cmd = ''' %s "optype -t opfind -N \"/\"\`opselectrecurse(\\"/\\",0)\`" ''' % self.hcommand # This is just a regular hscript command you would launch from hscript shell in houdini hscriptCmd = r'''optype -t opfind -N /`opselectrecurse("/",0)''' # hscriptCmd = r'''optype -t opfind -N "/"opselectrecurse("/",0)''' # change on WIN if os.name=='posix': hscriptCmd = subPorts.escape(hscriptCmd, 1) else: hscriptCmd = subPorts.escape(hscriptCmd, 2) # dont escape backticks in a shell # the command gets wrapped with double-quates - required by bash # and prepanded with full path hcommand cmd = r'''%s "%s"''' % (self.hcommand,hscriptCmd) print ("CMD getNodeType:", cmd) p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) cmd_stdout, cmd_stderr = p.communicate() selection = None selection = cmd_stdout.decode('ascii').strip() if selection == '': print ("=== nothing selected ===") print ("Node type: " ,selection) return selection
def run(self): if os.name=='posix': pidsDict={} pids = subPorts.getHoudiniPorts() for pid,port in pids.items(): ports = {'port':-1,'hipfile':''} # pids ports ports['port']=port ports['hipfile']=subPorts.getHipName(port) pidsDict[pid] = ports else: pidsDict = {} try: import SubTunnel.SubTunnelPortsWin as subWinPorts pidsDict = subWinPorts.getHPorts() except: pass print ("---", pidsDict) portName_list = subPorts.buildPortList(pidsDict) # Build list # pidsDict consist all the collected information print ("All Pids:", pidsDict) self.window.show_quick_panel(portName_list, lambda id: subPorts.savePort(id,pidsDict) ,sublime.MONOSPACE_FONT) print ("Port Set") pass
def getCodeAsText(self): ''' Introduce escape characters to avoid misinterpretation by the shell ''' view = self.window.active_view() codeText = view.substr(sublime.Region(0, view.size())) # Treat \n in the strings differently then new lines at the end of the line temp = [] textSplited = re.split('((?s)".*?")', codeText) for x in textSplited: if os.name=='posix': x = subPorts.escape(x) else: x = subPorts.escape(x,3) # WIN - code as text temp.append(x) codeText = r''.join(temp) ''' this command works from the bash hcommand 2223 "opparm /obj/geo1/python1 python \"print \\"______cccB\\" \" " ^ ^ ^ ^ queue single escape quote | | double escape ''' return codeText
def hdaRun(self,choice,hdaOptions,tunnel,tableAndOpName): # Currently there is no support for the vex context in vex HDA SOP if choice!=-1: # -1 is set when pressed ESC hscriptCmd = r'''otcontentadd %s %s %s''' % (tableAndOpName, hdaOptions[choice], tunnel.filePath) # Hscript command hscriptCmd = subPorts.escape(hscriptCmd, 1) cmd = r'''%s "%s"''' % (tunnel.hcommand,hscriptCmd) print ("CMD - HDA update",cmd) p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
def getNodePath(self): ''' get the node path ''' # cmd = ''' %s "opfind -N \"/\"\`opselectrecurse(\\"/\\",0)\`" ''' % self.hcommand # no space between \"/\"\`o # cmd = r''' %s "opfind -N "/"\`opselectrecurse(\"/\",0)\`" ''' % self.hcommand # raw works too hscriptCmd = r'''opfind -N "/"`opselectrecurse("/",0)''' # Hscript command if os.name=='posix': hscriptCmd = subPorts.escape(hscriptCmd, 1) else: hscriptCmd = subPorts.escape(hscriptCmd, 2) cmd = r'''%s "%s"''' % (self.hcommand,hscriptCmd) print ("CMD getNodePath:", cmd) p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) cmd_stdout, cmd_stderr = p.communicate() nodePath = cmd_stdout.decode('ascii').strip() print ("Node path: " ,nodePath) return nodePath
def run(self): prevShelfTool = subPorts.getConfig('shelftool') print (prevShelfTool) if prevShelfTool == None: prevShelfTool="_" self.window.show_input_panel("Shelf Tool Name:",prevShelfTool,self.on_done,None,None) # self.window.show_quick_panel(portName_list, lambda id: subPorts.savePort(id,pidsDict) ,sublime.MONOSPACE_FONT) pass
def run(self): port = subPorts.getPort() h = Tunnel(self.window,port) # print (h.nodeType) # print (h.nodePath) # print (h.filePath) # path to the temporary code file # print (h.getCodeAsText) # print ('HIP',h.hipfile) if h.nodeType in ['attribwrangle', 'pointwrangle', 'volumewrangle', 'popwrangle']: # VEX WRANGLE nodes hscriptCmd = r'''opparm %s snippet \"%s\"''' % (h.nodePath,h.codeAsText) # Hscript command + \" around already escaped code # hscriptCmd = subPorts.escape(hscriptCmd, 1) # No espcing here - the code already is escaped cmd = r'''%s "%s"''' % (h.hcommand,hscriptCmd) # cmd = ''' %s \"opparm %s snippet \\"%s\\" \"''' %(h.hcommand, h.nodePath,h.codeAsText) print ("CMD - vexsop", cmd) p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) cmd_stdout, cmd_stderr = p.communicate() elif h.nodeType in ['inline']: # INLINE VEX VOPSOP - same as wrangle nodes but with different param name # cmd = ''' %s \"opparm %s code \\"%s\\" \"''' %(h.hcommand, h.nodePath,h.codeAsText) hscriptCmd = r'''opparm %s code \"%s\"''' % (h.nodePath,h.codeAsText) # just and escape around codeAsText cmd = r'''%s "%s"''' % (h.hcommand,hscriptCmd) print ("CMD inline", cmd) p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) cmd_stdout, cmd_stderr = p.communicate() elif h.nodeType == "python": # PYTHON SOP # cmd = ''' %s \"opparm %s python \\"%s\\" \"''' %(h.hcommand, h.nodePath,h.codeAsText) # 2x backslash to have \" in terminal hscriptCmd = r'''opparm %s python \"%s\"''' % (h.nodePath,h.codeAsText) # just and escape around codeAsText cmd = r'''%s "%s"''' % (h.hcommand,hscriptCmd) print ("CMD python sop", cmd) p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) cmd_stdout, cmd_stderr = p.communicate() elif h.nodeType=="": # In case no node is selected portMesssage = '\tPort %s not opened' % h.port self.window.show_quick_panel(['\tNo Node selected or...', portMesssage, '\t-> run openport -a in Houdini Textport', '\t-> rerun "Tunnel Sessions" to connect to running Houdini session'], 0 ,sublime.MONOSPACE_FONT) else: # HDA code / scripts tab # For hda find its type to determine what network it is suppose to go tableAndOpName = self.getTableAndOpName(h.hcommand,h.nodePath) hdaOptions = self.getHdaContent(h.hcommand,tableAndOpName) hdaLabels = self.getHdaContent(h.hcommand,tableAndOpName) print ("NTWK type: ", tableAndOpName) print ("HDA Options:", hdaOptions) info = ['','INFO:', 'File Path: {:>25s}'.format(h.hipfile), 'Node Path: {:>25s}'.format(h.nodePath), 'Node Type: {:>25s}'.format(tableAndOpName)] hdaLabels.extend(info) # TODO there is still a problem with vex otl where the # otcontentadd Sop/testVex VexCode /home/kuba/temp/bbbbb.vex # has no effect self.window.run_command('save') # save the current sublime file self.window.show_quick_panel(hdaLabels, lambda id: self.hdaRun(id,hdaOptions,h,tableAndOpName) ,sublime.MONOSPACE_FONT)