forked from RallyTools/RallyRestToolkitForPython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_dist.py
executable file
·161 lines (128 loc) · 5.23 KB
/
build_dist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env python
#############################################################################
#
# build_dist.py -- Build the pyral distribution package for shipment
#
#############################################################################
import sys, os
import tarfile
import zipfile
PACKAGE_NAME = "pyral"
VERSION = "1.2.0"
AUX_FILES = ['MANIFEST.in',
'LICENSE',
'README.short',
'README.rst',
'setup.py',
'template.cfg',
'rallyfire.py'
]
EXAMPLES = ['getitem.py',
'periscope.py',
'showdefects.py',
'crtask.py',
'uptask.py',
'statecounts.py',
'repoitems.py',
'get_schema.py',
'typedef.py',
'wkspcounts.py',
'builddefs.py',
'creattach.py',
'get_attachments.py',
'get_schedulable_artifacts.py',
'add_tcrs.py',
'defrevs.py',
'updtag.py'
]
DOC_FILES = ['doc/Makefile',
'doc/source/conf.py',
'doc/source/index.rst',
'doc/source/overview.rst',
'doc/source/interface.rst',
'doc/build/html/genindex.html',
'doc/build/html/index.html',
'doc/build/html/overview.html',
'doc/build/html/interface.html',
'doc/build/html/search.html',
'doc/build/html/searchindex.js',
'doc/build/html/objects.inv',
'doc/build/html/_sources',
'doc/build/html/_static',
]
#
# The TEST_FILES are **NOT** placed into the distribution packages
#
TEST_FILES = ['test/rally_targets.py',
'test/test_conn.py',
'test/test_context.py',
'test/test_convenience.py',
'test/test_inflation.py',
'test/test_field_access.py',
'test/test_query.py',
'test/test_search.py',
'test/test_wksprj_setting.py',
'test/test_attachments.py',
'test/test_workspaces.py'
'test/test_ranking.py'
]
################################################################################
def main(args):
tarball = make_tarball(PACKAGE_NAME, VERSION, AUX_FILES, EXAMPLES, DOC_FILES)
print tarball
zipped = make_zipfile(PACKAGE_NAME, VERSION, AUX_FILES, EXAMPLES, DOC_FILES)
print zipped
zf = zipfile.ZipFile(zipped, 'r')
for info in zf.infolist():
#print(info.filename, info.date_time, info.file_size, info.compress_size)
if info.file_size:
reduction_fraction = float(info.compress_size) / float(info.file_size)
else:
reduction_fraction = 0.0
reduction_pct = int(reduction_fraction * 100)
print("%-52.52s %6d (%2d%%)" % (info.filename, info.compress_size, reduction_pct))
################################################################################
def make_tarball(pkg_name, pkg_version, base_files, example_files, doc_files):
base_dir = '%s-%s' % (pkg_name, pkg_version)
#tf_name = '%s-%s.tar' % (pkg_name, pkg_version)
tgz_name = '%s-%s.tar.gz' % (pkg_name, pkg_version)
tf = tarfile.open(tgz_name, 'w:gz')
for fn in base_files:
tf.add(fn, '%s/%s' % (base_dir, fn))
for fn in (pf for pf in os.listdir(pkg_name) if pf.endswith('.py')):
pkg_file = '%s/%s' % (pkg_name, fn)
tf.add(pkg_file, '%s/%s/%s' % (base_dir, pkg_name, fn))
for fn in example_files:
exf_path = 'examples/%s' % fn
tf.add(exf_path, '%s/%s' % (base_dir, exf_path))
for doc_item in doc_files:
full_item_path = '%s/%s' % (base_dir, doc_item)
tf.add(doc_item, full_item_path)
tf.close()
return tgz_name
################################################################################
def make_zipfile(pkg_name, pkg_version, base_files, example_files, doc_files):
base_dir = '%s-%s' % (pkg_name, pkg_version)
zf_name = '%s.zip' % base_dir
zf = zipfile.ZipFile(zf_name, 'w')
for fn in base_files:
zf.write(fn, '%s/%s' % (base_dir, fn), zipfile.ZIP_DEFLATED)
for fn in (pf for pf in os.listdir(pkg_name) if pf.endswith('.py')):
pkg_file = '%s/%s' % (pkg_name, fn)
zf.write(pkg_file, '%s/%s/%s' % (base_dir, pkg_name, fn), zipfile.ZIP_DEFLATED)
for fn in example_files:
exf_path = 'examples/%s' % fn
zf.write(exf_path, '%s/%s' % (base_dir, exf_path), zipfile.ZIP_DEFLATED)
for doc_item in doc_files:
if os.path.isfile(doc_item):
zf.write(doc_item, '%s/%s' % (base_dir, doc_item), zipfile.ZIP_DEFLATED)
elif os.path.isdir(doc_item):
sub_items = os.listdir(doc_item)
for sub_item in sub_items:
zf.write('%s/%s' % (doc_item, sub_item), '%s/%s/%s' % (base_dir, doc_item, sub_item), zipfile.ZIP_DEFLATED)
zf.close()
return zf_name
################################################################################
################################################################################
if __name__ == "__main__":
main(sys.argv[1:])