<commit_before>#!/usr/bin/env python

'''Module with class holding Server's config.'''

import ConfigParser
import os.path

class TorrentDownloaderConfig(object):
    '''Class holding server's config.

    Some useful fields:
    port - server port
    save_path - path to put .torrent files to
    self.users - list of (user, password) pairs.
    '''

    def __init__(self, filename):
        '''Takes config filename as parameter, initialises own fields.'''

        self.parser = ConfigParser.RawConfigParser()
        self.parser.read(filename)

        self.port = self._get_int('Server', 'port', default=80)
        self.save_path = self._get_path('Server', 'save_path')

        self.users = self.parser.items('Users')


    def _get_int(self, section, option, default=0):
        '''Gets int number from config.'''

        try:
            return self.parser.getint(section, option)
        except ConfigParser.Error:
            return default


    def _get_path(self, section, option, default='.'):
        '''Gets path from config.'''

        path = default
        try:
            path = self.parser.get(section, option)
        except ConfigParser.Error:
            pass

        path = os.path.expanduser(path)

        if not os.path.exists(path):
            raise RuntimeError('path does not exists')

        return path

<commit_msg>more verbose error message in config<commit_after>#!/usr/bin/env python

'''Module with class holding Server's config.'''

import ConfigParser
import os.path

class TorrentDownloaderConfig(object):
    '''Class holding server's config.

    Some useful fields:
    port - server port
    save_path - path to put .torrent files to
    self.users - list of (user, password) pairs.
    '''

    def __init__(self, filename):
        '''Takes config filename as parameter, initialises own fields.'''

        self.parser = ConfigParser.RawConfigParser()
        self.parser.read(filename)

        self.port = self._get_int('Server', 'port', default=80)
        self.save_path = self._get_path('Server', 'save_path')

        self.users = self.parser.items('Users')


    def _get_int(self, section, option, default=0):
        '''Gets int number from config.'''

        try:
            return self.parser.getint(section, option)
        except ConfigParser.Error:
            return default


    def _get_path(self, section, option, default='.'):
        '''Gets path from config.'''

        path = default
        try:
            path = self.parser.get(section, option)
        except ConfigParser.Error:
            pass

        path = os.path.expanduser(path)

        if not os.path.exists(path):
            raise RuntimeError("path '%s' does not exists" % path)

        return path


{'fraction_non_alphanumeric': 0.11195928753180662, 'fraction_numerical': 0.0021810250817884407, 'mean_word_length': 2.418633540372671, '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': '7672198', 'n_tokens_mistral': 789, 'n_tokens_neox': 750, 'n_words': 223}