Created
February 15, 2009 09:39
-
-
Save daqing/64664 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
""" | |
uncompress packages from ~/software/ directory | |
""" | |
import os, sys | |
p = os.path | |
cwd = os.getcwd() | |
if p.dirname(p.abspath(sys.argv[0])) != cwd: | |
print "Usage: ./uncompress.py" | |
sys.exit(1) | |
cwd += '/' # add slash | |
dir = p.expanduser('~') + "/software/" | |
if not p.exists(dir): | |
print "* [" + dir + "] not exists." | |
sys.exit(2) | |
packages = os.popen("ls " + dir + " | grep -i '[(gz|bz2)]$'").read().split('\n') | |
if not len(packages): | |
print "* nothing to uncompress." | |
sys.exit(3) | |
to_uncompress = filter(lambda x: not os.path.exists(cwd + x.split('tar')[0][:-1]), packages) | |
if len(to_uncompress): | |
for i in to_uncompress: | |
file = dir + i; | |
if p.isfile(file): | |
cmd = 'tar -x' | |
if i[-1:] == '2': | |
# bz2 package | |
cmd += 'jf ' | |
else: | |
# gzip package | |
cmd += 'zf ' | |
print "* uncompressing " + file | |
os.system(cmd + file) | |
else: | |
print "* [" + file + "] not exists." | |
else: | |
print "* nothing to uncompress." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment