Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

yarrbox.py 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. def apply_template_settings(tmplt, settings):
  43. cur = tmplt
  44. for k, v in settings.items():
  45. cur = cur.replace('${' + k + '}', v)
  46. return cur
  47. USAGE_STR = 'usage: yarrbox.py <init|edit|generate>'
  48. def main():
  49. if len(sys.argv) != 2:
  50. print(USAGE_STR)
  51. sys.exit(1)
  52. command = sys.argv[1]
  53. if command == 'init':
  54. # Make a new config object and read all the properties.
  55. cfg = {}
  56. for k in PROPS:
  57. ask_config_opt(cfg, k)
  58. print('')
  59. # Write it to file
  60. try:
  61. with open('config.json', 'w') as f:
  62. f.write(json.dumps(cfg))
  63. except e:
  64. print('error writing config, do we have write perms?', e)
  65. return
  66. elif command == 'edit':
  67. print('Leave options blank to leave unchanged!\n')
  68. # Read the file.
  69. cfg = None
  70. try:
  71. with open('config.json', 'r') as f:
  72. cfg = json.loads(f.read())
  73. except e:
  74. print('error loading config, is it missing or corrupt?', e)
  75. return
  76. # Go through all the properties again and reread them.
  77. for k in PROPS:
  78. ask_config_opt(cfg, k)
  79. print('')
  80. # Write it back.
  81. try:
  82. with open('config.json', 'w') as f:
  83. f.write(json.dumps(cfg))
  84. except e:
  85. print('error writing config, do we have write perms?', e)
  86. return
  87. elif command == 'generate':
  88. # Load the config.
  89. cfg = None
  90. try:
  91. with open('config.json', 'r') as f:
  92. cfg = json.loads(f.read())
  93. except e:
  94. print('error loading config, is it missing or corrupt?', e)
  95. return
  96. tmplt = None
  97. try:
  98. with open('compose-template.yml', 'r') as f:
  99. tmplt = f.read()
  100. except e:
  101. print('error reading template:', e)
  102. return
  103. gen = apply_template_settings(tmplt, cfg)
  104. try:
  105. with open('docker-compose.yml', 'w') as f:
  106. f.write(gen)
  107. except e:
  108. print('error writing generated file, do we have write perms?', e)
  109. return
  110. else:
  111. print(USAGE_STR)
  112. if __name__ == '__main__':
  113. main()