Skip to content

Instantly share code, notes, and snippets.

@daqing
Created February 15, 2009 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daqing/64664 to your computer and use it in GitHub Desktop.
Save daqing/64664 to your computer and use it in GitHub Desktop.
#! /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