# Path: pyilper/pilcore.py
# def buildconfigfilename(progname,filename,configversion,instance,production):
# #
# #  determine config file name
# #
#    fname=filename+instance+configversion
#    if not production:
#       fname+= "d"
# #
# #  determine path (os dependend)
# #
#    userhome=os.path.expanduser("~")
# 
#    if platform.system()=="Linux":
# #
# #     LINUX
# #        
#       configpath=os.path.join(userhome,".config",progname)
#    elif platform.system()=="Windows":
# #
# #     Windows
# #
#       configpath=os.path.join(os.environ['APPDATA'],progname)
#    elif platform.system()=="Darwin":
# #
# #     Mac OS X
# #
#       configpath=os.path.join(userhome,"Library","Application Support",progname)
# #
#    else:
# #
# #     Fallback
# #
#       configpath=os.path.join(userhome,progname)
#    configfilename=os.path.join(configpath,fname)
#     
#    return configfilename,configpath


import json
import os
from  .pilcore import buildconfigfilename
# 08.02.2016 jsi:
# - changed os detection to platform.system()
# 14.04.2016 jsi
# - use APPDATA environment variable for config directory on Windows
# - use json to serialize program configuration
# 18.04.2016 jsi
# - use pretty print json
# 18.09.2016 jsi
# - add instance to configuration file name
# 14.10.2016 jsi
# - added filename parameter to __init__
# 17.08.2016 jsi
# - added diagnostics to JSON encode/decode error messages
# 12.12.2021 jsi
# - add configversion parameter to constructor
# - use buildconfigfilename function from pilcore


class ConfigError(Exception):
   def __init__(self,msg,add_msg= None):
      self.msg= msg
      self.add_msg = add_msg


class cls_userconfig:

   def __init__(self,progname,filename,configversion,instance,production):
#
#  determine config file name
#

# Path: pyilper/pilcore.py
# def buildconfigfilename(progname,filename,configversion,instance,production):
# #
# #  determine config file name
# #
#    fname=filename+instance+configversion
#    if not production:
#       fname+= "d"
# #
# #  determine path (os dependend)
# #
#    userhome=os.path.expanduser("~")
# 
#    if platform.system()=="Linux":
# #
# #     LINUX
# #        
#       configpath=os.path.join(userhome,".config",progname)
#    elif platform.system()=="Windows":
# #
# #     Windows
# #
#       configpath=os.path.join(os.environ['APPDATA'],progname)
#    elif platform.system()=="Darwin":
# #
# #     Mac OS X
# #
#       configpath=os.path.join(userhome,"Library","Application Support",progname)
# #
#    else:
# #
# #     Fallback
# #
#       configpath=os.path.join(userhome,progname)
#    configfilename=os.path.join(configpath,fname)
#     
#    return configfilename,configpath


# Path: pyilper/userconfig.py
import json
import os
from  .pilcore import buildconfigfilename

# 08.02.2016 jsi:
# - changed os detection to platform.system()
# 14.04.2016 jsi
# - use APPDATA environment variable for config directory on Windows
# - use json to serialize program configuration
# 18.04.2016 jsi
# - use pretty print json
# 18.09.2016 jsi
# - add instance to configuration file name
# 14.10.2016 jsi
# - added filename parameter to __init__
# 17.08.2016 jsi
# - added diagnostics to JSON encode/decode error messages
# 12.12.2021 jsi
# - add configversion parameter to constructor
# - use buildconfigfilename function from pilcore


class ConfigError(Exception):
   def __init__(self,msg,add_msg= None):
      self.msg= msg
      self.add_msg = add_msg


class cls_userconfig:

   def __init__(self,progname,filename,configversion,instance,production):
#
#  determine config file name
#

      self.__configfile__,self.__configpath__=buildconfigfilename(progname,filename,configversion,instance,production)