1
# arch-tag: david@allouche.net - 2003-11-17 15:23:30 335369000
2
# Copyright (C) 2003 John Goerzen, David Allouche
3
# <jgoerzen@complete.org> <david@allouche.net>
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
"""Obsolete utility module
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
38
def exec_safe_stdout(program, args=[], expected=0, chdir=None, logger=None):
39
status, output = exec_safe_status_stdout(program, args, expected,
44
def exec_safe_silent(program, args = [], expected = 0, chdir = None):
45
"""Silently runs the specified program."""
47
proc = ChildProcess(program, args, expected, chdir)
48
proc.spawn(null, null, null)
53
def new_numbered_name(dir, prefix):
55
if not name.startswith(prefix):
58
tail = name[len(prefix):]
60
except ValueError: return 0
62
N = max(map(None, map(int_tail, os.listdir(dir))))
63
return dir/(prefix + str(N+1))
66
def maketree(path, addpath = DirName(), ignore = [], res = None):
67
"""Sorted recursive listing of the directory at @path.
69
@ignore is a list of regular expression strings. Files and
70
directories which match any of these are skipped.
72
The listing is actually a list of DirName and FileName objects.
73
They are storted directories first, then files.
78
res = [re.compile(x) for x in ignore]
79
for item in os.listdir(path):
82
if retest.search(item):
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))
95
retval.append(addpath/item)
96
return sorttree(retval + others)
99
def sorttree(srctree):
100
dirs = [x for x in srctree if isinstance(x, DirName)]
101
files = [x for x in srctree if isinstance(x, FileName)]
107
def copyfrom(srcdir, destdir, verbose=False):
108
"""Copy the contents of @srcdir into @destdir using a tar pipe.
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.
114
The sparse file preservation feature causes a dependence on GNU tar.
116
read_end, write_end = os.pipe()
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])