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

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

Issue 2392643003: Removes files from //build that we don't need (Closed)
Patch Set: Created 4 years, 2 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
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
deleted file mode 100644
index 7d3b95b10464263c1abb9f79f4f5e90322b741b6..0000000000000000000000000000000000000000
--- a/build/android/pylib/utils/device_temp_file.py
+++ /dev/null
@@ -1,57 +0,0 @@
-# Copyright 2013 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=W0622
-
-import random
-import time
-
-from pylib import cmd_helper
-from pylib.device import device_errors
-
-
-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
- # make sure that the temp dir is writable
- self._adb.Shell('test -d %s' % cmd_helper.SingleQuote(dir))
- while True:
- self.name = '{dir}/{prefix}-{time:d}-{nonce:d}{suffix}'.format(
- dir=dir, prefix=prefix, time=int(time.time()),
- nonce=random.randint(0, 1000000), suffix=suffix)
- self.name_quoted = cmd_helper.SingleQuote(self.name)
- try:
- self._adb.Shell('test -e %s' % self.name_quoted)
- except device_errors.AdbCommandFailedError:
- break # file does not exist
-
- # Immediately touch the file, so other temp files can't get the same name.
- self._adb.Shell('touch %s' % self.name_quoted)
-
- def close(self):
- """Deletes the temporary file from the device."""
- # ignore exception if the file is already gone.
- try:
- self._adb.Shell('rm -f %s' % self.name_quoted)
- except device_errors.AdbCommandFailedError:
- # file does not exist on Android version without 'rm -f' support (ICS)
- pass
-
- def __enter__(self):
- return self
-
- def __exit__(self, type, value, traceback):
- self.close()
« no previous file with comments | « build/android/pylib/utils/command_option_parser.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