# Path: sendit/apps/watcher/commands.py
# def start_watcher(request=None,as_command=False):
#     '''start the watcher, if the process is not started.
#     '''
# 
#     # Verify INOTIFIER_WATCH_PATHS is defined and non-empty
#     try:
#         assert settings.INOTIFIER_WATCH_PATHS
#     except (AttributeError, AssertionError):
#         return watcher_error(message="Missing/empty settings/watcher.py INOTIFY_WATCH_PATHS",
#                              as_command=as_command,
#                              request=request)
# 
# 
#     # Verify INOTIFIER_WATCH_PATHS is properly formatted
#     try:
#         length_3 = [len(tup) == 3 for tup in settings.INOTIFIER_WATCH_PATHS]
#         assert all(length_3)
#     except AssertionError:
#         message = '''setting INOTIFIER_WATCH_PATHS should be an iterable of
#                  3-tuples of the form [ ("/path1/", <pyinotify event mask>, <processor cls>), ]'''
#         return watcher_error(message=message,
#                              as_command=as_command,
#                              request=request)
# 
# 
#     error_message = verify_monitor_paths(return_message=True)
#     if error_message is not None:
#         return watcher_error(message=error_message,
#                              as_command=as_command,
#                              request=request)
# 
# 
#     # Setup watches using pyinotify
#     notifier = get_notifier()
# 
#     # Error with import or setup returns None
#     if notifier is None:
#         return watcher_error(message="Cannot import pyinotify.",
#                              as_command=as_command,
#                              request=request)
# 
#     pid_file = get_pid_file()
# 
#     # Daemonize, killing any existing process specified in pid file
#     daemon_kwargs = get_daemon_kwargs()
#     notifier.loop(daemonize=True, pid_file=pid_file, **daemon_kwargs)
#     watcher_message(message="Dicom watching has been started.",request=request)


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

class Command(BaseCommand):
    help = '''Starts monitoring the instance /data folder for file events,
              specifically for the addition of complete DICOM series datasets'''


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

# Path: sendit/apps/watcher/commands.py
# def start_watcher(request=None,as_command=False):
#     '''start the watcher, if the process is not started.
#     '''
# 
#     # Verify INOTIFIER_WATCH_PATHS is defined and non-empty
#     try:
#         assert settings.INOTIFIER_WATCH_PATHS
#     except (AttributeError, AssertionError):
#         return watcher_error(message="Missing/empty settings/watcher.py INOTIFY_WATCH_PATHS",
#                              as_command=as_command,
#                              request=request)
# 
# 
#     # Verify INOTIFIER_WATCH_PATHS is properly formatted
#     try:
#         length_3 = [len(tup) == 3 for tup in settings.INOTIFIER_WATCH_PATHS]
#         assert all(length_3)
#     except AssertionError:
#         message = '''setting INOTIFIER_WATCH_PATHS should be an iterable of
#                  3-tuples of the form [ ("/path1/", <pyinotify event mask>, <processor cls>), ]'''
#         return watcher_error(message=message,
#                              as_command=as_command,
#                              request=request)
# 
# 
#     error_message = verify_monitor_paths(return_message=True)
#     if error_message is not None:
#         return watcher_error(message=error_message,
#                              as_command=as_command,
#                              request=request)
# 
# 
#     # Setup watches using pyinotify
#     notifier = get_notifier()
# 
#     # Error with import or setup returns None
#     if notifier is None:
#         return watcher_error(message="Cannot import pyinotify.",
#                              as_command=as_command,
#                              request=request)
# 
#     pid_file = get_pid_file()
# 
#     # Daemonize, killing any existing process specified in pid file
#     daemon_kwargs = get_daemon_kwargs()
#     notifier.loop(daemonize=True, pid_file=pid_file, **daemon_kwargs)
#     watcher_message(message="Dicom watching has been started.",request=request)


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


class Command(BaseCommand):
    help = '''Starts monitoring the instance /data folder for file events,
              specifically for the addition of complete DICOM series datasets'''


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

        start_watcher(as_command=True)