Mercurial > sypikslang
comparison create-upload.py @ 0:d0de8832774b
Import skellington-1.9 into the repo
author | Neil Muller <drnlmuller+bitbucket@gmail.com> |
---|---|
date | Sat, 05 May 2012 13:52:29 +0200 |
parents | |
children | c90a6586cd66 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d0de8832774b |
---|---|
1 #! /usr/bin/env python | |
2 '''Helper script for bundling up a game in a ZIP file. | |
3 | |
4 This script will bundle all game files into a ZIP file which is named as | |
5 per the argument given on the command-line. The ZIP file will unpack into a | |
6 directory of the same name. | |
7 | |
8 The script ignores: | |
9 | |
10 - CVS or SVN subdirectories | |
11 - any dotfiles (files starting with ".") | |
12 - .pyc and .pyo files | |
13 | |
14 ''' | |
15 | |
16 import sys | |
17 import os | |
18 import zipfile | |
19 | |
20 if len(sys.argv) != 2: | |
21 print '''Usage: python %s <release filename-version> | |
22 | |
23 eg. python %s my_cool_game-1.0'''%(sys.argv[0], sys.argv[0]) | |
24 sys.exit() | |
25 | |
26 base = sys.argv[1] | |
27 zipname = base + '.zip' | |
28 | |
29 try: | |
30 package = zipfile.ZipFile(zipname, 'w', zipfile.ZIP_DEFLATED) | |
31 except RuntimeError: | |
32 package = zipfile.ZipFile(zipname, 'w') | |
33 | |
34 # core files | |
35 for name in 'README.txt run_game.py'.split(): | |
36 package.write(name, os.path.join(base, name)) | |
37 package.write('run_game.py', os.path.join(base, 'run_game.pyw')) | |
38 | |
39 # utility for adding subdirectories | |
40 def 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 | |
55 add_files(os.walk('gamelib')) | |
56 add_files(os.walk('data')) | |
57 | |
58 # calculate MD5 | |
59 import hashlib | |
60 d = hashlib.md5() | |
61 d.update(file(zipname, 'rb').read()) | |
62 print 'Created', zipname | |
63 print 'MD5 hash:', d.hexdigest() |