diff mbox

[Branch,~linaro-image-tools/linaro-image-tools/trunk] Rev 616: Disable automount, and enable it at exit.

Message ID 20130403112114.15034.96212.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Milo Casagrande April 3, 2013, 11:21 a.m. UTC
Merge authors:
  Milo Casagrande (milo)
Related merge proposals:
  https://code.launchpad.net/~milo/linaro-image-tools/disable-automount/+merge/156794
  proposed by: Milo Casagrande (milo)
------------------------------------------------------------
revno: 616 [merge]
committer: Milo Casagrande <milo@ubuntu.com>
branch nick: trunk
timestamp: Wed 2013-04-03 13:20:22 +0200
message:
  Disable automount, and enable it at exit.
modified:
  linaro-android-media-create
  linaro-media-create
  linaro_image_tools/utils.py


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk

You are subscribed to branch lp:linaro-image-tools.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'linaro-android-media-create'
--- linaro-android-media-create	2013-01-30 11:28:51 +0000
+++ linaro-android-media-create	2013-04-03 10:05:46 +0000
@@ -44,7 +44,9 @@ 
     additional_android_option_checks,
     andorid_hwpack_in_boot_tarball,
     ensure_command,
-    get_logger
+    get_logger,
+    disable_automount,
+    enable_automount,
     )
 
 
@@ -117,6 +119,10 @@ 
 
     ensure_required_commands(args)
 
+    # Do this by default, disable automount options and re-enable them at exit.
+    disable_automount()
+    atexit.register(enable_automount)
+
     media = Media(args.device)
     if media.is_block_device:
         if not confirm_device_selection_and_ensure_it_is_ready(args.device):

=== modified file 'linaro-media-create'
--- linaro-media-create	2013-02-25 18:18:09 +0000
+++ linaro-media-create	2013-04-03 10:05:46 +0000
@@ -57,6 +57,9 @@ 
     path_in_tarfile_exists,
     prep_media_path,
     get_logger,
+    UnableToFindPackageProvidingCommand,
+    disable_automount,
+    enable_automount,
     )
 
 # Just define the global variables
@@ -136,6 +139,10 @@ 
         logger.error(e.value)
         sys.exit(1)
 
+    # Do this by default, disable automount options and re-enable them at exit.
+    disable_automount()
+    atexit.register(enable_automount)
+
     board_config = get_board_config(args.dev)
     board_config.set_metadata(args.hwpacks, args.bootloader, args.dev)
     board_config.add_boot_args(args.extra_boot_args)

=== modified file 'linaro_image_tools/utils.py'
--- linaro_image_tools/utils.py	2013-02-25 18:18:09 +0000
+++ linaro_image_tools/utils.py	2013-04-03 10:05:46 +0000
@@ -35,6 +35,10 @@ 
 # The name of the hwpack file found in the boot tarball.
 HWPACK_NAME = "config"
 
+# dconf keys to disable automount options.
+AUTOMOUNT_DCONF_KEY = '/org/gnome/desktop/media-handling/automount'
+AUTOMOUNT_OPEN_DCONF_KEYU = '/org/gnome/desktop/media-handling/automount-open'
+
 
 # try_import was copied from python-testtools 0.9.12 and was originally
 # licensed under a MIT-style license but relicensed under the GPL in Linaro
@@ -406,3 +410,42 @@ 
 
     logger.addHandler(ch)
     return logger
+
+
+def disable_automount():
+    """Disables the desktop environment automount option.
+
+    This will work only under GNOME with dconf installed.
+    """
+    logger = logging.getLogger(DEFAULT_LOGGER_NAME)
+
+    if has_command('dconf'):
+        logger.info("Disabling desktop environment automount option.")
+        try:
+            cmd_runner.run(
+                ['dconf', 'write', AUTOMOUNT_DCONF_KEY, 'false'],
+                stdout=open('/dev/null', 'w')).wait()
+            cmd_runner.run(
+                ['dconf', 'write', AUTOMOUNT_OPEN_DCONF_KEYU, 'false'],
+                stdout=open('/dev/null', 'w')).wait()
+        except cmd_runner.SubcommandNonZeroReturnValue:
+            logger.error("Error disabling desktop environemnt automount.")
+
+
+def enable_automount():
+    """Re-enables back the desktop environment automount option.
+
+    This will work only under GNOME with dconf installed. It should be run
+    as an atexit function.
+    """
+    logger = logging.getLogger(DEFAULT_LOGGER_NAME)
+    if has_command('dconf'):
+        try:
+            cmd_runner.run(
+                ['dconf', 'write', AUTOMOUNT_DCONF_KEY, 'true'],
+                stdout=open('/dev/null', 'w')).wait()
+            cmd_runner.run(
+                ['dconf', 'write', AUTOMOUNT_OPEN_DCONF_KEYU, 'true'],
+                stdout=open('/dev/null', 'w')).wait()
+        except cmd_runner.SubcommandNonZeroReturnValue:
+            logger.error("Error enabling back desktop environemnt automount.")