<commit_before># -*- coding: utf-8 -*-
#
# common.py - part of the FDroid server tools
# Copyright (C) 2010-13, <NAME>, <EMAIL>
# Copyright (C) 2013 <NAME> <<EMAIL>>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import glob, os, sys, re
import shutil
import stat
import subprocess
import time
import operator
import Queue
import threading
import magic
from distutils.spawn import find_executable

import metadata

config = None
options = None

def read_config(opts, config_file='config.py'):
    """Read the repository config

    The config is read from config_file, which is in the current directory when
    any of the repo management commands are used.
    """
    global config, options

    if config is not None:
        return config
    if not os.path.isfile(config_file):
        print "Missing config file - is this a repo directory?"
        sys.exit(2)

    options = opts
    if not hasattr(options, 'verbose'):
        options.verbose = False

    defconfig = {
        'build_server_always': False,
        'mvn3': "mvn3",
        'archive_older': 0,
        'gradle': 'gradle',
        'update_stats': False,
        'archive_older': 0,
        'max_icon_size': 72,
        'stats_to_carbon': False,
        'repo_maxage': 0
    }
    config = {}

    if options.verbose:
        print "Reading %s..." % config_file
    execfile(config_file, config)

    if any(k in config for k in ["keystore", "keystorepass", "keypass"]):
        st = os.stat(config_file)
        if st.st_mode & stat.S_IRWXG or st.st_mode & stat.S_IRWXO:
            print "WARNING: unsafe permissions on {0} (should be 0600)!".format(config_file)

    # Expand environment variables
    for k, v in config.items():
        if type(v) != str:
            continue
        config[k] = os.path.expandvars(v)

    # Check that commands and binaries do exist
    for key in ('mvn3', 'gradle'):
        if key not in config:
            continue
        val = config[key]
        executable = find_executable(val)
        if not executable:
            print "ERROR: No such command or binary for %s: %s" % (key, val)
            sys.exit(3)

    # Check that directories exist
    for key in ('sdk_path', 'ndk_path', 'build_tools'):
        if key not in config:
            continue
        val = config[key]
        if key == 'build_tools':
            if 'sdk_path' not in config:<commit_msg>Also allow for '~' and '~user'<commit_after># -*- coding: utf-8 -*-
#
# common.py - part of the FDroid server tools
# Copyright (C) 2010-13, <NAME>, <EMAIL>
# Copyright (C) 2013 <NAME> <<EMAIL>>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import glob, os, sys, re
import shutil
import stat
import subprocess
import time
import operator
import Queue
import threading
import magic
from distutils.spawn import find_executable

import metadata

config = None
options = None

def read_config(opts, config_file='config.py'):
    """Read the repository config

    The config is read from config_file, which is in the current directory when
    any of the repo management commands are used.
    """
    global config, options

    if config is not None:
        return config
    if not os.path.isfile(config_file):
        print "Missing config file - is this a repo directory?"
        sys.exit(2)

    options = opts
    if not hasattr(options, 'verbose'):
        options.verbose = False

    defconfig = {
        'build_server_always': False,
        'mvn3': "mvn3",
        'archive_older': 0,
        'gradle': 'gradle',
        'update_stats': False,
        'archive_older': 0,
        'max_icon_size': 72,
        'stats_to_carbon': False,
        'repo_maxage': 0
    }
    config = {}

    if options.verbose:
        print "Reading %s..." % config_file
    execfile(config_file, config)

    if any(k in config for k in ["keystore", "keystorepass", "keypass"]):
        st = os.stat(config_file)
        if st.st_mode & stat.S_IRWXG or st.st_mode & stat.S_IRWXO:
            print "WARNING: unsafe permissions on {0} (should be 0600)!".format(config_file)

    # Expand environment variables
    for k, v in config.items():
        if type(v) != str:
            continue
        v = os.path.expanduser(v)
        config[k] = os.path.expandvars(v)

    # Check that commands and binaries do exist
    for key in ('mvn3', 'gradle'):
        if key not in config:
            continue
        val = config[key]
        executable = find_executable(val)
        if not executable:
            print "ERROR: No such command or binary for %s: %s" % (key, val)
            sys.exit(3)

    # Check that directories exist
    for key in ('sdk_path', 'ndk_path', 'build_tools'):
        if key not in config:
            continue
        val = config[key]
        if key == 'build_tools':
            if 'sdk_path' not in config:
{'fraction_non_alphanumeric': 0.09464611304491961, 'fraction_numerical': 0.008950770760815515, 'mean_word_length': 2.6636308439587126, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '3181546', 'n_tokens_mistral': 1811, 'n_tokens_neox': 1731, 'n_words': 695}