settings.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import os
  4. import datetime
  5. CONF_FILES = [
  6. "himport.conf",
  7. "himport.conf.local",
  8. ]
  9. __settings = None
  10. def get(opt):
  11. ret = __settings.get(opt)
  12. if ret is None:
  13. raise "Settings not found"
  14. return ret
  15. def get_ledger_account(code):
  16. account_names = __settings.get("PC_NAMES")
  17. if code in account_names:
  18. return account_names[code]
  19. else:
  20. return code
  21. __settings = {}
  22. for conf_file in CONF_FILES:
  23. if os.path.isfile(conf_file):
  24. execfile(conf_file, __settings)
  25. if __settings is None:
  26. raise Exception(
  27. "Need a configuration file. One of %s" % ','.join(CONF_FILES))
  28. if 'OUTPUT_DIR' not in __settings:
  29. raise Exception('need OUTPUT_DIR settings')
  30. if 'PC_REFS' not in __settings:
  31. raise Exception('need PC_REFS settings')
  32. if 'PC_NAMES' not in __settings:
  33. raise Exception('need PC_NAMES settings')
  34. if 'ACCOUNTING_YEARS' in __settings:
  35. __settings['ACCOUNTING_YEARS'] = [(
  36. year,
  37. datetime.datetime.strptime(dbegin, "%Y/%m/%d").date(),
  38. datetime.datetime.strptime(dend, "%Y/%m/%d").date(),
  39. ) for (year, dbegin, dend) in __settings['ACCOUNTING_YEARS']]