<commit_before>#!/bin/python
""" undine
    A wrapper for handling multi-archive backups with Borg
"""

from __future__ import print_function

__author__="<NAME> <<EMAIL>>"
__copyright__="Copyright (c) 2017 Vote Smart"
__version__="0.0.2"

import os, sys, argparse, socket, configparser, fasteners
from subprocess import Popen, PIPE
from envelopes import Envelope

try:
    from StringIO import StringIO
except ImportError:
    from io import StringIO

def main():
    """ Script meat """

    # Handle command line args
    parser = argparse.ArgumentParser(description='A wrapper for handling multi-archive backups with Borg')
    parser.add_argument('--dry-run', action='store_true', dest="dryrun", help="Do not actually create archives.")
    parser.add_argument('-v', '--verbose', action='store_true', dest="verbose", help="Show output")
    parser.add_argument('-d', '--debug', action='store_true', dest="debug", help="Show debug output")
    parser.add_argument('-l', '--lock-file', dest="lockfile", default=u"/tmp/backup.log", help="Lock file to use")
    args = parser.parse_args()

    # Config helper
    def get_bool_config(sect, key, default = False):
        try:
            conf = parser.get(sect, key)
            return conf
        except configparser.NoSectionError:
            return default

    # Config handling. 
    config_file = ""
    user_config_file = os.path.expanduser('~/.config/undine.ini')
    system_config_file = '/etc/undine.ini'
    # User ini trumps system ini
    if os.path.isfile(user_config_file):
        config_file = user_config_file
    elif os.path.isfile(system_config_file):
        config_file = system_config_file
    else:
        raise Exception("Could not find configuration ini file at ~/.config/undine.ini or /etc/undine.ini.")
    parser = configparser.ConfigParser()
    parser.read(config_file)

    config = {
        'debug': get_bool_config('default', 'debug'),
        'verbose': False,
        'repos': parser.get('default', 'repos', fallback='ssh://rsync//data1/home/9774/file0.ia.votesmart.org'),
        'notify_email': parser.get('default', 'notify_email', fallback='<EMAIL>'),
        'lockfile': args.lockfile or parser.get('default', 'lockfile', fallback='/tmp/udine.lock'),
        'units': dict(parser.items('units')),
        'hostname': parser.get('default', 'hostname', fallback=socket.gethostname()),
        'smtp_host': parser.get('smtp', 'host', fallback='localhost'),
        'smtp_port': parser.get('smtp', 'port', fallback='589'),
        'smtp_login': parser.get('smtp', 'login', fallback=None),
        'smtp_password': parser.get('smtp', 'password', fallback=None),
        'smtp_tls': parser.get('smtp', 'tls', fallback=True),
    }

    # debug turns on verbose
    if config['debug']:
        config['debug'] = True
        config['verbose'] = True

    # E-mail log
    email_log = []

    # Should probably prevent multiple backups from running
    with fasteners.InterProcessLock(config['lockfile']):<commit_msg>Fixeda  bug where the config file was never checked for lockfile location.<commit_after>#!/bin/python
""" undine
    A wrapper for handling multi-archive backups with Borg
"""

from __future__ import print_function

__author__="<NAME> <<EMAIL>>"
__copyright__="Copyright (c) 2017 Vote Smart"
__version__="0.0.2"

import os, sys, argparse, socket, configparser, fasteners
from subprocess import Popen, PIPE
from envelopes import Envelope

try:
    from StringIO import StringIO
except ImportError:
    from io import StringIO

def main():
    """ Script meat """

    # Handle command line args
    parser = argparse.ArgumentParser(description='A wrapper for handling multi-archive backups with Borg')
    parser.add_argument('--dry-run', action='store_true', dest="dryrun", help="Do not actually create archives.")
    parser.add_argument('-v', '--verbose', action='store_true', dest="verbose", help="Show output")
    parser.add_argument('-d', '--debug', action='store_true', dest="debug", help="Show debug output")
    parser.add_argument('-l', '--lock-file', dest="lockfile", default=u"/tmp/undine.lock", help="Lock file to use")
    args = parser.parse_args()

    # Config helper
    def get_bool_config(sect, key, default = False):
        try:
            conf = parser.get(sect, key)
            return conf
        except configparser.NoSectionError:
            return default

    # Config handling. 
    config_file = ""
    user_config_file = os.path.expanduser('~/.config/undine.ini')
    system_config_file = '/etc/undine.ini'
    # User ini trumps system ini
    if os.path.isfile(user_config_file):
        config_file = user_config_file
    elif os.path.isfile(system_config_file):
        config_file = system_config_file
    else:
        raise Exception("Could not find configuration ini file at ~/.config/undine.ini or /etc/undine.ini.")
    parser = configparser.ConfigParser()
    parser.read(config_file)

    config = {
        'debug': get_bool_config('default', 'debug'),
        'verbose': False,
        'repos': parser.get('default', 'repos', fallback='ssh://rsync//data1/home/9774/file0.ia.votesmart.org'),
        'notify_email': parser.get('default', 'notify_email', fallback='<EMAIL>'),
        'lockfile': parser.get('default', 'lockfile', fallback=None) or args.lockfile,
        'units': dict(parser.items('units')),
        'hostname': parser.get('default', 'hostname', fallback=socket.gethostname()),
        'smtp_host': parser.get('smtp', 'host', fallback='localhost'),
        'smtp_port': parser.get('smtp', 'port', fallback='589'),
        'smtp_login': parser.get('smtp', 'login', fallback=None),
        'smtp_password': parser.get('smtp', 'password', fallback=None),
        'smtp_tls': parser.get('smtp', 'tls', fallback=True),
    }

    # debug turns on verbose
    if config['debug']:
        config['debug'] = True
        config['verbose'] = True

    # E-mail log
    email_log = []

    # Should probably prevent multiple backups from running
    with fasteners.InterProcessLock(config['lockfile']):
{'fraction_non_alphanumeric': 0.14585051971621846, 'fraction_numerical': 0.00527965682230655, 'mean_word_length': 3.6098859315589356, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1260145', 'n_tokens_mistral': 1899, 'n_tokens_neox': 1820, 'n_words': 444}