Make osutils.TempDir more generally useful.

- osutils.TempDirContextManager is renamed to osutils.TempDir.
- osutils.TempDir is now a class. It can be used both as a context manager and
  as a regular object.
- osutils.TempDir now only sets itself as the global temporary directory if
  requested. This helps prevent unexpected behavior (e.g. unrelated temporary
  files are stored in this tempdir, and are deleted when context manager exits.)

BUG=chromium:212327
TEST=All unit tests. Trybot runs.

Change-Id: I0cb9b5d3174c380922c23661fb58c72b94e6e865
Reviewed-on: https://gerrit.chromium.org/gerrit/46520
Reviewed-by: Ryan Cui <rcui@chromium.org>
Tested-by: David James <davidjames@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: David James <davidjames@chromium.org>
diff --git a/scripts/deploy_chrome.py b/scripts/deploy_chrome.py
index 69a51a6..70ad0e3 100644
--- a/scripts/deploy_chrome.py
+++ b/scripts/deploy_chrome.py
@@ -447,7 +447,7 @@
   else:
     logging.getLogger().setLevel(logging.INFO)
 
-  with osutils.TempDirContextManager() as tempdir:
+  with osutils.TempDir(set_global=True) as tempdir:
     staging_dir = options.staging_dir
     if not staging_dir:
       staging_dir = os.path.join(tempdir, 'chrome')