Ejemplo n.º 1
0
        def __fork_pkg_cmd(self, subcommand, pargs_json=None, opts_json=None):
                try:
                        args = ["/usr/share/lib/pkg/rad-invoke"]
                        # If not JSON formatted string, need conversion.
                        if pargs_json and not isinstance(pargs_json,
                            six.string_types):
                                pargs_json = json.dumps(pargs_json)
                        if opts_json and not isinstance(opts_json,
                            six.string_types):
                                opts_json = json.dumps(opts_json)
                        if self.__image_path:
                                args.extend(["-R", self.__image_path])
                        if pargs_json:
                                args.extend(["--pargs", pargs_json])
                        if opts_json:
                                args.extend(["--opts", opts_json])
                        args.extend(["--prog-delay",
                            str(self.__progress_interval)])

                        args.append(subcommand)

                        p = subprocess.Popen(args, env=os.environ,
                            stdout=subprocess.PIPE)
                        actualret = None
                        # Process output JSON lines.
                        while True:
                                out_line = p.stdout.readline()
                                if out_line == b'' and p.poll() is not None:
                                        break
                                if out_line:
                                        out_json = json.loads(out_line)
                                        # This indicates it is progress output.
                                        if "phase" in out_json:
                                                self._prog_event_handler(
                                                    out_json)
                                        # This indicates it is the actual
                                        # return.
                                        elif "status" in out_json:
                                                actualret = out_json
                        if not actualret:
                                return {"status": ERROR, "errors": [{"reason":
                                    "no result collected in fork mode."}]}
                        return actualret
                except Exception as ex:
                        return {"status": ERROR, "errors": [{"reason": str(ex)}
                            ]}
Ejemplo n.º 2
0
def _write_status_response(status, htdocs_path, repo_prefix):
        """Writes a status status/0 response for the depot."""
        try:
                status_path = os.path.join(htdocs_path, repo_prefix,
                    os.path.sep.join(DEPOT_STATUS_DIRNAME), "index.html")
                misc.makedirs(os.path.dirname(status_path))
                with open(status_path, "w") as status_file:
                        status_file.write(json.dumps(status, ensure_ascii=False,
                            indent=2, sort_keys=True))
        except OSError as err:
                raise DepotException(
                    _("Unable to write status response: {0}").format(err))
Ejemplo n.º 3
0
                                    ).format(opt, script_path))
        except getopt.GetoptError as e:
                return error(_("illegal global option -- {0} in file: {1}"
                    ).format(e.opt, script_path))
        except ValueError as e:
                return error(_("invalid option argument: {0} in file: {1}"
                    ).format(str(e), script_path))
        if len(pargs) < 1:
                return error(_("missing argument in file: {0}").format(
                    script_path))
        return entry.rad_pkg(pargs[0], pargs_json=pargs_json,
            opts_json=opts_json, pkg_image=pkg_image,
            prog_delay=prog_delay)

if __name__ == "__main__":
        misc.setlocale(locale.LC_ALL, "")
        gettext.install("pkg", "/usr/share/locale",
            codeset=locale.getpreferredencoding())
        __init_log()
        ret_json = main_func()
        ips_logger.info(json.dumps(ret_json))
        try:
                logging.shutdown()
        except IOError:
                # Ignore python's spurious pipe problems.
                pass
        sys.exit(ret_json["status"])

# Vim hints
# vim:ts=8:sw=8:et:fdm=marker