1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """Obsolete utility module
20 """
21
22 import os
23 import re
24
25
26
27 from errors import ExecProblem
28 from pathname import PathName, DirName, FileName
29 from backends.logger import Logger
30 from backends.forkexec import exec_safe
31 from backends.forkexec import exec_safe_status_stdout
32 from backends.forkexec import exec_safe_iter_stdout
33 from backends.forkexec import ChildProcess
34 from backends.forkexec import getnull
35 from backends.forkexec import StringOutput
36
37
39 status, output = exec_safe_status_stdout(program, args, expected,
40 chdir, logger)
41 return output
42
43
45 """Silently runs the specified program."""
46 null = getnull()
47 proc = ChildProcess(program, args, expected, chdir)
48 proc.spawn(null, null, null)
49 proc.wait()
50 return proc.status
51
52
54 def int_tail(name):
55 if not name.startswith(prefix):
56 return 0
57 else:
58 tail = name[len(prefix):]
59 try: return int(tail)
60 except ValueError: return 0
61
62 N = max(map(None, map(int_tail, os.listdir(dir))))
63 return dir/(prefix + str(N+1))
64
65
67 """Sorted recursive listing of the directory at @path.
68
69 @ignore is a list of regular expression strings. Files and
70 directories which match any of these are skipped.
71
72 The listing is actually a list of DirName and FileName objects.
73 They are storted directories first, then files.
74 """
75 retval = []
76 others = []
77 if res == None:
78 res = [re.compile(x) for x in ignore]
79 for item in os.listdir(path):
80 skip = 0
81 for retest in res:
82 if retest.search(item):
83 skip = 1
84 break
85 if skip:
86 continue
87
88 dirname = os.path.join(path, item)
89 if os.path.isdir(dirname):
90 item, dirname = DirName(item), DirName(dirname)
91 retval.append(addpath/item)
92 others.extend(maketree(dirname, addpath/item, res = res))
93 else:
94 item = FileName(item)
95 retval.append(addpath/item)
96 return sorttree(retval + others)
97
98
100 dirs = [x for x in srctree if isinstance(x, DirName)]
101 files = [x for x in srctree if isinstance(x, FileName)]
102 dirs.sort()
103 files.sort()
104 return dirs + files
105
106
107 -def copyfrom(srcdir, destdir, verbose=False):
108 """Copy the contents of @srcdir into @destdir using a tar pipe.
109
110 All files in @srcdir will be copied into @destdir and files which
111 are unique to @destdir will be preserved. Sparse files and
112 permissions from @srcdir will be preserved.
113
114 The sparse file preservation feature causes a dependence on GNU tar.
115 """
116 read_end, write_end = os.pipe()
117 verbargs = []
118 if verbose:
119 verbargs.append('-v')
120 reader = ChildProcess("tar", ["-cSpf", "-", "."], chdir=srcdir)
121 reader.spawn(stdout = write_end, closefds = [read_end])
122 writer = ChildProcess("tar", ["-xSpf", "-"] + verbargs, chdir=destdir)
123 writer.spawn(stdin = read_end, closefds = [write_end])
124 os.close(read_end)
125 os.close(write_end)
126 reader.wait()
127 writer.wait()
128