forked from evanoconnor/NuLib
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnulib_extract_source_from_table.py
More file actions
48 lines (34 loc) · 925 Bytes
/
nulib_extract_source_from_table.py
File metadata and controls
48 lines (34 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
"""
Script that takes a NuLib table, checks
if the source code is present. If so,
it extracts the source tarball from
the hdf5 file and places it into a
separate directory.
Requires h5py and numpy and their dependencies.
"""
import os
import sys
import fnmatch
import glob
import h5py
import numpy as np
if len(sys.argv) < 2:
print "Usage: nulib_extract_source_in_table.py <NuLib Table Name>"
sys.exit()
nulib_table_name = sys.argv[1]
tarfile = "nulib_src.tar.gz"
# creating output directory
print "Creating output directory saved_nulib"
os.system("mkdir saved_nulib")
h5file = h5py.File(nulib_table_name,"r")
try:
indata = h5file['NuLib Source'][()]
except:
print "Sorry, no source availabe in this NuLib file."
h5file.close()
sys.exit()
h5file.close()
outfile = open("saved_nulib/"+tarfile,"wb")
outfile.write(indata)
outfile.close()