File: RecPos.py

package info (click to toggle)
aap 1.072-1.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 4,976 kB
  • ctags: 2,160
  • sloc: python: 15,113; makefile: 62; sh: 13
file content (45 lines) | stat: -rw-r--r-- 1,359 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Part of the A-A-P recipe executive: A position in a recipe

# Copyright (C) 2002-2003 Stichting NLnet Labs
# Permission to copy and use this file is specified in the file COPYING.
# If this file is missing you can find it here: http://www.a-a-p.org/COPYING


# A RecPos object contains:
#  name         - name of the recipe
#  line_nr      - line number in the recipe
#
# This is normally used in a stack, first item is the position where it
# includes the second item, etc.

class RecPos:
    def __init__(self, name, line_nr = 0):
        self.name = name
        self.line_nr = line_nr

    def __str__(self):
        return 'recipe "%s" line %d' % (self.name, self.line_nr)


def rpcopy(rpstack, line_nr):
    """Make a shallow copy of the stack of RecPos objects and make a copy of
       the item on the top to change its line_nr to "line_nr"."""
    r = rpstack[:]
    if len(r) > 0:
        r[-1] = RecPos(r[-1].name, line_nr)
    else:
        r = [ RecPos("unknown", line_nr) ]

    return r


def rpdeepcopy(rpstack, line_nr):
    """Make a deep copy of the stack of RecPos objects and for the item on the
       top change its line_nr to "line_nr"."""
    r = rpstack[:]
    for i in range(0, len(r) - 1):
        r[i] = RecPos(r[i].name, r[i].line_nr)
    r[-1] = RecPos(r[-1].name, line_nr)
    return r

# vim: set sw=4 et sts=4 tw=79 fo+=l: