Code Duplication    Length = 55-58 lines in 2 locations

gmp/xml.py 2 locations

@@ 636-693 (lines=58) @@
633
634
        return etree.tostring(xmlRoot).decode('utf-8')
635
636
    def create_schedule_command(self, name, kwargs):
637
        if not name:
638
            raise ValueError('create_schedule requires a name element')
639
640
        xmlRoot = etree.Element('create_schedule')
641
        _xmlName = etree.SubElement(xmlRoot, 'name')
642
        _xmlName.text = name
643
644
        comment = kwargs.get('comment', '')
645
        if comment:
646
            _xmlComment = etree.SubElement(xmlRoot, 'comment')
647
            _xmlComment.text = comment
648
649
        copy = kwargs.get('copy', '')
650
        if copy:
651
            _xmlCopy = etree.SubElement(xmlRoot, 'copy')
652
            _xmlCopy.text = copy
653
654
        first_time = kwargs.get('first_time', '')
655
        if first_time:
656
            first_time_minute = first_time['minute']
657
            first_time_hour = first_time['hour']
658
            first_time_day_of_month = first_time['day_of_month']
659
            first_time_month = first_time['month']
660
            first_time_year = first_time['year']
661
662
            _xmlFtime = etree.SubElement(xmlRoot, 'first_time')
663
            _xmlMinute = etree.SubElement(_xmlFtime, 'minute')
664
            _xmlMinute.text = str(first_time_minute)
665
            _xmlHour = etree.SubElement(_xmlFtime, 'hour')
666
            _xmlHour.text = str(first_time_hour)
667
            _xmlDay = etree.SubElement(_xmlFtime, 'day_of_month')
668
            _xmlDay.text = str(first_time_day_of_month)
669
            _xmlMonth = etree.SubElement(_xmlFtime, 'month')
670
            _xmlMonth.text = str(first_time_month)
671
            _xmlYear = etree.SubElement(_xmlFtime, 'year')
672
            _xmlYear.text = str(first_time_year)
673
674
        duration = kwargs.get('duration', '')
675
        if len(duration) > 1:
676
            _xmlDuration = etree.SubElement(xmlRoot, 'duration')
677
            _xmlDuration.text = str(duration[0])
678
            _xmlUnit = etree.SubElement(_xmlDuration, 'unit')
679
            _xmlUnit.text = str(duration[1])
680
681
        period = kwargs.get('period', '')
682
        if len(period) > 1:
683
            _xmlPeriod = etree.SubElement(xmlRoot, 'period')
684
            _xmlPeriod.text = str(period[0])
685
            _xmlPUnit = etree.SubElement(_xmlPeriod, 'unit')
686
            _xmlPUnit.text = str(period[1])
687
688
        timezone = kwargs.get('timezone', '')
689
        if timezone:
690
            _xmlTimezone = etree.SubElement(xmlRoot, 'timezone')
691
            _xmlTimezone.text = str(timezone)
692
693
        return etree.tostring(xmlRoot).decode('utf-8')
694
695
    def create_tag_command(self, name, resource_id, resource_type, kwargs):
696
@@ 1437-1491 (lines=55) @@
1434
1435
        return etree.tostring(xmlRoot).decode('utf-8')
1436
1437
    def modify_schedule_command(self, schedule_id, kwargs):
1438
        if not schedule_id:
1439
            raise ValueError('modify_schedule requires a schedule_id element')
1440
1441
        xmlRoot = etree.Element('modify_schedule', schedule_id=schedule_id)
1442
        comment = kwargs.get('comment', '')
1443
        if comment:
1444
            _xmlComment = etree.SubElement(xmlRoot, 'comment')
1445
            _xmlComment.text = comment
1446
1447
        name = kwargs.get('name', '')
1448
        if name:
1449
            _xmlName = etree.SubElement(xmlRoot, 'name')
1450
            _xmlName.text = name
1451
1452
        first_time = kwargs.get('first_time', '')
1453
        if first_time:
1454
            first_time_minute = first_time['minute']
1455
            first_time_hour = first_time['hour']
1456
            first_time_day_of_month = first_time['day_of_month']
1457
            first_time_month = first_time['month']
1458
            first_time_year = first_time['year']
1459
1460
            _xmlFtime = etree.SubElement(xmlRoot, 'first_time')
1461
            _xmlMinute = etree.SubElement(_xmlFtime, 'minute')
1462
            _xmlMinute.text = str(first_time_minute)
1463
            _xmlHour = etree.SubElement(_xmlFtime, 'hour')
1464
            _xmlHour.text = str(first_time_hour)
1465
            _xmlDay = etree.SubElement(_xmlFtime, 'day_of_month')
1466
            _xmlDay.text = str(first_time_day_of_month)
1467
            _xmlMonth = etree.SubElement(_xmlFtime, 'month')
1468
            _xmlMonth.text = str(first_time_month)
1469
            _xmlYear = etree.SubElement(_xmlFtime, 'year')
1470
            _xmlYear.text = str(first_time_year)
1471
1472
        duration = kwargs.get('duration', '')
1473
        if len(duration) > 1:
1474
            _xmlDuration = etree.SubElement(xmlRoot, 'duration')
1475
            _xmlDuration.text = str(duration[0])
1476
            _xmlUnit = etree.SubElement(_xmlDuration, 'unit')
1477
            _xmlUnit.text = str(duration[1])
1478
1479
        period = kwargs.get('period', '')
1480
        if len(period) > 1:
1481
            _xmlPeriod = etree.SubElement(xmlRoot, 'period')
1482
            _xmlPeriod.text = str(period[0])
1483
            _xmlPUnit = etree.SubElement(_xmlPeriod, 'unit')
1484
            _xmlPUnit.text = str(period[1])
1485
1486
        timezone = kwargs.get('timezone', '')
1487
        if timezone:
1488
            _xmlTimezone = etree.SubElement(xmlRoot, 'timezone')
1489
            _xmlTimezone.text = str(timezone)
1490
1491
        return etree.tostring(xmlRoot).decode('utf-8')
1492
1493
    def modify_tag_command(self, tag_id, kwargs):
1494
        if not tag_id: