You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

yarrbox.py 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env python3
  2. from collections import OrderedDict
  3. import sys
  4. import getpass
  5. import json
  6. # Each entry here is key => (label, hide input)
  7. PROPS = OrderedDict([
  8. ('net.vpn.provider', ('VPN Provider', 'See https://github.com/sscraggles/docker-deluge-openvpn for options')),
  9. ('net.vpn.username', ('VPN Username', None)),
  10. ('net.vpn.password', ('VPN Password', None)),
  11. ('vol.media.movies', ('Movies Storage Path', None)),
  12. ('vol.media.tv', ('TV Storage Path', None)),
  13. ('vol.media.anime', ('Anime Storage Path', None)),
  14. ('vol.conf.torrent', ('Torrent Data Dir', 'Directory for torrent client(s) to store configs and state')),
  15. ('vol.conf.bootybot', ('Bootybot Config Dir', 'Config directory for Bootybot')),
  16. ('vol.conf.plex', ('Plex Data Dir', 'Directory for all of Plex\'s stuff')),
  17. ('vol.ingest.torrent', ('Torrent Ingest Dir', 'Directory to drop .torrent files to download through VPN')),
  18. ('vol.ingest.media', ('Media Ingest Dir', 'Directory to drop full media files for Bootybot to later process')),
  19. ('vol.work.plextrans', ('Plex Transcode Dir', 'Directory for Plex to store certain transcoded files')),
  20. ('vol.work.bootybot', ('Bootybot Extract Dir', 'Directory where Bootybot temporarily stores contents of archives, etc'))
  21. ])
  22. PROMPT = '> '
  23. def ask_config_opt(config, key):
  24. label, desc = PROPS[key]
  25. nodisp = 'password' in key
  26. # Print titles
  27. title = '= ' + label + ' ='
  28. bars = '=' * len(title)
  29. print(bars + '\n' + title + '\n' + bars)
  30. if desc is not None:
  31. print(desc)
  32. # Current state stuff.
  33. if key in config:
  34. if not nodisp:
  35. print('Current: \'' + config[key] + '\'')
  36. # Actually ask for input.
  37. if not nodisp:
  38. val = input(PROMPT)
  39. else:
  40. val = getpass.getpass('(hidden) ' + PROMPT)
  41. config[key] = val
  42. USAGE_STR = 'usage: yarrbox.py <init|edit|generate>'
  43. def main():
  44. if len(sys.argv) != 2:
  45. print(USAGE_STR)
  46. sys.exit(1)
  47. command = sys.argv[1]
  48. if command == 'init':
  49. # Make a new config object and read all the properties.
  50. cfg = {}
  51. for k in PROPS:
  52. ask_config_opt(cfg, k)
  53. print('')
  54. # Write it to file
  55. with open('config.json', 'w') as f:
  56. f.write(json.dumps(cfg))
  57. elif command == 'edit':
  58. print('Leave options blank to leave unchanged!\n')
  59. # Read the file.
  60. cfg = None
  61. with open('config.json', 'r') as f:
  62. cfg = json.loads(f.read())
  63. # Go through all the properties again and reread them.
  64. for k in PROPS:
  65. ask_config_opt(cfg, k)
  66. print('')
  67. # Write it back.
  68. with open('config.json', 'w') as f:
  69. f.write(json.dumps(cfg))
  70. else:
  71. print(USAGE_STR)
  72. if __name__ == '__main__':
  73. main()