Code Duplication    Length = 22-25 lines in 3 locations

gmp/xml.py 3 locations

@@ 569-593 (lines=25) @@
566
567
        return etree.tostring(xmlRoot).decode('utf-8')
568
569
    def create_role_command(self, name, kwargs):
570
571
        if not name:
572
            raise ValueError('create_role requires a name element')
573
574
        xmlRoot = etree.Element('create_role')
575
        _xmlName = etree.SubElement(xmlRoot, 'name')
576
        _xmlName.text = name
577
578
        comment = kwargs.get('comment', '')
579
        if comment:
580
            _xmlComment = etree.SubElement(xmlRoot, 'comment')
581
            _xmlComment.text = comment
582
583
        copy = kwargs.get('copy', '')
584
        if copy:
585
            _xmlCopy = etree.SubElement(xmlRoot, 'copy')
586
            _xmlCopy.text = copy
587
588
        users = kwargs.get('users', '')
589
        if users:
590
            _xmlUser = etree.SubElement(xmlRoot, 'users')
591
            _xmlUser.text = users
592
593
        return etree.tostring(xmlRoot).decode('utf-8')
594
595
    def create_scanner_command(self, name, host, port, type, ca_pub,
596
                               credential_id, kwargs):
@@ 1372-1394 (lines=23) @@
1369
1370
        return etree.tostring(xmlRoot).decode('utf-8')
1371
1372
    def modify_role_command(self, role_id, kwargs):
1373
        if not role_id:
1374
            raise ValueError('modify_role requires a role_id element')
1375
1376
        xmlRoot = etree.Element('modify_role',
1377
                                role_id=role_id)
1378
1379
        comment = kwargs.get('comment', '')
1380
        if comment:
1381
            _xmlComment = etree.SubElement(xmlRoot, 'comment')
1382
            _xmlComment.text = comment
1383
1384
        name = kwargs.get('name', '')
1385
        if name:
1386
            _xmlName = etree.SubElement(xmlRoot, 'name')
1387
            _xmlName.text = name
1388
1389
        users = kwargs.get('users', '')
1390
        if users:
1391
            _xmlUser = etree.SubElement(xmlRoot, 'users')
1392
            _xmlUser.text = users
1393
1394
        return etree.tostring(xmlRoot).decode('utf-8')
1395
1396
    def modify_scanner_command(self, scanner_id, host, port, scanner_type,
1397
                               kwargs):
@@ 1163-1184 (lines=22) @@
1160
1161
        return etree.tostring(xmlRoot).decode('utf-8')
1162
1163
    def modify_group_command(self, group_id, kwargs):
1164
        if not group_id:
1165
            raise ValueError('modify_group requires a group_id attribute')
1166
1167
        xmlRoot = etree.Element('modify_group', group_id=group_id)
1168
1169
        comment = kwargs.get('comment', '')
1170
        if comment:
1171
            _xmlComment = etree.SubElement(xmlRoot, 'comment')
1172
            _xmlComment.text = comment
1173
1174
        name = kwargs.get('name', '')
1175
        if name:
1176
            _xmlName = etree.SubElement(xmlRoot, 'name')
1177
            _xmlName.text = name
1178
1179
        users = kwargs.get('users', '')
1180
        if users:
1181
            _xmlUser = etree.SubElement(xmlRoot, 'users')
1182
            _xmlUser.text = users
1183
1184
        return etree.tostring(xmlRoot).decode('utf-8')
1185
1186
    def modify_note_command(self, note_id, text, kwargs):
1187
        if not note_id: