<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created by <NAME>
This file is part of the CernVM File System auxiliary tools.
"""

from manifest     import *
from repository   import *
from availability import *
from _common      import _split_md5
from _common      import _combine_md5

import subprocess
import re

class ServerNotInstalled(Exception):
    pass

class ClientNotInstalled(Exception):
    pass

class VersionNotDetected(Exception):
    def __init__(self, input_string):
        self.input_string = input_string


def __extract_version_string(input_str):
    match = re.search('.*([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*).*', input_str)
    if not match or len(match.groups()) != 1:
        raise VersionNotDetected(input_str)
    return match.groups()[0]


def _get_server_version():
    output = ''
    try:
        output = subprocess.check_output(['cvmfs_server'],
                                         stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError, e:
        return __extract_version_string(e.output)
    except OSError, e:
        raise ServerNotInstalled()


def _get_client_version():
    output = ''
    try:
        output = subprocess.check_output(['cvmfs2', '--version'],
                                         stderr=subprocess.STDOUT)
    except OSError, e:
        raise ClientNotInstalled()
    return __extract_version_string(output)


has_server = True
has_client = True
server_version = None
client_version = None


try:
    server_version = _get_server_version()
except (ServerNotInstalled, VersionNotDetected) as e:
    has_server = False

try:
    client_version = _get_client_version()
except ClientNotInstalled, e:
    has_client = False<commit_msg>COMPAT: python 2.6 does not provide subprocess.check_output<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created by <NAME>
This file is part of the CernVM File System auxiliary tools.
"""

from manifest     import *
from repository   import *
from availability import *
from _common      import _split_md5
from _common      import _combine_md5

import subprocess
import re

class ServerNotInstalled(Exception):
    pass

class ClientNotInstalled(Exception):
    pass

class VersionNotDetected(Exception):
    def __init__(self, input_string):
        self.input_string = input_string


def __extract_version_string(input_str):
    match = re.search('.*([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*).*', input_str)
    if not match or len(match.groups()) != 1:
        raise VersionNotDetected(input_str)
    return match.groups()[0]


def check_output(popen_args):
    """ instead of using subprocess.check_output that was
        introduced with python 2.7                        """
    return subprocess.Popen(popen_args,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT).communicate()[0]


def _get_server_version():
    output = ''
    try:
        output = check_output(['cvmfs_server'])
        return __extract_version_string(output)
    except OSError, e:
        raise ServerNotInstalled()


def _get_client_version():
    output = ''
    try:
        output = check_output(['cvmfs2', '--version'])
    except OSError, e:
        raise ClientNotInstalled()
    return __extract_version_string(output)


has_server = True
has_client = True
server_version = None
client_version = None


try:
    server_version = _get_server_version()
except (ServerNotInstalled, VersionNotDetected) as e:
    has_server = False

try:
    client_version = _get_client_version()
except ClientNotInstalled, e:
    has_client = False
{'fraction_non_alphanumeric': 0.10226644555002765, 'fraction_numerical': 0.011332227750138198, 'mean_word_length': 3.10783200908059, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3361438', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1090, 'n_words': 266}