| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | __revision__ = "$Id$" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  | import os | 
					
						
							|  |  |  | from types import StringType | 
					
						
							|  |  |  | from distutils.core import Command | 
					
						
							| 
									
										
										
										
											2000-05-25 02:14:26 +00:00
										 |  |  | from distutils.util import change_root | 
					
						
							| 
									
										
										
										
											2000-05-12 00:52:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +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', | 
					
						
							|  |  |  |          "directory to install the files to"), | 
					
						
							|  |  |  |         ('root=', None, | 
					
						
							|  |  |  |          "install everything relative to this alternate root directory"), | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def initialize_options (self): | 
					
						
							|  |  |  |         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 | 
					
						
							|  |  |  |         self.data_files = self.distribution.data_files | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-12 00:52:23 +00:00
										 |  |  |     def finalize_options (self): | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  |         self.set_undefined_options('install', | 
					
						
							|  |  |  | 	                           ('install_data', 'install_dir'), | 
					
						
							|  |  |  | 				   ('root', 'root'), | 
					
						
							|  |  |  | 				  ) | 
					
						
							| 
									
										
										
										
											2000-05-12 00:52:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def run (self): | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  |         self.mkpath(self.install_dir) | 
					
						
							|  |  |  |         for f in self.data_files: | 
					
						
							|  |  |  |             if type(f) == StringType: | 
					
						
							|  |  |  |                 # its a simple file, so copy it | 
					
						
							| 
									
										
										
										
											2000-06-21 03:13:51 +00:00
										 |  |  |                 out = self.copy_file(f, self.install_dir) | 
					
						
							|  |  |  |                 self.outfiles.append(out) | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  |             else: | 
					
						
							|  |  |  |                 # its a tuple with path to install to and a list of files | 
					
						
							|  |  |  |                 dir = f[0] | 
					
						
							|  |  |  |                 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) | 
					
						
							|  |  |  |                 for data in f[1]: | 
					
						
							| 
									
										
										
										
											2000-06-21 03:13:51 +00:00
										 |  |  |                     out = self.copy_file(data, dir) | 
					
						
							|  |  |  |                     self.outfiles.append(out) | 
					
						
							| 
									
										
										
										
											2000-05-13 03:07:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def get_inputs (self): | 
					
						
							| 
									
										
										
										
											2000-05-25 01:19:18 +00:00
										 |  |  |         return self.data_files or [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def get_outputs (self): | 
					
						
							| 
									
										
										
										
											2000-06-21 03:13:51 +00:00
										 |  |  |         return self.outfiles |