added ability to define data folder
This commit is contained in:
parent
7277ee14f9
commit
73d92e1e1b
3 changed files with 40 additions and 8 deletions
|
@ -1,8 +1,9 @@
|
||||||
# Varken
|
# Varken
|
||||||
Dutch for PIG. PIG is an Acronym for Plex/InfluxDB/Grafana
|
Dutch for PIG. PIG is an Acronym for Plex/InfluxDB/Grafana
|
||||||
|
|
||||||
Varken is a standalone commmand-line utility that will aggregate date
|
Varken is a standalone command-line utility to aggregate data
|
||||||
from the plex ecosystem into influxdb to be displayed in grafana
|
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/)
|
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/)
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import sys
|
import sys
|
||||||
import configparser
|
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
|
from Varken.helpers import OmbiServer, TautulliServer, SonarrServer, InfluxServer, RadarrServer
|
||||||
|
|
||||||
|
|
||||||
class INIParser(object):
|
class INIParser(object):
|
||||||
def __init__(self):
|
def __init__(self, data_folder):
|
||||||
self.config = configparser.ConfigParser()
|
self.config = configparser.ConfigParser()
|
||||||
|
self.data_folder = data_folder
|
||||||
|
|
||||||
self.influx_server = InfluxServer()
|
self.influx_server = InfluxServer()
|
||||||
|
|
||||||
|
@ -28,9 +30,12 @@ class INIParser(object):
|
||||||
self.parse_opts()
|
self.parse_opts()
|
||||||
|
|
||||||
def read_file(self):
|
def read_file(self):
|
||||||
file_path = abspath(join(dirname(__file__), '..', 'data', 'varken.ini'))
|
file_path = join(self.data_folder, 'varken.ini')
|
||||||
|
if exists(file_path):
|
||||||
with open(file_path) as config_ini:
|
with open(file_path) as config_ini:
|
||||||
self.config.read_file(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):
|
def parse_opts(self):
|
||||||
self.read_file()
|
self.read_file()
|
||||||
|
|
28
varken.py
28
varken.py
|
@ -1,6 +1,10 @@
|
||||||
import schedule
|
import schedule
|
||||||
import threading
|
import threading
|
||||||
|
from sys import exit
|
||||||
from time import sleep
|
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.iniparser import INIParser
|
||||||
from Varken.sonarr import SonarrAPI
|
from Varken.sonarr import SonarrAPI
|
||||||
|
@ -15,7 +19,29 @@ def threaded(job):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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)
|
DBMANAGER = DBManager(CONFIG.influx_server)
|
||||||
|
|
||||||
if CONFIG.sonarr_enabled:
|
if CONFIG.sonarr_enabled:
|
||||||
|
|
Loading…
Reference in a new issue