<commit_before>#! /usr/bin/env python
"""
   Copyright 2016 The Trustees of University of Arizona

   Licensed under the Apache License, Version 2.0 (the "License" );
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
"""

import os
import os.path
import hashlib
import backends as sdm_backends

from os.path import expanduser

MOUNT_TABLE_PATH = "~/.sdm/sdm_mtab"


class MountTableException(Exception):
    pass


class MountRecordStatus(object):
    UNMOUNTED = "UNMOUNTED"
    MOUNTED = "MOUNTED"


class MountRecord(object):
    """
    mount table record
    """
    def __init__(self, record_id="", dataset="", mount_path="", backend=sdm_backends.Backends.FUSE, status=MountRecordStatus.UNMOUNTED):
        self.dataset = dataset.strip().lower()
        self.mount_path = os.path.abspath(expanduser(mount_path.strip()))

        if record_id:
            self.record_id = record_id.strip().lower()
        else:
            self.record_id = self._make_record_id(self.dataset, mount_path)

        self.backend = backend

        if status.strip().upper() == MountRecordStatus.MOUNTED:
            self.status = MountRecordStatus.MOUNTED
        else:
            self.status = MountRecordStatus.UNMOUNTED

    def _make_record_id(self, dataset, mount_path):
        seed = "seed123%sMountRecord%s" % (dataset, mount_path)
        return hashlib.sha256(seed).hexdigest().lower()

    @classmethod
    def from_line(cls, line):
        fields = line.strip().split("\t")
        if len(fields) == 5:
            record_id = fields[0].strip()
            dataset = fields[1].strip()
            mount_path = fields[2].strip()
            backend = sdm_backends.Backends.from_str(fields[3].strip())
            status = fields[4].strip()
            return MountRecord(record_id, dataset, mount_path, backend, status)
        else:
            raise MountTableException("unrecognized format - %s" % line)

    def to_line(self):<commit_msg>Generate mount id using dataset/mount_path/backend<commit_after>#! /usr/bin/env python
"""
   Copyright 2016 The Trustees of University of Arizona

   Licensed under the Apache License, Version 2.0 (the "License" );
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
"""

import os
import os.path
import hashlib
import backends as sdm_backends

from os.path import expanduser

MOUNT_TABLE_PATH = "~/.sdm/sdm_mtab"


class MountTableException(Exception):
    pass


class MountRecordStatus(object):
    UNMOUNTED = "UNMOUNTED"
    MOUNTED = "MOUNTED"


class MountRecord(object):
    """
    mount table record
    """
    def __init__(self, record_id="", dataset="", mount_path="", backend=sdm_backends.Backends.FUSE, status=MountRecordStatus.UNMOUNTED):
        self.dataset = dataset.strip().lower()
        self.mount_path = os.path.abspath(expanduser(mount_path.strip()))

        if record_id:
            self.record_id = record_id.strip().lower()
        else:
            self.record_id = self._make_record_id(self.dataset, mount_path, backend)

        self.backend = backend

        if status.strip().upper() == MountRecordStatus.MOUNTED:
            self.status = MountRecordStatus.MOUNTED
        else:
            self.status = MountRecordStatus.UNMOUNTED

    def _make_record_id(self, dataset, mount_path, backend):
        seed = "seed123%sMountRecord%sBackend%s" % (dataset, mount_path, backend)
        return hashlib.sha256(seed).hexdigest().lower()

    @classmethod
    def from_line(cls, line):
        fields = line.strip().split("\t")
        if len(fields) == 5:
            record_id = fields[0].strip()
            dataset = fields[1].strip()
            mount_path = fields[2].strip()
            backend = sdm_backends.Backends.from_str(fields[3].strip())
            status = fields[4].strip()
            return MountRecord(record_id, dataset, mount_path, backend, status)
        else:
            raise MountTableException("unrecognized format - %s" % line)

    def to_line(self):
{'fraction_non_alphanumeric': 0.10035247771096828, 'fraction_numerical': 0.008293593199253577, 'mean_word_length': 2.993377483443709, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3912583', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1372, 'n_words': 388}