<commit_before># -*- coding: utf-8 -*-
# Akvo RSR is covered by the GNU Affero General Public License.
# See more details in the license.txt file located at the root folder of the Akvo RSR module.
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.


import fabric.api
import fabric.contrib.files as files
import fabric.utils

import fab.helpers.permissions


class PathsHelper():

    def __init__(self, permissions_helper):
        self.permissions = permissions_helper

    def ensure_path_exists_with_akvo_group_permissions(self, path):
        if not files.exists(path):
            self._ensure_path_exists_with(path, fabric.api.sudo)
            self.permissions.set_akvo_group_permissions_on_path(path)
        else:
            print ">> Found expected path: %s" % path

    def ensure_path_exists(self, path):
        self._ensure_path_exists_with(path, fabric.api.run)

    def ensure_path_exists_with_sudo(self, path):
        self._ensure_path_exists_with(path, fabric.api.sudo)

    def _ensure_path_exists_with(self, path, run_command):
        if not files.exists(path):
            print ">> Creating path: %s" % path
            run_command("mkdir %s" % path)
            run_command("chmod 775 %s" % path)
        else:
            print ">> Found expected path: %s" % path

    def exit_if_path_does_not_exist(self, path):
        if not files.exists(path):
            fabric.utils.abort("\n>> Expected path does not exist: %s" % path)

    def path_without_trailing_separator(self, path):
        return path.strip("/")<commit_msg>[#6699037] Removed unnecessary PathsHelper.path_without_trailing_separator() method -- use inline path.strip("/") instead.<commit_after># -*- coding: utf-8 -*-
# Akvo RSR is covered by the GNU Affero General Public License.
# See more details in the license.txt file located at the root folder of the Akvo RSR module.
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.


import fabric.api
import fabric.contrib.files as files
import fabric.utils

import fab.helpers.permissions


class PathsHelper():

    def __init__(self, permissions_helper):
        self.permissions = permissions_helper

    def ensure_path_exists_with_akvo_group_permissions(self, path):
        if not files.exists(path):
            self._ensure_path_exists_with(path, fabric.api.sudo)
            self.permissions.set_akvo_group_permissions_on_path(path)
        else:
            print ">> Found expected path: %s" % path

    def ensure_path_exists(self, path):
        self._ensure_path_exists_with(path, fabric.api.run)

    def ensure_path_exists_with_sudo(self, path):
        self._ensure_path_exists_with(path, fabric.api.sudo)

    def _ensure_path_exists_with(self, path, run_command):
        if not files.exists(path):
            print ">> Creating path: %s" % path
            run_command("mkdir %s" % path)
            run_command("chmod 775 %s" % path)
        else:
            print ">> Found expected path: %s" % path

    def exit_if_path_does_not_exist(self, path):
        if not files.exists(path):
            fabric.utils.abort("\n>> Expected path does not exist: %s" % path)
{'fraction_non_alphanumeric': 0.0983860955927995, 'fraction_numerical': 0.004655493482309125, 'mean_word_length': 3.100508905852417, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1444588', 'n_tokens_mistral': 991, 'n_tokens_neox': 956, 'n_words': 260}