#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  DShortDaemon.py
#  
#  Copyright (C) 2016, LLC "NTC IT ROSA"
#  Authors:
#     Michl Voznesensky <m.voznesensky@rosalinux.ru>
#  
#  This file is path of DShort
#  
#  DShort is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 3 of the License, or
#  (at your option) any later version.
#  
#  DShort is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with DShort; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#  
# 

import sys
import dshort.dshort as app
from dshort.daemon import Daemon

import os

class MyDaemon(Daemon):
	def run(self):
		app.start()

if __name__ == '__main__':
	daemon = MyDaemon(os.path.expanduser("~") + '/.cache/DShort.pid')
	if len(sys.argv) == 2:
		if 'start' == sys.argv[1]:
			daemon.start()
		elif 'stop' == sys.argv[1]:
			daemon.stop()
		elif 'restart' == sys.argv[1]:
			daemon.restart()
		elif 'startup' == sys.argv[1]:
			daemon.startup()
		else:
			print "Unknown command"
			sys.exit(2)
		sys.exit(0)
	
	else:
		print "usage: %s start|stop|restart" % sys.argv[0]
		sys.exit(2)