1#!/usr/bin/env python 2# Copyright 2017 Google Inc. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16################################################################################ 17 18from __future__ import print_function 19 20import contextlib 21import os 22import subprocess 23 24 25def DpkgHostArchitecture(): 26 """Return the host architecture.""" 27 return subprocess.check_output( 28 ['dpkg-architecture', '-qDEB_HOST_GNU_TYPE']).strip() 29 30 31def InstallWrapper(bin_dir, name, contents, extra_names=None): 32 """Install a custom wrapper script into |bin_dir|.""" 33 path = os.path.join(bin_dir, name) 34 with open(path, 'w') as f: 35 f.write(contents) 36 37 os.chmod(path, 0755) 38 39 if extra_names: 40 CreateSymlinks(path, bin_dir, extra_names) 41 42 43def CreateSymlinks(original_path, bin_dir, extra_names): 44 """Create symlinks.""" 45 for extra_name in extra_names: 46 extra_path = os.path.join(bin_dir, extra_name) 47 os.symlink(original_path, extra_path) 48