Code Duplication    Length = 22-25 lines in 3 locations

gmp/xml.py 3 locations

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