Preparation for new Config code

pull/292/head
Halali 6 years ago
parent 71421de09e
commit ead1f31eb1

@ -0,0 +1,78 @@
# coding=utf-8
import os
import configparser
from get_argv import config_dir
class _ConfigSection(object):
"""Hold settings for a section of the configuration file."""
def __getattr__(self, attr):
if attr in self.__dict__:
return self.__dict__[attr]
else:
raise AttributeError('No "%s" setting in section.' % attr)
def __getitem__(self, item):
return getattr(self, item)
def __repr__(self):
return str(tuple(self.__dict__.keys()))
def read(config_file):
"""Read settings from file and return a dot notation object."""
config = configparser.ConfigParser()
config.read(unicode(config_file))
dotini = _ConfigSection()
for section in config.sections():
s = _ConfigSection()
for key, value in config.items(section):
if value == "True":
value = True
elif value == "False":
value = False
setattr(s, key, value)
setattr(dotini, section, s)
return dotini
settings = read(os.path.join(os.path.join(config_dir, 'config', 'config.ini')))
# sonarr url
if settings.sonarr.ssl:
protocol_sonarr = "https"
else:
protocol_sonarr = "http"
if settings.sonarr.base_url == '':
settings.sonarr.base_url = "/"
if not settings.sonarr.base_url.startswith("/"):
settings.sonarr.base_url = "/" + settings.sonarr.base_url
if settings.sonarr.base_url.endswith("/"):
settings.sonarr.base_url = settings.sonarr.base_url[:-1]
url_sonarr = protocol_sonarr + "://" + settings.sonarr.ip + ":" + settings.sonarr.port + settings.sonarr.base_url
url_sonarr_short = protocol_sonarr + "://" + settings.sonarr.ip + ":" + settings.sonarr.port
# radarr url
if settings.radarr.ssl:
protocol_radarr = "https"
else:
protocol_radarr = "http"
if settings.radarr.base_url == '':
settings.radarr.base_url = "/"
if not settings.radarr.base_url.startswith("/"):
settings.radarr.base_url = "/" + settings.radarr.base_url
if settings.radarr.base_url.endswith("/"):
settings.radarr.base_url = settings.radarr.base_url[:-1]
url_radarr = protocol_radarr + "://" + settings.radarr.ip + ":" + settings.radarr.port + settings.radarr.base_url
url_radarr_short = protocol_radarr + "://" + settings.radarr.ip + ":" + settings.radarr.port

@ -0,0 +1,64 @@
# coding=utf-8
import os
import re
from config import settings
def path_replace(path):
for path_mapping in settings.general.path_mappings:
if path_mapping[0] in path:
path = path.replace(path_mapping[0], path_mapping[1])
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
path = path.replace('/', '\\')
elif path.startswith('/'):
path = path.replace('\\', '/')
break
return path
def path_replace_reverse(path):
for path_mapping in settings.general.path_mappings:
if path_mapping[1] in path:
path = path.replace(path_mapping[1], path_mapping[0])
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
path = path.replace('/', '\\')
elif path.startswith('/'):
path = path.replace('\\', '/')
break
return path
def path_replace_movie(path):
for path_mapping in settings.general.path_mappings_movie:
if path_mapping[0] in path:
path = path.replace(path_mapping[0], path_mapping[1])
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
path = path.replace('/', '\\')
elif path.startswith('/'):
path = path.replace('\\', '/')
break
return path
def path_replace_reverse_movie(path):
for path_mapping in settings.general.path_mappings_movie:
if path_mapping[1] in path:
path = path.replace(path_mapping[1], path_mapping[0])
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
path = path.replace('/', '\\')
elif path.startswith('/'):
path = path.replace('\\', '/')
break
return path
def pp_replace(pp_command, episode, subtitles, language, language_code2, language_code3):
pp_command = pp_command.replace('{{directory}}', os.path.dirname(episode))
pp_command = pp_command.replace('{{episode}}', episode)
pp_command = pp_command.replace('{{episode_name}}', os.path.splitext(os.path.basename(episode))[0])
pp_command = pp_command.replace('{{subtitles}}', subtitles)
pp_command = pp_command.replace('{{subtitles_language}}', language)
pp_command = pp_command.replace('{{subtitles_language_code2}}', language_code2)
pp_command = pp_command.replace('{{subtitles_language_code3}}', language_code3)
return pp_command
Loading…
Cancel
Save