# Path: backends/log.py
# class Log():
# 
#     def __init__(self, logfile):
#         self.logfile = logfile
#         self.log = None
# 
#     def __open(self):
#         """ Open log file for writing. """
#         try:
#             self.log = open(self.logfile, "a+")
#         except:
#             self.log = None
# 
#     def __close(self):
#         """ Close log file. """
#         if self.log is not None:
#             self.log.close()
# 
#     def __get_time(self):
#         """ Return current time string. """
#         return strftime("%a %d %H:%M:%S : ")
# 
#     def write(self, message):
#         self.__open()
#         if self.log is None:
#             return
#         line = self.__get_time() + message + "\n"
#         self.log.write(line)
#         self.__close()


from backends.log import Log
    from backends.session.util.config import SessionConfig
    from backends.system.util.config import SystemConfig
import sys
import os.path

# Power management scripts locations
PM_DEVICES_POWER_MANAGEMENT = "/usr/lib/pm-utils/power.d/samsung-tools_devices-power-management"
PM_USB_AUTOSUSPEND = "/usr/lib/pm-utils/power.d/samsung-tools_usb-autosuspend"
PM_VM_WRITEBACK_TIME = "/usr/lib/pm-utils/power.d/samsung-tools_vm-writeback-time"
PM_SCRIPTS = (PM_DEVICES_POWER_MANAGEMENT,
              PM_USB_AUTOSUSPEND,
              PM_VM_WRITEBACK_TIME)

###
# Stuff for session service only
###
if os.path.basename(sys.argv[0]) == "session-service.py":
    # Config/Log
    SESSION_CONFIG_FILE = "/etc/samsung-tools/session.conf"
    USER_DIRECTORY = os.path.join(os.getenv('HOME'), ".samsung-tools")
    USER_CONFIG_FILE = os.path.join(
        USER_DIRECTORY,
        os.path.basename(SESSION_CONFIG_FILE))
    SESSION_LOG_FILE = os.path.join(USER_DIRECTORY, "log")
    sessionlog = Log(SESSION_LOG_FILE)
    sessionconfig = SessionConfig(USER_CONFIG_FILE)

###
# Stuff for system service only
###
if os.path.basename(sys.argv[0]) == "system-service.py":
    # Config/Log
    SYSTEM_CONFIG_FILE = "/etc/samsung-tools/system.conf"
    SYSTEM_LOG_FILE = "/var/log/samsung-tools.log"

# Path: backends/log.py
# class Log():
# 
#     def __init__(self, logfile):
#         self.logfile = logfile
#         self.log = None
# 
#     def __open(self):
#         """ Open log file for writing. """
#         try:
#             self.log = open(self.logfile, "a+")
#         except:
#             self.log = None
# 
#     def __close(self):
#         """ Close log file. """
#         if self.log is not None:
#             self.log.close()
# 
#     def __get_time(self):
#         """ Return current time string. """
#         return strftime("%a %d %H:%M:%S : ")
# 
#     def write(self, message):
#         self.__open()
#         if self.log is None:
#             return
#         line = self.__get_time() + message + "\n"
#         self.log.write(line)
#         self.__close()


# Path: backends/globals.py
from backends.log import Log
    from backends.session.util.config import SessionConfig
    from backends.system.util.config import SystemConfig
import sys
import os.path


# Power management scripts locations
PM_DEVICES_POWER_MANAGEMENT = "/usr/lib/pm-utils/power.d/samsung-tools_devices-power-management"
PM_USB_AUTOSUSPEND = "/usr/lib/pm-utils/power.d/samsung-tools_usb-autosuspend"
PM_VM_WRITEBACK_TIME = "/usr/lib/pm-utils/power.d/samsung-tools_vm-writeback-time"
PM_SCRIPTS = (PM_DEVICES_POWER_MANAGEMENT,
              PM_USB_AUTOSUSPEND,
              PM_VM_WRITEBACK_TIME)

###
# Stuff for session service only
###
if os.path.basename(sys.argv[0]) == "session-service.py":
    # Config/Log
    SESSION_CONFIG_FILE = "/etc/samsung-tools/session.conf"
    USER_DIRECTORY = os.path.join(os.getenv('HOME'), ".samsung-tools")
    USER_CONFIG_FILE = os.path.join(
        USER_DIRECTORY,
        os.path.basename(SESSION_CONFIG_FILE))
    SESSION_LOG_FILE = os.path.join(USER_DIRECTORY, "log")
    sessionlog = Log(SESSION_LOG_FILE)
    sessionconfig = SessionConfig(USER_CONFIG_FILE)

###
# Stuff for system service only
###
if os.path.basename(sys.argv[0]) == "system-service.py":
    # Config/Log
    SYSTEM_CONFIG_FILE = "/etc/samsung-tools/system.conf"
    SYSTEM_LOG_FILE = "/var/log/samsung-tools.log"

    systemlog = Log(SYSTEM_LOG_FILE)