#!/usr/bin/python3

# Copyright (c) 2016, Troy Telford
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
#    this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
#    this list of conditions and the following disclaimer in the documentation
#    and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are
# those of the authors and should not be interpreted as representing official
# policies, either expressed or implied.

import configparser
import logging
import sys
from dhdns import dhdns

def main(argv=None):
    if argv is None:
        argv = sys.argv

    # read configuration from file
    config = configparser.ConfigParser()
    try:
        config.read("dhdynupdate.conf")
    except:
        print("Error reading config file!")
        sys.exit()
    config_name = "DreamHost API Test Account"
    
    # set up logger
    try:
        logger = logging.basicConfig(
                 format='%(levelname)s:%(message)s',
                 filename = config["Global"]["log_file"],
                 filemode='w',
                 level=logging.DEBUG)
    except:
        print("Could not set up logger!")
        exit()

    dh_dns = dhdns(config, config_name)
    dh_dns.update_addresses()

if __name__ == "__main__":
    main()

# vim: ts=4 sw=4 et

#!/usr/bin/python3

# Copyright (c) 2016, Troy Telford
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
#    this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
#    this list of conditions and the following disclaimer in the documentation
#    and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are
# those of the authors and should not be interpreted as representing official
# policies, either expressed or implied.

import argparse
import configparser
import logging
import sys
from dhdns import dhdns

def main(argv=None):
    if argv is None:
        argv = sys.argv
    # Command line parsing...
    cmd_parser = argparse.ArgumentParser()
    cmd_parser.add_argument("-d", "--daemon", action='store_true',
                            default=False, required=False,
                            dest="daemonize",
                            help="Execute %(prog)s as a dæmon")
    cmd_parser.add_argument("-c", "--config", action='store',
                            type=str, default="DreamHost API Test Account",
                            required=False, metavar="config",
                            dest="config_name",
                            help="Configuration name")
    args = cmd_parser.parse_args()

    # read configuration from file
    config = configparser.ConfigParser()
    try:
        config.read("dhdynupdate.conf")
    except:
        print("Error reading config file!")
        sys.exit()
    
    # set up logger
    try:
        logger = logging.basicConfig(
                 format='%(levelname)s:%(message)s',
                 filename = config["Global"]["log_file"],
                 filemode='w',
                 level=logging.DEBUG)
    except:
        print("Could not set up logger!")
        exit()

    dh_dns = dhdns(config, args.config_name)
    dh_dns.update_addresses()

if __name__ == "__main__":
    main()

# vim: ts=4 sw=4 et

Add initial argparse code