• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Copyright (c) 2020 Huawei Device Co., Ltd.
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18import argparse
19import os
20import sys
21import shutil
22sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir))
23from utils import makedirs # noqa: E402
24
25
26def make_archive(source: str, destination: str):
27    base = os.path.basename(destination)
28    fields = base.split('.')
29    name = fields[0] + '.' + fields[1] + '.' + fields[2]
30    file_format = fields[3]
31    archive_from = os.path.dirname(source)
32    archive_to = os.path.basename(source.strip(os.sep))
33    print('Zipping: ', source, destination, archive_from, archive_to)
34    shutil.make_archive(name, file_format, archive_from, archive_to)
35    shutil.move('%s.%s' % (name, file_format), destination)
36
37
38def main():
39    parser = argparse.ArgumentParser(
40        description='NDK archive tool.')
41    parser.add_argument(
42        '--src_dir',
43        help='NDK source path.',
44        required=True)
45    parser.add_argument(
46        '--name',
47        help='NDK name.',
48        required=True)
49    parser.add_argument(
50        '--dest_dir',
51        help='NDK zip dest path.',
52        required=True)
53    args = parser.parse_args()
54
55    src = args.src_dir
56
57    if not os.path.exists(src):
58        raise Exception('NDK build directory not exist, please confirm NDK build result.')
59
60    dest = args.dest_dir
61    if not os.path.exists(dest):
62        makedirs(dest)
63    else:
64        shutil.rmtree(dest)
65
66    name = args.name
67    print(dest, name)
68    make_archive(src, dest + '-' + name + '.zip')
69    return 0
70
71
72if __name__ == '__main__':
73    sys.exit(main())
74