| 
									
										
										
										
											1995-07-29 13:48:41 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # Turn a pyc file into a resource file containing it in 'PYC ' resource form | 
					
						
							|  |  |  | from Res import * | 
					
						
							|  |  |  | import Res | 
					
						
							|  |  |  | from Resources import * | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | import macfs | 
					
						
							|  |  |  | import sys | 
					
						
							| 
									
										
										
										
											1996-05-31 13:02:52 +00:00
										 |  |  | import py_resource | 
					
						
							| 
									
										
										
										
											1995-07-29 13:48:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | error = 'mkpycresourcefile.error' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def mkpycresourcefile(src, dst): | 
					
						
							|  |  |  | 	"""Copy pyc file/dir src to resource file dst.""" | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if not os.path.isdir(src) and src[-4:] <> '.pyc': | 
					
						
							|  |  |  | 			raise error, 'I can only handle .pyc files or directories' | 
					
						
							| 
									
										
										
										
											1996-05-31 13:02:52 +00:00
										 |  |  | 	fsid = py_resource.create(dst) | 
					
						
							| 
									
										
										
										
											1995-07-29 13:48:41 +00:00
										 |  |  | 	if os.path.isdir(src): | 
					
						
							| 
									
										
										
										
											1996-05-31 13:02:52 +00:00
										 |  |  | 		handlesubdir(src) | 
					
						
							| 
									
										
										
										
											1995-07-29 13:48:41 +00:00
										 |  |  | 	else: | 
					
						
							| 
									
										
										
										
											1996-05-31 13:02:52 +00:00
										 |  |  | 		id, name = py_resource.frompycfile(src) | 
					
						
							|  |  |  | 		print 'Wrote %d: %s %s'%(id, name, src) | 
					
						
							|  |  |  | 	CloseResFile(fsid) | 
					
						
							| 
									
										
										
										
											1995-07-29 13:48:41 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											1996-05-31 13:02:52 +00:00
										 |  |  | def handlesubdir(srcdir): | 
					
						
							| 
									
										
										
										
											1995-07-29 13:48:41 +00:00
										 |  |  | 	"""Recursively scan a directory for pyc files and copy to resources""" | 
					
						
							|  |  |  | 	src = os.listdir(srcdir) | 
					
						
							|  |  |  | 	for file in src: | 
					
						
							|  |  |  | 		file = os.path.join(srcdir, file) | 
					
						
							|  |  |  | 		if os.path.isdir(file): | 
					
						
							| 
									
										
										
										
											1996-05-31 13:02:52 +00:00
										 |  |  | 			handlesubdir(file) | 
					
						
							| 
									
										
										
										
											1995-07-29 13:48:41 +00:00
										 |  |  | 		elif file[-4:] == '.pyc': | 
					
						
							| 
									
										
										
										
											1996-05-31 13:02:52 +00:00
										 |  |  | 			id, name = py_resource.frompycfile(file) | 
					
						
							|  |  |  | 			print 'Wrote %d: %s %s'%(id, name, file) | 
					
						
							| 
									
										
										
										
											1995-07-29 13:48:41 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | if __name__ == '__main__': | 
					
						
							|  |  |  | 	args = sys.argv[1:] | 
					
						
							|  |  |  | 	if not args: | 
					
						
							| 
									
										
										
										
											1995-08-14 12:21:12 +00:00
										 |  |  | 		ifss, ok = macfs.GetDirectory('Select root of tree to pack:') | 
					
						
							|  |  |  | 		if not ok: | 
					
						
							|  |  |  | 			sys.exit(0) | 
					
						
							|  |  |  | 		args = [ifss.as_pathname()] | 
					
						
							| 
									
										
										
										
											1995-07-29 13:48:41 +00:00
										 |  |  | 	for ifn in args: | 
					
						
							|  |  |  | 		ofss, ok = macfs.StandardPutFile('Output for '+os.path.split(ifn)[1]) | 
					
						
							|  |  |  | 		if not ok: | 
					
						
							|  |  |  | 			sys.exit(0) | 
					
						
							|  |  |  | 		mkpycresourcefile(ifn, ofss.as_pathname()) | 
					
						
							|  |  |  | 	sys.exit(1)			# So we can see something... |