# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.1617import os18import sys19import tarfile2021if __name__ == "__main__":22outdir = sys.argv[2]23if not os.path.exists(outdir):24os.makedirs(outdir)2526tar = tarfile.open(sys.argv[1])27for member in tar.getmembers():28parts = member.name.split("/")29parts.pop(0)30if not len(parts):31continue3233basepath = os.path.join(*parts)34basepath = os.path.normpath(basepath)35member.name = basepath3637dir = os.path.join(outdir, os.path.dirname(basepath))38if not os.path.exists(dir):39os.makedirs(dir)4041tar.extract(member, outdir)42tar.close()434445