<commit_before>'''
Created on Jan 5, 2012

@package support - cdm
@copyright 2012 Sourcefabric o.p.s.
@license http: // www.gnu.org / licenses / gpl - 3.0.txt
@author: <NAME>

Contains the Content Delivery Manager implementation for local file system
'''

from cdm.spec import ICDM

# --------------------------------------------------------------------

class LocalFileSystemCDM(ICDM):
    '''
    @see ICDM (Content Delivery Manager interface)
    '''

    repositoryPath = str
    # The path where the content repository is placed

    def __init__(self):
        assert isinstance(self.repositoryPath, str), 'Invalid repository path %s' % self.repositoryPath

    def publishFromFile(self, path, filePath):
        '''
        @see ICDM.publishFromFile
        '''

    def publishContent(self, path, content):
        '''
        @see ICDM.publishContent
        '''

    def getURI(self, path, protocols):
        '''
        @see ICDM.getURI
        '''
<commit_msg>NR-23 : Implement the content delivery manager<commit_after>'''
Created on Jan 5, 2012

@package support - cdm
@copyright 2012 Sourcefabric o.p.s.
@license http: // www.gnu.org / licenses / gpl - 3.0.txt
@author: <NAME>

Contains the Content Delivery Manager implementation for local file system
'''

from cdm.spec import ICDM

import abc
import os
from os.path import isdir, isfile, join

# --------------------------------------------------------------------

class IDelivery(metaclass = abc.ABCMeta):
    '''
    Delivery protocol interface
    '''

    @abc.abstractmethod
    def getURI(self, repoFilePath):
        '''
        Returns the URI for a given repository file path in the context of
        this delivery protocol.
        '''


class HTTPDelivery(IDelivery):
    '''
    @see IDelivery
    '''

    documentRoot = str
    # The HTTP server document root directory path

    port = int
    # The HTTP server listening port

    repositorySubdir = str
    # The sub-directory of the document root where the file repository is

    def __init__(self):
        assert isinstance(self.documentRoot, str), 'Invalid document root value %s' % self.documentRoot
        assert isdir(self.documentRoot) and os.access(self.documentRoot, os.W_OK), \
            'Unable to access the document root directory %s' % self.documentRoot
        assert isinstance(self.port, int)
        assert isinstance(self.repositorySubdir, str), 'Invalid repository sub-directory value %s' % self.documentRoot
        if len(self.repositorySubdir) > 0:
            repositoryPath = join(self.documentRoot, self.repositorySubdir)
            assert isdir(repositoryPath) and os.access(repositoryPath, os.W_OK), \
                'Unable to access the repository directory %s' % self.documentRoot

    def getURI(self, repoFilePath):
        assert isinstance(repoFilePath, str), 'Invalid repository file path value %s' % repoFilePath


class LocalFileSystemCDM(ICDM):
    '''
    @see ICDM (Content Delivery Manager interface)
    '''

    repositoryPath = str
    # The path where the content repository is placed

    def __init__(self):
        assert isinstance(self.repositoryPath, str), 'Invalid repository path %s' % self.repositoryPath
        assert isdir(self.repositoryPath) and os.access(self.repositoryPath, os.W_OK), \
            'Unable to access repository directory %s' % self.repositoryPath

    def publishFromFile(self, path, filePath):
        '''
        @see ICDM.publishFromFile
        '''
        assert isinstance(path, str), 'Invalid content path %s' % path
        assert isinstance(filePath, str), 'Invalid file path value %s' % path
        assert isfile(filePath) and os.access(filePath, os.R_OK), \
            'Unable to read file path %s' % filePath

    def publishContent(self, path, content):
        '''
        @see ICDM.publishContent
        '''
        assert isinstance(path, str), 'Invalid content path %s' % path
        assert isinstance(content, str), 'Invalid content string %s' % path

    def getURI(self, path, protocols = ('http', 'https')):
        '''
        @see ICDM.getURI
        '''
        assert isinstance(path, str), 'Invalid content path %s' % path
        assert isinstance(protocols, tuple), 'Invalid protocols %s' % path

{'fraction_non_alphanumeric': 0.1284101599247413, 'fraction_numerical': 0.005879586077140169, 'mean_word_length': 2.523612261806131, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '820869', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1120, 'n_words': 379}