summaryrefslogtreecommitdiff
path: root/gr-utils
diff options
context:
space:
mode:
authorJosh Blum2010-03-16 18:22:10 -0700
committerJosh Blum2010-03-16 18:22:10 -0700
commitd43d40813c1a8343a86abb231876a8b7c0e9f806 (patch)
treee919c7da99aca7918ca5533e899cd7c9bbbf76bd /gr-utils
parent19d3c0cab37123f8bfd19fdfc576f44b6069300f (diff)
parentac422b700282e21956dbf7643ee2dfbeeebdaf45 (diff)
downloadgnuradio-d43d40813c1a8343a86abb231876a8b7c0e9f806.tar.gz
gnuradio-d43d40813c1a8343a86abb231876a8b7c0e9f806.tar.bz2
gnuradio-d43d40813c1a8343a86abb231876a8b7c0e9f806.zip
Merge branch 'master' of http://gnuradio.org/git/gnuradio into uhd
Diffstat (limited to 'gr-utils')
-rw-r--r--gr-utils/src/python/Makefile.am1
-rwxr-xr-xgr-utils/src/python/create-gnuradio-out-of-tree-project69
2 files changed, 70 insertions, 0 deletions
diff --git a/gr-utils/src/python/Makefile.am b/gr-utils/src/python/Makefile.am
index fb21e4f44..9c4e222c8 100644
--- a/gr-utils/src/python/Makefile.am
+++ b/gr-utils/src/python/Makefile.am
@@ -35,6 +35,7 @@ ourpython_PYTHON = \
pyqt_filter.py
bin_SCRIPTS = \
+ create-gnuradio-out-of-tree-project \
gr_plot_char.py \
gr_plot_const.py \
gr_plot_fft.py \
diff --git a/gr-utils/src/python/create-gnuradio-out-of-tree-project b/gr-utils/src/python/create-gnuradio-out-of-tree-project
new file mode 100755
index 000000000..1f512b219
--- /dev/null
+++ b/gr-utils/src/python/create-gnuradio-out-of-tree-project
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+
+from optparse import OptionParser
+import os
+import re
+import sys
+import subprocess
+
+tarball_url="http://gnuradio.org/releases/gnuradio/gr-howto-write-a-block-3.3git-651-g642252d8.tar.gz"
+
+def open_tarball(tarball_name=None):
+ """Return a readable fileobject that references the tarball.
+ If tarball_name is None, download from the net
+ """
+ if tarball_name:
+ return open(tarball_name, 'r')
+ p = subprocess.Popen(["wget", "-O", "-", tarball_url],
+ close_fds=True, stdout=subprocess.PIPE)
+ return p.stdout
+
+def extract_and_rename_files(tarball, module_name):
+ # Requires GNU tar.
+ tar_cmd = 'tar xz --strip-components=1 --transform="s/howto/%s/g"' % (module_name,)
+ p = subprocess.Popen(tar_cmd, shell=True, stdin=tarball, close_fds=True)
+ sts = os.waitpid(p.pid, 0)
+ return sts == 0
+
+def main():
+ usage = "%prog: [options] new_module_name"
+ description="Create a prototype 'out of tree' GNU Radio project"
+ parser = OptionParser(usage=usage, description=description)
+ parser.add_option("-T", "--tarball", type="string", default=None,
+ help="path to gr-howto-build-a-block gzipped tarball [default=<get from web>]")
+ (options, args) = parser.parse_args()
+ if len(args) != 1:
+ parser.print_help()
+ raise SystemExit,2
+ module_name = args[0]
+ if not re.match(r'[_a-z][_a-z0-9]*$', module_name):
+ sys.stderr.write("module_name '%s' may only contain [a-z0-9_]\n" % (module_name))
+ raise SystemExit, 1
+
+ # Ensure there's no file or directory called <module_name>
+ if os.path.exists(module_name):
+ sys.stderr.write("A file or directory named '%s' already exists\n" % (module_name,))
+ raise SystemExit, 1
+
+ os.mkdir(module_name)
+ os.chdir(module_name)
+
+ ok = extract_and_rename_files(open_tarball(options.tarball), module_name)
+
+ # rename file contents
+ upper_module_name = module_name.upper()
+ sed_cmd = 'sed -i -e "s/howto/%s/g" -e "s/HOWTO/%s/g"' % (module_name,
+ upper_module_name)
+ os.system('find . -type f -print0 | xargs -0 ' + sed_cmd)
+
+ sys.stdout.write("""
+Project '%s' is now ready to build.
+
+ $ ./bootstrap
+ $ ./configure --prefix=/home/[user]/install
+ $ (make && make check && make install) 2>&1 | tee make.log
+
+""" % (module_name,))
+
+if __name__ == '__main__':
+ main()