Merge lp:~opensense/cubic/cubic-auto-20230201a into lp:cubic

Proposed by Open Sense Solutions
Status: Needs review
Proposed branch: lp:~opensense/cubic/cubic-auto-20230201a
Merge into: lp:cubic
Diff against target: 221 lines (+123/-7)
6 files modified
usr/share/cubic/commands/cubic-console-script (+15/-0)
usr/share/cubic/commands/start-console (+48/-4)
usr/share/cubic/cubic/pages/terminal_page.py (+8/-1)
usr/share/cubic/cubic/utilities/console.py (+23/-2)
usr/share/cubic/cubic/utilities/displayer.py (+22/-0)
usr/share/cubic/cubic_wizard.py (+7/-0)
To merge this branch: bzr merge lp:~opensense/cubic/cubic-auto-20230201a
Reviewer Review Type Date Requested Status
Cubic PPA Pending
Review via email: mp+436738@code.launchpad.net

Commit message

added --auto-mode option for automatic builds including custom console script and files

Description of the change

auto-mode is accomplished by adding a virtual click of the "next" button after that button becomes active on each screen.

Parameters like iso and directory can be specified on the command line, and other settings that do not have command line options (ex. compression level) can be set by running cubic manually once and re-using the project directory.

When running in auto-mode a script is run instead of a console shell. There is a default script that does nothing but wait 10 seconds, otherwise if the file cubic-custom-console-script exists in the project directory that will be run instead.

If cubic-custom-console-files exists in the project directory it is made available in /var/tmp/ while cubic-custom-console-script is running.

To post a comment you must log in.

Unmerged revisions

75. By Open Sense Solutions

added --auto-mode option for automatic builds including custom console script and files

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'usr/share/cubic/commands/cubic-console-script'
2--- usr/share/cubic/commands/cubic-console-script 1970-01-01 00:00:00 +0000
3+++ usr/share/cubic/commands/cubic-console-script 2023-02-02 03:30:33 +0000
4@@ -0,0 +1,15 @@
5+#!/bin/bash
6+
7+echo
8+echo "You are seeing this message because you specified --auto_mode"
9+echo "but did not create a file called cubic-custom-console-script"
10+echo "in the project directory."
11+echo
12+echo "This default script doesn't do anything other than display these messages"
13+echo "and wait 10 seconds."
14+echo
15+echo
16+echo "Waiting 10 seconds before exiting the console..."
17+sleep 10
18+
19+
20
21=== modified file 'usr/share/cubic/commands/start-console'
22--- usr/share/cubic/commands/start-console 2022-11-19 20:36:29 +0000
23+++ usr/share/cubic/commands/start-console 2023-02-02 03:30:33 +0000
24@@ -49,11 +49,41 @@
25 number_arguments=${#}
26 machine_name=${1}
27 directory=${2}
28+#auto_mode#
29+project_directory=${3}
30+parent_console_script=${4}
31
32 # echo "program..................... ${program}"
33 # echo "number of arguments......... ${number_arguments}"
34 # echo "machine_name................ ${machine_name}"
35-# echo "directory................... ${directory}"
36+# echo "root directory.............. ${directory}"
37+#auto_mode#
38+# echo "project directory........... ${project_directory}"
39+# echo "parent console script....... ${parent_console_script}"
40+#
41+# add ability to automatically run a script in the console
42+# the parameter passed in specifies the location in the parent system,
43+# so we copy it into the local filesystem ( in /var/tmp/ ) and make it
44+# executable
45+if [[ -n $parent_console_script ]] ; then
46+ if [[ -e ${parent_console_script} ]] ; then
47+ local_console_script=/var/tmp/cubic-console-script
48+ local_console_script_in_parent=${directory}/$local_console_script
49+ cp ${parent_console_script} $local_console_script_in_parent
50+ chmod +x ${directory}/$local_console_script
51+
52+ # sync in files from project directory/cubic-custom-console-files for the console script to use
53+ if [[ -e "$project_directory/cubic-custom-console-files" ]] ; then
54+ echo rsync -av $project_directory/cubic-custom-console-files/ ${directory}/var/tmp/cubic-custom-console-files/
55+ rsync -av $project_directory/cubic-custom-console-files/ ${directory}/var/tmp/cubic-custom-console-files/
56+ fi
57+ else
58+ local_console_script=""
59+ fi
60+else
61+ local_console_script=""
62+fi
63+
64
65 ########################################################################
66 # Command
67@@ -122,7 +152,10 @@
68 --register=yes \
69 --bind-ro="${bind_path}" \
70 --machine="${machine_name}" \
71- --directory="${directory}"
72+ --directory="${directory}" \
73+ $local_console_script
74+ #if local_console_script is empty then there is no positional command
75+ # argument to run and systemd-nspawn runs a shell
76 else
77 # Automatically handle resolv.conf as outlined in:
78 # https://www.freedesktop.org/software/systemd/man/systemd-nspawn.html#--resolv-conf=
79@@ -131,8 +164,19 @@
80 --notify-ready=yes \
81 --register=yes \
82 --machine="${machine_name}" \
83- --directory="${directory}"
84-fi
85+ --directory="${directory}" \
86+ $local_console_script
87+ #if local_console_script is empty then there is no positional command
88+ # argument to run and systemd-nspawn runs a shell
89+fi
90+
91+#auto_mode# get rid of console script in /var/tmp which is not automatically erased like /tmp/
92+# note that we couldn't easily put it in /tmp/ because that is mounted as a tmpfs ( using ram )
93+if [[ -e $local_console_script_in_parent ]] ; then
94+ rm $local_console_script_in_parent
95+ rm -rf ${directory}/var/tmp/cubic-custom-console-files/
96+fi
97+
98 exit_code=$?
99 exit $exit_code
100
101
102=== modified file 'usr/share/cubic/cubic/pages/terminal_page.py'
103--- usr/share/cubic/cubic/pages/terminal_page.py 2022-11-19 20:36:29 +0000
104+++ usr/share/cubic/cubic/pages/terminal_page.py 2023-02-02 03:30:33 +0000
105@@ -660,7 +660,14 @@
106 is_running = status
107
108 # Reset buttons based on status.
109- displayer.reset_buttons(is_back_sensitive=True, is_next_sensitive=status)
110+
111+ #auto_mode# in interactive usage the next navigation button is active as long as the terminal is active.
112+ # but when running in auto mode we invert this behavior so we can continue when the terminal has finished
113+ if model.arguments.auto_mode :
114+ displayer.reset_buttons(is_back_sensitive=True, is_next_sensitive=not status)
115+ else:
116+ displayer.reset_buttons(is_back_sensitive=True, is_next_sensitive=status)
117+
118 displayer.set_sensitive('terminal_page__copy_header_bar_button', status)
119
120 # Display the status.
121
122=== modified file 'usr/share/cubic/cubic/utilities/console.py'
123--- usr/share/cubic/cubic/utilities/console.py 2022-11-19 20:36:29 +0000
124+++ usr/share/cubic/cubic/utilities/console.py 2023-02-02 03:30:33 +0000
125@@ -105,7 +105,14 @@
126 global status_callback
127
128 first_time = True
129- reenter = True
130+
131+ #auto_mode# in interactive usage the terminal just respawns when you exit it
132+ # but when running in auto mode or with a custom_console_command we stop after the initial terminal exits
133+ if model.arguments.auto_mode :
134+ reenter = False
135+ else:
136+ reenter = True
137+
138 attempts = 0
139 status_callback = new_status_callback
140
141@@ -122,7 +129,21 @@
142
143 program = os.path.join(model.application.directory, 'commands', 'start-console')
144 # The command must be a list, as required by spawn_async().
145- command = ['pkexec', program, MACHINE_NAME, model.project.custom_root_directory]
146+
147+ #auto_mode# if running in auto mode, run default or custom script instead of a shell
148+ # it might be better to convert to keyword arguments intead of everything being positional
149+ if model.arguments.auto_mode :
150+ custom_script_file=os.path.join(model.project.directory,'cubic-custom-console-script')
151+ if os.path.exists(custom_script_file):
152+ script_file=custom_script_file
153+ else:
154+ script_file=os.path.join(model.application.directory,'commands','cubic-console-script')
155+
156+ logger.log_value('auto_mode: using console script', script_file)
157+ command = ['pkexec', program, MACHINE_NAME, model.project.custom_root_directory, model.project.directory, script_file ]
158+ else:
159+ command = ['pkexec', program, MACHINE_NAME, model.project.custom_root_directory, model.project.directory ]
160+
161 display_command = ' '.join([os.path.basename(command[1].strip('"'))] + command[2:])
162 logger.log_value('Command', display_command)
163
164
165=== modified file 'usr/share/cubic/cubic/utilities/displayer.py'
166--- usr/share/cubic/cubic/utilities/displayer.py 2021-12-27 18:45:40 +0000
167+++ usr/share/cubic/cubic/utilities/displayer.py 2023-02-02 03:30:33 +0000
168@@ -272,6 +272,28 @@
169 if is_sensitive is not None:
170 GLib.idle_add(Gtk.Button.set_sensitive, button, is_sensitive)
171
172+ #auto_mode# look for the next button becoming active so we can auto click it
173+ if model.arguments.auto_mode and name == "next_button" and is_sensitive == True :
174+ logger.log_value('auto_mode: next_button was just set active, auto clicking in 5 seconds', True)
175+ GLib.timeout_add(5000, next_button_auto_click)
176+
177+
178+#auto_mode# function to trigger a click of the "next" button for automation
179+def next_button_auto_click():
180+ button = model.builder.get_object('next_button')
181+ is_sensitive=button.get_sensitive()
182+ logger.log_value('auto_mode: checking next button sensitivity',is_sensitive)
183+ if is_sensitive:
184+ button.clicked()
185+ logger.log_value('auto_mode: clicked next button',True)
186+ # don't run this function again automatically
187+ return False
188+ else:
189+ logger.log_value('auto_mode: WARNING: next button is no longer active, not clicking it!',True)
190+ # could return True here to try again after another timeout period but that should be unnecessary,
191+ # if things are working properly the next button should go active again and trigger this function again
192+ return False
193+
194
195 def update_button_style(name, style):
196 """
197
198=== modified file 'usr/share/cubic/cubic_wizard.py'
199--- usr/share/cubic/cubic_wizard.py 2022-12-01 23:17:25 +0000
200+++ usr/share/cubic/cubic_wizard.py 2023-02-02 03:30:33 +0000
201@@ -72,6 +72,10 @@
202 description='Cubic (Custom Ubuntu ISO Creator) is a GUI wizard to create a customized Live ISO image for Ubuntu and Debian based distributions.')
203 parser.add_argument('directory', nargs='?', help='directory for a new or existing project')
204 parser.add_argument('iso', nargs='?', help='original ISO file for a new project (ignored for existing projects)')
205+
206+#auto_mode# add --auto-mode argument
207+parser.add_argument("-a", "--auto-mode", action="store_true", help="automatically advance through each screen once the \"next\" button becomes active, will run cubic-custom-console-script in the console if it exists in the project directory, and will make the cubic-custom-console-files directory from the project directory available in /var/tmp/ while the cubic-custom-console-script is running")
208+
209 parser.add_argument("-v", "--verbose", action="store_true", help="output formatted log to the console")
210 parser.add_argument("-V", "--version", action="store_true", help="print version information and exit")
211
212@@ -128,6 +132,9 @@
213 # logger.log_value('Original ISO file path argument', arguments.iso)
214 model.arguments.file_path = os.path.realpath(arguments.iso)
215
216+ #auto_mode# store this argument globally
217+ model.arguments.auto_mode=arguments.auto_mode
218+
219 # Add additional mime types.
220 mimetypes.init()
221 file_path = os.path.join(model.application.directory, 'assets', 'mime.types')

Subscribers

People subscribed via source and target branches