Skip to content

Commit

Permalink
take optional --config_path argument to move cfg files to a subfolder
Browse files Browse the repository at this point in the history
  • Loading branch information
david l goodrich committed Jun 4, 2020
1 parent 457b4b2 commit 545e61d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
16 changes: 13 additions & 3 deletions ATVSettings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python

import sys
from os import sep
from os import sep, makedirs
from os.path import isdir
import ConfigParser
import fnmatch

Expand Down Expand Up @@ -83,9 +84,10 @@


class CATVSettings():
def __init__(self):
def __init__(self, path):
dprint(__name__, 1, "init class CATVSettings")
self.cfg = None
self.path = path
self.loadSettings()


Expand All @@ -109,7 +111,15 @@ def saveSettings(self):
f.close()

def getSettingsFile(self):
return sys.path[0] + sep + "ATVSettings.cfg"
if self.path.startswith('.'):
# relative to current path
directory = sys.path[0] + sep + self.path
else:
# absolute path
directory = self.path
if not isdir(directory):
makedirs(directory)
return directory + "/ATVSettings.cfg"

def checkSection(self, UDID):
# check for existing UDID section
Expand Down
12 changes: 10 additions & 2 deletions PlexConnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from multiprocessing import Process, Pipe
from multiprocessing.managers import BaseManager
import signal, errno
import argparse

from Version import __VERSION__
import DNSServer, WebServer
Expand All @@ -22,6 +23,7 @@
from Debug import * # dprint()


CONFIG_PATH = '.'

def getIP_self():
cfg = param['CSettings']
Expand Down Expand Up @@ -60,7 +62,7 @@ def startup():
global running

# Settings
cfg = Settings.CSettings()
cfg = Settings.CSettings(CONFIG_PATH)
param['CSettings'] = cfg

# Logfile
Expand Down Expand Up @@ -89,7 +91,7 @@ def startup():
proxy = BaseManager()
proxy.register('ATVSettings', ATVSettings.CATVSettings)
proxy.start(initProxy)
param['CATVSettings'] = proxy.ATVSettings()
param['CATVSettings'] = proxy.ATVSettings(CONFIG_PATH)

running = True

Expand Down Expand Up @@ -181,6 +183,12 @@ def sighandler_shutdown(signum, frame):
if __name__=="__main__":
signal.signal(signal.SIGINT, sighandler_shutdown)
signal.signal(signal.SIGTERM, sighandler_shutdown)
parser = argparse.ArgumentParser()
parser.add_argument('--config_path', metavar='<config_path>', required=False,
help='path of folder containing config files, relative to PlexConnect.py')
args = parser.parse_args()
if args.config_path:
CONFIG_PATH = args.config_path

dprint('PlexConnect', 0, "***")
dprint('PlexConnect', 0, "PlexConnect")
Expand Down
18 changes: 14 additions & 4 deletions Settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python

import sys
from os import sep
from os import sep, makedirs
from os.path import isdir
import ConfigParser
import re

Expand Down Expand Up @@ -57,11 +58,12 @@


class CSettings():
def __init__(self):
def __init__(self, path):
dprint(__name__, 1, "init class CSettings")
self.cfg = ConfigParser.SafeConfigParser()
self.section = 'PlexConnect'

self.path = path

# set option for fixed ordering
self.cfg.add_section(self.section)
for (opt, (dflt, vldt)) in g_settings:
Expand All @@ -84,7 +86,15 @@ def saveSettings(self):
f.close()

def getSettingsFile(self):
return sys.path[0] + sep + "Settings.cfg"
if self.path.startswith('.'):
# relative to current path
directory = sys.path[0] + sep + self.path
else:
# absolute path
directory = self.path
if not isdir(directory):
makedirs(directory)
return directory + "/Settings.cfg"

def checkSection(self):
modify = False
Expand Down

0 comments on commit 545e61d

Please sign in to comment.