Example #1
0
    def prompt_begin(self, interface):
        directory = posixpath.dirname(self.filename)
        safe_make_directory(directory)

        # Try to lock the process
        self._lock = GlobalLock(self.filename, logger=self.logger)
        try:
            self._lock.acquire()
        except LockAlreadyAcquired:
            if time() - os.stat(self.filename).st_atime > self.timeout:
                self._manager.reactor.fire(
                    "prompt-error", interface, _("There is another checkbox running. Please close it first.")
                )
            self._manager.reactor.stop_all()

        # Stop the process if the lock is deleted
        def handler(signum, frame):
            if not posixpath.exists(self.filename):
                self._manager.reactor.stop_all()

        signal.signal(signal.SIGIO, handler)
        self._fd = os.open(directory, os.O_RDONLY)

        fcntl.fcntl(self._fd, fcntl.F_SETSIG, 0)
        fcntl.fcntl(self._fd, fcntl.F_NOTIFY, fcntl.DN_DELETE | fcntl.DN_MULTISHOT)
Example #2
0
    def report(self):
        # Prepare the payload and attach it to the form
        stylesheet_path = os.path.join(os.path.dirname(self.filename), os.path.basename(self.stylesheet))
        report_manager = LaunchpadReportManager("system", "1.0", stylesheet_path, self.schema)
        payload = report_manager.dumps(self._report).toprettyxml("")

        # Write the report
        stylesheet_data = open(self.stylesheet).read() % os.environ
        open(stylesheet_path, "w").write(stylesheet_data)
        directory = os.path.dirname(self.filename)
        safe_make_directory(directory)
        open(self.filename, "w").write(payload)

        # Validate the report
        if not report_manager.validate(payload):
            self._manager.reactor.fire(
                "report-error",
                _(
                    """\
The generated report seems to have validation errors,
so it might not be processed by Launchpad."""
                ),
            )

        self._manager.reactor.fire("launchpad-report", self.filename)
    def prompt_begin(self, interface):
        directory = posixpath.dirname(self.filename)
        safe_make_directory(directory)

        self._lock = GlobalLock(self.filename)
        try:
            self._lock.acquire()
        except LockAlreadyAcquired:
            self._manager.reactor.fire("prompt-error", interface,
                _("Another checkbox is running"),
                _("There is another checkbox running. Please close it first."))
            self._manager.reactor.stop_all()
Example #4
0
    def create_application(self, args=sys.argv):
        # Create data directory
        data_directory = get_variable("CHECKBOX_DATA", ".")
        safe_make_directory(data_directory)

        # Prepend environment options
        string_options = get_variable("CHECKBOX_OPTIONS", "")
        args[:0] = split(string_options)
        (options, args) = self.parse_options(args)

        # Replace shorthands
        for shorthand in "blacklist", "blacklist_file", "whitelist", "whitelist_file":
            key = ".*/jobs_info/%s" % shorthand
            value = getattr(options, shorthand)
            if value:
                options.config.append("=".join([key, value]))

        # Set logging early
        set_logging(options.log_level, options.log)

        # Config setup
        if len(args) != 2:
            sys.stderr.write(_("Missing configuration file as argument.\n"))
            sys.exit(1)

        config = Config()
        config_filename = posixpath.expanduser(args[1])
        config.read_filename(config_filename)
        config.read_configs(options.config)

        section_name = "checkbox/plugins/client_info"
        section = config.get_section(section_name)
        if not section:
            section = config.add_section(section_name)
        section.set("name", posixpath.basename(args[1]) \
            .replace(".ini", ""))
        section.set("version", config.get_defaults().version)

        # Check options
        if options.version:
            print(config.get_defaults().version)
            sys.exit(0)

        return self.application_factory(config)
Example #5
0
    def create_application(self, args=sys.argv):
        # Create data directory
        data_directory = get_variable("CHECKBOX_DATA", ".")
        safe_make_directory(data_directory)

        # Prepend environment options
        string_options = get_variable("CHECKBOX_OPTIONS", "")
        args[:0] = split(string_options)
        (options, args) = self.parse_options(args)

        # Replace shorthands
        for shorthand in "blacklist", "blacklist_file", "whitelist", "whitelist_file":
            key = ".*/jobs_info/%s" % shorthand
            value = getattr(options, shorthand)
            if value:
                options.config.append("=".join([key, value]))

        # Set logging early
        set_logging(options.log_level, options.log)

        # Config setup
        if len(args) != 2:
            sys.stderr.write(_("Missing configuration file as argument.\n"))
            sys.exit(1)

        config = Config()
        config_filename = posixpath.expanduser(args[1])
        config.read_filename(config_filename)
        config.read_configs(options.config)

        section_name = "checkbox/plugins/client_info"
        section = config.get_section(section_name)
        if not section:
            section = config.add_section(section_name)
        section.set("name", posixpath.basename(args[1]) \
            .replace(".ini", ""))
        section.set("version", config.get_defaults().version)

        # Check options
        if options.version:
            print(config.get_defaults().version)
            sys.exit(0)

        return self.application_factory(config)
    def report(self):
        # Copy stylesheet to report directory
        stylesheet = posixpath.join(
            posixpath.dirname(self.filename),
            posixpath.basename(self.stylesheet))
        shutil.copy(self.stylesheet, stylesheet)

        # Prepare the payload and attach it to the form
        stylesheet = posixpath.abspath(stylesheet)
        report_manager = LaunchpadReportManager("system", "1.0", stylesheet)
        payload = report_manager.dumps(self._report).toprettyxml("")

        directory = posixpath.dirname(self.filename)
        safe_make_directory(directory)

        file = open(self.filename, "w")
        file.write(payload)
        file.close()

        self._manager.reactor.fire("exchange-report", self.filename)
Example #7
0
    def report(self):
        # Prepare the payload and attach it to the form
        stylesheet_path = os.path.join(
            os.path.dirname(self.filename),
            os.path.basename(self.stylesheet))
        report_manager = LaunchpadReportManager(
            "system", "1.0", stylesheet_path, self.schema)
        payload = report_manager.dumps(self._report).toprettyxml("")

        # Write the report
        stylesheet_data = open(self.stylesheet).read() % os.environ
        open(stylesheet_path, "w").write(stylesheet_data)
        directory = os.path.dirname(self.filename)
        safe_make_directory(directory)
        open(self.filename, "w").write(payload)

        # Validate the report
        if not report_manager.validate(payload):
            self._manager.reactor.fire("report-error", _("""\
The generated report seems to have validation errors,
so it might not be processed by Launchpad."""))

        self._manager.reactor.fire("launchpad-report", self.filename)
Example #8
0
    def prompt_begin(self, interface):
        directory = posixpath.dirname(self.filename)
        safe_make_directory(directory)

        # Try to lock the process
        self._lock = GlobalLock(self.filename, logger=self.logger)
        try:
            self._lock.acquire()
        except LockAlreadyAcquired:
            if time() - os.stat(self.filename).st_atime > self.timeout:
                self._manager.reactor.fire("prompt-error", interface,
                    _("There is another checkbox running. Please close it first."))
            self._manager.reactor.stop_all()

        # Stop the process if the lock is deleted
        def handler(signum, frame):
            if not posixpath.exists(self.filename):
                self._manager.reactor.stop_all()
        
        signal.signal(signal.SIGIO, handler)
        self._fd = os.open(directory,  os.O_RDONLY)

        fcntl.fcntl(self._fd, fcntl.F_SETSIG, 0)
        fcntl.fcntl(self._fd, fcntl.F_NOTIFY, fcntl.DN_DELETE|fcntl.DN_MULTISHOT)