/stdhome

To get this branch, use:
bzr branch http://bzr.ed.am/stdhome

« back to all changes in this revision

Viewing changes to lib/stdhome/command/add.py

  • Committer: Tim Marston
  • Date: 2014-07-23 18:47:26 UTC
  • Revision ID: tim@ed.am-20140723184726-plcl9oe1z97durta
during add, ensure parent directories are added

Show diffs side-by-side

added added

removed removed

109
109
        def expand_home_dir_files( files ):
110
110
                """Returns a unique, sorted list of relative filenames, calculated from the list
111
111
                provided, which is made up from individual files and directories
112
 
                relative to the CWD.  Directories and are not recursed in to.  Specified
113
 
                filenames must exist in the home directory (although they may not exist
114
 
                in the repo).
 
112
                relative to the CWD.  Directories and are not recursed in to, but
 
113
                leading path components are also returned.  Specified filenames must
 
114
                exist in the home directory (although they may not exist in the repo).
 
115
 
115
116
                """
116
117
 
117
 
                ret = list()
 
118
                ret = set()
118
119
                home_dir_prefix = os.path.realpath( the.full_home_dir ) + os.sep
119
120
 
120
121
                # iterate through file list
126
127
                        # check the file is in the home directory
127
128
                        if abs_file[ : len( home_dir_prefix ) ] != home_dir_prefix:
128
129
                                raise the.program.FatalError(
129
 
                                        'not in home directory: %s' % abs_file )
 
130
                                        'not under home directory: %s' % abs_file )
130
131
 
131
132
                        # relative file
132
133
                        rel_file = abs_file[ len( home_dir_prefix ) : ]
134
135
                        # check if file exists in home directory
135
136
                        if not os.path.lexists( abs_file ):
136
137
                                raise the.program.FatalError(
137
 
                                        'not in home directory: %s' % rel_file )
138
 
 
139
 
                        # append the file or directory tree
140
 
                        ret.append( rel_file )
141
 
 
142
 
                return sorted( set ( ret ) )
 
138
                                        'not found in home directory: %s' % rel_file )
 
139
 
 
140
                        # append path parts
 
141
                        path = rel_file
 
142
                        while True:
 
143
                                path, dummy = os.path.split( path )
 
144
                                if len( path ): ret.add( path )
 
145
                                else: break
 
146
 
 
147
                        # append the file or directory
 
148
                        ret.add( rel_file )
 
149
 
 
150
                return sorted( ret )