Browse Source

Improved workflow for load/save configs, other tweaks.

master
treyzania 4 years ago
parent
commit
911a1e7ac8
1 changed files with 41 additions and 43 deletions
  1. 41
    43
      yarrbox.py

+ 41
- 43
yarrbox.py View File

@@ -8,18 +8,20 @@ import json

# Each entry here is key => (label, hide input)
PROPS = OrderedDict([
('net.vpn.provider', ('VPN Provider', 'See https://github.com/sscraggles/docker-deluge-openvpn for options')),
('net.vpn.username', ('VPN Username', None)),
('net.vpn.password', ('VPN Password', None)),
('vol.media.movies', ('Movies Storage Path', None)),
('vol.media.tv', ('TV Storage Path', None)),
('vol.media.anime', ('Anime Storage Path', None)),
('vol.conf.torrent', ('Torrent Data Dir', 'Directory for torrent client(s) to store configs and state')),
('vol.conf.bootybot', ('Bootybot Config Dir', 'Config directory for Bootybot')),
('vol.conf.plex', ('Plex Data Dir', 'Directory for all of Plex\'s stuff')),
('vol.ingest.torrent', ('Torrent Ingest Dir', 'Directory to drop .torrent files to download through VPN')),
('vol.ingest.media', ('Media Ingest Dir', 'Directory to drop full media files for Bootybot to later process')),
('vol.work.plextrans', ('Plex Transcode Dir', 'Directory for Plex to store certain transcoded files')),
('net.vpn.host', ('VPN Provider', 'See https://github.com/sscraggles/docker-deluge-openvpn for options')),
('net.vpn.username', ('VPN Username', None)),
('net.vpn.password', ('VPN Password', None)),
('vol.media.movies', ('Movies Storage Path', None)),
('vol.media.tv', ('TV Storage Path', None)),
('vol.media.anime', ('Anime Storage Path', None)),
('vol.conf.torrent', ('Torrent Data Dir', 'Directory for torrent client(s) to store configs and state')),
('vol.conf.bootybot', ('Bootybot Config Dir', 'Config directory for Bootybot')),
('vol.conf.plex', ('Plex Data Dir', 'Directory for all of Plex\'s stuff (databases, etc.)')),
('vol.ingest.torrent', ('Torrent Ingest Dir', 'Directory to drop .torrent files to download through VPN')),
('vol.ingest.media', ('Media Ingest Dir', 'Directory to drop full media files for Bootybot to later process')),
('vol.torrent.active', ('Torrent Download Dir', 'Directory for actively downloading torrents to be stored')),
('vol.torrent.seed', ('Torrent Seeding Dir', 'Directory to move torrents after download finished for seeding')),
('vol.work.plextrans', ('Plex Transcode Dir', 'Directory for Plex to store certain transcoded files')),
('vol.work.bootybot', ('Bootybot Extract Dir', 'Directory where Bootybot temporarily stores contents of archives, etc'))
])

@@ -44,10 +46,12 @@ def ask_config_opt(config, key):
# Actually ask for input.
if not nodisp:
val = input(PROMPT)
if len(val) > 0:
config[key] = val
else:
val = getpass.getpass('(hidden) ' + PROMPT)
config[key] = val
if len(val) > 0:
config[key] = val

def apply_template_settings(tmplt, settings):
cur = tmplt
@@ -55,6 +59,23 @@ def apply_template_settings(tmplt, settings):
cur = cur.replace('${' + k + '}', v)
return cur

def read_config():
try:
with open('config.json', 'r') as f:
return json.loads(f.read())
except e:
print('error loading config, is it missing or corrupt?', e)
sys.exit(1)

def save_config(cfg):
try:
with open('config.json', 'w') as f:
f.write(json.dumps(cfg, sort_keys=True, indent=' '))
f.write('\n') # json.dumps doesn't put trailing newline
except e:
print('error writing config, do we have write perms?', e)
sys.exit(1)

USAGE_STR = 'usage: yarrbox.py <init|edit|generate>'

def main():
@@ -71,23 +92,11 @@ def main():
print('')

# Write it to file
try:
with open('config.json', 'w') as f:
f.write(json.dumps(cfg))
except e:
print('error writing config, do we have write perms?', e)
return
save_config(cfg)

elif command == 'edit':
print('Leave options blank to leave unchanged!\n')
# Read the file.
cfg = None
try:
with open('config.json', 'r') as f:
cfg = json.loads(f.read())
except e:
print('error loading config, is it missing or corrupt?', e)
return
cfg = read_config()

# Go through all the properties again and reread them.
for k in PROPS:
@@ -95,22 +104,11 @@ def main():
print('')

# Write it back.
try:
with open('config.json', 'w') as f:
f.write(json.dumps(cfg))
except e:
print('error writing config, do we have write perms?', e)
return
save_config(cfg)

elif command == 'generate':
# Load the config.
cfg = None
try:
with open('config.json', 'r') as f:
cfg = json.loads(f.read())
except e:
print('error loading config, is it missing or corrupt?', e)
return
cfg = read_config()

tmplt = None
try:
@@ -118,7 +116,7 @@ def main():
tmplt = f.read()
except e:
print('error reading template:', e)
return
sys.exit(1)

gen = apply_template_settings(tmplt, cfg)
try:
@@ -126,7 +124,7 @@ def main():
f.write(gen)
except e:
print('error writing generated file, do we have write perms?', e)
return
sys.exit(1)
else:
print(USAGE_STR)


Loading…
Cancel
Save