|
1 | 1 | #!/usr/bin/env python
|
2 | 2 |
|
3 |
| -import os, shutil |
| 3 | +from glob import glob |
| 4 | +from os import chdir, sep as SEP |
| 5 | +from os.path import abspath, dirname, join |
| 6 | +from time import localtime |
4 | 7 | from zipfile import ZipFile, ZIP_DEFLATED
|
5 | 8 |
|
6 |
| -VERSION = "1.0" |
7 |
| -THIS_DIR = os.path.dirname(os.path.abspath(__file__)) |
8 |
| -#execfile(os.path.join(THIS_DIR, '..', 'src', 'Selenium2Library', 'version.py')) |
| 9 | +NAME = 'WebDemo' |
| 10 | +ZIP_NAME = NAME + '-%d%02d%02d.zip' % localtime()[:3] |
| 11 | +FILES = ['README.rst', |
| 12 | + 'demoapp/server.py', |
| 13 | + 'demoapp/html/*.html', |
| 14 | + 'demoapp/html/*.css', |
| 15 | + 'login_tests/*.txt'] |
9 | 16 |
|
10 |
| -FILES = { |
11 |
| - '': ['rundemo.py'], |
12 |
| - 'testcases': ['valid_login.txt', 'invalid_login.txt','content_check.txt','resource.txt'], |
13 |
| - 'demoapp': ['server.py'], |
14 |
| - 'demoapp/html': ['index.html', 'welcome.html', 'error.html', 'demo.css', 'file_information.txt', 'file_names.txt', 'file_places.txt'] |
15 |
| -} |
16 |
| - |
17 |
| -def main(): |
18 |
| - cwd = os.getcwd() |
19 |
| - try: |
20 |
| - os.chdir(THIS_DIR) |
21 |
| - name = 'robotframework-selenium2library-%s-demo' % VERSION |
22 |
| - zipname = '%s.zip' % name |
23 |
| - if os.path.exists(zipname): |
24 |
| - os.remove(zipname) |
25 |
| - zipfile = ZipFile(zipname, 'w', ZIP_DEFLATED) |
26 |
| - for dirname in FILES: |
27 |
| - for filename in FILES[dirname]: |
28 |
| - path = os.path.join('.', dirname.replace('/', os.sep), filename) |
29 |
| - print 'Adding: ', os.path.normpath(path) |
30 |
| - zipfile.write(path, os.path.join(name, path)) |
31 |
| - zipfile.close() |
32 |
| - target_path = os.path.join('.', 'dist') |
33 |
| - if os.path.exists(target_path): |
34 |
| - shutil.rmtree(target_path, ignore_errors=True) |
35 |
| - os.makedirs(target_path) |
36 |
| - os.rename(zipname, os.path.join(target_path, zipname)) |
37 |
| - print 'Created: ', os.path.abspath(target_path) |
38 |
| - finally: |
39 |
| - os.chdir(cwd) |
40 |
| - |
41 |
| - |
42 |
| -if __name__ == '__main__': |
43 |
| - main() |
| 17 | +chdir(dirname(abspath(__file__))) |
| 18 | +zipfile = ZipFile(ZIP_NAME, 'w', ZIP_DEFLATED) |
| 19 | +for pattern in FILES: |
| 20 | + for path in glob(pattern.replace('/', SEP)): |
| 21 | + print 'Adding: ', path |
| 22 | + zipfile.write(path, join(NAME, path)) |
| 23 | +zipfile.close() |
| 24 | +print 'Created: ', ZIP_NAME |
0 commit comments