added ability to define data folder

This commit is contained in:
Nicholas St. Germain 2018-12-03 23:47:46 -06:00
parent 7277ee14f9
commit 73d92e1e1b
3 changed files with 40 additions and 8 deletions

View file

@ -1,8 +1,9 @@
# Varken
Dutch for PIG. PIG is an Acronym for Plex/InfluxDB/Grafana
Varken is a standalone commmand-line utility that will aggregate date
from the plex ecosystem into influxdb to be displayed in grafana
Varken is a standalone command-line utility to aggregate data
from the plex ecosystem into InfluxDB. Examples use Grafana for a
frontend
Requirements /w install links: [Grafana](http://docs.grafana.org/installation/), [Python3](https://www.python.org/downloads/), [InfluxDB](https://docs.influxdata.com/influxdb/v1.5/introduction/installation/)

View file

@ -1,12 +1,14 @@
import sys
import configparser
from os.path import abspath, dirname, join
from sys import exit
from os.path import join, exists
from Varken.helpers import OmbiServer, TautulliServer, SonarrServer, InfluxServer, RadarrServer
class INIParser(object):
def __init__(self):
def __init__(self, data_folder):
self.config = configparser.ConfigParser()
self.data_folder = data_folder
self.influx_server = InfluxServer()
@ -28,9 +30,12 @@ class INIParser(object):
self.parse_opts()
def read_file(self):
file_path = abspath(join(dirname(__file__), '..', 'data', 'varken.ini'))
with open(file_path) as config_ini:
self.config.read_file(config_ini)
file_path = join(self.data_folder, 'varken.ini')
if exists(file_path):
with open(file_path) as config_ini:
self.config.read_file(config_ini)
else:
exit("You do not have a varken.ini file in {}".format(self.data_folder))
def parse_opts(self):
self.read_file()

View file

@ -1,6 +1,10 @@
import schedule
import threading
from sys import exit
from time import sleep
from os import access, R_OK
from os.path import isdir, abspath, dirname, join
from argparse import ArgumentParser, RawTextHelpFormatter
from Varken.iniparser import INIParser
from Varken.sonarr import SonarrAPI
@ -15,7 +19,29 @@ def threaded(job):
if __name__ == "__main__":
CONFIG = INIParser()
parser = ArgumentParser(prog='Varken',
description='Command-line utility to aggregate data from the plex ecosystem into InfluxDB',
formatter_class=RawTextHelpFormatter)
parser.add_argument("-d", "--data-folder", help='Define an alternate data folder location')
parser.add_argument("-l", "--log-level", choices=['info', 'error', 'debug'], help='Not yet implemented')
opts = parser.parse_args()
DATA_FOLDER = abspath(join(dirname(__file__), 'data'))
if opts.data_folder:
ARG_FOLDER = opts.data_folder
if isdir(ARG_FOLDER):
DATA_FOLDER = ARG_FOLDER
if not access(ARG_FOLDER, R_OK):
exit("Read permission error for {}".format(ARG_FOLDER))
else:
exit("{} does not exist".format(ARG_FOLDER))
CONFIG = INIParser(DATA_FOLDER)
DBMANAGER = DBManager(CONFIG.influx_server)
if CONFIG.sonarr_enabled: