| 
									
										
										
										
											2000-05-12 01:58:29 +00:00
										 |  |  | """distutils.command.install_data
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Implements the Distutils 'install_data' command, for installing | 
					
						
							|  |  |  | platform-independent data files."""
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # contributed by Bastian Kleineidam | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  | import os | 
					
						
							|  |  |  | from distutils.core import Command | 
					
						
							| 
									
										
										
										
											2001-01-28 12:22:14 +00:00
										 |  |  | from distutils.util import change_root, convert_path | 
					
						
							| 
									
										
										
										
											2000-05-12 00:52:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-30 03:52:21 +00:00
										 |  |  | class install_data(Command): | 
					
						
							| 
									
										
										
										
											2000-05-12 00:52:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     description = "install data files" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  |     user_options = [ | 
					
						
							|  |  |  |         ('install-dir=', 'd', | 
					
						
							| 
									
										
										
										
											2000-07-27 02:13:20 +00:00
										 |  |  |          "base directory for installing data files " | 
					
						
							| 
									
										
										
										
											2000-06-24 17:36:24 +00:00
										 |  |  |          "(default: installation base dir)"), | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  |         ('root=', None, | 
					
						
							|  |  |  |          "install everything relative to this alternate root directory"), | 
					
						
							| 
									
										
										
										
											2000-09-13 01:02:25 +00:00
										 |  |  |         ('force', 'f', "force installation (overwrite existing files)"), | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  |         ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-25 01:41:15 +00:00
										 |  |  |     boolean_options = ['force'] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-30 03:52:21 +00:00
										 |  |  |     def initialize_options(self): | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  |         self.install_dir = None | 
					
						
							| 
									
										
										
										
											2000-06-21 03:13:51 +00:00
										 |  |  |         self.outfiles = [] | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  |         self.root = None | 
					
						
							| 
									
										
										
										
											2000-09-13 01:02:25 +00:00
										 |  |  |         self.force = 0 | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  |         self.data_files = self.distribution.data_files | 
					
						
							| 
									
										
										
										
											2000-09-15 01:21:07 +00:00
										 |  |  |         self.warn_dir = 1 | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-30 03:52:21 +00:00
										 |  |  |     def finalize_options(self): | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  |         self.set_undefined_options('install', | 
					
						
							| 
									
										
										
										
											2000-10-14 04:06:40 +00:00
										 |  |  |                                    ('install_data', 'install_dir'), | 
					
						
							|  |  |  |                                    ('root', 'root'), | 
					
						
							| 
									
										
										
										
											2000-09-13 01:02:25 +00:00
										 |  |  |                                    ('force', 'force'), | 
					
						
							| 
									
										
										
										
											2000-10-14 04:06:40 +00:00
										 |  |  |                                   ) | 
					
						
							| 
									
										
										
										
											2000-05-12 00:52:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-30 03:52:21 +00:00
										 |  |  |     def run(self): | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  |         self.mkpath(self.install_dir) | 
					
						
							|  |  |  |         for f in self.data_files: | 
					
						
							| 
									
										
										
										
											2007-10-16 18:12:55 +00:00
										 |  |  |             if isinstance(f, str): | 
					
						
							| 
									
										
										
										
											2000-06-24 17:36:24 +00:00
										 |  |  |                 # it's a simple file, so copy it | 
					
						
							| 
									
										
										
										
											2001-01-28 12:22:14 +00:00
										 |  |  |                 f = convert_path(f) | 
					
						
							| 
									
										
										
										
											2000-09-15 01:21:07 +00:00
										 |  |  |                 if self.warn_dir: | 
					
						
							|  |  |  |                     self.warn("setup script did not provide a directory for " | 
					
						
							|  |  |  |                               "'%s' -- installing right in '%s'" % | 
					
						
							|  |  |  |                               (f, self.install_dir)) | 
					
						
							| 
									
										
										
										
											2000-09-30 17:34:50 +00:00
										 |  |  |                 (out, _) = self.copy_file(f, self.install_dir) | 
					
						
							| 
									
										
										
										
											2000-06-21 03:13:51 +00:00
										 |  |  |                 self.outfiles.append(out) | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  |             else: | 
					
						
							| 
									
										
										
										
											2000-06-24 17:36:24 +00:00
										 |  |  |                 # it's a tuple with path to install to and a list of files | 
					
						
							| 
									
										
										
										
											2001-01-28 12:22:14 +00:00
										 |  |  |                 dir = convert_path(f[0]) | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  |                 if not os.path.isabs(dir): | 
					
						
							|  |  |  |                     dir = os.path.join(self.install_dir, dir) | 
					
						
							|  |  |  |                 elif self.root: | 
					
						
							| 
									
										
										
										
											2000-05-25 02:14:26 +00:00
										 |  |  |                     dir = change_root(self.root, dir) | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  |                 self.mkpath(dir) | 
					
						
							| 
									
										
										
										
											2001-09-04 20:42:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 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) | 
					
						
							| 
									
										
										
										
											2000-05-13 03:07:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-30 03:52:21 +00:00
										 |  |  |     def get_inputs(self): | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  |         return self.data_files or [] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-30 03:52:21 +00:00
										 |  |  |     def get_outputs(self): | 
					
						
							| 
									
										
										
										
											2000-06-21 03:13:51 +00:00
										 |  |  |         return self.outfiles |