def fetch_api(self):
        base_error_message = (
            "Failed to connect to Nuxeo server %s"
        ) % (self.server_url)
        url = self.automation_url
        headers = self._get_common_headers()
        cookies = self._get_cookies()
        log.trace("Calling %s with headers %r and cookies %r",
            url, headers, cookies)
        req = urllib2.Request(url, headers=headers)
        try:
            response = json.loads(self.opener.open(
                req, timeout=self.timeout).read())
        except urllib2.HTTPError as e:
            if e.code == 401 or e.code == 403:
                raise Unauthorized(self.server_url, self.user_id, e.code)
            else:
                msg = base_error_message + "\nHTTP error %d" % e.code
                if hasattr(e, 'msg'):
                    msg = msg + ": " + e.msg
                e.msg = msg
                raise e
        except urllib2.URLError as e:
            msg = base_error_message
            if hasattr(e, 'message') and e.message:
                msg = msg + force_decode(": " + e.message)
            elif hasattr(e, 'reason') and e.reason:
                if (hasattr(e.reason, 'message')
                    and e.reason.message):
                    msg = msg + force_decode(": " + e.reason.message)
                elif (hasattr(e.reason, 'strerror')
                    and e.reason.strerror):
                    msg = msg + force_decode(": " + e.reason.strerror)
            if self.is_proxy:
                msg = (msg + "\nPlease check your Internet connection,"
                       + " make sure the Nuxeo server URL is valid"
                       + " and check the proxy settings.")
            else:
                msg = (msg + "\nPlease check your Internet connection"
                       + " and make sure the Nuxeo server URL is valid.")
            e.msg = msg
            raise e
        except Exception as e:
            msg = base_error_message
            if hasattr(e, 'msg'):
                msg = msg + ": " + e.msg
            e.msg = msg
            raise e
        self.operations = {}
        for operation in response["operations"]:
            self.operations[operation['id']] = operation

        # Is event log id available in change summary?
        # See https://jira.nuxeo.com/browse/NXP-14826
        change_summary_op = self._check_operation(CHANGE_SUMMARY_OPERATION)
        self.is_event_log_id = 'lowerBound' in [
                        param['name'] for param in change_summary_op['params']]
示例#2
0
    def fetch_api(self):
        base_error_message = ("Failed to connect to Nuxeo server %s") % (
            self.server_url)
        url = self.automation_url
        headers = self._get_common_headers()
        cookies = self._get_cookies()
        log.trace("Calling %s with headers %r and cookies %r", url, headers,
                  cookies)
        req = urllib2.Request(url, headers=headers)
        try:
            response = json.loads(
                self.opener.open(req, timeout=self.timeout).read())
        except urllib2.HTTPError as e:
            if e.code == 401 or e.code == 403:
                raise Unauthorized(self.server_url, self.user_id, e.code)
            else:
                msg = base_error_message + "\nHTTP error %d" % e.code
                if hasattr(e, 'msg'):
                    msg = msg + ": " + e.msg
                e.msg = msg
                raise e
        except urllib2.URLError as e:
            msg = base_error_message
            if hasattr(e, 'message') and e.message:
                msg = msg + force_decode(": " + e.message)
            elif hasattr(e, 'reason') and e.reason:
                if (hasattr(e.reason, 'message') and e.reason.message):
                    msg = msg + force_decode(": " + e.reason.message)
                elif (hasattr(e.reason, 'strerror') and e.reason.strerror):
                    msg = msg + force_decode(": " + e.reason.strerror)
            if self.is_proxy:
                msg = (msg + "\nPlease check your Internet connection," +
                       " make sure the Nuxeo server URL is valid" +
                       " and check the proxy settings.")
            else:
                msg = (msg + "\nPlease check your Internet connection" +
                       " and make sure the Nuxeo server URL is valid.")
            e.msg = msg
            raise e
        except Exception as e:
            msg = base_error_message
            if hasattr(e, 'msg'):
                msg = msg + ": " + e.msg
            e.msg = msg
            raise e
        self.operations = {}
        for operation in response["operations"]:
            self.operations[operation['id']] = operation

        # Is event log id available in change summary?
        # See https://jira.nuxeo.com/browse/NXP-14826
        change_summary_op = self._check_operation(CHANGE_SUMMARY_OPERATION)
        self.is_event_log_id = 'lowerBound' in [
            param['name'] for param in change_summary_op['params']
        ]
 def fetch_api(self):
     base_error_message = (
         "Failed to connect to Nuxeo server %s"
     ) % (self.server_url)
     url = self.automation_url
     headers = self._get_common_headers()
     cookies = self._get_cookies()
     log.trace("Calling %s with headers %r and cookies %r",
         url, headers, cookies)
     req = urllib2.Request(url, headers=headers)
     try:
         response = json.loads(self.opener.open(
             req, timeout=self.timeout).read())
     except urllib2.HTTPError as e:
         if e.code == 401 or e.code == 403:
             raise Unauthorized(self.server_url, self.user_id, e.code)
         else:
             msg = base_error_message + "\nHTTP error %d" % e.code
             if hasattr(e, 'msg'):
                 msg = msg + ": " + e.msg
             e.msg = msg
             raise e
     except urllib2.URLError as e:
         msg = base_error_message
         if hasattr(e, 'message') and e.message:
             msg = msg + force_decode(": " + e.message)
         elif hasattr(e, 'reason') and e.reason:
             if (hasattr(e.reason, 'message')
                 and e.reason.message):
                 msg = msg + force_decode(": " + e.reason.message)
             elif (hasattr(e.reason, 'strerror')
                 and e.reason.strerror):
                 msg = msg + force_decode(": " + e.reason.strerror)
         if self.is_proxy:
             msg = (msg + "\nPlease check your Internet connection,"
                    + " make sure the Nuxeo server URL is valid"
                    + " and check the proxy settings.")
         else:
             msg = (msg + "\nPlease check your Internet connection"
                    + " and make sure the Nuxeo server URL is valid.")
         e.msg = msg
         raise e
     except Exception as e:
         msg = base_error_message
         if hasattr(e, 'msg'):
             msg = msg + ": " + e.msg
         e.msg = msg
         raise e
     self.operations = {}
     for operation in response["operations"]:
         self.operations[operation['id']] = operation
 def fetch_api(self):
     base_error_message = ("Failed to connect to Nuxeo server %s") % (
         self.server_url)
     url = self.automation_url
     headers = self._get_common_headers()
     cookies = self._get_cookies()
     log.trace("Calling %s with headers %r and cookies %r", url, headers,
               cookies)
     req = urllib2.Request(url, headers=headers)
     try:
         response = json.loads(
             self.opener.open(req, timeout=self.timeout).read())
     except urllib2.HTTPError as e:
         if e.code == 401 or e.code == 403:
             raise Unauthorized(self.server_url, self.user_id, e.code)
         else:
             msg = base_error_message + "\nHTTP error %d" % e.code
             if hasattr(e, 'msg'):
                 msg = msg + ": " + e.msg
             e.msg = msg
             raise e
     except urllib2.URLError as e:
         msg = base_error_message
         if hasattr(e, 'message') and e.message:
             msg = msg + force_decode(": " + e.message)
         elif hasattr(e, 'reason') and e.reason:
             if (hasattr(e.reason, 'message') and e.reason.message):
                 msg = msg + force_decode(": " + e.reason.message)
             elif (hasattr(e.reason, 'strerror') and e.reason.strerror):
                 msg = msg + force_decode(": " + e.reason.strerror)
         if self.is_proxy:
             msg = (msg + "\nPlease check your Internet connection," +
                    " make sure the Nuxeo server URL is valid" +
                    " and check the proxy settings.")
         else:
             msg = (msg + "\nPlease check your Internet connection" +
                    " and make sure the Nuxeo server URL is valid.")
         e.msg = msg
         raise e
     except Exception as e:
         msg = base_error_message
         if hasattr(e, 'msg'):
             msg = msg + ": " + e.msg
         e.msg = msg
         raise e
     self.operations = {}
     for operation in response["operations"]:
         self.operations[operation['id']] = operation
示例#5
0
 def handle_watchdog_event(self, evt):
     self._action = Action("Handle watchdog event")
     log.debug("Handling watchdog event [%s] on %r", evt.event_type, evt.src_path)
     try:
         src_path = normalize_event_filename(evt.src_path)
         # Event on the folder by itself
         if os.path.isdir(src_path):
             return
         ref = self._local_client.get_path(src_path)
         file_name = os.path.basename(src_path)
         if self._local_client.is_temp_file(file_name):
             return
         queue = False
         if evt.event_type == 'modified' or evt.event_type == 'created':
             queue = True
         if evt.event_type == 'moved':
             ref = self._local_client.get_path(evt.dest_path)
             file_name = os.path.basename(evt.dest_path)
             queue = True
         dir_path = self._local_client.get_path(os.path.dirname(src_path))
         name = self._local_client.get_remote_id(dir_path, "nxdriveeditname")
         if name is None:
             return
         decoded_name = force_decode(name)
         if decoded_name is not None:
             name = decoded_name
         if name != file_name:
             return
         if queue:
             # ADD TO UPLOAD QUEUE
             self._upload_queue.put(ref)
             return
     except Exception as e:
         log.warn("Watchdog exception : %r" % e)
         log.exception(e)
     finally:
         self._end_action()
示例#6
0
    def _prepare_edit(self, server_url, doc_id, filename, user=None, download_url=None):
        engine = self._get_engine(server_url, user=user)
        if engine is None:
            # TO_REVIEW Display an error message
            log.debug("No engine found for %s(%s)", server_url, doc_id)
            return
        # Get document info
        remote_client = engine.get_remote_doc_client()
        # Avoid any link with the engine, remote_doc are not cached so we can do that
        remote_client.check_suspended = self.stop_client
        info = remote_client.get_info(doc_id)

        # Create local structure
        dir_path = os.path.join(self._folder, doc_id)
        if not os.path.exists(dir_path):
            os.mkdir(dir_path)

        log.trace('Raw filename: %r', filename)
        filename = safe_filename(urllib2.unquote(filename))
        log.trace('Unquoted filename = %r', filename)
        decoded_filename = force_decode(filename)
        if decoded_filename is None:
            decoded_filename = filename
        else:
            # Always use utf-8 encoding for xattr
            filename = decoded_filename.encode('utf-8')
        log.debug("Editing %r ('nxdriveeditname' xattr: %r)", decoded_filename, filename)
        file_path = os.path.join(dir_path, decoded_filename)

        # Download the file
        url = None
        if download_url is not None:
            url = server_url
            if not url.endswith('/'):
                url += '/'
            url += download_url
        tmp_file = self._download_content(engine, remote_client, info, file_path, url=url)
        if tmp_file is None:
            log.debug("Download failed")
            return
        # Set the remote_id
        dir_path = self._local_client.get_path(os.path.dirname(file_path))
        self._local_client.set_remote_id(dir_path, doc_id)
        self._local_client.set_remote_id(dir_path, server_url, "nxdriveedit")
        if user is not None:
            self._local_client.set_remote_id(dir_path, user, "nxdriveedituser")
        if info.digest is not None:
            self._local_client.set_remote_id(dir_path, info.digest, "nxdriveeditdigest")
            # Set digest algorithm if not sent by the server
            digest_algorithm = info.digest_algorithm
            if digest_algorithm is None:
                digest_algorithm = guess_digest_algorithm(info.digest)
            self._local_client.set_remote_id(dir_path, digest_algorithm, "nxdriveeditdigestalgorithm")
        self._local_client.set_remote_id(dir_path, filename, "nxdriveeditname")
        # Rename to final filename
        # Under Windows first need to delete target file if exists, otherwise will get a 183 WindowsError
        if sys.platform == 'win32' and os.path.exists(file_path):
            os.unlink(file_path)
        os.rename(tmp_file, file_path)

        return file_path