コード例 #1
0
ファイル: test_build.py プロジェクト: KhanhKhoa/digital_scale
def main(args):
    if os.path.exists(args.custom_h):
        raise SystemExit(
            clr(
                Color.YELLOW,
                "{} already exists, please run this script in a git-worktree(1) or a separate directory"
                .format(args.custom_h),
            ))

    configurations = []
    if not args.no_default:
        configurations = list(glob.glob(args.default_configurations))

    configurations.extend(x for x in (args.add or []))
    if not configurations:
        raise SystemExit(clr(Color.YELLOW, "No configurations selected"))

    if len(configurations) > 1:
        atexit.register(print_total_time)

    print(clr(Color.BOLD, "> Selected configurations:"))
    for cfg in configurations:
        print(cfg)
    if args.list:
        return

    if not args.environment:
        raise SystemExit(clr(Color.YELLOW, "No environment selected"))
    print(
        clr(Color.BOLD, "> Selected environment: {}".format(args.environment)))

    atexit.register(try_remove, args.custom_h)

    run_configurations(args, configurations)
コード例 #2
0
ファイル: test_build.py プロジェクト: KhanhKhoa/digital_scale
def print_total_time():
    print()
    print(
        clr(
            Color.BOLD,
            "> Total time: {}".format(datetime.timedelta(seconds=total_time)),
        ))
コード例 #3
0
ファイル: test_build.py プロジェクト: KhanhKhoa/digital_scale
def run_configurations(args, configurations):
    cmd = ["platformio", "run"]
    if not args.no_silent:
        cmd.extend(["-s"])
    cmd.extend(["-e", args.environment])

    for cfg in configurations:
        print(clr(Color.BOLD, "> Building {}".format(cfg)))
        with open(args.custom_h, "w") as custom_h:

            def write(line):
                sys.stdout.write(line)
                custom_h.write(line)

            name, _ = os.path.splitext(cfg)
            name = os.path.basename(name)
            write('#define MANUFACTURER "TEST_BUILD"\n')
            write('#define DEVICE "{}"\n'.format(name.upper()))
            with open(cfg, "r") as cfg_file:
                for line in cfg_file:
                    write(line)

        os_env = os.environ.copy()
        os_env["PLATFORMIO_SRC_BUILD_FLAGS"] = "-DUSE_CUSTOM_H"
        os_env["PLATFORMIO_BUILD_CACHE_DIR"] = "test/pio_cache"
        if not args.no_single_source:
            os_env["ESPURNA_BUILD_SINGLE_SOURCE"] = "1"

        start = time.time()
        subprocess.check_call(cmd, env=os_env)
        diff = time.time() - start

        global total_time
        total_time += diff

        print(
            clr(
                Color.BOLD,
                "> {}: {} bytes, {}".format(
                    cfg,
                    os.stat(
                        os.path.join(".pio", "build", args.environment,
                                     "firmware.bin")).st_size,
                    datetime.timedelta(seconds=diff),
                ),
            ))
コード例 #4
0
def main(args):
    configurations = []
    if not args.no_default:
        configurations = list(glob.glob(args.default_configurations))

    configurations.extend(x for x in (args.add or []))
    if not configurations:
        raise SystemExit(clr(Color.YELLOW, "No configurations selected"))

    print(clr(Color.BOLD, "> Selected configurations:"))
    for cfg in configurations:
        print(cfg)
    if args.list:
        return

    if not args.environment:
        raise SystemExit(clr(Color.YELLOW, "No environment selected"))
    print(
        clr(Color.BOLD, "> Selected environment: {}".format(args.environment)))

    for cfg in configurations:
        print(clr(Color.BOLD, "> Building {}".format(cfg)))
        with open(CUSTOM_HEADER, "w") as custom_h:

            def write(line):
                sys.stdout.write(line)
                custom_h.write(line)

            name, _ = os.path.splitext(cfg)
            name = os.path.basename(name)
            write('#define MANUFACTURER "TEST_BUILD"\n')
            write('#define DEVICE "{}"\n'.format(name.upper()))
            with open(cfg, "r") as cfg_file:
                for line in cfg_file:
                    write(line)

        os_env = os.environ.copy()
        os_env["PLATFORMIO_SRC_BUILD_FLAGS"] = "-DUSE_CUSTOM_H"
        os_env["PLATFORMIO_BUILD_CACHE_DIR"] = "test/pio_cache"
        cmd = ["platformio", "run", "-s", "-e", args.environment]

        start = time.time()
        subprocess.check_call(cmd, env=os_env)
        end = time.time()
        print(
            clr(
                Color.BOLD,
                "> {}: {} bytes, {}".format(
                    cfg,
                    os.stat(
                        os.path.join(".pio", "build", args.environment,
                                     "firmware.bin")).st_size,
                    datetime.timedelta(seconds=(end - start)),
                ),
            ))
コード例 #5
0
import time
import glob
import argparse
import atexit
import subprocess
import os
import sys
import datetime
from espurna_utils.display import Color, clr, print_warning

CUSTOM_HEADER = "espurna/config/custom.h"
if os.path.exists(CUSTOM_HEADER):
    raise SystemExit(
        clr(
            Color.YELLOW,
            "{} already exists, please run this script in a git-worktree(1) or a separate directory"
            .format(CUSTOM_HEADER),
        ))


def try_remove(path):
    try:
        os.remove(path)
    except:  # pylint: disable=bare-except
        print_warning("Please manually remove the file `{}`".format(path))


atexit.register(try_remove, CUSTOM_HEADER)


def main(args):