# Path: sendit/apps/watcher/commands.py
# def stop_watcher(request=None,as_command=False):
#     '''stop the watcher, if the process is started. Returns True
#     if success.
#     '''
# 
#     pid_file = get_pid_file()
# 
#     if os.path.exists(pid_file):
#         pid = int(open(pid_file).read())
# 
#         import signal
#         try:
#             os.kill(pid, signal.SIGHUP)
#         except OSError:
#             os.remove(pid_file)
#             # This needs testing - shouldn't normally trigger when stopped
#             return watcher_error(message="Cleaned up pid file %s" %(pid),
#                                  as_command=as_command,
#                                  request=request)
#         time.sleep(2)
# 
#         try:
#             os.kill(pid, signal.SIGKILL)
#         except OSError:
#             pass
# 
#         os.remove(pid_file)
#         watcher_message(message="Dicom watching has been stopped.",request=request)
#     else:
#         return watcher_error(message="No pid file exists. The watched is not started.",
#                              as_command=as_command,
#                              request=request)
#     if not as_command:
#         return True


from sendit.apps.watcher.commands import stop_watcher
from django.core.management.base import (
    BaseCommand
)

class Command(BaseCommand):
    help = 'Stops monitoring the /data directory'

    def handle(self, *args, **options):

# Path: sendit/apps/watcher/commands.py
# def stop_watcher(request=None,as_command=False):
#     '''stop the watcher, if the process is started. Returns True
#     if success.
#     '''
# 
#     pid_file = get_pid_file()
# 
#     if os.path.exists(pid_file):
#         pid = int(open(pid_file).read())
# 
#         import signal
#         try:
#             os.kill(pid, signal.SIGHUP)
#         except OSError:
#             os.remove(pid_file)
#             # This needs testing - shouldn't normally trigger when stopped
#             return watcher_error(message="Cleaned up pid file %s" %(pid),
#                                  as_command=as_command,
#                                  request=request)
#         time.sleep(2)
# 
#         try:
#             os.kill(pid, signal.SIGKILL)
#         except OSError:
#             pass
# 
#         os.remove(pid_file)
#         watcher_message(message="Dicom watching has been stopped.",request=request)
#     else:
#         return watcher_error(message="No pid file exists. The watched is not started.",
#                              as_command=as_command,
#                              request=request)
#     if not as_command:
#         return True


# Path: sendit/apps/watcher/management/commands/stop_watcher.py
from sendit.apps.watcher.commands import stop_watcher
from django.core.management.base import (
    BaseCommand
)


class Command(BaseCommand):
    help = 'Stops monitoring the /data directory'

    def handle(self, *args, **options):

        stop_watcher(as_command=True)