Shell script and call from Python
This commit is contained in:
commit
2997686d70
4 changed files with 89 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
__pycache__
|
||||
9
lib.py
Executable file
9
lib.py
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import subprocess
|
||||
|
||||
def script (*args):
|
||||
p = subprocess.run (('./script.sh',) + args, stdout=subprocess.PIPE)
|
||||
p = p.stdout.split (b'\n')
|
||||
del p[-1]
|
||||
return p
|
||||
8
query.py
Executable file
8
query.py
Executable file
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import lib
|
||||
|
||||
p = lib.script ('list-tags')
|
||||
p = b'\n'.join (p)
|
||||
p = p.decode()
|
||||
print (p)
|
||||
71
script.sh
Executable file
71
script.sh
Executable file
|
|
@ -0,0 +1,71 @@
|
|||
#!/bin/sh
|
||||
|
||||
# FIXME: hardcoded path
|
||||
cd /srv/git/linux
|
||||
|
||||
test $# -gt 0 || set invalid
|
||||
|
||||
cmd=$1
|
||||
shift
|
||||
|
||||
case $cmd in
|
||||
list-tags)
|
||||
git tag |
|
||||
sed 's/$/.0/' |
|
||||
sort -V |
|
||||
sed 's/\.0$//'
|
||||
;;
|
||||
|
||||
get-blob)
|
||||
git cat-file blob $1
|
||||
;;
|
||||
|
||||
get-dir)
|
||||
git ls-tree -l "v$1:$2" |
|
||||
awk '{print $2" "$5" "$4}' |
|
||||
grep -v ' \.' |
|
||||
sort -t ' ' -k 1,1r -k 2,2
|
||||
;;
|
||||
|
||||
list-blobs)
|
||||
if [ "$1" = '-p' ]; then
|
||||
format='\1 \2'
|
||||
shift
|
||||
elif [ "$1" = '-f' ]; then
|
||||
format='\1 \4'
|
||||
shift
|
||||
else
|
||||
format='\1'
|
||||
fi
|
||||
|
||||
git ls-tree -r "v$1" |
|
||||
sed -r "s/^\S* blob (\S*)\t(([^/]*\/)*(.*))$/$format/"
|
||||
;;
|
||||
|
||||
tokenize-blob)
|
||||
git cat-file blob $1 |
|
||||
tr '\n<>' '\1\2\3' |
|
||||
sed 's/\/\*/</g' |
|
||||
sed 's/\*\//>/g' |
|
||||
sed -r 's/(\W*)(<[^>]*>)?(\w*)/\1\2\n\3\n/g'
|
||||
;;
|
||||
|
||||
untokenize)
|
||||
tr -d '\n' |
|
||||
sed 's/>/\*\//g' |
|
||||
sed 's/</\/\*/g' |
|
||||
tr '\1\2\3' '\n<>'
|
||||
;;
|
||||
|
||||
parse-defs)
|
||||
tmp=`mktemp -d`
|
||||
git cat-file blob "$1" > $tmp/$2
|
||||
ctags -x $tmp/$2 | awk '{print $1" "$2" "$3}'
|
||||
rm $tmp/$2
|
||||
rmdir $tmp
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 [list-tags | get-blob | get-dir | list-blobs | tokenize-blob | parse-defs]"
|
||||
exit 1
|
||||
esac
|
||||
Loading…
Reference in a new issue