Code Duplication    Length = 45-46 lines in 2 locations

gvm/xml.py 2 locations

@@ 196-241 (lines=46) @@
193
194
        return cmd.to_string()
195
196
    def create_schedule_command(self, name, kwargs):
197
        """Generates xml string for create schedule on gvmd."""
198
        if not name:
199
            raise ValueError('create_schedule requires a name element')
200
201
        cmd = XmlCommand('create_schedule')
202
        cmd.add_element('name', name)
203
204
        comment = kwargs.get('comment', '')
205
        if comment:
206
            cmd.add_element('comment', comment)
207
208
        copy = kwargs.get('copy', '')
209
        if copy:
210
            cmd.add_element('copy', copy)
211
212
        first_time = kwargs.get('first_time', '')
213
        if first_time:
214
            first_time_minute = first_time['minute']
215
            first_time_hour = first_time['hour']
216
            first_time_day_of_month = first_time['day_of_month']
217
            first_time_month = first_time['month']
218
            first_time_year = first_time['year']
219
220
            _xmlftime = cmd.add_element('first_time')
221
            _xmlftime.add_element('minute', first_time_minute)
222
            _xmlftime.add_element('hour', str(first_time_hour))
223
            _xmlftime.add_element('day_of_month', str(first_time_day_of_month))
224
            _xmlftime.add_element('month', str(first_time_month))
225
            _xmlftime.add_element('year', str(first_time_year))
226
227
        duration = kwargs.get('duration', '')
228
        if len(duration) > 1:
229
            _xmlduration = cmd.add_element('duration', str(duration[0]))
230
            _xmlduration.add_element('unit', str(duration[1]))
231
232
        period = kwargs.get('period', '')
233
        if len(period) > 1:
234
            _xmlperiod = cmd.add_element('period', str(period[0]))
235
            _xmlperiod.add_element('unit', str(period[1]))
236
237
        timezone = kwargs.get('timezone', '')
238
        if timezone:
239
            cmd.add_element('timezone', str(timezone))
240
241
        return cmd.to_string()
242
243
    def create_tag_command(self, name, resource_id, resource_type, kwargs):
244
        """Generates xml string for create tag on gvmd."""
@@ 813-857 (lines=45) @@
810
811
        return cmd.to_string()
812
813
    def modify_schedule_command(self, schedule_id, kwargs):
814
        """Generates xml string for modify schedule on gvmd."""
815
        if not schedule_id:
816
            raise ValueError('modify_schedule requires a schedule_id element')
817
818
        cmd = XmlCommand('modify_schedule')
819
        cmd.set_attribute('schedule_id', schedule_id)
820
        comment = kwargs.get('comment', '')
821
        if comment:
822
            cmd.add_element('comment', comment)
823
824
        name = kwargs.get('name', '')
825
        if name:
826
            cmd.add_element('name', name)
827
828
        first_time = kwargs.get('first_time', '')
829
        if first_time:
830
            first_time_minute = first_time['minute']
831
            first_time_hour = first_time['hour']
832
            first_time_day_of_month = first_time['day_of_month']
833
            first_time_month = first_time['month']
834
            first_time_year = first_time['year']
835
836
            _xmlftime = cmd.add_element('first_time')
837
            _xmlftime.add_element('minute', str(first_time_minute))
838
            _xmlftime.add_element('hour', str(first_time_hour))
839
            _xmlftime.add_element('day_of_month', str(first_time_day_of_month))
840
            _xmlftime.add_element('month', str(first_time_month))
841
            _xmlftime.add_element('year', str(first_time_year))
842
843
        duration = kwargs.get('duration', '')
844
        if len(duration) > 1:
845
            _xmlduration = cmd.add_element('duration', str(duration[0]))
846
            _xmlduration.add_element('unit', str(duration[1]))
847
848
        period = kwargs.get('period', '')
849
        if len(period) > 1:
850
            _xmlperiod = cmd.add_element('period', str(period[0]))
851
            _xmlperiod.add_element('unit', str(period[1]))
852
853
        timezone = kwargs.get('timezone', '')
854
        if timezone:
855
            cmd.add_element('timezone', str(timezone))
856
857
        return cmd.to_string()
858
859
    def modify_setting_command(self, setting_id, name, value):
860
        """Generates xml string for modify setting format on gvmd."""