__init__.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/usr/bin/env python3.5
  2. # Copyright 2017 Digital
  3. #
  4. # This file is part of DigiLib.
  5. #
  6. # DigiLib is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # DigiLib is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with DigiLib. If not, see <http://www.gnu.org/licenses/>.
  18. import logging
  19. import random
  20. import string
  21. import sys
  22. import time
  23. import yaml
  24. log = logging.getLogger(__name__+"")
  25. LOREM_IPSUM = """Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  26. Pellentesque vel mauris non odio pharetra ultricies quis eu turpis.
  27. Proin et tortor eu magna ultricies facilisis tincidunt vehicula nisi.
  28. Donec hendrerit massa id viverra lobortis.
  29. In sed nisl a metus gravida faucibus.
  30. Praesent bibendum mi semper, sagittis mi sit amet, auctor dui.
  31. Sed ac dui sagittis quam ultricies dapibus.
  32. In non elit non felis convallis vestibulum.
  33. Vivamus ornare ante suscipit faucibus pulvinar.
  34. Cras consequat nulla quis quam faucibus mollis.
  35. Nulla dictum sapien in justo sagittis malesuada.
  36. Sed ornare orci quis laoreet elementum.
  37. Sed ornare lacus ac ipsum vulputate vulputate.
  38. Sed accumsan ante nec magna sollicitudin maximus.
  39. Aliquam condimentum magna nec convallis efficitur.
  40. Nam posuere mauris et dui pulvinar, quis iaculis leo aliquam.
  41. Nunc cursus arcu et leo vehicula, quis feugiat mi semper.
  42. """
  43. class Container():
  44. # This class should only be used as a storage space for variables.
  45. pass
  46. config_files = [
  47. "config/controllers.yaml",
  48. "config/commands.yaml",
  49. ]
  50. def load_files(file_list,call):
  51. if not type(file_list) is list:
  52. file_list = [file_list]
  53. for file_ in file_list:
  54. with open(file_,"r") as f:
  55. data = f.read()
  56. config = yaml.safe_load(data)
  57. call(config)
  58. def parse_to_int_list(
  59. parse,*args,
  60. delimeter=",",
  61. true_list=["true"],
  62. false_list=["false"]):
  63. if type(parse) is list:
  64. return parse
  65. elif type(parse) is int:
  66. return [parse]
  67. elif type(parse) is bool:
  68. return [int(parse)]
  69. elif type(parse) is not str:
  70. raise ValueError("Failed to parse value {}".format(parse))
  71. if parse.lower() in true_list:
  72. return [1]
  73. elif parse.lower() in false_list:
  74. return [0]
  75. parse = parse.split(delimeter)
  76. for part in parse.copy():
  77. parse.remove(part)
  78. parse.append(int(part))
  79. return parse
  80. #