1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """The state user function definitions."""
24
25
26 from pipe_control.state import load_state, save_state
27 from user_functions.data import Uf_info; uf_info = Uf_info()
28 from user_functions.objects import Desc_container
29 from user_functions.wildcards import WILDCARD_RELAX_SAVE
30
31
32
33 uf_class = uf_info.add_class('state')
34 uf_class.title = "Class for saving or loading the program state."
35 uf_class.menu_text = "&state"
36 uf_class.gui_icon = "relax.relax"
37
38
39
40 uf = uf_info.add_uf('state.load')
41 uf.title = "Load a saved program state."
42 uf.title_short = "Saved state loading."
43 uf.add_keyarg(
44 name = "state",
45 default = "state.bz2",
46 arg_type = "file sel read",
47 desc_short = "file name",
48 desc = "The file name, which can be a string or a file descriptor object, of a saved program state.",
49 wiz_filesel_wildcard = WILDCARD_RELAX_SAVE,
50 wiz_filesel_preview = False
51 )
52 uf.add_keyarg(
53 name = "dir",
54 arg_type = "dir",
55 desc_short = "directory name",
56 desc = "The name of the directory in which the file is found.",
57 can_be_none = True
58 )
59 uf.add_keyarg(
60 name = "force",
61 default = False,
62 basic_types = ["bool"],
63 desc_short = "force flag",
64 desc = "A boolean flag which if True will cause the current program state to be overwritten."
65 )
66
67 uf.desc.append(Desc_container())
68 uf.desc[-1].add_paragraph("This is able to handle uncompressed, bzip2 compressed files, or gzip compressed files automatically. The full file name including extension can be supplied, however, if the file cannot be found, this function will search for the file name with '.bz2' appended followed by the file name with '.gz' appended.")
69 uf.desc[-1].add_paragraph("For more advanced users, file descriptor objects are supported. If the force flag is set to True, then the relax data store will be reset prior to the loading of the saved state.")
70
71 uf.desc.append(Desc_container("Prompt examples"))
72 uf.desc[-1].add_paragraph("The following commands will load the state saved in the file 'save'.")
73 uf.desc[-1].add_prompt("relax> state.load('save')")
74 uf.desc[-1].add_prompt("relax> state.load(state='save')")
75 uf.desc[-1].add_paragraph("Use one of the following commands to load the state saved in the bzip2 compressed file 'save.bz2':")
76 uf.desc[-1].add_prompt("relax> state.load('save')")
77 uf.desc[-1].add_prompt("relax> state.load(state='save')")
78 uf.desc[-1].add_prompt("relax> state.load('save.bz2')")
79 uf.desc[-1].add_prompt("relax> state.load(state='save.bz2', force=True)")
80 uf.backend = load_state
81 uf.menu_text = "&load"
82 uf.gui_icon = "oxygen.actions.document-open"
83 uf.wizard_size = (800, 600)
84 uf.gui_sync = True
85
86
87
88 uf = uf_info.add_uf('state.save')
89 uf.title = "Save the program state."
90 uf.title_short = "Saving state."
91 uf.add_keyarg(
92 name = "state",
93 default = "state.bz2",
94 arg_type = "file sel write",
95 desc_short = "file name",
96 desc = "The file name, which can be a string or a file descriptor object, to save the current program state in.",
97 wiz_filesel_wildcard = WILDCARD_RELAX_SAVE,
98 )
99 uf.add_keyarg(
100 name = "dir",
101 arg_type = "dir",
102 desc_short = "directory name",
103 desc = "The name of the directory in which to place the file.",
104 can_be_none = True
105 )
106 uf.add_keyarg(
107 name = "compress_type",
108 default = 1,
109 basic_types = ["int"],
110 desc_short = "compression type",
111 desc = "The type of compression to use when creating the file.",
112 wiz_element_type = "combo",
113 wiz_combo_choices = ["No compression", "bzip2 compression", "gzip compression"],
114 wiz_combo_data = [0, 1, 2]
115 )
116 uf.add_keyarg(
117 name = "force",
118 default = False,
119 basic_types = ["bool"],
120 desc_short = "force flag",
121 desc = "A boolean flag which if set to True will cause the file to be overwritten."
122 )
123
124 uf.desc.append(Desc_container())
125 uf.desc[-1].add_paragraph("This will place the program state - the relax data store - into a file for later reloading or reference. The default format is an XML formatted file.")
126 uf.desc[-1].add_paragraph("The default behaviour of this function is to compress the file using bzip2 compression. If the extension '.bz2' is not included in the file name, it will be added. The compression can, however, be changed to either no compression or gzip compression. This is controlled by the compression type which can be set to")
127 uf.desc[-1].add_item_list_element("0", "No compression (no file extension).")
128 uf.desc[-1].add_item_list_element("1", "bzip2 compression ('.bz2' file extension).")
129 uf.desc[-1].add_item_list_element("2", "gzip compression ('.gz' file extension).")
130
131 uf.desc.append(Desc_container("Prompt examples"))
132 uf.desc[-1].add_paragraph("The following commands will save the current program state, uncompressed, into the file 'save':")
133 uf.desc[-1].add_prompt("relax> state.save('save', compress_type=0)")
134 uf.desc[-1].add_prompt("relax> state.save(state='save', compress_type=0)")
135 uf.desc[-1].add_paragraph("The following commands will save the current program state into the bzip2 compressed file 'save.bz2':")
136 uf.desc[-1].add_prompt("relax> state.save('save')")
137 uf.desc[-1].add_prompt("relax> state.save(state='save')")
138 uf.desc[-1].add_prompt("relax> state.save('save.bz2')")
139 uf.desc[-1].add_prompt("relax> state.save(state='save.bz2')")
140 uf.desc[-1].add_paragraph("If the file 'save' already exists, the following commands will save the current program state by overwriting the file.")
141 uf.desc[-1].add_prompt("relax> state.save('save', force=True)")
142 uf.desc[-1].add_prompt("relax> state.save(state='save', force=True)")
143 uf.backend = save_state
144 uf.menu_text = "&save"
145 uf.gui_icon = "oxygen.actions.document-save"
146 uf.wizard_height_desc = 400
147 uf.wizard_size = (900, 700)
148