"git@developer.sourcefind.cn:zhaoyu6/sglang.git" did not exist on "13bc39c5d631f7783675674fa7615d594ed533b2"
common.py 1.19 KB
Newer Older
drunkpig's avatar
drunkpig committed
1
"""common definitions."""
quyuan's avatar
quyuan committed
2
import os
drunkpig's avatar
drunkpig committed
3
import shutil
quyuan's avatar
add ci  
quyuan committed
4
5


quyuan's avatar
quyuan committed
6
def check_shell(cmd):
drunkpig's avatar
drunkpig committed
7
    """shell successful."""
quyuan's avatar
quyuan committed
8
    res = os.system(cmd)
quyuan's avatar
quyuan committed
9
10
    assert res == 0

drunkpig's avatar
drunkpig committed
11
12
13
14
15
16
17
18
19
20
21

def cli_count_folders_and_check_contents(file_path):
    """" count cli files."""
    if os.path.exists(file_path):
        for files in os.listdir(file_path):
            folder_count = os.path.getsize(os.path.join(file_path, files))
            assert folder_count > 0
    assert len(os.listdir(file_path)) > 5

def sdk_count_folders_and_check_contents(file_path):
    """count folders."""
quyuan's avatar
add ci  
quyuan committed
22
    if os.path.exists(file_path):
drunkpig's avatar
drunkpig committed
23
24
25
26
        file_count = os.path.getsize(file_path)
        assert file_count > 0
    else:
        exit(1)
quyuan's avatar
quyuan committed
27
28


drunkpig's avatar
drunkpig committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def delete_file(path):
    """delete file."""
    if not os.path.exists(path):
        if os.path.isfile(path):
            try:
                os.remove(path)
                print(f"File '{path}' deleted.")
            except TypeError as e:
                print(f"Error deleting file '{path}': {e}")
    elif os.path.isdir(path):
        try:
            shutil.rmtree(path)
            print(f"Directory '{path}' and its contents deleted.")
        except TypeError as e:
            print(f"Error deleting directory '{path}': {e}")