Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions lib/mintstick.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,43 @@
else:
self.go_button.set_sensitive(False)

def has_polkit_rule_format(self):
return self.check_polkit_permission('com.linuxmint.mintstick-format')

def has_polkit_rule_write(self):
return self.check_polkit_permission('com.linuxmint.mintstick-write')

def check_polkit_permission(self, action_id):
try:
authority = Polkit.Authority.get_sync()
subject = Polkit.UnixProcess.new_for_owner(os.getpid(), 0, os.getuid())
result = authority.check_authorization_sync(
subject, action_id, None, Polkit.CheckAuthorizationFlags.NONE, None)
return result.get_is_authorized()
except:
return False

def confirm_action(self, title, question):
dialog = Gtk.MessageDialog(
parent=self.window,
flags=Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
type=Gtk.MessageType.QUESTION,
buttons=Gtk.ButtonsType.YES_NO,
message_format=f"{title}\n\n{question}"
)

response = dialog.run()
dialog.destroy()
return response == Gtk.ResponseType.YES


def do_format(self, widget):
if self.has_polkit_rule_format():
if not self.confirm_action(
"Confirm formatting",
"Do you really want to format the device?"
):
return
if self.debug:
print("DEBUG: Format %s as %s" % (self.dev, self.filesystem))
return
Expand Down Expand Up @@ -360,7 +395,7 @@
self.show_format_result("dialog-information", _('The USB stick was formatted successfully.'))
return False
elif rc == 5:
message = _("An error occured while creating a partition on %s.") % usb_path

Check failure on line 398 in lib/mintstick.py

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22.3-amd64, Mint 22, true) / Mint 22

occured ==> occurred
elif rc == 127:
message = _('Authentication Error.')
elif rc == 126: # Cancelled by the user.
Expand All @@ -376,6 +411,12 @@
return False

def do_write(self, widget):
if self.has_polkit_rule_write():
if not self.confirm_action(
"Confirm ISO-writing",
"Do you really want to write the ISO to the device?"
):
return
if self.debug:
print("DEBUG: Write %s to %s" % (self.chooser.get_filename(), self.dev))
return
Expand Down Expand Up @@ -470,7 +511,7 @@
elif rc == 3:
message = _('Not enough space on the USB stick.')
elif rc == 4:
message = _('An error occured while copying the image.')

Check failure on line 514 in lib/mintstick.py

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22.3-amd64, Mint 22, true) / Mint 22

occured ==> occurred
elif rc == 127:
message = _('Authentication Error.')
elif rc == 126: # Cancelled by the user.
Expand Down
Loading