| #!/usr/bin/python3 |
| |
| import os |
| import subprocess |
| from argparse import ArgumentParser, RawTextHelpFormatter |
| |
| class bcolors: |
| HEADER = '\033[95m' |
| OKBLUE = '\033[94m' |
| OKGREEN = '\033[92m' |
| WARNING = '\033[93m' |
| FAIL = '\033[91m' |
| ENDC = '\033[0m' |
| BOLD = '\033[1m' |
| UNDERLINE = '\033[4m' |
| |
| def parse_arg(): |
| arg_parser = ArgumentParser(description = "compress img with MD, DSP", |
| formatter_class = RawTextHelpFormatter) |
| |
| arg_parser.add_argument("img_folder", help = "Folder of BACH image") |
| arg_parser.print_help() |
| print() |
| return arg_parser.parse_args() |
| |
| def check_req(keyword, content): |
| if not keyword in content: |
| print(bcolors.FAIL + keyword + " doesn't exist" + bcolors.ENDC) |
| print() |
| return 1 |
| return 0 |
| |
| def check_bundle(content): |
| checksum = 0 |
| checksum = checksum | check_req("modem.img", content) |
| checksum = checksum | check_req(".EDB", content) |
| checksum = checksum | check_req("dsp.bin", content) |
| assert checksum == 0, bcolors.FAIL + "\n Please add them into image folder\n You can copy them from BACH official release" + bcolors.ENDC + "\n" |
| |
| def tar_files(source): |
| cmd = "tar jcvf source.tar.bz2" + source |
| print(cmd) |
| subprocess.call(cmd, shell=True) |
| print(bcolors.OKGREEN + "compressed file is in " + os.getcwd() + bcolors.ENDC) |
| |
| if __name__ == '__main__': |
| console_args = parse_arg() |
| directory = "./" + console_args.img_folder |
| if not os.path.isdir(directory): |
| print(console_args.img_folder + " doesn't exist") |
| exit(1) |
| |
| compress_files = " " |
| for filename in os.listdir(directory): |
| if not os.path.isdir(directory + "/" + filename): |
| compress_files += filename + " " |
| |
| check_bundle(compress_files) |
| os.chdir(directory) |
| tar_files(compress_files) |
| # TODO: show final tar file location |
| |