Example #1
0
 def drive_edit(self, url):
     try:
         info = parse_protocol_url(str(url))
         self._manager.get_drive_edit().edit(info['server_url'], info['doc_id'], info['filename'],
                                             user=info['user'], download_url=info['download_url'])
     except Exception as e:
         log.exception(e)
 def handle_url(self, url=None):
     if url is None:
         url = self._url
     if url is None:
         return
     log.debug("DirectEdit load: '%r'", url)
     try:
         info = parse_protocol_url(str(url))
     except UnicodeEncodeError:
         # Firefox seems to be different on the encoding part
         info = parse_protocol_url(unicode(url))
     if info is None:
         return
     # Handle backward compatibility
     if info.get('item_id') is not None:
         self.edit(info['server_url'], info['item_id'])
     else:
         self.edit(info['server_url'], info['doc_id'], user=info['user'], download_url=info['download_url'])
Example #3
0
 def handle_url(self, url=None):
     if url is None:
         url = self._url
     if url is None:
         return
     log.debug("DirectEdit load: '%r'", url)
     try:
         info = parse_protocol_url(str(url))
     except UnicodeEncodeError:
         # Firefox seems to be different on the encoding part
         info = parse_protocol_url(unicode(url))
     if info is None:
         return
     # Handle backward compatibility
     if info.get('item_id') is not None:
         self.edit(info['server_url'], info['item_id'])
     else:
         self.edit(info['server_url'],
                   info['doc_id'],
                   user=info['user'],
                   download_url=info['download_url'])
Example #4
0
    def parse_cli(self, argv):
        """Parse the command line argument using argparse and protocol URL"""
        # Filter psn argument provided by OSX .app service launcher
        # https://developer.apple.com/library/mac/documentation/Carbon/Reference/LaunchServicesReference/LaunchServicesReference.pdf
        # When run from the .app bundle generated with py2app with
        # argv_emulation=True this is already filtered out but we keep it
        # for running CLI from the source folder in development.
        argv = [a for a in argv if not a.startswith("-psn_")]

        # Preprocess the args to detect protocol handler calls and be more
        # tolerant to missing subcommand
        has_command = False
        protocol_url = None

        filtered_args = []
        for arg in argv[1:]:
            if arg.startswith('nxdrive://'):
                protocol_url = arg
                continue
            if not arg.startswith('-'):
                has_command = True
            filtered_args.append(arg)

        parser = self.make_cli_parser(add_subparsers=has_command)
        # Change default value according to config.ini
        self.load_config(parser)
        options = parser.parse_args(filtered_args)
        if options.debug:
            # Install Post-Mortem debugger hook

            def info(etype, value, tb):
                traceback.print_exception(etype, value, tb)
                print
                debugger.pm()

            sys.excepthook = info

        # Merge any protocol info into the other parsed commandline
        # parameters
        if protocol_url is not None:
            protocol_info = parse_protocol_url(protocol_url)
            for k, v in protocol_info.items():
                setattr(options, k, v)

        return options
Example #5
0
 def event(self, event):
     """Handle URL scheme events under OSX"""
     if hasattr(event, 'url'):
         url = str(event.url().toString())
         log.debug("Event URL: %s", url)
         try:
             info = parse_protocol_url(url)
             log.debug("URL info: %r", info)
             if info is not None:
                 log.debug("Received nxdrive URL scheme event: %s", url)
                 if info.get('command') == 'download_edit':
                     # This is a quick operation, no need to fork a QThread
                     self.manager.get_drive_edit().edit(
                         info['server_url'], info['doc_id'], info['filename'], user=info['user'], download_url=info['download_url'])
                 elif info.get('command') == 'edit':
                     # TO_REVIEW Still used ?
                     self.manager.get_drive_edit().edit(
                         info['server_url'], info['item_id'])
         except:
             log.error("Error handling URL event: %s", url, exc_info=True)
     return super(Application, self).event(event)
Example #6
0
 def event(self, event):
     """Handle URL scheme events under OSX"""
     if hasattr(event, "url"):
         url = str(event.url().toString())
         log.debug("Event URL: %s", url)
         try:
             info = parse_protocol_url(url)
             log.debug("URL info: %r", info)
             if info is not None:
                 log.debug("Received nxdrive URL scheme event: %s", url)
                 if info.get("command") == "download_edit":
                     # This is a quick operation, no need to fork a QThread
                     self.manager.get_drive_edit().edit(
                         info["server_url"], info["doc_id"], user=info["user"], download_url=info["download_url"]
                     )
                 elif info.get("command") == "edit":
                     # Kept for backward compatibility
                     self.manager.get_drive_edit().edit(info["server_url"], info["item_id"])
         except:
             log.error("Error handling URL event: %s", url, exc_info=True)
     return super(Application, self).event(event)
Example #7
0
 def event(self, event):
     """Handle URL scheme events under OSX"""
     if hasattr(event, 'url'):
         url = str(event.url().toString())
         log.debug("Event URL: %s", url)
         try:
             info = parse_protocol_url(url)
             log.debug("URL info: %r", info)
             if info is not None:
                 log.debug("Received nxdrive URL scheme event: %s", url)
                 if info.get('command') == 'download_edit':
                     # This is a quick operation, no need to fork a QThread
                     self.manager.get_drive_edit().edit(
                         info['server_url'],
                         info['doc_id'],
                         user=info['user'],
                         download_url=info['download_url'])
                 elif info.get('command') == 'edit':
                     # Kept for backward compatibility
                     self.manager.get_drive_edit().edit(
                         info['server_url'], info['item_id'])
         except:
             log.error("Error handling URL event: %s", url, exc_info=True)
     return super(Application, self).event(event)
Example #8
0
 def event(self, event):
     """Handle URL scheme events under OSX"""
     if hasattr(event, 'url'):
         url = str(event.url().toString())
         try:
             info = parse_protocol_url(url)
             log.debug('Event url=%s, info=%r', url, info)
             if info is not None:
                 log.debug('Received nxdrive URL scheme event: %s', url)
                 if info.get('command') == 'download_edit':
                     # This is a quick operation, no need to fork a QThread
                     self.manager.direct_edit.edit(
                         info['server_url'],
                         info['doc_id'],
                         user=info['user'],
                         download_url=info['download_url'],
                     )
                 elif info.get('command') == 'edit':
                     # Kept for backward compatibility
                     self.manager.direct_edit.edit(
                         info['server_url'], info['item_id'])
         except:
             log.exception('Error handling URL event: %s', url)
     return super(Application, self).event(event)