1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 # Runs on Buildbot master, to unpack incoming unload.zip into latest
20 # builds directory and remove older builds.
31 def strip_extension(filename):
32 extensions = '.zip', '.tar', '.bz2', '.gz', '.tgz', '.tbz', '.exe'
33 filename_noext, ext = os.path.splitext(filename)
35 return strip_extension(filename_noext) # may have .tar.bz2
40 # extract platform from package name
41 def get_platform(filename):
42 # name is blender-version-platform.extension. we want to get the
43 # platform out, but there may be some variations, so we fiddle a
44 # bit to handle current and hopefully future names
45 filename = strip_extension(filename)
46 filename = strip_extension(filename)
48 tokens = filename.split("-")
49 platforms = ('osx', 'mac', 'bsd',
50 'win', 'linux', 'source',
57 for platform in platforms:
58 if platform in token.lower():
63 platform_tokens += [token]
65 return '-'.join(platform_tokens)
68 def get_branch(filename):
69 tokens = filename.split("-")
76 branch = branch + "-" + token
78 if token == "blender":
85 sys.stderr.write("Not enough arguments, expecting file to unpack\n")
88 filename = sys.argv[1]
91 if not os.path.exists(filename):
92 sys.stderr.write("File %r not found.\n" % filename)
96 z = zipfile.ZipFile(filename, "r")
98 sys.stderr.write('Failed to open zip file: %s\n' % str(ex))
101 if len(z.namelist()) != 1:
102 sys.stderr.write("Expected one file in %r." % filename)
105 package = z.namelist()[0]
106 packagename = os.path.basename(package)
108 # detect platform and branch
109 platform = get_platform(packagename)
110 branch = get_branch(packagename)
113 sys.stderr.write('Failed to detect platform ' +
114 'from package: %r\n' % packagename)
118 directory = 'public_html/download'
122 f = file(os.path.join(directory, packagename), "wb")
124 shutil.copyfileobj(zf, f)
130 except Exception, ex:
131 sys.stderr.write('Failed to unzip package: %s\n' % str(ex))
134 # remove other files from the same platform and branch
136 for f in os.listdir(directory):
137 if get_platform(f) == platform and get_branch(f) == branch:
139 os.remove(os.path.join(directory, f))
140 except Exception, ex:
141 sys.stderr.write('Failed to remove old packages: %s\n' % str(ex))