3 from optparse import OptionParser
9 tarball_url="http://gnuradio.org/releases/gnuradio/gr-howto-write-a-block-3.3git-651-g642252d8.tar.gz"
11 def open_tarball(tarball_name=None):
12 """Return a readable fileobject that references the tarball.
13 If tarball_name is None, download from the net
16 return open(tarball_name, 'r')
17 p = subprocess.Popen(["wget", "-O", "-", tarball_url],
18 close_fds=True, stdout=subprocess.PIPE)
21 def extract_and_rename_files(tarball, module_name):
23 tar_cmd = 'tar xz --strip-components=1 --transform="s/howto/%s/g"' % (module_name,)
24 p = subprocess.Popen(tar_cmd, shell=True, stdin=tarball, close_fds=True)
25 sts = os.waitpid(p.pid, 0)
29 usage = "%prog: [options] new_module_name"
30 description="Create a prototype 'out of tree' GNU Radio project"
31 parser = OptionParser(usage=usage, description=description)
32 parser.add_option("-T", "--tarball", type="string", default=None,
33 help="path to gr-howto-build-a-block gzipped tarball [default=<get from web>]")
34 (options, args) = parser.parse_args()
39 if not re.match(r'[_a-z][_a-z0-9]*$', module_name):
40 sys.stderr.write("module_name '%s' may only contain [a-z0-9_]\n" % (module_name))
43 # Ensure there's no file or directory called <module_name>
44 if os.path.exists(module_name):
45 sys.stderr.write("A file or directory named '%s' already exists\n" % (module_name,))
51 ok = extract_and_rename_files(open_tarball(options.tarball), module_name)
53 # rename file contents
54 upper_module_name = module_name.upper()
55 sed_cmd = 'sed -i -e "s/howto-write-a-block/%s/g" -e "s/howto/%s/g" -e "s/HOWTO/%s/g"' % (module_name, module_name, \
57 os.system('find . -type f -print0 | xargs -0 ' + sed_cmd)
60 Project '%s' is now ready to build.
63 $ ./configure --prefix=/home/[user]/install
64 $ (make && make check && make install) 2>&1 | tee make.log
68 if __name__ == '__main__':