本文整理汇总了Python中utils.tmp_dir函数的典型用法代码示例。如果您正苦于以下问题:Python tmp_dir函数的具体用法?Python tmp_dir怎么用?Python tmp_dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tmp_dir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--msvs_version', required=True)
parser.add_argument('--chrome_path')
parser.add_argument('--skia_path')
args = parser.parse_args()
isolate_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'win_toolchain.isolate')
with utils.print_timings():
with utils.tmp_dir() as tmp_dir:
chrome_path = args.chrome_path
if not chrome_path:
print ('Syncing Chrome from scratch. If you already have a checkout, '
'specify --chrome_path to save time.')
chrome_path = os.path.join(tmp_dir.name, 'src')
if not os.path.isdir(chrome_path):
utils.git_clone(REPO_CHROME, chrome_path)
skia_path = args.skia_path
if not skia_path:
print ('Syncing Skia from scratch. If you already have a checkout, '
'specify --chrome_path to save time.')
skia_path = os.path.join(tmp_dir.name, 'skia')
if not os.path.isdir(skia_path):
utils.git_clone(REPO_SKIA, skia_path)
isolated_hash = gen_toolchain(chrome_path, args.msvs_version,
isolate_file)
update_toolchain_file(skia_path, args.msvs_version, isolated_hash)
示例2: create_asset
def create_asset(target_dir):
"""Create the asset."""
with utils.tmp_dir():
subprocess.check_call(['wget', URL, '--output-document=cmake.tar.gz'])
subprocess.check_call(['tar', '--extract', '--gunzip', '--file',
'cmake.tar.gz', '--directory', target_dir,
'--strip-components', '1'])
示例3: main
def main():
if sys.platform != 'win32':
print >> sys.stderr, 'This script only runs on Windows.'
sys.exit(1)
parser = argparse.ArgumentParser()
parser.add_argument('--gsutil')
parser.add_argument('--sdk_path', '-s', required=True)
parser.add_argument('--runtime_path', '-r',
default=os.path.join("C:","System32","vulkan-1.dll"),
required=True)
args = parser.parse_args()
with utils.tmp_dir():
cwd = os.getcwd()
create_script = os.path.join(common.FILE_DIR, 'create.py')
upload_script = os.path.join(common.FILE_DIR, 'upload.py')
try:
cmd = ['python', create_script,
'-t', cwd,
'--sdk_path', args.sdk_path,
'--runtime_path', args.runtime_path]
subprocess.check_call(cmd)
cmd = ['python', upload_script, '-t', cwd]
if args.gsutil:
cmd.extend(['--gsutil', args.gsutil])
subprocess.check_call(cmd)
except subprocess.CalledProcessError:
# Trap exceptions to avoid printing two stacktraces.
sys.exit(1)
示例4: main
def main():
if 'linux' not in sys.platform:
print >> sys.stderr, 'This script only runs on Linux.'
sys.exit(1)
parser = argparse.ArgumentParser()
parser.add_argument('--gsutil')
parser.add_argument('--lib_path', '-l', required=True)
args = parser.parse_args()
with utils.tmp_dir():
cwd = os.getcwd()
create_script = os.path.join(common.FILE_DIR, 'create.py')
upload_script = os.path.join(common.FILE_DIR, 'upload.py')
try:
subprocess.check_call(['python', create_script,
'-t', cwd,
'-l', args.lib_path])
cmd = ['python', upload_script, '-t', cwd]
if args.gsutil:
cmd.extend(['--gsutil', args.gsutil])
subprocess.check_call(cmd)
except subprocess.CalledProcessError:
# Trap exceptions to avoid printing two stacktraces.
sys.exit(1)
示例5: download_version
def download_version(self, version, target_dir):
"""Download the specified version of the asset."""
gs_path = GS_PATH_TMPL % (self._gs_subdir, str(version))
target_dir = os.path.abspath(target_dir)
with utils.tmp_dir():
zip_file = os.path.join(os.getcwd(), '%d.zip' % version)
self._gs.copy(gs_path, zip_file)
zip_utils.unzip(zip_file, target_dir)
示例6: download
def download(self, name, version, target_dir):
"""Download from GS."""
gs_path = GS_PATH_TMPL % (GS_SUBDIR_TMPL % (self._gs_bucket, name), str(version))
target_dir = os.path.abspath(target_dir)
with utils.tmp_dir():
zip_file = os.path.join(os.getcwd(), "%d.zip" % version)
self.copy(gs_path, zip_file)
zip_utils.unzip(zip_file, target_dir)
示例7: upload
def upload(self, name, version, target_dir):
"""Upload to GS."""
target_dir = os.path.abspath(target_dir)
with utils.tmp_dir():
zip_file = os.path.join(os.getcwd(), "%d.zip" % version)
zip_utils.zip(target_dir, zip_file, blacklist=ZIP_BLACKLIST)
gs_path = GS_PATH_TMPL % (GS_SUBDIR_TMPL % (self._gs_bucket, name), str(version))
self.copy(zip_file, gs_path)
示例8: _json_output
def _json_output(self, cmd):
"""Run the given command, return the JSON output."""
with utils.tmp_dir():
json_output = os.path.join(os.getcwd(), 'output.json')
self._run(cmd + ['--json-output', json_output])
with open(json_output) as f:
parsed = json.load(f)
return parsed.get('result', [])
示例9: _write_to_storage
def _write_to_storage(task):
"""Writes the specified compile task to Google storage."""
with utils.tmp_dir():
json_file = os.path.join(os.getcwd(), _get_task_file_name(task))
with open(json_file, 'w') as f:
json.dump(task, f)
subprocess.check_call(['gsutil', 'cp', json_file, '%s/' % _get_gs_bucket()])
print 'Created %s/%s' % (_get_gs_bucket(), os.path.basename(json_file))
示例10: create_asset
def create_asset(chrome_src_path, browser_executable, target_dir,
upload_to_partner_bucket):
"""Create the asset."""
browser_executable = os.path.realpath(browser_executable)
chrome_src_path = os.path.realpath(chrome_src_path)
target_dir = os.path.realpath(target_dir)
if not os.path.exists(target_dir):
os.makedirs(target_dir)
with utils.tmp_dir():
if os.environ.get('CHROME_HEADLESS'):
# Start Xvfb if running on a bot.
try:
subprocess.Popen(['sudo', 'Xvfb', ':0', '-screen', '0', '1280x1024x24'])
except Exception:
# It is ok if the above command fails, it just means that DISPLAY=:0
# is already up.
pass
webpages_playback_cmd = [
'python', os.path.join(SKIA_TOOLS, 'skp', 'webpages_playback.py'),
'--page_sets', 'all',
'--browser_executable', browser_executable,
'--non-interactive',
'--output_dir', os.getcwd(),
'--chrome_src_path', chrome_src_path,
]
if upload_to_partner_bucket:
webpages_playback_cmd.append('--upload_to_partner_bucket')
print 'Running webpages_playback command:\n$ %s' % (
' '.join(webpages_playback_cmd))
try:
subprocess.check_call(webpages_playback_cmd)
finally:
# Clean up any leftover browser instances. This can happen if there are
# telemetry crashes, processes are not always cleaned up appropriately by
# the webpagereplay and telemetry frameworks.
procs = subprocess.check_output(['ps', 'ax'])
for line in procs.splitlines():
if browser_executable in line:
pid = line.strip().split(' ')[0]
if pid != str(os.getpid()) and not 'python' in line:
try:
subprocess.check_call(['kill', '-9', pid])
except subprocess.CalledProcessError as e:
print e
else:
print 'Refusing to kill self.'
src = os.path.join(os.getcwd(), 'playback', 'skps')
for f in os.listdir(src):
if f.endswith('.skp'):
shutil.copyfile(os.path.join(src, f), os.path.join(target_dir, f))
# Copy over private SKPs from Google storage into the target_dir.
subprocess.check_call([
'gsutil', 'cp', os.path.join(PRIVATE_SKPS_GS, '*'), target_dir])
示例11: _test_versions
def _test_versions(self, store):
with utils.tmp_dir():
# Create input files and directories.
input_dir = os.path.join(os.getcwd(), 'input')
_write_stuff(input_dir)
self.assertEqual(store.get_available_versions(self.asset_name), [])
store.upload(self.asset_name, 0, input_dir)
self.assertEqual(store.get_available_versions(self.asset_name), [0])
store.upload(self.asset_name, 1, input_dir)
self.assertEqual(store.get_available_versions(self.asset_name), [0, 1])
store.delete_contents(self.asset_name)
self.assertEqual(store.get_available_versions(self.asset_name), [])
示例12: _test_upload_download
def _test_upload_download(self, store):
with utils.tmp_dir():
# Create input files and directories.
input_dir = os.path.join(os.getcwd(), 'input')
_write_stuff(input_dir)
# Upload a version, download it again.
store.upload(self.asset_name, 0, input_dir)
output_dir = os.path.join(os.getcwd(), 'output')
store.download(self.asset_name, 0, output_dir)
# Compare.
test_utils.compare_trees(self, input_dir, output_dir)
示例13: test_upload_download
def test_upload_download(self):
with utils.tmp_dir():
# Create input files and directories.
input_dir = os.path.join(os.getcwd(), 'input')
_write_stuff(input_dir)
# Upload a version, download it again.
self.a.upload_new_version(input_dir)
output_dir = os.path.join(os.getcwd(), 'output')
self.a.download_current_version(output_dir)
# Compare.
test_utils.compare_trees(self, input_dir, output_dir)
示例14: download
def download(self, name, version, target_dir):
"""Download a CIPD package."""
pkg_name = CIPD_PACKAGE_NAME_TMPL % name
version_tag = TAG_VERSION_TMPL % version
target_dir = os.path.abspath(target_dir)
with utils.tmp_dir():
infile = os.path.join(os.getcwd(), 'input')
with open(infile, 'w') as f:
f.write('%s %s' % (pkg_name, version_tag))
self._run([
'ensure',
'--root', target_dir,
'--list', infile,
])
示例15: create_asset
def create_asset(target_dir, msvs_version, chrome_path=None):
"""Create the asset."""
if not os.path.isdir(target_dir):
os.makedirs(target_dir)
with utils.tmp_dir() as tmp_dir:
if not chrome_path:
print ('Syncing Chrome from scratch. If you already have a checkout, '
'specify --chrome_path to save time.')
chrome_path = os.path.join(tmp_dir.name, 'src')
if not os.path.isdir(chrome_path):
subprocess.check_call([utils.GCLIENT, 'config', REPO_CHROME, '--managed'])
subprocess.check_call([utils.GCLIENT, 'sync'])
gen_toolchain(chrome_path, msvs_version, target_dir)