Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def extract_cmd(filepath, overwrite=False):
- """
- Determines the file type of file at filepath, returns extract cmd based on file suffix
- """
- filename = os.path.basename(filepath)
- exts = [x.lower() for x in filename.split('.')]
- target = '.'.join(exts[:-1])
- cmd_tmpl = None
- extract_cmds = {
- # gzipped or gzipped tarball
- '.gz': "gunzip -c %(filepath)s > %(target)s",
- '.tar.gz': "tar xzf %(filepath)s",
- '.tgz': "tar xzf %(filepath)s",
- '.gtgz': "tar xzf %(filepath)s",
- # bzipped or bzipped tarball
- '.bz2': "bunzip2 %(filepath)s",
- '.tar.bz2': "tar xjf %(filepath)s",
- '.tbz': "tar xjf %(filepath)s",
- '.tbz2': "tar xjf %(filepath)s",
- '.tb2': "tar xjf %(filepath)s",
- # xzipped or xzipped tarball
- '.xz': "unxz %(filepath)s",
- '.tar.xz': "unxz %(filepath)s --stdout | tar x",
- '.txz': "unxz %(filepath)s --stdout | tar x",
- # tarball
- '.tar': "tar xf %(filepath)s",
- # zip file
- '.zip': "unzip -qq -o %(filepath)s" if overwrite else "unzip -qq %(filepath)s",
- # iso file
- '.iso': "7z x %(filepath)s",
- }
- for i in extract_cmds.keys():
- if filename[-len(i):] == i:
- cmd_tmpl=extract_cmds[i]
- if cmd_tmpl is None:
- raise EasyBuildError('Unknown file type for file %s (%s)', filepath, exts)
- return cmd_tmpl % {'filepath': filepath, 'target': target}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement