<commit_before>""" Local filesystem adaptor implementation """

import os
import pprint
import shutil
import traceback
import stat
import errno

import saga.url
import saga.adaptors.base
import saga.adaptors.cpi.filesystem
import saga.utils.misc
import saga.utils.pty_shell as sups

from saga.adaptors.cpi.decorators import SYNC_CALL


###############################################################################
# adaptor info
#

_ADAPTOR_NAME          = 'saga.adaptor.srm_file'
_ADAPTOR_SCHEMAS       = ['srm']
_ADAPTOR_OPTIONS       = []
_ADAPTOR_CAPABILITIES  = {}

_ADAPTOR_DOC           = {
    'name'             : _ADAPTOR_NAME,
    'cfg_options'      : _ADAPTOR_OPTIONS, 
    'capabilities'     : _ADAPTOR_CAPABILITIES,
    'description'      : 'The SRM filesystem adaptor.',
    'details'          : """This adaptor interacts with SRM Storage Elements
                         """,
    'schemas'          : {'srm': 'srm filesystem.'}
    
}

_ADAPTOR_INFO          = {
    'name'             : _ADAPTOR_NAME,
    'version'          : 'v0.2',
    'schemas'          : _ADAPTOR_SCHEMAS,
    'cpis'             : [
        {
        'type'         : 'saga.namespace.Directory',
        'class'        : 'SRMDirectory'
        },
        {
        'type'         : 'saga.namespace.Entry',
        'class'        : 'SRMFile'
        },
        {
        'type'         : 'saga.filesystem.Directory',
        'class'        : 'SRMDirectory'
        }, 
        {
        'type'         : 'saga.filesystem.File',
        'class'        : 'SRMFile'
        }
    ]
}

CONNTIMEOUT = 180
SNDTIMEOUT = 7200
SRMTIMEOUT = 180

###############################################################################
# The adaptor class

class Adaptor(saga.adaptors.base.Base):
    """
    This is the actual adaptor class, which gets loaded by SAGA (i.e. by the
    SAGA engine), and which registers the CPI implementation classes which
    provide the adaptor's functionality.
    """

    def __init__(self) :
        saga.adaptors.base.Base.__init__(self, _ADAPTOR_INFO, _ADAPTOR_OPTIONS)

        self.cfg = self.get_config('saga.adaptor.srm_file')
        if 'pty_url' in self.cfg:
            self.pty_url = self.cfg['pty_url'].get_value()
        else:
            self.pty_url = 'fork://localhost/'


    def sanity_check(self):
        pass


    def file_get_size(self, shell, url):

        # In case of SURL the fields are:
        # file mode, number of links to the file, user id, group id, file size(bytes), locality, file name.
        # srm://srm.hep.fiu.edu:8443/srm/v2/server?SFN=/mnt/hadoop/osg/marksant/TESTFILE")
        # -rwxr-xr-x   1     1     2      19               ONLINE /mnt/hadoop/osg/marksant/TESTFILE
        try:
            # 'lcg-ls' uses the wrong timeout setting for connection timeout
            rc, out, _ = shell.run_sync("lcg-ls --sendreceive-timeout %d -l -b -D srmv2 %s" % (CONNTIMEOUT, url))
        except:
            shell.finalize(kill_pty=True)
            raise Exception("get_size failed")

        if rc != 0:
            if 'SRM_INVALID_PATH' in out:
                raise saga.exceptions.DoesNotExist(url)
            else:
                raise Exception("Couldn't list file")
<commit_msg>Use the adaptors options mechanism.<commit_after>""" Local filesystem adaptor implementation """

import os
import pprint
import shutil
import traceback
import stat
import errno

import saga.url
import saga.adaptors.base
import saga.adaptors.cpi.filesystem
import saga.utils.misc
import saga.utils.pty_shell as sups

from saga.adaptors.cpi.decorators import SYNC_CALL


###############################################################################
# adaptor info
#

_ADAPTOR_NAME          = 'saga.adaptor.srm_file'
_ADAPTOR_SCHEMAS       = ['srm']
_ADAPTOR_OPTIONS       = [
    {
        'category': 'saga.adaptor.srm_file',
        'name': 'pty_url',
        'type': str,
        'default': 'fork://localhost/',
        'documentation': '''The local or remote url the adaptor connects to.''',
        'env_variable': None
    }
]
_ADAPTOR_CAPABILITIES  = {}

_ADAPTOR_DOC           = {
    'name'             : _ADAPTOR_NAME,
    'cfg_options'      : _ADAPTOR_OPTIONS, 
    'capabilities'     : _ADAPTOR_CAPABILITIES,
    'description'      : 'The SRM filesystem adaptor.',
    'details'          : """This adaptor interacts with SRM Storage Elements
                         """,
    'schemas'          : {'srm': 'srm filesystem.'}
    
}

_ADAPTOR_INFO          = {
    'name'             : _ADAPTOR_NAME,
    'version'          : 'v0.2',
    'schemas'          : _ADAPTOR_SCHEMAS,
    'cpis'             : [
        {
        'type'         : 'saga.namespace.Directory',
        'class'        : 'SRMDirectory'
        },
        {
        'type'         : 'saga.namespace.Entry',
        'class'        : 'SRMFile'
        },
        {
        'type'         : 'saga.filesystem.Directory',
        'class'        : 'SRMDirectory'
        }, 
        {
        'type'         : 'saga.filesystem.File',
        'class'        : 'SRMFile'
        }
    ]
}

CONNTIMEOUT = 180
SNDTIMEOUT = 7200
SRMTIMEOUT = 180

###############################################################################
# The adaptor class

class Adaptor(saga.adaptors.base.Base):
    """
    This is the actual adaptor class, which gets loaded by SAGA (i.e. by the
    SAGA engine), and which registers the CPI implementation classes which
    provide the adaptor's functionality.
    """

    def __init__(self) :
        saga.adaptors.base.Base.__init__(self, _ADAPTOR_INFO, _ADAPTOR_OPTIONS)

        self.cfg = self.get_config(_ADAPTOR_NAME)
        self.pty_url = self.cfg['pty_url'].get_value()


    def sanity_check(self):
        pass


    def file_get_size(self, shell, url):

        # In case of SURL the fields are:
        # file mode, number of links to the file, user id, group id, file size(bytes), locality, file name.
        # srm://srm.hep.fiu.edu:8443/srm/v2/server?SFN=/mnt/hadoop/osg/marksant/TESTFILE")
        # -rwxr-xr-x   1     1     2      19               ONLINE /mnt/hadoop/osg/marksant/TESTFILE
        try:
            # 'lcg-ls' uses the wrong timeout setting for connection timeout
            rc, out, _ = shell.run_sync("lcg-ls --sendreceive-timeout %d -l -b -D srmv2 %s" % (CONNTIMEOUT, url))
        except:
            shell.finalize(kill_pty=True)
            raise Exception("get_size failed")

        if rc != 0:
            if 'SRM_INVALID_PATH' in out:
                raise saga.exceptions.DoesNotExist(url)
            else:
                raise Exception("Couldn't list file")

{'fraction_non_alphanumeric': 0.15289691497366442, 'fraction_numerical': 0.007223476297968397, 'mean_word_length': 2.0542279411764706, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6253367', 'n_tokens_mistral': 2232, 'n_tokens_neox': 2100, 'n_words': 465}