source: create-upload.py @ 2:e057e9483488

Last change on this file since 2:e057e9483488 was 2:e057e9483488, checked in by Jeremy Thurgood <firxen@…>, 11 years ago

Added pyweek skellington.

File size: 1.7 KB
Line 
1#! /usr/bin/env python
2'''Helper script for bundling up a game in a ZIP file.
3
4This script will bundle all game files into a ZIP file which is named as
5per the argument given on the command-line. The ZIP file will unpack into a
6directory of the same name.
7
8The script ignores:
9
10- CVS or SVN subdirectories
11- any dotfiles (files starting with ".")
12- .pyc and .pyo files
13
14'''
15
16import sys
17import os
18import zipfile
19
20if len(sys.argv) != 2:
21    print '''Usage: python %s <release filename-version>
22
23eg. python %s my_cool_game-1.0'''%(sys.argv[0], sys.argv[0])
24    sys.exit()
25
26base = sys.argv[1]
27zipname = base + '.zip'
28
29try:
30    package = zipfile.ZipFile(zipname, 'w', zipfile.ZIP_DEFLATED)
31except RuntimeError:
32    package = zipfile.ZipFile(zipname, 'w')
33
34# core files
35for name in 'README.txt run_game.py'.split():
36    package.write(name, os.path.join(base, name))
37package.write('run_game.py', os.path.join(base, 'run_game.pyw'))
38
39# utility for adding subdirectories
40def add_files(generator):
41    for dirpath, dirnames, filenames in generator:
42        for name in list(dirnames):
43            if name == 'CVS' or name.startswith('.'):
44                dirnames.remove(name)
45
46        for name in filenames:
47            if name.startswith('.'): continue
48            suffix = os.path.splitext(name)[1]
49            if suffix in ('.pyc', '.pyo'): continue
50            if name[0] == '.': continue
51            filename = os.path.join(dirpath, name)
52            package.write(filename, os.path.join(base, filename))
53
54# add the lib and data directories
55add_files(os.walk('gamelib'))
56add_files(os.walk('data'))
57
58# calculate MD5
59import hashlib
60d = hashlib.md5()
61d.update(file(zipname, 'rb').read())
62print 'Created', zipname
63print 'MD5 hash:', d.hexdigest()
Note: See TracBrowser for help on using the repository browser.