Exemplo n.º 1
0
 def __func(self, *args, **kwargs):
     r = func(self, *args, **kwargs)
     if isinstance(r, types.GeneratorType):
         self.set_run_in_background(True)
         promise = workflows.driver(r)
         promise.then(lambda x: self.set_run_in_background(False),
                      lambda x: self.set_run_in_background(False))
     else:
         promise = Promise()
         promise.resolve(r)
     return promise
Exemplo n.º 2
0
 def __func(self, *args, **kwargs):
     r = func(self, *args, **kwargs)
     if isinstance(r, types.GeneratorType):
         if isinstance(self, Extension):
             vcs = self.base
         else:
             vcs = self
         vcs.set_run_in_background(True)
         promise = workflows.driver(r)
         promise.then(lambda x: vcs.set_run_in_background(False),
                      lambda x: vcs.set_run_in_background(False))
     else:
         promise = Promise()
         promise.resolve(r)
     return promise
Exemplo n.º 3
0
    def has_defined_activity(self, synchronous):
        """
        Whether there is a defined activity currently defined, which is
        necessary to be able to do a checkout.

        :param bool synchronous: whether to compute this synchronously.
        :returntype: a promise that will be resolved to a boolean, to
            indicate whether there is a defined activity.
        """

        if synchronous:
            p = subprocess.Popen(['cleartool', 'lsact', '-cact', '-s'],
                                 cwd=self.working_dir.path,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT)
            output, error = p.communicate()
            status = p.wait()
            return status == 0 and output != ''
        else:
            result = Promise()

            def on_terminate(status, output):
                # if status!=0, could be a clearcase-only view, or not a view
                result.resolve(status == 0 and output != '')

            p = self._cleartool(['cleartool', 'lsactivity',
                                 '-cact',   # display info for current activity
                                 '-s'])     # short display
            p.wait_until_terminate().then(on_terminate)
            return result
Exemplo n.º 4
0
Arquivo: tree.py Projeto: zackboll/gps
    def click(self, column, path=None, value=None, *args, **kwargs):
        """
        If path not given, then find the first node in the tree that contains
        value in the given column. Click on the column in a row of the path.
        Return promise to wait selection changed.
        This function accepts other parameters to pass them to click_in_tree,
        such as button, events, process_events, control, alt, shift, modifier.

        Example:

        yield my_tree.click (column=1, value="key", button=1)

        :param int column: the model's column to check.
        :param str path:   the path in the tree to click.
        :param str value:  the value to find in the model, if path not set.
        :return Promise:   the event of selection change.
        """

        if not path:
            path = pygps.tree.find_in_tree(self.treeview,
                                           column=column,
                                           key=value)

        p = Promise()

        def handler(selection):
            p.resolve()

        self.treeview.get_selection().connect("changed", handler)
        pygps.tree.click_in_tree(self.treeview, path, *args, **kwargs)

        return p
Exemplo n.º 5
0
Arquivo: git.py Projeto: lupine37/gps
    def _current_branch(self):
        """
        A promise that returns the name of the current branch
        """
        result = Promise()

        def online(line):
            result.resolve(line)

        p = self._git(['rev-parse', '--abbrev-ref', 'HEAD'])
        p.lines.subscribe(online)
        return result
Exemplo n.º 6
0
def get_completion():
    """
    Return the content, as a list of strings, of the completion window. Waits
    until it stops computing

    :rtype: Promise[Iterator[str]]
    """
    p = Promise()

    def timeout_handler(t):
        try:
            pop_tree = get_widget_by_name("completion-view")
            comps = [row[0] for row in dump_tree_model(pop_tree.get_model())]
            if comps[-1] != 'Computing...':
                t.remove()
                p.resolve(comps)
        except Exception, e:
            pass
Exemplo n.º 7
0
    def request_promise(self, method, params):
        """Make a language server request as a promise.

           method and params are the same arguments as request.

           The way to use this is in a workflow, in the following way:

               # Retrieve the language server
               als = GPS.LanguageServer.get_by_language_name("Ada")

               # call this with a yield
               result = yield als.request_promise(method, params)

               # result is a LanguageServerResponse object: typically
               # inspect result.is_valid, result.is_error, result.is_reject,
               # and process result.data if result.is_valid.
        """
        from workflows.promises import Promise
        p = Promise()
        result = LanguageServerResponse()

        def on_error(code, message, data):
            result.is_error = True
            result.error_message = message
            result.data = json.loads(data)
            p.resolve(result)

        def on_result(data):
            result.is_valid = True
            result.data = json.loads(data)
            p.resolve(result)

        def on_reject():
            result.is_reject = True
            p.resolve(result)

        self.request(method, params, on_result, on_error, on_reject)
        return p