• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3
4"""
5Copyright (c) 2022 Huawei Device Co., Ltd.
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12Unless required by applicable law or agreed to in writing, software
13distributed under the License is distributed on an "AS IS" BASIS,
14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15See the License for the specific language governing permissions and
16limitations under the License.
17
18Description: Use ark to execute test 262 test suite
19"""
20
21import os
22import datetime
23import shutil
24import difflib
25from config import *
26import subprocess
27import json
28
29
30def command_os(order):
31    subprocess.run(order)
32
33
34def mk_dir(path):
35    if not os.path.exists(path):
36        os.makedirs(path)
37
38
39def remove_dir(path):
40    if os.path.exists(path):
41        shutil.rmtree(path)
42
43
44def remove_file(path):
45    if os.path.exists(path):
46        os.remove(path)
47
48
49def clean_file(path):
50    with open(path, "w") as utils_clean:
51        utils_clean.write("")
52
53
54def read_file(path):
55    util_read_content = []
56    with open(path, "r") as utils_read:
57        util_read_content = utils_read.readlines()
58
59    return util_read_content
60
61
62def write_file(path, write_content):
63    with open(path, "w") as utils_write:
64        utils_write.write(write_content)
65
66
67def write_append(path, add_content):
68    fd = os.open(path, os.O_APPEND|os.O_CREAT|os.O_WRONLY)
69    with os.fdopen(fd, 'a+') as utils_append:
70        utils_append.write(add_content)
71
72
73def move_file(srcfile, dstfile):
74    subprocess.getstatusoutput("mv %s %s" % (srcfile, dstfile))
75
76
77def current_time():
78    return datetime.datetime.now()
79
80
81def excuting_npm_install(args):
82    ark_frontend_tool = os.path.join(DEFAULT_ARK_FRONTEND_TOOL)
83    if args.ark_frontend_tool:
84        ark_frontend_tool = os.path.join(args.ark_frontend_tool)
85
86    ts2abc_build_dir = os.path.join(os.path.dirname(os.path.realpath(ark_frontend_tool)), "..")
87    if os.path.exists(os.path.join(ts2abc_build_dir, "package.json")):
88        npm_install(ts2abc_build_dir)
89    elif os.path.exists(os.path.join(ts2abc_build_dir, "..", "package.json")):
90        npm_install(os.path.join(ts2abc_build_dir, ".."))
91
92
93def npm_install(cwd):
94    try:
95        os.chdir(cwd)
96        command_os(["npm", "install"])
97        os.chdir(WORK_PATH)
98    except BaseException as e:
99        print(e)
100