Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2329)

Unified Diff: build/android/pylib/utils/device_temp_file.py

Issue 1314913009: [Android] Move some pylib modules into devil/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/pylib/utils/base_error.py ('k') | build/android/pylib/utils/device_temp_file_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/utils/device_temp_file.py
diff --git a/build/android/pylib/utils/device_temp_file.py b/build/android/pylib/utils/device_temp_file.py
index 1364f7a7d93872fe757c2ca96e9ccb270781c1e3..ae1edc863cd1954a912683a8622270d973a3d2e5 100644
--- a/build/android/pylib/utils/device_temp_file.py
+++ b/build/android/pylib/utils/device_temp_file.py
@@ -1,63 +1,8 @@
-# Copyright 2013 The Chromium Authors. All rights reserved.
+# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-"""A temp file that automatically gets pushed and deleted from a device."""
+# pylint: disable=unused-wildcard-import
+# pylint: disable=wildcard-import
-# pylint: disable=W0622
-
-import threading
-
-from pylib import cmd_helper
-from pylib.device import device_errors
-
-_COMMAND_TEMPLATE = (
- # Make sure that the temp dir is writable
- 'test -d {dir} && '
- # If 5 random attempts fail, something is up.
- 'for i in 1 2 3 4 5; do '
- 'fn={dir}/{prefix}-$(date +%s)-"$RANDOM"{suffix};'
- 'test -e "$fn" || break;'
- 'done && '
- # Touch the file, so other temp files can't get the same name.
- 'touch "$fn" && echo -n "$fn"')
-
-class DeviceTempFile(object):
- def __init__(self, adb, suffix='', prefix='temp_file', dir='/data/local/tmp'):
- """Find an unused temporary file path in the devices external directory.
-
- When this object is closed, the file will be deleted on the device.
-
- Args:
- adb: An instance of AdbWrapper
- suffix: The suffix of the name of the temp file.
- prefix: The prefix of the name of the temp file.
- dir: The directory on the device where to place the temp file.
- """
- self._adb = adb
- command = _COMMAND_TEMPLATE.format(
- dir=cmd_helper.SingleQuote(dir),
- suffix=cmd_helper.SingleQuote(suffix),
- prefix=cmd_helper.SingleQuote(prefix))
- self.name = self._adb.Shell(command)
- self.name_quoted = cmd_helper.SingleQuote(self.name)
-
- def close(self):
- """Deletes the temporary file from the device."""
- # ignore exception if the file is already gone.
- def helper():
- try:
- self._adb.Shell('rm -f %s' % self.name_quoted, expect_status=None)
- except device_errors.AdbCommandFailedError:
- # file does not exist on Android version without 'rm -f' support (ICS)
- pass
-
- # It shouldn't matter when the temp file gets deleted, so do so
- # asynchronously.
- threading.Thread(target=helper).start()
-
- def __enter__(self):
- return self
-
- def __exit__(self, type, value, traceback):
- self.close()
+from devil.android.device_temp_file import *
« no previous file with comments | « build/android/pylib/utils/base_error.py ('k') | build/android/pylib/utils/device_temp_file_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698