# Coverage for grm\plugin\gmp_file.py : 0%

## 54 statements

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 import xml.etree.ElementTree as ET

2

3 from utils import *

4 from config import NAMESPACE

5

6 class GMPFILE(object):

7

8 def __init__(self, path):

9 self.tree = ET.parse(path)

10 self.root = self.tree.getroot()

11 self.project_settings_node = self.tree.find("{0}ProjectSettings".format(NAMESPACE))

12 self.subwatershed_settings_node = self.tree.find("{0}SubWatershedSettings".format(NAMESPACE))

13 self.watch_points_node = self.tree.find("{0}WatchPoints".format(NAMESPACE))

14 self.flow_control_grid_node = self.tree.find("{0}FlowControlGrid".format(NAMESPACE))

15 self.green_ampt_parameter_node = self.tree.find("{0}GreenAmptParameter".format(NAMESPACE))

16 self.land_cover_node = self.tree.find("{0}LandCover".format(NAMESPACE))

17 self.subwatershed_list = self.root.findall('{0}SubWatershedSettings'.format(NAMESPACE))

18

19 def get_project_settings_attributes(self, attribute_name):

20 path = "{0}{1}".format(NAMESPACE, attribute_name)

21 return self.project_settings_node.find(path).text

22

23 def get_computation_time_step_sec(self):

24 return ""

25

26 def get_enable_analyzer(self):

27 return False

28

29 def set_select_watershed_index(self):

30 for i in self.subwatershed_list:

31 if c_bool(i.find(NAMESPACE+"UserSet").text):

32 self.selected_watershed_index = self.subwatershed_list.index(i)

33

34 def set_project_settings_attributes(self, attribute_name, value):

35 node = self.project_settings_node.find("{0}{1}".format(NAMESPACE, attribute_name))

36 node.text = str(value)

37

38 def set_computation_time_step_sec(self, value):

39 pass

40

41 def set_enable_analyzer(self, value):

42 pass

43

44 def get_selected_watershed_info(self, tag_name):

45 i = self.subwatershed_list[self.selected_watershed_index]

46 return i.find(NAMESPACE+tag_name).text if i.find(NAMESPACE+tag_name) != None else ""

47

48 def set_selected_watershed_info(self, tag_name=None, dlg_obj=None):

49 if dlg_obj:

50 self.updated_watershed = dlg_obj.select_watershed.currentText()

51

52 if tag_name:

53 for subwatershed in self.subwatershed_list:

54 if subwatershed.find(NAMESPACE+"ID").text == self.updated_watershed:

55 return subwatershed.find(NAMESPACE+tag_name)

56

57 def set_watershed(self, value):

58 watershed = self.set_selected_watershed_info(tag_name="ID")

59 watershed.text = str(value)

60

61 def set_watershed_attributes(self, attribute_name, value):

62 node = self.set_selected_watershed_info(tag_name=attribute_name)

63 if node:

64 ini_saturation.text = str(value)

65

66 def set_apply_initial_stream_check(self, value):

67 apply_initial_stream_check = self.set_selected_watershed_info(tag_name ="UserSet")

68 apply_initial_stream_check.text = bool_c(value)

69

70 def save(self, output_file):

71 self.tree.write(open(output_file, 'wb'), encoding='utf-8', xml_declaration=True,

72 default_namespace="http://tempuri.org/GRMProject.xsd")