Пример #1
0
class TestConfig:
  def setup_method(self, method):
    self.contents = StringIO('''
[startup]
launch = LAUNCH_KEY
    ''')
    self.config = Config()
    self.config.load(self.contents)

  def testAutoLaunchKeyIsLoaded(self):
    assert self.config.getLaunchCommand() == 'LAUNCH_KEY'
Пример #2
0
  def setup_method(self, method):
    self.contents = StringIO('''
[startup]
launch = LAUNCH_KEY
    ''')
    self.config = Config()
    self.config.load(self.contents)
Пример #3
0
  def setup_method(self, method):
    self.logPath = 'some/path'
    self.contents = StringIO('''
[log]
path = %s
    ''' % self.logPath)
    self.config = Config()
    self.config.load(self.contents)
Пример #4
0
  def setup_method(self, method):
    self.contents = StringIO('''
[KEY_NAME]
process = processName
search = searchString
needsKill = false
[KILL_NAME]
process = anotherProcessName
needsKill = true
    ''')
    self.config = Config()
    self.config.load(self.contents)
Пример #5
0
class TestConfig:
  def setup_method(self, method):
    self.contents = StringIO('''
[KEY_NAME]
process = processName
search = searchString
needsKill = false
[KILL_NAME]
process = anotherProcessName
needsKill = true
    ''')
    self.config = Config()
    self.config.load(self.contents)

  def testCommandsLoadedWithCorrectProcess(self):
    assert self.config.getCommand('KEY_NAME').process == 'processName'

  def testCommandsLoadedWithCorrectSearchString(self):
    assert self.config.getCommand('KEY_NAME').search == 'searchString'

  def testCommandsLoadedWithCorrectKillFlagWhenFalse(self):
    assert self.config.getCommand('KEY_NAME').needsKill == False

  def testCommandsLoadedWithCorrectKillFlagWhenTrue(self):
    assert self.config.getCommand('KILL_NAME').needsKill == True
Пример #6
0
  def __init__(self, ostools = None, config = None):
    self.ostools = ostools
    if not self.ostools:
      self.ostools = OsTools()

    self.config = config
    if not self.config:
      self.config = Config()

    self._startLogging()
    self._loadConfig()
    self._startFileLogging()

    self.irReader = IrReader()
    self.processManager = ProcessManager()
Пример #7
0
class TestConfig:
  def setup_method(self, method):
    self.logPath = 'some/path'
    self.contents = StringIO('''
[log]
path = %s
    ''' % self.logPath)
    self.config = Config()
    self.config.load(self.contents)

  def testLogPathIsSetToUserHomeDirectoryIfNoneGiven(self):
    emptyConfig = StringIO('')
    self.config = Config()
    self.config.load(emptyConfig)
    assert self.config.getLogPath() == os.path.expanduser(os.path.join('~', '.' + DEFAULT_LOG_FILE))

  def testLogPathMatchesConfigured(self):
    assert self.config.getLogPath() == self.logPath
Пример #8
0
class HtpcLauncherApp:
  def __init__(self, ostools = None, config = None):
    self.ostools = ostools
    if not self.ostools:
      self.ostools = OsTools()

    self.config = config
    if not self.config:
      self.config = Config()

    self._startLogging()
    self._loadConfig()
    self._startFileLogging()

    self.irReader = IrReader()
    self.processManager = ProcessManager()

  def run(self):
    try:
      self._processIrCode(self.config.getLaunchCommand())

      while True:
        try:
          try:
            code = self.irReader.getNextCode()
          except IrReaderError:
            time.sleep(5)
            continue
          self._processIrCode(code)
        except KeyboardInterrupt:
          break
    except:
      self.log.exception('Unhandled exception')

  def _startFileLogging(self):
    formatter = logging.Formatter('%(asctime)s %(levelname)s - %(message)s')
    filePath = os.path.expanduser(DEFAULT_LOG_FILE)

    self.log.info('Logging to %s', self.config.getLogPath())
    handler = self.ostools.getRotatingLogHandler(self.config.getLogPath(), maxBytes = 1024000, backupCount = 5)
    handler.setFormatter(formatter)
    self.log.addHandler(handler)

  def _startLogging(self):
    self.log = logging.getLogger()
    self.log.setLevel(logging.DEBUG)
    self.log.addHandler(logging.StreamHandler())

  def _loadConfig(self):
    self.log.info('Loading config file from home directory')
    configFile = self.ostools.openUserFile('.%s' % DEFAULT_CONF_FILE)

    if not configFile:
      self.log.info('Config not found in home directory; loading from system config')
      configFile = self.ostools.openSystemConfFile(DEFAULT_CONF_FILE)

    if not configFile:
      raise RuntimeError('Failed to find configuration file')
    self.config.load(configFile)

  def _processIrCode(self, code):
    command = self.config.getCommand(code)
    if not command:
      return
    self.processManager.execute(command)
Пример #9
0
 def testLogPathIsSetToUserHomeDirectoryIfNoneGiven(self):
   emptyConfig = StringIO('')
   self.config = Config()
   self.config.load(emptyConfig)
   assert self.config.getLogPath() == os.path.expanduser(os.path.join('~', '.' + DEFAULT_LOG_FILE))