32
def resolve_homedir_file( file ):
33
"""Given a filename, which could be absolute or relative to the CWD, this
34
returns a pair of 'resolved' filenames: the name of the file relative to
35
the homedir and the full, absolute filename. Neither of the returned
36
filenames are guaranteed nor required to exist. But the supplied
37
filename will cause an error if it is not iteself or when resolved (if
38
it is a symlink) under the homedirectory.
32
def expand_files( files ):
33
"""Returns a unique, sorted list of relative files, calculated from the list of
34
files provided, which is made up from individual files and directories
35
to scan that are all relative to the CWD and must be contained within
41
40
home_dir_prefix = os.path.realpath( the.full_home_dir ) + os.sep
43
# obtain absolute filename
44
abs_file = os.path.abspath( file )
46
# if absolute filename is not under home directory, attempt to
48
if abs_file[ : len( home_dir_prefix ) ] != home_dir_prefix:
49
parts = os.path.split( file )
50
if os.path.exists( parts[ 0 ] ):
51
abs_file = os.path.join(
52
os.path.realpath( parts[ 0 ] ), parts[ 1 ] )
54
# absolute file must now be under home directory and exist
55
if abs_file[ : len( home_dir_prefix ) ] != home_dir_prefix:
56
raise the.program.FatalError(
57
'not under home directory: %s' % file )
60
rel_file = abs_file[ len( home_dir_prefix ) : ]
62
return ( rel_file, abs_file )
66
def expand_files( files, recurse = True ):
67
"""Returns a unique, sorted list of relative files, calculated from the list
68
provided, which is made up from individual files and directories
69
relative to the CWD (and which must be contained within the home
70
directory, although the files need not actually exist in the home
71
directory). All files must exist in the repository. Directories are
72
recursed in to as required.
78
42
# iterate through file list
80
( rel_file, abs_file ) = self.resolve_homedir_file( file )
82
# check that file exists in repository
44
abs_file = os.path.realpath( file )
46
# check the file is in the home directory
47
if abs_file[ : len( home_dir_prefix ) ] != home_dir_prefix:
48
raise the.program.FatalError(
49
'not in home directory: %s' % abs_file )
52
rel_file = abs_file[ len( home_dir_prefix ) : ]
54
# check if file exists in repository
83
55
repo_file = os.path.join( the.repo.full_dir, rel_file )
84
56
if not os.path.lexists( repo_file ):
85
57
raise the.program.FatalError(
86
58
'not managed by stdhome: %s' % rel_file )
88
60
# append the file or directory tree
89
ret.update( Walker.generate_walk_list(
90
the.repo.full_dir, rel_file, recurse ) )
61
ret.extend( Walker.generate_walk_list(
62
the.repo.full_dir, rel_file ) )
92
return sorted( set ( ret ) )