<commit_before>import os.path
import subprocess
from velstor.restapi import namespace
from velstor.pcapi.exceptions import RESTException


class Volume:
    def __init__(self, session, mount_point, workspace):
        self._session = session
        self._mount_point = os.path.abspath(mount_point)
        self._workspace = workspace

    def mount(self, **kwargs):
        if self._workspace.pathname is None:
            raise ValueError('Workspace has no pathname')
        hard = kwargs['hard'] if 'hard' in kwargs else False
        #
        #  Create the vtrq_path if it doesn't already exist
        #
        try:
            namespace.mkdir(
                self._session,
                self.workspace.vtrq_id,
                0o777,
                True,  # Create parents
                self.mount_point
            )
        except RESTException as e:
            #  We don't care if it already exists
            if hard and e.error_sym != 'EEXIST':
                raise e
        #
        #  Ensure the workspace is on the vtrq
        #
        self.workspace.set(hard=hard)
        #
        #  Run the VP in a sub-shell.  We'll let it daemonize itself.
        #  There's no need to remember process ids, fusermount will bring
        #  it down with just the mount point.
        #
        cmd = [
            'vp',
            '--mount={}'.format(self.mount_point),
            '--mentor={}'.format('cnc,7110,tcp4'),  # Mastiff vpm, hardwired for now.
            '--workspace={}'.format(self.workspace.pathname)
        ]
        if self.workspace.is_private:
            cmd = cmd + ['--fuse-cache=none', '--timeout=0']
        subprocess.check_output(cmd)

    def unmount(self):
        subprocess.check_output(['fusermount', '-uz', self.mount_point])

    @property
    def mount_point(self):
        return self._mount_point

    @property
    def workspace(self):
        return self._workspace<commit_msg>api-python: apply the proper FUSE options to the VP call per Dima's email 5 July 2017<commit_after>import os.path
import subprocess
from velstor.restapi import namespace
from velstor.pcapi.exceptions import RESTException


class Volume:
    def __init__(self, session, mount_point, workspace):
        self._session = session
        self._mount_point = os.path.abspath(mount_point)
        self._workspace = workspace

    def mount(self, **kwargs):
        if self._workspace.pathname is None:
            raise ValueError('Workspace has no pathname')
        hard = kwargs['hard'] if 'hard' in kwargs else False
        #
        #  Create the vtrq_path if it doesn't already exist
        #
        try:
            namespace.mkdir(
                self._session,
                self.workspace.vtrq_id,
                0o777,
                True,  # Create parents
                self.mount_point
            )
        except RESTException as e:
            #  We don't care if it already exists
            if hard and e.error_sym != 'EEXIST':
                raise e
        #
        #  Ensure the workspace is on the vtrq
        #
        self.workspace.set(hard=hard)
        #
        #  Run the VP in a sub-shell.  We'll let it daemonize itself.
        #  There's no need to remember process ids, fusermount will bring
        #  it down with just the mount point.
        #
        cmd = [
            'vp',
            '--mount={}'.format(self.mount_point),
            '--mentor={}'.format('cnc,7110,tcp4'),  # Mastiff vpm, hardwired for now.
            '--workspace={}'.format(self.workspace.pathname)
        ]
        if self.workspace.is_private:
            cmd = cmd + ['--fuse-cache=auto', '--timeout=1']
        else:
            cmd = cmd + ['--fuse-cache=none', '--timeout=0']
        subprocess.check_output(cmd)

    def unmount(self):
        subprocess.check_output(['fusermount', '-uz', self.mount_point])

    @property
    def mount_point(self):
        return self._mount_point

    @property
    def workspace(self):
        return self._workspace
{'fraction_non_alphanumeric': 0.09739130434782609, 'fraction_numerical': 0.006459627329192546, 'mean_word_length': 1.825263157894737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1666863', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1158, 'n_words': 315}