<commit_before># Copyright 2014 PressLabs SRL
#
# 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 getpass
import os
import socket
import tempfile
import grp
from logging import Formatter
from logging.handlers import TimedRotatingFileHandler, SysLogHandler
from collections import OrderedDict
from urlparse import urlparse

from gitfs.log import log


class Args(object):
    def __init__(self, parser):
        self.DEFAULTS = OrderedDict([
            ("repo_path", (self.get_repo_path, "string")),
            ("user", (self.get_current_user, "string")),
            ("group", (self.get_current_group, "string")),
            ("username", ("", "string")),
            ("password", ("", "string")),
            ("ssh_key", (self.get_ssh_key, "string")),
            ("ssh_user", (self.get_ssh_user, "string")),
            ("foreground", (False, "bool")),
            ("branch", ("master", "string")),
            ("allow_other", (False, "bool")),
            ("allow_root", (True, "bool")),
            ("commiter_name", (self.get_current_user, "string")),
            ("commiter_email", (self.get_current_email, "string")),
            ("max_size", (10, "float")),
            ("fetch_timeout", (30, "float")),
            ("merge_timeout", (5, "float")),
            ("debug", (False, "bool")),
            ("log", ("syslog", "string")),
            ("log_level", ("warning", "string")),
        ])
        self.config = self.build_config(parser.parse_args())

    def build_config(self, args):
        if args.o:
            for arg in args.o.split(","):
                if "=" in arg:
                    item, value = arg.split("=")
                    setattr(args, item, value)

        return self.check_args(self.set_defaults(args))

    def check_args(self, args):
        # check allow_other and allow_root
        if args.allow_other:
            args.allow_root = False
        else:
            args.allow_root = True

        # check log_level
        if args.debug:
            args.log_level = 'debug'

        if args.log != "syslog":
            handler = TimedRotatingFileHandler(args.log, when="midnight")
            handler.setFormatter(Formatter(fmt='%(asctime)s %(threadName)s: '
                                           '%(message)s',
                                           datefmt='%B-%d-%Y %H:%M:%S'))
        else:
            handler = SysLogHandler(address="/dev/log")
            handler.setFormatter(Formatter(fmt='GitFS: %(threadName)s: '
                                           '%(message)s'))

        log.addHandler(handler)
        log.setLevel(args.log_level.upper())

        return args<commit_msg>fix log path on OSX<commit_after># Copyright 2014 PressLabs SRL
#
# 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 getpass
import os
import socket
import tempfile
import grp
import sys
from logging import Formatter
from logging.handlers import TimedRotatingFileHandler, SysLogHandler
from collections import OrderedDict
from urlparse import urlparse

from gitfs.log import log


class Args(object):
    def __init__(self, parser):
        self.DEFAULTS = OrderedDict([
            ("repo_path", (self.get_repo_path, "string")),
            ("user", (self.get_current_user, "string")),
            ("group", (self.get_current_group, "string")),
            ("username", ("", "string")),
            ("password", ("", "string")),
            ("ssh_key", (self.get_ssh_key, "string")),
            ("ssh_user", (self.get_ssh_user, "string")),
            ("foreground", (False, "bool")),
            ("branch", ("master", "string")),
            ("allow_other", (False, "bool")),
            ("allow_root", (True, "bool")),
            ("commiter_name", (self.get_current_user, "string")),
            ("commiter_email", (self.get_current_email, "string")),
            ("max_size", (10, "float")),
            ("fetch_timeout", (30, "float")),
            ("merge_timeout", (5, "float")),
            ("debug", (False, "bool")),
            ("log", ("syslog", "string")),
            ("log_level", ("warning", "string")),
        ])
        self.config = self.build_config(parser.parse_args())

    def build_config(self, args):
        if args.o:
            for arg in args.o.split(","):
                if "=" in arg:
                    item, value = arg.split("=")
                    setattr(args, item, value)

        return self.check_args(self.set_defaults(args))

    def check_args(self, args):
        # check allow_other and allow_root
        if args.allow_other:
            args.allow_root = False
        else:
            args.allow_root = True

        # check log_level
        if args.debug:
            args.log_level = 'debug'

        if args.log != "syslog":
            handler = TimedRotatingFileHandler(args.log, when="midnight")
            handler.setFormatter(Formatter(fmt='%(asctime)s %(threadName)s: '
                                           '%(message)s',
                                           datefmt='%B-%d-%Y %H:%M:%S'))
        else:
            if sys.platform == 'darwin':
                handler = SysLogHandler(address="/var/run/syslog")
            else:
                handler = SysLogHandler(address="/dev/log")

            handler.setFormatter(Formatter(fmt='GitFS: %(threadName)s: '
                                           '%(message)s'))

        log.addHandler(handler)
        log.setLevel(args.log_level.upper())

        return args
{'fraction_non_alphanumeric': 0.13577185368877867, 'fraction_numerical': 0.0040297582145071295, 'mean_word_length': 2.2168494516450648, 'pattern_counts': {'":': 2, '<': 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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2714443', 'n_tokens_mistral': 1831, 'n_tokens_neox': 1778, 'n_words': 489}