1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 """
22 Utility routines.
23 """
24
25 import os, sys
26
28 """
29 Generate sequential, unique ids.
30
31 @ivar next_id: next id to return
32 @type next_id: C{int}
33 """
35 """
36 Save the starting id.
37
38 @param start_id: starting id
39 @type start_id: C{int}
40 """
41 self.next_id = start_id
42
44 """
45 Get the next id in the sequence and increment it.
46
47 @return: next id
48 @rtype: C{int}
49 """
50 ret_val = self.next_id
51 self.next_id += 1
52 return ret_val
53
55 """
56 A L{BaseId} modification that starts numbering after the ids in the
57 waypoints for a given segment list.
58 """
59
61 """
62 Get the max id in the segment list and start at the next highest one.
63
64 @param seg_list: C{list} of L{Segment}s to check against
65 @type seg_list: C{list} of L{Segment}
66 """
67 start_id = max([max([int(pt.id) for pt in seg.waypoints])
68 for seg in seg_list]) + 1
69 BaseId.__init__(self, start_id)
70
72 """
73 Determine the path to the file containing this routine. This is handy for
74 getting the directory a package is located in. Obviously, this works best
75 when all the files for a package are in the same directory and not split
76 into sub-directories.
77
78 This is based on code found in the distutils tutorial at
79 U{http://wiki.python.org/moin/Distutils/Tutorial}. Apparently the tutorial
80 author found it in wxglade.py.
81
82 @return: directory part of path this file is in
83 @rtype: C{string}
84 """
85 root = __file__
86 if os.path.islink (root):
87 root = os.path.realpath (root)
88 return os.path.dirname (os.path.abspath (root))
89