Exemplo n.º 1
0
def generate_completes(force=False):
    # check parsed functions
    cache_file = vex_settings.get_autocomplete_cache_file()
    if os.path.exists(cache_file) and not force:
        return True
    # get vcc
    vcc = os.path.join(hou.getenv('HFS'), 'bin', 'vcc').replace('/','\\')
    if os.name == 'nt':
        vcc = vcc + '.exe'
    if not os.path.exists(vcc):
        return False
    # generate new
    funcs = {}
    attrs = {}
    process = QProcess()
    process.start(' '.join([vcc, '-X']))
    process.waitForFinished()
    lines =  str(process.readAll()).split('\n')
    for context in lines:
        if context:
            process.start(' '.join([vcc, '-X', context]))
            process.waitForFinished()
            context_lines =  str(process.readAll())
            # variables
            variables = re.search(r'Global Variables:(.*)Control Statements:', context_lines, re.DOTALL)
            if variables:
                lines = variables.group(1).strip().split('\n')
                for l in lines:
                    s = l.split()
                    if len(s)==3:
                        attrs[s[-1]] = s[-2]
            # functions
            pat = r'^\s*(\w+\[?\]?)\s(\w+)(\(.+\))'
            for l in context_lines.split('\n'):
                func = re.findall(pat, str(l))
                if func:
                    f_name = func[0][1]
                    f_args = func[0][2]
                    if f_name in funcs:
                        if not f_args in funcs[f_name].get('args', []):
                            funcs[f_name]['args'].append(f_args)
                    else:
                        funcs[f_name] = {'args':  [f_args]}
    # parse help if Houdini 15
    if hou.applicationVersion()[0] >= 15:
        funcs = parse_help(funcs)
    # save to cache
    if os.path.exists(cache_file):
        comp = json.load(open(cache_file))
    else:
        comp = {}
    comp['functions'] = funcs
    comp['attributes'] = attrs
    json.dump(comp, open(cache_file, 'w'))
    return True
Exemplo n.º 2
0
def generate_completes(force=False):
    # check parsed functions
    cache_file = vex_settings.get_autocomplete_cache_file()
    if os.path.exists(cache_file) and not force:
        return True
    # get vcc
    vcc = os.path.join(hou.getenv('HFS'), 'bin', 'vcc').replace('/','\\')
    if os.name == 'nt':
        vcc = vcc + '.exe'
    if not os.path.exists(vcc):
        return False
    # generate new
    funcs = {}
    attrs = {}
    process = QProcess()
    process.start(' '.join([vcc, '-X']))
    process.waitForFinished()
    lines =  str(process.readAll()).split('\n')
    for context in lines:
        if context:
            process.start(' '.join([vcc, '-X', context]))
            process.waitForFinished()
            context_lines =  str(process.readAll())
            # variables
            variables = re.search(r'Global Variables:(.*)Control Statements:', context_lines, re.DOTALL)
            if variables:
                lines = variables.group(1).strip().split('\n')
                for l in lines:
                    s = l.split()
                    if len(s)==3:
                        attrs[s[-1]] = s[-2]
            # functions
            pat = r'^\s*(\w+\[?\]?)\s(\w+)(\(.+\))'
            for l in context_lines.split('\n'):
                func = re.findall(pat, str(l))
                if func:
                    if func[0][1] in funcs:
                        funcs[func[0][1]].append({'ret': func[0][0], 'args':func[0][2]})
                    else:
                        funcs[func[0][1]] = [{'ret': func[0][0], 'args':func[0][2]}]
    # save to cache
    if os.path.exists(cache_file):
        comp = json.load(open(cache_file))
    else:
        comp = {}
    comp['functions'] = funcs
    comp['attributes'] = attrs
    json.dump(comp, open(cache_file, 'w'), indent=4)
    return True
Exemplo n.º 3
0
 def get_output(cmd):
     if isinstance(cmd, list):
         cmd = ' '.join(cmd)
     process = QProcess()
     process.start(cmd)
     process.waitForFinished()
     return str(process.readAll())
Exemplo n.º 4
0
 def get_output(cmd):
     if isinstance(cmd, list):
         cmd = ' '.join(cmd)
     process = QProcess()
     process.start(cmd)
     process.waitForFinished()
     return str(process.readAll())
Exemplo n.º 5
0
class TasksPool(QObject):
    """
    This class allows you to add_task() for execution queue. Launch_list() starts the queue.
    """
    task_done = Signal()
    return_signal = Signal(str)

    def __init__(self):

        super(TasksPool, self).__init__()
        self.tasks_pool = []
        self.process = None
        if not QApplication.instance():
            self.qapp = QApplication([])

    def add_task(self, command):
        """
        :type command: str
        :param command: A console command with arguments
        Adds a task to the pool for later execution
        """
        self.tasks_pool.append(command)

    def __execute_task(self, task):
        """
        :param task: Is a string used to start a process
        """
        self.process = QProcess(self)
        self.process.finished.connect(
            lambda *x: logger.debug(task + ' reports complete'))
        self.process.finished.connect(lambda *x: self.return_signal.emit(
            '►' + task + '◄reports complete'))
        self.process.finished.connect(self.task_done)
        # self.process.readyRead.connect(lambda *x: print(str(self.process.readAll())))
        self.process.readyRead.connect(
            lambda *x: self.return_signal.emit(str(self.process.readAll())))
        self.process.setProcessChannelMode(QProcess.MergedChannels)
        self.process.start(task)

    def launch_list(self):
        """
        Starts the execution of the queue in consecutive order, waiting for previous process to finish
        """
        for task in self.tasks_pool:
            loop = QEventLoop()
            self.task_done.connect(loop.quit)
            self.__execute_task(task)
            loop.exec_()
Exemplo n.º 6
0
class TasksPool(QObject):
    startNextTaskSignal = Signal()
    allTasksCompleteSignal = Signal()

    def __init__(self):
        super(TasksPool, self).__init__()
        self.tasks_pool = []
        self.process = QProcess()

        self.startNextTaskSignal.connect(self.execute_task)
        self.allTasksCompleteSignal.connect(self.tasks_complete)

        self.source = ''

    def add_task(self, command):
        self.tasks_pool.append(command)
        self.startNextTaskSignal.emit()

    def execute_task(self):
        print('Start next?')
        if self.process.isOpen():
            self.process.waitForFinished()
        if not self.tasks_pool:
            self.allTasksCompleteSignal.emit()
            return
        self.process = QProcess()
        self.process.finished.connect(
            lambda *x: QTimer.singleShot(1000, self.startNextTaskSignal.emit))
        self.process.setProcessChannelMode(QProcess.MergedChannels)
        self.process.readyRead.connect(self.process_output)
        next_task = self.tasks_pool.pop(0)
        print('NEXT TASK', next_task)
        self.process.start(next_task)

    def process_output(self):
        output = self.process.readAll()
        output = str(output).strip()
        if output:
            print(output)

    def tasks_complete(self):
        print('ALL TASKS COMPLETE')
Exemplo n.º 7
0
def runtapinstall(args, errorok=False):
    EXE = '%s/%s' % (TAPDIR, TAPINSTALL)
#    args.insert(0, EXE)
#    cmd = ' '.join(args)
    process = QProcess()
    process.start(EXE, args)
    if not process.waitForFinished():
        print "tapinstall failed. waitForFinished()"
        sys.exit(1)
    output = process.readAll();
    rv = process.exitStatus()
    output=str(output).strip()
    if rv != 0 and not errorok:
        print """tapinstall failed.
command was: %s
output was: %s
returnvalue was: %d""" % (cmd, output, rv)
        sys.exit(1)
    else:
        return (rv, output)