Changeset - 8f96c640d09d
[Not reviewed]
0 1 0
Lance Edgar (lance) - 11 years ago 2013-04-21 12:13:34
lance@edbob.org
Added admin rights check for Windows file monitor registration.

Now the registration process is checked for an "elevated token" and if none is
found, a message is displayed and it exits without attempting the registration.

fixes #5
1 file changed with 68 insertions and 8 deletions:
0 comments (0 inline, 0 general)
rattail/commands.py
Show inline comments
 
@@ -80,22 +80,82 @@ class DatabaseSyncCommand(commands.Subcommand):
 
            dbsync.stop_daemon()
 

	
 

	
 
class FileMonitorCommand(commands.FileMonitorCommand):
 
class FileMonitorCommand(commands.Subcommand):
 
    """
 
    Interacts with the file monitor service; called as ``rattail filemon``.
 
    This command expects a subcommand; one of the following:
 

	
 
    See :class:`edbob.commands.FileMonitorCommand` for more information.
 
    * ``rattail filemon start``
 
    * ``rattail filemon stop``
 

	
 
    On Windows platforms, the following additional subcommands are available:
 

	
 
    * ``rattail filemon install``
 
    * ``rattail filemon uninstall`` (or ``rattail filemon remove``)
 

	
 
    .. note::
 
       The Windows Vista family of operating systems requires you to launch
 
       ``cmd.exe`` as an Administrator in order to have sufficient rights to
 
       run the above commands.
 

	
 
    .. See :doc:`howto.use_filemon` for more information.
 
    """
 

	
 
    appname = 'rattail'
 
    name = 'filemon'
 
    description = "Manage the file monitor service"
 

	
 
    def add_parser_args(self, parser):
 
        subparsers = parser.add_subparsers(title='subcommands')
 

	
 
        start = subparsers.add_parser('start', help="Start service")
 
        start.set_defaults(subcommand='start')
 
        stop = subparsers.add_parser('stop', help="Stop service")
 
        stop.set_defaults(subcommand='stop')
 

	
 
        if sys.platform == 'win32':
 
            install = subparsers.add_parser('install', help="Install service")
 
            install.set_defaults(subcommand='install')
 
            install.add_argument('-a', '--auto-start', action='store_true',
 
                                 help="Configure service to start automatically")
 
            remove = subparsers.add_parser('remove', help="Uninstall (remove) service")
 
            remove.set_defaults(subcommand='remove')
 
            uninstall = subparsers.add_parser('uninstall', help="Uninstall (remove) service")
 
            uninstall.set_defaults(subcommand='remove')
 

	
 
    def get_win32_module(self):
 
    def run(self, args):
 
        if sys.platform == 'linux2':
 
            from edbob.filemon import linux as filemon
 

	
 
            if args.subcommand == 'start':
 
                filemon.start_daemon('rattail')
 

	
 
            elif args.subcommand == 'stop':
 
                filemon.stop_daemon('rattail')
 

	
 
        elif sys.platform == 'win32':
 
            from edbob import win32
 
            from rattail import filemon
 
        return filemon
 
            from rattail.win32 import require_elevation
 

	
 
            require_elevation()
 

	
 
    def get_win32_service(self):
 
        from rattail.filemon import RattailFileMonitor
 
        return RattailFileMonitor
 
            # Execute typical service command.
 
            options = []
 
            if args.subcommand == 'install' and args.auto_start:
 
                options = ['--startup', 'auto']
 
            win32.execute_service_command(filemon, args.subcommand, *options)
 

	
 
            # If installing auto-start service on Windows 7, we should update
 
            # its startup type to be "Automatic (Delayed Start)".
 
            # TODO: Improve this check to include Vista?
 
            if args.subcommand == 'install' and args.auto_start:
 
                if platform.release() == '7':
 
                    name = filemon.RattailFileMonitor._svc_name_
 
                    win32.delayed_auto_start_service(name)
 

	
 
        else:
 
            sys.stderr.write("File monitor is not supported on platform: {0}\n".format(sys.platform))
 
            sys.exit(1)
 

	
 

	
 
class LoadHostDataCommand(commands.Subcommand):
0 comments (0 inline, 0 general)