def __call__(self, parser, namespace, values, option_string=None): try: sh.dpkg_architecture("-a", values, _tty_out=False) except sh.ErrorReturnCode: raise argparse.ArgumentError(self, "Architecture {} is a not valid DPKG one.".format(values)) setattr(namespace, self.dest, values)
def get_machinekit_hal_changelog_data(self: object) -> None: control_template_file = "{}/debian/control.in".format( self.normalized_path) with open(control_template_file, "r") as reader: control_template_string = reader.read() self.name = re.search( "Source: (.+)\n", control_template_string).group(1).strip().lower() version_file = "{}/VERSION".format(self.normalized_path) with open(version_file, "r") as reader: version_string = reader.read() base_version = version_string.strip().split('.') self.major_version = base_version[0] self.minor_version = base_version[1] self.distro_id = sh.lsb_release("-is", _tty_out=False).strip().replace( " ", "").lower() self.distro_codename = sh.lsb_release("-cs", _tty_out=False).strip().replace( " ", "").lower() self.git_sha = sh.git("rev-parse", "HEAD", _tty_out=False, _cwd=self.normalized_path).strip() self.commit_count = int( sh.git("rev-list", "--count", "HEAD", _tty_out=False, _cwd=self.normalized_path).strip()) self.commiter_name = sh.git("show", "-s", "--pretty=%cn", "HEAD", _tty_out=False, _cwd=self.normalized_path).rstrip('\n') self.commiter_email = sh.git("show", "-s", "--format=%ce", "HEAD", _tty_out=False, _cwd=self.normalized_path).strip() self.commit_message_short = sh.git("show", "-s", "--format=format:%s", "HEAD", _tty_out=False, _cwd=self.normalized_path).strip() self.commit_time = sh.git("show", "-s", "--format=format:%aD", "HEAD", _tty_out=False, _cwd=self.normalized_path).strip() self.debian_host_architecture = sh.dpkg_architecture( "-qDEB_HOST_ARCH", _tty_out=False).strip() self.debian_build_architecture = sh.dpkg_architecture( "-qDEB_BUILD_ARCH", _tty_out=False).strip()
def cli(cls): parser = argparse.ArgumentParser( description="Run commands in a builder container", epilog="""Args to the 'docker run' command my be supplied before VERSION; in this case, add '--' after ARCHITECTURE; e.g. "rundocker.py --interactive --env=FOO=BAR --user=1000:1000 20.04 arm64 -- bash -c 'echo $FOO'" """, ) # Optional arguments parser.add_argument("-p", "--path", action=helpers.PathExistsAction, default=os.getcwd(), help="Path to root of git repository") parser.add_argument("--notty", action="store_true", help="Do NOT set 'docker run -tty' arg") parser.add_argument("--env", action="append", help="Pass or set environment variable in container; see docker-run(1)", ) parser.add_argument("--volume", action="append", help="Bind-mount directory in container; see docker-run(1)", ) # Positional arguments parser.add_argument("version", metavar="VERSION", help="OS version number or codename") parser.add_argument("architecture", action=helpers.HostArchitectureValidAction, default=sh.dpkg_architecture( "-qDEB_HOST_ARCH", _tty_out=False).strip(), metavar="ARCHITECTURE", help="Debian architecture") parser.add_argument("command", metavar="COMMAND", nargs=argparse.REMAINDER, help="Command to run in container") args, docker_args = parser.parse_known_args() args_dict = args.__dict__ path = args_dict.pop('path') env = args_dict.pop('env') volume = args_dict.pop('volume') notty = args_dict.pop('notty') version = args_dict.pop('version') architecture = args_dict.pop('architecture') cmd = args_dict.pop('command') rd = cls(path=path, version=version, architecture=architecture, notty=notty, env=env, volume=volume, docker_args=docker_args) try: rd.run_cmd(cmd) except ValueError as e: sys.stderr.write("Error: Command exited non-zero: {}\n".format(str(e)))
description="Build packages for Debian like distributions") # Optional argument for path to Machinekit-HAL repository parser.add_argument("-p", "--path", action=helpers.PathExistsAction, dest="path", default=os.getcwd(), help="Path to root of Machinekit-HAL repository") # Optional argument for Debian host architecture parser.add_argument("-a", "--host-architecture", dest="host_architecture", action=HostArchitectureValidAction, default=sh.dpkg_architecture( "-qDEB_HOST_ARCH", _tty_out=False).strip(), metavar="ARCHITECTURE", help="Build packages for specific architecture") # Optional argument for many jobs to start parser.add_argument("-j", "--jobs", dest="jobs", action="store", type=int, metavar="PROCESSES", default=sh.nproc(_tty_out=False).strip(), help="Number of processes started at given time by the underlying buildsystem.") args = parser.parse_args()
def cli(cls): """ This is executed when run from the command line """ parser = argparse.ArgumentParser( description="Build packages for Debian like distributions") # Default architecture default_architecture = os.environ.get( "ARCHITECTURE", sh.dpkg_architecture("-qDEB_HOST_ARCH", _tty_out=False).strip()) # Optional arguments parser.add_argument("-p", "--path", action=helpers.PathExistsAction, dest="path", default=os.getcwd(), help="Path to root of git repository") parser.add_argument("-a", "--architecture", dest="architecture", action=helpers.HostArchitectureValidAction, default=default_architecture, metavar="ARCHITECTURE", help="Build packages for specific architecture") parser.add_argument( "--configure-source", action='store_true', help="Run configureSourceCmd to prepare source tree") parser.add_argument("--build-packages", action='store_true', help="Build packages") parser.add_argument( "--import-gpg-from-secret-env-var", help="Import a GPG secret key from the given environment variable") parser.add_argument( "--print-gpg-keyid-from-secret-env-var", help="Print GPG secret key ID from the given environment variable") parser.add_argument("--sign-packages", action='store_true', help="Sign packages") parser.add_argument("--list-packages", action='store_true', help="Print list of package files") parser.add_argument("--with-buildinfo", action='store_true', help="With --list-packages, print .buildinfo file") parser.add_argument("--with-changes", action='store_true', help="With --list-packages, print .changes file") args = parser.parse_args() try: buildpackages = cls(args.path, args.architecture) if args.configure_source: buildpackages.configure_source() if args.build_packages: buildpackages.build_packages() if args.import_gpg_from_secret_env_var: buildpackages.import_gpg_from_secret_env_var( args.import_gpg_from_secret_env_var) if args.print_gpg_keyid_from_secret_env_var: buildpackages.print_gpg_keyid_from_secret_env_var( args.print_gpg_keyid_from_secret_env_var) if args.sign_packages: buildpackages.sign_packages() if args.list_packages: buildpackages.list_packages(args.with_buildinfo, args.with_changes) except ValueError as e: sys.stderr.write("Error: Command exited non-zero: {}\n".format( str(e))) sys.exit(1)