diff options
| author | FELD Boris <lothiraldan@gmail.com> | 2011-01-28 17:10:57 +0100 |
|---|---|---|
| committer | FELD Boris <lothiraldan@gmail.com> | 2011-01-28 17:10:57 +0100 |
| commit | 4ba3ca4e82fda0e9a7f6d6eb0e66849392d4bbb4 (patch) | |
| tree | 38348d5a104a967749b14decd03c5b859871f615 /distutils2/command/install_data.py | |
| parent | 1c3780c40cb36bf0be1e47429ab9f46c079b64ac (diff) | |
| download | disutils2-4ba3ca4e82fda0e9a7f6d6eb0e66849392d4bbb4.tar.gz | |
Distutils 2 now install datafiles in the right place (indicated by sysconfig).
Data files are read from config file.
Data files are installed to the expanded category file.
Data files list is written in DATAFILES file in .dist-info dir.
Diffstat (limited to 'distutils2/command/install_data.py')
| -rw-r--r-- | distutils2/command/install_data.py | 69 |
1 files changed, 28 insertions, 41 deletions
diff --git a/distutils2/command/install_data.py b/distutils2/command/install_data.py index e77b11c..6fe3805 100644 --- a/distutils2/command/install_data.py +++ b/distutils2/command/install_data.py @@ -9,6 +9,7 @@ platform-independent data files.""" import os from distutils2.command.cmd import Command from distutils2.util import change_root, convert_path +from distutils2._backport.sysconfig import _expand_vars, _subst_vars, get_paths class install_data(Command): @@ -28,6 +29,7 @@ class install_data(Command): def initialize_options(self): self.install_dir = None self.outfiles = [] + self.data_files_out = [] self.root = None self.force = 0 self.data_files = self.distribution.data_files @@ -40,50 +42,32 @@ class install_data(Command): def run(self): self.mkpath(self.install_dir) - for f in self.data_files: - if isinstance(f, str): - # it's a simple file, so copy it - f = convert_path(f) - if self.warn_dir: - self.warn("setup script did not provide a directory for " - "'%s' -- installing right in '%s'" % - (f, self.install_dir)) - (out, _) = self.copy_file(f, self.install_dir) - self.outfiles.append(out) - else: - # it's a tuple with path to install to and a list of files - dir = convert_path(f[0]) - if not os.path.isabs(dir): - dir = os.path.join(self.install_dir, dir) - elif self.root: - dir = change_root(self.root, dir) - self.mkpath(dir) - - if f[1] == []: - # If there are no files listed, the user must be - # trying to create an empty directory, so add the - # directory to the list of output files. - self.outfiles.append(dir) - else: - # Copy files, adding them to the list of output files. - for data in f[1]: - data = convert_path(data) - (out, _) = self.copy_file(data, dir) - self.outfiles.append(out) + for file in self.data_files.items(): + destination = convert_path(self.expand_categories(file[1])) + dir_dest = os.path.abspath(os.path.dirname(destination)) + + self.mkpath(dir_dest) + (out, _) = self.copy_file(file[0], dir_dest) + + self.outfiles.append(out) + self.data_files_out.append((file[0], destination)) + + def expand_categories(self, path_with_categories): + local_vars = get_paths() + local_vars['distribution.name'] = self.distribution.metadata['Name'] + expanded_path = _subst_vars(path_with_categories, local_vars) + expanded_path = _subst_vars(expanded_path, local_vars) + if '{' in expanded_path and '}' in expanded_path: + self.warn("Unable to expand %s, some categories may missing." % + path_with_categories) + return expanded_path def get_source_files(self): sources = [] - for item in self.data_files: - if isinstance(item, str): # plain file - item = convert_path(item) - if os.path.isfile(item): - sources.append(item) - else: # a (dirname, filenames) tuple - dirname, filenames = item - for f in filenames: - f = convert_path(f) - if os.path.isfile(f): - sources.append(f) + for file in self.data_files: + destination = convert_path(self.expand_categories(file[1])) + if os.path.file(destination): + sources.append(destination) return sources def get_inputs(self): @@ -91,3 +75,6 @@ class install_data(Command): def get_outputs(self): return self.outfiles + + def get_datafiles_out(self): + return self.data_files_out
\ No newline at end of file |
