Beispiel #1
0
 def run(self, vm):
     for row, col, block in reversed(vm.blocks):
         if not isinstance(block, If):
             block.resume(vm, row, col)
             break
     else:
         raise ExecutionError('Continue could not find a block to continue')
Beispiel #2
0
 def goto(self, row, col):
     if row >= 0 and row < len(self.code)\
         and col >= 0 and col < len(self.code[row]):
         self.line = row
         self.col = col
     else:
         raise ExecutionError('cannot goto (%i, %i)' % (row, col))
Beispiel #3
0
    def run(self, vm):
        if self.arg == None:
            raise ExecutionError('If statement without condition')

        true = bool(vm.get(self.arg))

        cur = vm.cur()
        if isinstance(cur, Then):
            vm.push_block()
            vm.inc()

            if not true:
                end = self.find_end(vm, or_else=True)
                if end:
                    row, col, end = end
                    if isinstance(end, End):
                        vm.pop_block()

                    vm.goto(row, col)
                    vm.inc()
                else:
                    raise StopError(
                        'If/Then could not find End on negative expression')
        elif true:
            vm.run(cur)
        else:
            vm.inc_row()
Beispiel #4
0
 def run(self, vm):
     for row, col, block in reversed(vm.blocks):
         if not isinstance(block, If):
             block.stop(vm, row, col)
             break
     else:
         raise ExecutionError('Break could not find a block to end')
Beispiel #5
0
    def loop(self, vm):
        if len(self.arg) in (3, 4):
            var = self.arg.contents[0]
            args = [vm.get(arg) for arg in self.arg.contents[1:]]

            forward = True
            if len(args) == 3:
                inc = args[2]
                args = args[:2]
                forward = False
            else:
                inc = 1

            start, end = args

            if self.pos is None:
                self.pos = start
            else:
                self.pos += inc

            var.set(vm, self.pos)
            if forward and self.pos > end or not forward and self.pos < end:
                return False
            else:
                return True
        else:
            raise ExecutionError('incorrect arguments to For loop')
Beispiel #6
0
def get_repo_top_level():
    cmd = ['git', 'rev-parse', '--show-toplevel']
    rc, toplevel = run_command(cmd)
    if rc != 0:
        raise ExecutionError('Failed to get top level of repo, are you'
                             ' standing in a working copy?')

    return toplevel.strip()
Beispiel #7
0
def rev_parse(refname):
    cmd = ['git', 'rev-parse', refname]
    rc, output = run_command(cmd)
    if rc != 0:
        err = ('Failed to run command "{0}"'.format(' '.join(cmd)))
        raise ExecutionError(err)

    return output.strip()
Beispiel #8
0
    def push_block(self, block=None):
        if not block and self.running:
            block = self.running[-1]

        if block:
            self.blocks.append(block)
        else:
            raise ExecutionError('tried to push an invalid block to the stack')
Beispiel #9
0
    def run(self, vm):
        if not self.arg:
            raise ExecutionError('%s used without arguments')

        if isinstance(self.arg, Tuple):
            for var in self.arg.contents:
                self.prompt(vm, var)
        else:
            self.prompt(vm, self.arg)
Beispiel #10
0
    def goto(vm, token):
        label = Lbl.guess_label(vm, token)
        if label:
            for row, col, token in vm.find(Lbl, wrap=True):
                if token.get_label(vm) == label:
                    vm.goto(row, col)
                    return

        raise ExecutionError('could not find a label to Goto: %s' % token)
Beispiel #11
0
 def run_pgrm(self, name):
     for ref in os.listdir('.'):
         if ref.endswith('.bas'):
             test = ref.rsplit('.', 1)[0]
             if test.lower() == name.lower():
                 sub = Interpreter.from_file(ref)
                 sub.execute()
                 return
     raise ExecutionError('pgrm{} not found'.format(name))
Beispiel #12
0
    def run(self, vm):
        args = self.arg.contents[:]
        l = len(args)
        if l >= 3 and (l - 3) % 2 == 0:
            title = args.pop(0)

            menu = (title, zip(args[::2], args[1::2])),

            label = vm.io.menu(menu)
            Goto.goto(vm, label)
        else:
            raise ExecutionError('Invalid arguments to Menu(): %s' % args)
Beispiel #13
0
def get_git_client_version():
    cmd = ['git', '--version']
    rc, output = run_command(cmd)
    if rc != 0:
        raise ExecutionError(
            'Make sure that the git client has been installed')

    version = output.split(' ')
    if len(version) == 3:
        version = version[2]
    else:
        raise Warning('Unexpected git version format: {0}'.format(output))

    return version
Beispiel #14
0
    def run(self, cur):
        self.history.append((self.line, self.col, cur))
        self.history = self.history[-self.hist_len:]

        cur.line, cur.col = self.line, self.col

        if cur.can_run:
            self.running.append((self.line, self.col, cur))
            self.inc()
            cur.run(self)
            self.running.pop()
        elif cur.can_get:
            self.inc()
            self.set_var('Ans', cur.get(self))
            self.serial = time.time()
        else:
            raise ExecutionError('cannot seem to run token: %s' % cur)
Beispiel #15
0
def get_repo_name():
    repo = None
    url = None

    cmd = ['git', 'config', '--get', 'remote.origin.pushurl']
    rc, output = run_command(cmd)
    if rc == 0:
        url = output.strip()

    if url is None:
        cmd = ['git', 'config', '--get', 'remote.origin.url']
        rc, output = run_command(cmd)
        if rc == 0:
            url = output.strip()

    if url is not None:
        match = re.search(r'^(ssh://|).+@[^(/|:)]+(/|:)(?P<repo>.+)$', url)
        repo = match.group('repo')
    else:
        raise ExecutionError('Failed to determine the name of the repo.')

    return repo
Beispiel #16
0
    def run(self, vm):
        if self.arg == None:
            raise ExecutionError('%s statement without condition' % self.token)

        row, col, _ = vm.running[-1]
        self.resume(vm, row, col)
Beispiel #17
0
 def run(self, vm):
     raise ExecutionError('cannot execute a standalone Then statement')
Beispiel #18
0
 def pop_block(self):
     if self.blocks:
         return self.blocks.pop()
     else:
         raise ExecutionError('tried to pop an empty block stack')