added license

This commit is contained in:
Johannes Findeisen 2020-09-06 07:45:00 +02:00
commit 3f4e9bd684
3 changed files with 92 additions and 12 deletions

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Johannes Findeisen <you@hanez.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -1,13 +1,8 @@
{ {
"interval": 60, "interval": 60,
"database": "uplink.sqlite3",
"logdir": "./log/uplink.log",
"logsize": 1024000,
"logcount": 5,
"loglevel": "INFO",
"database": "./uplink.sqlite3", "database": "./uplink.sqlite3",
"uplinks": [ "uplinks": [
{ "provider": "Cable Provider", "ip": "192.168.0.1", "password": "1234" }, { "provider": "Cable Provider", "ip": "192.168.0.1", "password": "1234" },
{ "provider": "DSL Provider", "ip": "192.168.1.1", "password": "1234" } { "provider": "DSL Provider", "ip": "192.168.1.1", "password": "1234" }
] ]
} }

View file

@ -1,5 +1,26 @@
#!/usr/bin/python3 -d #!/usr/bin/python3 -d
# Copyright (c) 2020 Johannes Findeisen <you@hanez.org>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is furnished
# to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import argparse
import calendar import calendar
import datetime import datetime
# import daemon # import daemon
@ -13,8 +34,48 @@ import time
from fritzconnection.lib.fritzstatus import FritzStatus from fritzconnection.lib.fritzstatus import FritzStatus
__version__ = "0.1"
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def parse_args():
parser = argparse.ArgumentParser(
description="uplink.",
epilog="uplink is not some program expecting uplinks to work!",
prog="uplink")
parser.add_argument("--version", action="version", version="%(prog)s " + str(__version__))
parser.add_argument("config", metavar="CONFIGFILE",
help="the configfile to use")
parser.add_argument("-n", "--nocolor",
help="disable colored output")
parser.add_argument("-l", "--logfile", default="./log/uplink.log", metavar="FILE",
help="set logfile to use (default: ./log/uplink.log)")
parser.add_argument("-c", "--logcount", default=5, type=int,
help="maximum number of logfiles in rotation (default: 5)")
parser.add_argument("-m", "--logsize", default=10485760, type=int,
help="maximum logfile size in bytes (default: 10485760)")
output = parser.add_mutually_exclusive_group()
output.add_argument("-q", "--quiet", action="store_const", dest="loglevel", const=logging.ERROR,
help="output only errors")
output.add_argument("-w", "--warning", action="store_const", dest="loglevel", const=logging.WARNING,
help="output warnings")
output.add_argument("-v", "--verbose", action="store_const", dest="loglevel", const=logging.INFO,
help="output info messages")
output.add_argument("-d", "--debug", action="store_const", dest="loglevel", const=logging.DEBUG,
help="output debug messages")
output.set_defaults(loglevel=logging.INFO)
return parser.parse_args()
def get_data(config): def get_data(config):
conn = sqlite3.connect(config["database"]) conn = sqlite3.connect(config["database"])
@ -52,20 +113,23 @@ def run(config):
if __name__ == "__main__": if __name__ == "__main__":
with open('config.json', 'r') as configfile: args = parse_args()
configpath = args.config
with open(configpath, 'r') as configfile:
config_data = configfile.read() config_data = configfile.read()
_config = json.loads(config_data) _config = json.loads(config_data)
logfile = path.expanduser(_config["logdir"]) logfile = path.expanduser(args.logfile)
if not path.exists(path.dirname(logfile)): if not path.exists(path.dirname(logfile)):
os.makedirs(path.dirname(logfile)) os.makedirs(path.dirname(logfile))
root_logger = logging.getLogger() root_logger = logging.getLogger()
formatter = logging.Formatter("%(asctime)s:%(levelname)s:%(name)s:%(message)s") formatter = logging.Formatter("%(asctime)s:%(levelname)s:%(name)s:%(message)s")
handler = logging.handlers.RotatingFileHandler(logfile, maxBytes=_config["logsize"], handler = logging.handlers.RotatingFileHandler(args.logfile, maxBytes=args.logsize, backupCount=args.logcount)
backupCount=_config["logcount"])
handler.setFormatter(formatter) handler.setFormatter(formatter)
root_logger.addHandler(handler) root_logger.addHandler(handler)
root_logger.setLevel(_config["loglevel"]) root_logger.setLevel(args.loglevel)
run(_config) run(_config)