Exemple #1
0
    def process_abap_object_xml(self, object_elem):
        """Converts Object XML into a python object"""

        attributes = object_elem.attributes

        description = attributes.get('tm:obj_desc', attributes.get('tm:obj_info', None))
        if description is None:
            # pylint: disable=consider-using-f-string
            description = '(PGMID={},TYPE={},NAME={})'.format(attributes.get('tm:pgmid', '*'),
                                                              attributes.get('tm:type', '*'),
                                                              attributes.get('tm:name', '*'))

        mod_log().debug('Processing CTS ABAP Object(PGMID=%s,TYPE=%s,NAME=%s)',
                        attributes.get('tm:pgmid', '*'),
                        attributes.get('tm:type', '*'),
                        attributes.get('tm:name', '*'))

        abap_object = WorkbenchABAPObject(
            attributes['tm:pgmid'],
            attributes['tm:type'],
            attributes['tm:name'],
            attributes.get('tm:wbtype', ''),
            description,
            attributes.get('tm:lock_status', ' ') == 'X',
            attributes.get('tm:position', '000000')
        )

        return abap_object
Exemple #2
0
    def lock(self):
        """Locks the object"""

        resp = self.connection.execute(
            'POST',
            self.uri,
            params=lock_params(LOCK_ACCESS_MODE_MODIFY),
            headers={
                'X-sap-adt-sessiontype':
                'stateful',
                'Accept':
                ', '.join([
                    'application/vnd.sap.as+xml;charset=UTF-8;dataname=com.sap.adt.lock.result;q=0.8',
                    'application/vnd.sap.as+xml;charset=UTF-8;dataname=com.sap.adt.lock.result2;q=0.9'
                ])
            })

        if 'dataname=com.sap.adt.lock.Result' not in resp.headers[
                'Content-Type']:
            raise SAPCliError(
                f'Object {self.uri}: lock response does not have lock result\n'
                + resp.text)

        mod_log().debug(resp.text)

        # TODO: check encoding
        lock_handle = re.match('.*<LOCK_HANDLE>(.*)</LOCK_HANDLE>.*',
                               resp.text)[1]
        mod_log().debug('LockHandle=%s', lock_handle)

        return lock_handle
Exemple #3
0
    def change_text(self, content):
        """Changes the source code"""

        text_uri = self.objtype.get_uri_for_type('text/plain')

        resp = self._connection.execute(
            'PUT',
            self.uri + text_uri,
            params={'lockHandle': self._lock},
            headers={'Content-Type': 'text/plain; charset=utf-8'},
            body=content)

        mod_log().debug("Change text response status: %i", resp.status_code)
Exemple #4
0
        def change_text(self, content):
            """Changes source codes"""

            resp = self._clas.connection.execute(
                'PUT',
                self._clas.uri + self._metadata.source_uri,
                params={'lockHandle': self._clas.lock_handle},
                headers={
                    'Accept': 'text/plain',
                    'Content-Type': 'text/plain; charset=utf-8'
                },
                body=content)

            mod_log().debug("Change text response status: %i",
                            resp.status_code)
Exemple #5
0
    def write(self, content):
        """Changes Source Code of the source object"""

        text_uri = self.uri + self.get_uri_for_type('text/plain')

        if content[-1] == '\n':
            content = content[:-1]

        data = bytes(content, 'utf-8')

        resp = self.connection.execute('PUT',
                                       text_uri,
                                       params=modify_object_params(
                                           self.lock_handle, self.corrnr),
                                       headers=self.get_headers(),
                                       body=data)

        mod_log().debug("Write text response status: %i", resp.status_code)