seawolf2357 commited on
Commit
b922192
·
verified ·
1 Parent(s): ba6503e
misc/cleanup-pyc.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ import logging
3
+ import os.path
4
+
5
+
6
+ logger = logging.getLogger(os.path.splitext(os.path.basename(__file__))[0])
7
+
8
+
9
+ def find_files(root):
10
+ import os
11
+ import os.path
12
+ for name in os.listdir(root):
13
+ path = os.path.join(root, name)
14
+ yield path
15
+ if os.path.isdir(path):
16
+ for x in find_files(path):
17
+ yield x
18
+
19
+
20
+ def find_pyc_files(root):
21
+ for path in find_files(root):
22
+ if path.endswith('.pyc') or path.endswith('$py.class'):
23
+ yield path
24
+
25
+
26
+ def main():
27
+ import sys
28
+ import os.path
29
+
30
+ logging.basicConfig(level=logging.INFO)
31
+
32
+ for root in sys.argv[1:]:
33
+ if os.path.isdir(root):
34
+ for path in find_pyc_files(root):
35
+ if not os.path.isdir(path):
36
+ logger.info('unlink %s', path)
37
+ os.unlink(path)
38
+
39
+
40
+ if __name__ == '__main__':
41
+ main()
misc/copylxml.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import os.path
3
+ import shutil
4
+
5
+ def main():
6
+ if sys.platform == 'win32':
7
+ try:
8
+ import lxml
9
+ except ImportError:
10
+ print 'no lxml found'
11
+ else:
12
+ lxml_path = os.path.dirname(lxml.__file__)
13
+ dest_path = os.path.join(sys.argv[1], 'lxml')
14
+ shutil.copytree(lxml_path, dest_path)
15
+ sys.exit(0)
16
+ else:
17
+ sys.exit(os.system('pip install lxml'))
18
+
19
+
20
+ if __name__ == '__main__':
21
+ main()
misc/docs-upload ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+
3
+ # exit if any statement returns non-true return value
4
+ set -e
5
+
6
+ # exit on uninitialized variable
7
+ set -u
8
+
9
+ HTML_BASE=${buildout:directory}/docs/.build/html
10
+ BUILD_DIR=${buildout:directory}/build
11
+
12
+ cd ${buildout:directory}
13
+
14
+ [ -d $BUILD_DIR/docs/ ] || (echo $BUILD_DIR/docs/ missing; exit 1)
15
+ [ -d $BUILD_DIR/docs/ko/ ] || (echo $BUILD_DIR/docs/ko/ missing; exit 1)
16
+
17
+ python setup.py upload_docs -r https://pypi.python.org/pypi --upload-dir=$BUILD_DIR/docs
misc/fix-coverage.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ ''' fix pyhwp source paths in coverage.xml
3
+ '''
4
+ import re
5
+ import sys
6
+
7
+
8
+ def main():
9
+ f = file(sys.argv[2], 'w')
10
+ try:
11
+ for line in file(sys.argv[1]):
12
+ line = re.sub('filename="[^"]*/hwp5/', 'filename="pyhwp/hwp5/', line)
13
+ f.write(line)
14
+ finally:
15
+ f.close()
16
+
17
+
18
+ if __name__ == '__main__':
19
+ main()
misc/install-lxml.py.in ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+
3
+ def main():
4
+ import sys
5
+ import os.path
6
+ from subprocess import check_call
7
+ from subprocess import Popen
8
+ import shutil
9
+
10
+ if sys.platform == 'win32':
11
+ src = '${lxml-location}'
12
+ dst = sys.argv[1]
13
+ src_path = os.path.join(src, 'lxml')
14
+ dst_path = os.path.join(dst, 'lxml')
15
+ print('lxml src: %s' % src_path)
16
+ print('lxml dst: %s' % dst_path)
17
+ if os.path.exists(src_path):
18
+ print('lxml: copytree-ing...')
19
+ shutil.copytree(src_path, dst_path)
20
+ else:
21
+ print('lxml: not found. skipping...')
22
+ sys.exit(0)
23
+ else:
24
+ check_call(['pip', 'install', 'lxml'])
25
+
26
+ if __name__ == '__main__':
27
+ main()
misc/mkdir.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+
3
+ import sys
4
+ import os.path
5
+ import shutil
6
+
7
+ if __name__ == '__main__':
8
+ d = sys.argv[1]
9
+ if os.path.exists(d):
10
+ print('rmtree: %s' % d)
11
+ shutil.rmtree(d)
12
+ print('mkdir: %s' % d)
13
+ os.makedirs(d)
misc/oxt-build.in ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ DIST_DIR=${buildout:directory}/dist
3
+ SRC_DIR=${buildout:directory}/oxt
4
+ BIN_DIR=${buildout:directory}/bin
5
+ VERSION=`git describe --dirty`
6
+ OUTPUT=$DIST_DIR/hwp5-$VERSION.oxt
7
+
8
+ [ ! -e $DIST_DIR ] && mkdir $DIST_DIR
9
+ cp $SRC_DIR/description.xml description.xml
10
+ $BIN_DIR/oxt-desc-version description.xml $VERSION
11
+ $BIN_DIR/oxt-pkg-build -d description.xml -o $OUTPUT $SRC_DIR pythonpath -E '*.pyc:*.class:*/docopt*:*/OleFileIO*:'
12
+ $BIN_DIR/oxt-pkg-check $OUTPUT || exit 1
13
+ $BIN_DIR/oxt-pkg-show $OUTPUT
14
+ ln -sf $OUTPUT $DIST_DIR/hwp5.oxt
15
+ rm -f description.xml
misc/prepare-hwp5-xsl-fixtures.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ from __future__ import with_statement
3
+ import os.path
4
+ import logging
5
+ import sys
6
+
7
+
8
+ logger = logging.getLogger('hwp5.xsltests')
9
+
10
+
11
+ def find_hwp5files(dir):
12
+ import glob
13
+ return glob.glob(os.path.join(dir, '*.hwp'))
14
+
15
+
16
+ def main():
17
+ doc = ''' convert fixture hwp5 files into *.xml
18
+
19
+ Usage:
20
+ prepare [--fixtures-dir=<dir>] [--out-dir=<dir>]
21
+ prepare --help
22
+
23
+ Options:
24
+ -h --help Show this screen
25
+ --fixtures-dir=<dir> Fixture directory
26
+ --out-dir=<dir> Output directory
27
+ '''
28
+ from docopt import docopt
29
+ from hwp5.xmlmodel import Hwp5File
30
+
31
+ args = docopt(doc, version='0.0')
32
+
33
+ logging.getLogger().addHandler(logging.StreamHandler())
34
+ logging.getLogger('hwp5.xsltests').setLevel(logging.INFO)
35
+
36
+ if args['--fixtures-dir']:
37
+ fixture_dir = args['--fixtures-dir']
38
+ else:
39
+ import hwp5
40
+ hwp5_pkgdir = os.path.dirname(hwp5.__file__)
41
+ fixture_dir = os.path.join(hwp5_pkgdir, 'tests', 'fixtures')
42
+
43
+ out_dir = args['--out-dir']
44
+
45
+ for path in find_hwp5files(fixture_dir):
46
+ name = os.path.basename(path)
47
+ rootname = os.path.splitext(name)[0]
48
+ out_path = rootname + '.xml'
49
+ if out_dir is not None:
50
+ if not os.path.exists(out_dir):
51
+ os.makedirs(out_dir)
52
+ out_path = os.path.join(out_dir, out_path)
53
+
54
+ logger.info('%s', out_path)
55
+
56
+ opts = {}
57
+ try:
58
+ hwp5file = Hwp5File(path)
59
+ with file(out_path, 'w') as f:
60
+ hwp5file.xmlevents(**opts).dump(f)
61
+ except Exception:
62
+ e = sys.exc_info()[1]
63
+ logger.exception(e)
64
+
65
+
66
+ if __name__ == '__main__':
67
+ sys.exit(main())
misc/redirect.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import with_statement
2
+ import subprocess
3
+ import sys
4
+
5
+ if __name__ == '__main__':
6
+ with file(sys.argv[1], 'wb') as f:
7
+ p = subprocess.Popen(sys.argv[2:], stdout=f)
8
+ p.wait()
9
+ raise SystemExit(p.returncode)
misc/test-cli.in ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/sh
2
+ PATH=${buildout:bin-directory}:$PATH
3
+ . ${buildout:directory}/pyhwp-tests/hwp5_cli_tests.sh
misc/test-cli.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ import os.path
3
+ import logging
4
+
5
+
6
+ logger = logging.getLogger('test-cli')
7
+
8
+
9
+ def main():
10
+ logging.basicConfig(level=logging.INFO)
11
+
12
+ if not os.path.exists('/bin/sh'):
13
+ logger.warning('/bin/sh: not-found')
14
+ logger.warning('skipping test-cli')
15
+ return 0
16
+
17
+ d = 'pyhwp-tests'
18
+ shscript = os.path.join(d, 'hwp5_cli_tests.sh')
19
+
20
+ cmd = ['/bin/sh', shscript]
21
+ cmd = ' '.join(cmd)
22
+ logger.info('running: %s', cmd)
23
+ ret = os.system(cmd)
24
+ logger.info('exit with %d', ret)
25
+ if ret != 0:
26
+ raise SystemExit(-1)
27
+
28
+
29
+ if __name__ == '__main__':
30
+ main()
misc/test-coverage ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ # Remove old results
3
+ ${buildout:directory}/bin/coverage erase
4
+
5
+ # Collect test coverage results for all packages
6
+ # Runs a code coverage analysis on top of the "bin/test" script for
7
+ # all packages. The data will be collected in a ".coverage" output file
8
+ # in the buildout directory.
9
+
10
+ ${buildout:directory}/bin/coverage run -p --source=hwp5 ${buildout:directory}/bin/test
11
+
12
+ # Combine all package analysis
13
+ ${buildout:directory}/bin/coverage combine
14
+ # Generates a "coverage.xml" file that Jenkins can read and process from the
15
+ # ".coverage" file that the coverage report created.
16
+ ${buildout:directory}/bin/coverage xml -i -o ${buildout:directory}/coverage.xml
misc/test-for-bisect ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+
3
+ # usage: git bisect run bin/test-for-bisect
4
+
5
+ cd ${buildout:directory}
6
+ bin/buildout -o && bin/test && exit 0 || exit 1
misc/test-in-lo.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ def main():
5
+ import os
6
+ args = ['${buildout:bin-directory}/oxt-test',
7
+ '${buildout:parts-directory}/test']
8
+ os.system(' '.join(args))
9
+
10
+
11
+ if __name__ == '__main__':
12
+ main()
misc/test-pypi.in ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+
3
+ # exit if any statement returns non-true return value
4
+ set -e
5
+
6
+ # exit on uninitialized variable
7
+ set -u
8
+
9
+ cd ${buildout:directory}
10
+
11
+ VERSION=`cat VERSION.txt`
12
+
13
+ mkdir -p releases
14
+ rm -rf releases/$VERSION
15
+ mkvenv cp2 releases/$VERSION
16
+ set +u
17
+ . releases/$VERSION/bin/activate
18
+ set -u
19
+ pip install pyhwp==$VERSION
20
+ hwp5proc --version | head -n 1 | grep "$VERSION$"
misc/test-sdist ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # exit if any statement returns non-true return value
4
+ set -e
5
+
6
+ # exit on uninitialized variable
7
+ set -u
8
+
9
+ VERSION=`python setup.py --version`
10
+ echo pyhwp version: $VERSION
11
+ VENV=venv-$VERSION
12
+ SDIST=dist/pyhwp-$VERSION.tar.gz
13
+
14
+ [ -f $SDIST ] && rm -f $SDIST
15
+ python setup.py sdist > sdist.log
16
+ tar tfz $SDIST | grep -F "pyhwp-$VERSION/README"
17
+ tar tfz $SDIST | grep -F "pyhwp-$VERSION/COPYING"
18
+ tar tfz $SDIST | grep -F "pyhwp-$VERSION/pyhwp/hwp5/README"
19
+ tar tfz $SDIST | grep -F "pyhwp-$VERSION/pyhwp/hwp5/COPYING"
20
+
21
+ [ -f $VENV/bin/activate ] || mkvenv cp2 $VENV
22
+ set +eu
23
+ . $VENV/bin/activate
24
+ set -eu
25
+
26
+ pip install $SDIST
27
+ python -c 'print __import__("pkg_resources").resource_filename("hwp5", "README")' | grep README
28
+ python -c 'print __import__("pkg_resources").resource_filename("hwp5", "COPYING")' | grep COPYING
29
+ hwp5proc --version | grep -F "$VERSION"
30
+ hwp5odt --version | grep -F "$VERSION"
31
+ bin/test-cli > test-cli.log
32
+
33
+ pip uninstall pyhwp --yes
34
+ rm -rf $VENV
35
+ echo 'test-sdist SUCCESSFUL'
misc/test-sdist.in ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/bin/sh
2
+ bash ${buildout:directory}/misc/test-sdist
misc/test-upload.in ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+
3
+ # exit if any statement returns non-true return value
4
+ set -e
5
+
6
+ # exit on uninitialized variable
7
+ set -u
8
+
9
+ cd ${buildout:directory}
10
+
11
+ VERSION=`cat VERSION.txt`
12
+ python setup.py sdist upload -r https://testpypi.python.org/pypi | tee upload.log
13
+ tail -n 1 upload.log | grep 200
14
+
15
+ rm -rf testpypi
16
+ mkvenv cp2 testpypi
17
+ set +u
18
+ . testpypi/bin/activate
19
+ set -u
20
+ pip install --download=testpypi --no-deps --index-url https://testpypi.python.org/simple/ pyhwp==$VERSION
21
+ pip install --extra-index-url https://testpypi.python.org/simple/ pyhwp==$VERSION
22
+ hwp5proc --version | head -n 1 | grep "$VERSION$"
misc/test-xsl.in ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+
3
+ set -e
4
+ set -u
5
+
6
+ cd ${buildout:directory}
7
+ rm -rf test-xsl
8
+ mkdir -p test-xsl
9
+
10
+ IMPORT_DIR=${buildout:directory}/test-xsl/fixtures
11
+ GEN_DIR=${buildout:directory}/test-xsl/gen
12
+
13
+ mkdir -p $IMPORT_DIR
14
+ mkdir -p $GEN_DIR
15
+
16
+ ${buildout:bin-directory}/console ${buildout:directory}/misc/prepare-hwp5-xsl-fixtures.py --fixtures-dir=${buildout:directory}/pyhwp-tests/hwp5_tests/fixtures --out-dir=$IMPORT_DIR
17
+ ${buildout:bin-directory}/xsltest --styles-dir=${buildout:directory}/pyhwp/hwp5/xsl --import-dir=$IMPORT_DIR --gen-dir=$GEN_DIR ${buildout:directory}/pyhwp-tests/hwp5_xsl_tests
18
+
19
+ test_xsl_cov="${buildout:bin-directory}/test-xsl-cov"
20
+ [ ! -e "$test_xsl_cov" ] || "$test_xsl_cov" xsltcoverage.xml ${buildout:directory}/test-xsl/gen/*.py
misc/upload ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/sh
2
+ cd ${buildout:directory}
3
+ python setup.py sdist upload --sign