#!/usr/bin/python3
-#
-# This file is part of the sigrok-util project.
-#
-# Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#
+##
+## This file is part of the sigrok-util project.
+##
+## Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
+##
+## This program is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program. If not, see <http://www.gnu.org/licenses/>.
+##
import os
import sys
import socket
import datetime
-TMPL_AUTOCONF_AC_ARG_ENABLE = """AC_ARG_ENABLE(${short}, AC_HELP_STRING([--enable-${short}],
- [enable ${name} driver support [default=yes]]),
- [HW_${upper}="$enableval"],
- [HW_${upper}=yes])
+TMPL_AUTOCONF_AC_ARG_ENABLE = """\
+AC_ARG_ENABLE(${short}, AC_HELP_STRING([--enable-${short}],
+ [enable ${name} driver support [default=yes]]),
+ [HW_${upper}="$enableval"],
+ [HW_${upper}=yes])
AM_CONDITIONAL(HW_${upper}, test x$HW_${upper} = xyes)
if test "x$HW_${upper}" = "xyes"; then
- AC_DEFINE(HAVE_HW_${upper}, 1, [${name} driver support])
+ AC_DEFINE(HAVE_HW_${upper}, 1, [${name} driver support])
fi
"""
def make_patch(gitdir):
os.chdir(gitdir)
command('git add hardware/' + names['short'])
- cmd = 'git commit -m "%s: initial driver skeleton" ' % names['short']
+ cmd = 'git commit -m "%s: Initial driver skeleton." ' % names['short']
cmd += 'configure.ac hardware/Makefile.am hardware/' + names['short']
command(cmd)
cmd = "git format-patch HEAD~1"
def parse_gitconfig():
- try:
- author = email = None
- for line in open(os.environ['HOME'] + '/.gitconfig').readlines():
- m = re.match('\s*(\w+)\s*=\s*(.*)\s*$', line)
- if m:
- key, value = m.groups()
- if key == 'name':
- author = value
- elif key == 'email':
- email = value
- if author and email:
- break
- except:
- pass
- if not author or not email:
- print("Please put your name and email in ~/.gitconfig")
- sys.exit()
-
- return author, email
+ try:
+ author = email = None
+ for line in open(os.environ['HOME'] + '/.gitconfig').readlines():
+ m = re.match('\s*(\w+)\s*=\s*(.*)\s*$', line)
+ if m:
+ key, value = m.groups()
+ if key == 'name':
+ author = value
+ elif key == 'email':
+ email = value
+ if author and email:
+ break
+ except:
+ pass
+ if not author or not email:
+ print("Please put your name and email in ~/.gitconfig")
+ sys.exit()
+
+ return author, email
#
# main
scriptdir = os.getcwd()
if socket.gethostname() == 'sigrok':
- LIBSR = '/data/git/libsigrok'
- TMPLDIR = '/data/tools/tmpl'
+ LIBSR = '/data/git/libsigrok'
+ TMPLDIR = '/data/tools/tmpl'
else:
- LIBSR = 'git://sigrok.org/libsigrok'
- TMPLDIR = scriptdir
+ LIBSR = 'git://sigrok.org/libsigrok'
+ TMPLDIR = scriptdir
if len(sys.argv) < 2:
- print("Usage: new-driver.py <name>")
+ print("Usage: new-driver <name>")
sys.exit()
author, email = parse_gitconfig()
'lib': re.sub('[^a-z0-9]', '_', name.lower()),
'upper': re.sub('[^A-Z0-9]', '_', name.upper()),
'libupper': re.sub('[^A-Z0-9]', '', name.upper()),
- 'year': datetime.datetime.now().year,
- 'author': author,
- 'email': email,
+ 'year': datetime.datetime.now().year,
+ 'author': author,
+ 'email': email,
}
new_driver()
-