Code Duplication    Length = 45-46 lines in 2 locations

gmp/xml.py 2 locations

@@ 585-630 (lines=46) @@
582
583
        return cmd.to_string()
584
585
    def create_schedule_command(self, name, kwargs):
586
        """Generates xml string for create schedule on gvmd."""
587
        if not name:
588
            raise ValueError('create_schedule requires a name element')
589
590
        cmd = XmlCommand('create_schedule')
591
        cmd.add_element('name', name)
592
593
        comment = kwargs.get('comment', '')
594
        if comment:
595
            cmd.add_element('comment', comment)
596
597
        copy = kwargs.get('copy', '')
598
        if copy:
599
            cmd.add_element('copy', copy)
600
601
        first_time = kwargs.get('first_time', '')
602
        if first_time:
603
            first_time_minute = first_time['minute']
604
            first_time_hour = first_time['hour']
605
            first_time_day_of_month = first_time['day_of_month']
606
            first_time_month = first_time['month']
607
            first_time_year = first_time['year']
608
609
            _xmlftime = cmd.add_element('first_time')
610
            _xmlftime.add_element('minute', first_time_minute)
611
            _xmlftime.add_element('hour', str(first_time_hour))
612
            _xmlftime.add_element('day_of_month', str(first_time_day_of_month))
613
            _xmlftime.add_element('month', str(first_time_month))
614
            _xmlftime.add_element('year', str(first_time_year))
615
616
        duration = kwargs.get('duration', '')
617
        if len(duration) > 1:
618
            _xmlduration = cmd.add_element('duration', str(duration[0]))
619
            _xmlduration.add_element('unit', str(duration[1]))
620
621
        period = kwargs.get('period', '')
622
        if len(period) > 1:
623
            _xmlperiod = cmd.add_element('period', str(period[0]))
624
            _xmlperiod.add_element('unit', str(period[1]))
625
626
        timezone = kwargs.get('timezone', '')
627
        if timezone:
628
            cmd.add_element('timezone', str(timezone))
629
630
        return cmd.to_string()
631
632
    def create_tag_command(self, name, resource_id, resource_type, kwargs):
633
        """Generates xml string for create tag on gvmd."""
@@ 1305-1349 (lines=45) @@
1302
1303
        return cmd.to_string()
1304
1305
    def modify_schedule_command(self, schedule_id, kwargs):
1306
        """Generates xml string for modify schedule on gvmd."""
1307
        if not schedule_id:
1308
            raise ValueError('modify_schedule requires a schedule_id element')
1309
1310
        cmd = XmlCommand('modify_schedule')
1311
        cmd.set_attribute('schedule_id', schedule_id)
1312
        comment = kwargs.get('comment', '')
1313
        if comment:
1314
            cmd.add_element('comment', comment)
1315
1316
        name = kwargs.get('name', '')
1317
        if name:
1318
            cmd.add_element('name', name)
1319
1320
        first_time = kwargs.get('first_time', '')
1321
        if first_time:
1322
            first_time_minute = first_time['minute']
1323
            first_time_hour = first_time['hour']
1324
            first_time_day_of_month = first_time['day_of_month']
1325
            first_time_month = first_time['month']
1326
            first_time_year = first_time['year']
1327
1328
            _xmlftime = cmd.add_element('first_time')
1329
            _xmlftime.add_element('minute', str(first_time_minute))
1330
            _xmlftime.add_element('hour', str(first_time_hour))
1331
            _xmlftime.add_element('day_of_month', str(first_time_day_of_month))
1332
            _xmlftime.add_element('month', str(first_time_month))
1333
            _xmlftime.add_element('year', str(first_time_year))
1334
1335
        duration = kwargs.get('duration', '')
1336
        if len(duration) > 1:
1337
            _xmlduration = cmd.add_element('duration', str(duration[0]))
1338
            _xmlduration.add_element('unit', str(duration[1]))
1339
1340
        period = kwargs.get('period', '')
1341
        if len(period) > 1:
1342
            _xmlperiod = cmd.add_element('period', str(period[0]))
1343
            _xmlperiod.add_element('unit', str(period[1]))
1344
1345
        timezone = kwargs.get('timezone', '')
1346
        if timezone:
1347
            cmd.add_element('timezone', str(timezone))
1348
1349
        return cmd.to_string()
1350
1351
    def modify_setting_command(self, setting_id, name, value):
1352
        """Generates xml string for modify setting format on gvmd."""