Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/py/private/untar.py
2867 views
1
# Licensed to the Software Freedom Conservancy (SFC) under one
2
# or more contributor license agreements. See the NOTICE file
3
# distributed with this work for additional information
4
# regarding copyright ownership. The SFC licenses this file
5
# to you under the Apache License, Version 2.0 (the
6
# "License"); you may not use this file except in compliance
7
# with the License. You may obtain a copy of the License at
8
#
9
# http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing,
12
# software distributed under the License is distributed on an
13
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
# KIND, either express or implied. See the License for the
15
# specific language governing permissions and limitations
16
# under the License.
17
18
import os
19
import sys
20
import tarfile
21
22
if __name__ == "__main__":
23
outdir = sys.argv[2]
24
if not os.path.exists(outdir):
25
os.makedirs(outdir)
26
27
tar = tarfile.open(sys.argv[1])
28
for member in tar.getmembers():
29
parts = member.name.split("/")
30
parts.pop(0)
31
if not len(parts):
32
continue
33
34
basepath = os.path.join(*parts)
35
basepath = os.path.normpath(basepath)
36
member.name = basepath
37
38
dir = os.path.join(outdir, os.path.dirname(basepath))
39
if not os.path.exists(dir):
40
os.makedirs(dir)
41
42
tar.extract(member, outdir)
43
tar.close()
44
45