Example #1
0
    def run(self):
        if self.command in ('update', 'uninstall'):
            path_binary_file = PosixPath(binaries_dir, binary_file)
            path_systemd_file = PosixPath(systemd_dir, systemd_file)

            # Uninstalling Onion
            call(['systemctl', 'stop', 'onion'], stdout=DEVNULL, stderr=STDOUT)
            call(['systemctl', 'disable', 'onion'],
                 stdout=DEVNULL,
                 stderr=STDOUT)
            path_binary_file.unlink()
            path_systemd_file.unlink()

        if self.command in ('install', 'update'):
            path_setup_dir = PosixPath(SETUP_EXTRACT_DIR)

            # Installing Onion
            vcopy(path_setup_dir / 'bin', binaries_dir)
            vcopy(path_setup_dir / 'config', config_dir)
            vcopy(path_setup_dir / 'systemd', systemd_dir)

            call(['systemctl', 'daemon-reload'], stdout=DEVNULL, stderr=STDOUT)
            call(['systemctl', 'enable', 'onion'],
                 stdout=DEVNULL,
                 stderr=STDOUT)

        elif self.command == 'uninstall':
            # Deleting the user configuration
            rmtree(config_dir)
            call(['systemctl', 'daemon-reload'], stdout=DEVNULL, stderr=STDOUT)
Example #2
0
    def convert(self,
                destination_file: PosixPath,
                subset_numbered_keys: Optional[str] = None):

        ktx_dict = self.getter.get_dict()
        destination_file = Path(destination_file)

        getter_tag = self.getter.get_getter_tag()
        format_tag = self.get_format_tag()

        # - Initialise file
        md_file = mdutils.MdUtils(file_name=str(destination_file))

        # - Write header if any:
        for hdr_key in self.getter.get_headers_keys():
            prefix, suffix, add_key = keys_to_decorations(
                getter_tag, format_tag, hdr_key)
            if add_key:
                prefix += f"{hdr_key}. "
            md_file.write(prefix + ktx_dict[hdr_key] + suffix)

        # - Write numbered keys if any:
        n_keys = self.getter.get_quantity_numbered_keys()
        numbered_keys = self.getter.get_numbered_keys()

        if isinstance(numbered_keys, dict):
            numbered_keys = numbered_keys[subset_numbered_keys]

        num_numbered_keys_found = 0
        for n in range(n_keys[0], n_keys[1] + 1):
            for key in numbered_keys:
                prefix, suffix, add_key = keys_to_decorations(
                    getter_tag, format_tag, key)
                nmb_key = f"{key}{n}"
                if add_key:
                    prefix += f"{n}. "
                if nmb_key in ktx_dict.keys():
                    num_numbered_keys_found += 1
                    md_file.write(prefix + ktx_dict[nmb_key] + suffix)

        # Delete file if one with the same name is found
        if destination_file.exists():
            destination_file.unlink()

        # Write sequence to file
        md_file.create_md_file()

        print(
            f"File {destination_file} created with {num_numbered_keys_found} numbered keys."
        )
Example #3
0
    def _clean_up_old_log_file(self, file: PosixPath):
        '''
        Triggers an action on expired log file
        depending on the value specified by self.log_cleanup_action
        '''
        action = self.log_cleanup_action
        assert LogFileCleanupAction(action)

        if action == LogFileCleanupAction.REMOVE:
            file.unlink()
            msg = 'Log file has been removed'
        elif action == LogFileCleanupAction.HIDE:
            new_name = file.parent / ('.' + file.name)
            file.rename(new_name)
            msg = 'Log file {} is now hidden'.format(file)
        elif action == LogFileCleanupAction.RENAME:
            new_file = file.parent / ('old_' + file.name)
            file.rename(new_file)
            file = new_file
            msg = 'Log file has been renamed'

        log.info(msg)
Example #4
0
    #    Remote gateway: DOWN
    if server_status and not gateway_status:
        gateway_warning += 1
        # The 'gateway_warning' variable avoids false positives if the
        # OnionRing threads are out of sync
        if gateway_warning > 2:
            log('CRITICAL', 'Onion is suspended and waits for the gateway reply')
            sleep(2.5)
    else:
        gateway_warning = 0

    sleep(0.5)

# STOPPING ONION
log('INFO', 'Onion is shutting down...')

# Waiting for the OnionRing threads to stop
server.join()
gateway.join()

# Setting the Onion mode to passive
if latest_scenario != 2:
    set_scenario('passive')
    sleep(1)

# Deleting the Onion PID file
PID_FILE.unlink()

log('INFO', 'Onion shutdown completed')
exit(0)
Example #5
0
    def convert(self,
                destination_file: PosixPath,
                subset_numbered_keys: Optional[str] = None):

        ktx_dict = self.getter.get_dict()
        destination_file = Path(destination_file)

        getter_tag = self.getter.get_getter_tag()
        format_tag = self.get_format_tag()

        # Create cells sequence
        nb = nbf.v4.new_notebook()
        nb["cells"] = []

        # - Write header if any:
        for hdr_key in self.getter.get_headers_keys():
            prefix, suffix, add_key = keys_to_decorations(
                getter_tag, format_tag, hdr_key)
            if add_key:
                prefix += f"{hdr_key}. "
            nb["cells"].append(
                nbf.v4.new_markdown_cell(prefix + ktx_dict[hdr_key] + suffix))

        # - Write initializer - for interactive formats
        nb["cells"].append(nbf.v4.new_code_cell(self.getter.get_initializer()))

        # - Write numbered keys if any:
        n_keys = self.getter.get_quantity_numbered_keys()
        numbered_keys = self.getter.get_numbered_keys()

        if isinstance(numbered_keys, dict):
            if subset_numbered_keys is None:
                raise ValueError(
                    "Please specify a key for the provided dictionary of keyed text"
                )
            numbered_keys = numbered_keys[subset_numbered_keys]

        num_numbered_keys_found = 0
        for n in range(n_keys[0], n_keys[1] + 1):
            for key in numbered_keys:
                prefix, suffix, add_key = keys_to_decorations(
                    getter_tag, format_tag, key)
                nmb_key = f"{key}{n}"
                if add_key:
                    prefix += f"{n}. "
                if nmb_key in ktx_dict.keys():
                    num_numbered_keys_found += 1
                    nb["cells"].append(
                        nbf.v4.new_markdown_cell(prefix + ktx_dict[nmb_key] +
                                                 suffix))
                    nb["cells"].append(nbf.v4.new_code_cell(""))

        # - Delete file if one with the same name is found
        if destination_file.exists():
            destination_file.unlink()

        # - Save result to file
        nbf.write(nb, str(destination_file))
        print(
            f"File {destination_file} created with {num_numbered_keys_found} numbered keys."
        )