Coverage for /opt/cloud/slavespace/usr1/096471637100f3de0fcfc01072822a80/ut/src/asys/common/compress_output_dir.py: 92%
12 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-19 17:46 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-19 17:46 +0800
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# ----------------------------------------------------------------------------
4# Copyright (c) 2025 Huawei Technologies Co., Ltd.
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17# ----------------------------------------------------------------------------
19import os
20import shutil
21import tarfile
22from common import FileOperate as f
23from params import ParamDict
26def compress_output_dir_tar():
27 """
28 Compress the output directory using tar.
29 """
31 output_dir = ParamDict().asys_output_timestamp_dir
32 if not (output_dir and f.check_dir(output_dir)):
33 return
34 with tarfile.open(os.path.join(os.path.dirname(output_dir), os.path.basename(output_dir) + ".tar.gz"), "w:gz") \
35 as tar:
36 tar.add(output_dir, arcname=os.path.basename(output_dir))
38 # remove output dir
39 shutil.rmtree(output_dir)