1 # Copyright 2016 Cisco Systems, Inc. All rights reserved.
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
18 TREX_OPT = '/opt/trex'
22 '_t-rex-64-debug', '_t-rex-64-debug-o', 'bp-sim-64', 'bp-sim-64-debug',
23 't-rex-64-debug', 't-rex-64-debug-o', 'automation/__init__.py',
24 'automation/graph_template.html',
25 'automation/config', 'automation/h_avc.py', 'automation/phantom',
26 'automation/readme.txt', 'automation/regression', 'automation/report_template.html',
27 'automation/sshpass.exp', 'automation/trex_perf.py', 'wkhtmltopdf-amd64'
31 def remove_unused_libs(path, files):
33 Remove files not used by traffic generator.
36 f = os.path.join(path, f)
48 def get_dir_size(start_path='.'):
50 Computes size of directory.
52 :return: size of directory with subdirectiories
55 for dirpath, dirnames, filenames in os.walk(start_path):
58 fp = os.path.join(dirpath, f)
59 total_size += os.path.getsize(fp)
64 if __name__ == "__main__":
65 versions = os.listdir(TREX_OPT)
66 for version in versions:
67 trex_path = os.path.join(TREX_OPT, version)
68 print 'Cleaning TRex', version
70 size_before = get_dir_size(trex_path)
71 remove_unused_libs(trex_path, TREX_UNUSED)
72 size_after = get_dir_size(trex_path)
73 print '==== Saved Space ===='
74 print size_before - size_after
77 print traceback.print_exc()
78 print 'Cleanup was not finished.'