| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | # ##### BEGIN GPL LICENSE BLOCK ##### | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #  This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  | #  modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  | #  as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  | #  of the License, or (at your option) any later version. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #  This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | #  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | #  GNU General Public License for more details. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #  You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | #  along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  | #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # ##### END GPL LICENSE BLOCK ##### | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Runs on Buildbot master, to unpack incoming unload.zip into latest | 
					
						
							|  |  |  | # builds directory and remove older builds. | 
					
						
							| 
									
										
										
										
											2011-03-23 01:08:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-27 05:23:14 +00:00
										 |  |  | # <pep8 compliant> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | import os | 
					
						
							|  |  |  | import shutil | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | import zipfile | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 01:08:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | # extension stripping | 
					
						
							|  |  |  | def strip_extension(filename): | 
					
						
							| 
									
										
										
										
											2011-03-23 01:08:10 +00:00
										 |  |  |     extensions = '.zip', '.tar', '.bz2', '.gz', '.tgz', '.tbz', '.exe' | 
					
						
							|  |  |  |     filename_noext, ext = os.path.splitext(filename) | 
					
						
							|  |  |  |     if ext in extensions: | 
					
						
							|  |  |  |         return strip_extension(filename_noext)  # may have .tar.bz2 | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         return filename | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # extract platform from package name | 
					
						
							|  |  |  | def get_platform(filename): | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |     # name is blender-version-platform.extension. we want to get the | 
					
						
							|  |  |  |     # platform out, but there may be some variations, so we fiddle a | 
					
						
							|  |  |  |     # bit to handle current and hopefully future names | 
					
						
							|  |  |  |     filename = strip_extension(filename) | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |     tokens = filename.split("-") | 
					
						
							| 
									
										
										
										
											2011-03-23 01:08:10 +00:00
										 |  |  |     platforms = 'osx', 'mac', 'bsd', 'win', 'linux', 'source', 'irix', 'solaris' | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |     platform_tokens = [] | 
					
						
							|  |  |  |     found = False | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |     for i, token in enumerate(tokens): | 
					
						
							|  |  |  |         if not found: | 
					
						
							|  |  |  |             for platform in platforms: | 
					
						
							| 
									
										
										
										
											2011-03-23 01:08:10 +00:00
										 |  |  |                 if platform in token.lower(): | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |                     found = True | 
					
						
							| 
									
										
										
										
											2011-03-23 01:08:10 +00:00
										 |  |  |                     break | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |         if found: | 
					
						
							|  |  |  |             platform_tokens += [token] | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |     return '-'.join(platform_tokens) | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # get filename | 
					
						
							|  |  |  | if len(sys.argv) < 2: | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |     sys.stderr.write("Not enough arguments, expecting file to unpack\n") | 
					
						
							|  |  |  |     sys.exit(1) | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | filename = sys.argv[1] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # open zip file | 
					
						
							|  |  |  | if not os.path.exists(filename): | 
					
						
							| 
									
										
										
										
											2011-03-23 01:08:10 +00:00
										 |  |  |     sys.stderr.write("File %r not found.\n" % filename) | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |     sys.exit(1) | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | try: | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |     z = zipfile.ZipFile(filename, "r") | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | except Exception, ex: | 
					
						
							| 
									
										
										
										
											2011-03-23 01:08:10 +00:00
										 |  |  |     sys.stderr.write('Failed to open zip file: %s\n' % str(ex)) | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |     sys.exit(1) | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | if len(z.namelist()) != 1: | 
					
						
							| 
									
										
										
										
											2011-03-23 01:08:10 +00:00
										 |  |  |     sys.stderr.write("Expected one file in %r." % filename) | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |     sys.exit(1) | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | package = z.namelist()[0] | 
					
						
							|  |  |  | packagename = os.path.basename(package) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # detect platform | 
					
						
							|  |  |  | platform = get_platform(packagename) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if platform == '': | 
					
						
							| 
									
										
										
										
											2011-03-23 01:08:10 +00:00
										 |  |  |     sys.stderr.write('Failed to detect platform from package: %r\n' % packagename) | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |     sys.exit(1) | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # extract | 
					
						
							| 
									
										
										
										
											2011-04-01 02:41:15 +00:00
										 |  |  | directory = 'public_html/download' | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | try: | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |     zf = z.open(package) | 
					
						
							| 
									
										
										
										
											2011-04-01 02:41:15 +00:00
										 |  |  |     f = file(os.path.join(directory, packagename), "wb") | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |     shutil.copyfileobj(zf, f) | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |     zf.close() | 
					
						
							|  |  |  |     z.close() | 
					
						
							| 
									
										
										
										
											2011-03-23 01:08:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |     os.remove(filename) | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | except Exception, ex: | 
					
						
							| 
									
										
										
										
											2011-03-23 01:08:10 +00:00
										 |  |  |     sys.stderr.write('Failed to unzip package: %s\n' % str(ex)) | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |     sys.exit(1) | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # remove other files from the same platform | 
					
						
							|  |  |  | try: | 
					
						
							| 
									
										
										
										
											2011-04-01 02:41:15 +00:00
										 |  |  |     for f in os.listdir(directory): | 
					
						
							| 
									
										
										
										
											2011-03-23 01:08:10 +00:00
										 |  |  |         if platform.lower() in f.lower(): | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |             if f != packagename: | 
					
						
							| 
									
										
										
										
											2011-04-01 02:41:15 +00:00
										 |  |  |                 os.remove(os.path.join(directory, f)) | 
					
						
							| 
									
										
										
										
											2011-03-21 16:46:26 +00:00
										 |  |  | except Exception, ex: | 
					
						
							| 
									
										
										
										
											2011-03-23 01:08:10 +00:00
										 |  |  |     sys.stderr.write('Failed to remove old packages: %s\n' % str(ex)) | 
					
						
							| 
									
										
										
										
											2011-03-22 15:25:18 +00:00
										 |  |  |     sys.exit(1) |