Code Duplication    Length = 55-58 lines in 2 locations

gmp/xml.py 2 locations

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